Form\Generate and DB\Extend\ArrayIO split
Move DB\Extend\ArrayIO to internal class in variable and do not extend Form\Generate from it (as we do not have a base class anymore, this is no longer neded) Update all calls in connected classes. Add interface methods for DB\Extend\ArrayIO to interface with all class vars that are now all private
This commit is contained in:
@@ -42,6 +42,7 @@
|
|||||||
<textarea name="{$element.data.name}"{if $element.data.rows} rows="{$element.data.rows}"{/if}{if $element.data.cols} cols="{$element.data.cols}"{/if}>{$element.data.value}</textarea>
|
<textarea name="{$element.data.name}"{if $element.data.rows} rows="{$element.data.rows}"{/if}{if $element.data.cols} cols="{$element.data.cols}"{/if}>{$element.data.value}</textarea>
|
||||||
{/if}
|
{/if}
|
||||||
{if $element.type == 'drop_down'}
|
{if $element.type == 'drop_down'}
|
||||||
|
{* {$element.data.selected} *}
|
||||||
{html_options name=$element.data.name values=$element.data.value output=$element.data.output selected=$element.data.selected}
|
{html_options name=$element.data.name values=$element.data.value output=$element.data.output selected=$element.data.selected}
|
||||||
{if $drop_down_input}
|
{if $drop_down_input}
|
||||||
<input type="text" name="{$element.data.input_name}" value="{$element.data.input_value}"{if $element.data.input_size} size="{$element.data.input_size}"{/if}{if $element.data.input_length} maxlength="{$element.data.input_length}"{/if}>
|
<input type="text" name="{$element.data.input_name}" value="{$element.data.input_value}"{if $element.data.input_size} size="{$element.data.input_size}"{/if}{if $element.data.input_length} maxlength="{$element.data.input_length}"{/if}>
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ class EditBase
|
|||||||
$q = "UPDATE " . $table_name
|
$q = "UPDATE " . $table_name
|
||||||
. " SET order_number = " . $row_data_order[$i]
|
. " SET order_number = " . $row_data_order[$i]
|
||||||
. " WHERE " . $table_name . "_id = " . $row_data_id[$i];
|
. " WHERE " . $table_name . "_id = " . $row_data_id[$i];
|
||||||
$q = $this->form->dbExec($q);
|
$q = $this->form->dba->dbExec($q);
|
||||||
}
|
}
|
||||||
} // for all article ids ...
|
} // for all article ids ...
|
||||||
} // if write
|
} // if write
|
||||||
@@ -173,7 +173,7 @@ class EditBase
|
|||||||
$options_name = [];
|
$options_name = [];
|
||||||
$options_selected = [];
|
$options_selected = [];
|
||||||
// DB read data for menu
|
// DB read data for menu
|
||||||
while (is_array($res = $this->form->dbReturn($q))) {
|
while (is_array($res = $this->form->dba->dbReturn($q))) {
|
||||||
$row_data[] = [
|
$row_data[] = [
|
||||||
"id" => $res[$table_name . "_id"],
|
"id" => $res[$table_name . "_id"],
|
||||||
"name" => $res["name"],
|
"name" => $res["name"],
|
||||||
@@ -431,9 +431,9 @@ class EditBase
|
|||||||
$elements[] = $this->form->formCreateElement('template');
|
$elements[] = $this->form->formCreateElement('template');
|
||||||
break;
|
break;
|
||||||
case 'edit_pages':
|
case 'edit_pages':
|
||||||
if (!isset($this->form->table_array['edit_page_id']['value'])) {
|
if (!isset($this->form->dba->getTableArray()['edit_page_id']['value'])) {
|
||||||
$q = "DELETE FROM temp_files";
|
$q = "DELETE FROM temp_files";
|
||||||
$this->form->dbExec($q);
|
$this->form->dba->dbExec($q);
|
||||||
// gets all files in the current dir and dirs given ending with .php
|
// gets all files in the current dir and dirs given ending with .php
|
||||||
$folders = ['../admin/', '../frontend/'];
|
$folders = ['../admin/', '../frontend/'];
|
||||||
$files = ['*.php'];
|
$files = ['*.php'];
|
||||||
@@ -461,16 +461,16 @@ class EditBase
|
|||||||
if ($t_q) {
|
if ($t_q) {
|
||||||
$t_q .= ', ';
|
$t_q .= ', ';
|
||||||
}
|
}
|
||||||
$t_q .= "('" . $this->form->dbEscapeString($pathinfo['dirname']) . "', '"
|
$t_q .= "('" . $this->form->dba->dbEscapeString($pathinfo['dirname']) . "', '"
|
||||||
. $this->form->dbEscapeString($pathinfo['basename']) . "')";
|
. $this->form->dba->dbEscapeString($pathinfo['basename']) . "')";
|
||||||
}
|
}
|
||||||
$this->form->dbExec($q . $t_q, 'NULL');
|
$this->form->dba->dbExec($q . $t_q, 'NULL');
|
||||||
$elements[] = $this->form->formCreateElement('filename');
|
$elements[] = $this->form->formCreateElement('filename');
|
||||||
} else {
|
} else {
|
||||||
// show file menu
|
// show file menu
|
||||||
// just show name of file ...
|
// just show name of file ...
|
||||||
$this->DATA['filename_exist'] = 1;
|
$this->DATA['filename_exist'] = 1;
|
||||||
$this->DATA['filename'] = $this->form->table_array['filename']['value'];
|
$this->DATA['filename'] = $this->form->dba->getTableArray()['filename']['value'];
|
||||||
} // File Name View IF
|
} // File Name View IF
|
||||||
$elements[] = $this->form->formCreateElement('hostname');
|
$elements[] = $this->form->formCreateElement('hostname');
|
||||||
$elements[] = $this->form->formCreateElement('name');
|
$elements[] = $this->form->formCreateElement('name');
|
||||||
|
|||||||
@@ -39,13 +39,13 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
{
|
{
|
||||||
// main calss variables
|
// main calss variables
|
||||||
/** @var array<mixed> */
|
/** @var array<mixed> */
|
||||||
public array $table_array; // the array from the table to work on
|
private array $table_array; // the array from the table to work on
|
||||||
/** @var string */
|
/** @var string */
|
||||||
public string $table_name; // the table_name
|
private string $table_name; // the table_name
|
||||||
/** @var string */
|
/** @var string */
|
||||||
public string $pk_name = ''; // the primary key from this table
|
private string $pk_name = ''; // the primary key from this table
|
||||||
/** @var int|string|null */
|
/** @var int|string|null */
|
||||||
public int|string|null $pk_id; // the PK id
|
private int|string|null $pk_id; // the PK id
|
||||||
// security values
|
// security values
|
||||||
/** @var int base acl for current page */
|
/** @var int base acl for current page */
|
||||||
private int $base_acl_level = 0;
|
private int $base_acl_level = 0;
|
||||||
@@ -74,24 +74,21 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
// instance db_io class
|
// instance db_io class
|
||||||
parent::__construct($db_config, $log);
|
parent::__construct($db_config, $log);
|
||||||
// more error vars for this class
|
// more error vars for this class
|
||||||
$this->error_string['1999'] = 'No table array or table name set';
|
$this->error_string['1998'] = 'No table name set';
|
||||||
|
$this->error_string['1999'] = 'No table array set';
|
||||||
$this->error_string['1021'] = 'No Primary Key given';
|
$this->error_string['1021'] = 'No Primary Key given';
|
||||||
$this->error_string['1022'] = 'Could not run Array Query';
|
$this->error_string['1022'] = 'Could not run Array Query';
|
||||||
|
|
||||||
$this->table_array = $table_array;
|
$this->setTableArray($table_array);
|
||||||
$this->table_name = $table_name;
|
$this->setTableName($table_name);
|
||||||
|
|
||||||
// error abort if no table array or no table name
|
|
||||||
if (empty($table_array) || empty($table_name)) {
|
|
||||||
$this->__dbError(1999, false, 'MAJOR ERROR: Core settings missing');
|
|
||||||
throw new \RuntimeException('MAJOR ERROR: Core settings missing', 1999);
|
|
||||||
}
|
|
||||||
|
|
||||||
// set primary key for given table_array
|
// set primary key for given table_array
|
||||||
foreach ($this->table_array as $key => $value) {
|
foreach ($this->table_array as $key => $value) {
|
||||||
if (!empty($value['pk'])) {
|
if (empty($value['pk'])) {
|
||||||
$this->pk_name = $key;
|
continue;
|
||||||
}
|
}
|
||||||
|
$this->setPkName($key);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
$this->dbArrayIOSetAcl($base_acl_level, $acl_admin);
|
$this->dbArrayIOSetAcl($base_acl_level, $acl_admin);
|
||||||
}
|
}
|
||||||
@@ -104,6 +101,144 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
parent::__destruct();
|
parent::__destruct();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the overall table array
|
||||||
|
*
|
||||||
|
* @param array<mixed> $table_array
|
||||||
|
* @return void
|
||||||
|
* @throws \RuntimeException 1999 for empty table array
|
||||||
|
*/
|
||||||
|
public function setTableArray(array $table_array): void
|
||||||
|
{
|
||||||
|
$this->table_array = $table_array;
|
||||||
|
if (empty($this->table_array)) {
|
||||||
|
$this->__dbError(1999, false, 'MAJOR ERROR: Core settings missing: table_arrry');
|
||||||
|
throw new \RuntimeException('MAJOR ERROR: Core settings missing: table_array', 1999);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return full table array, or [] if empty
|
||||||
|
* of reset is set to true, will reset array first
|
||||||
|
*
|
||||||
|
* @param bool $reset [=false] run a reset before returning
|
||||||
|
* @return array<mixed>
|
||||||
|
*/
|
||||||
|
public function getTableArray(bool $reset = false): array
|
||||||
|
{
|
||||||
|
if (!$reset) {
|
||||||
|
return $this->table_array ?? [];
|
||||||
|
}
|
||||||
|
$table_array = $this->table_array ?? [];
|
||||||
|
reset($table_array);
|
||||||
|
return $table_array;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get a table array entry under the key with element pos
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @param string $pos
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function getTableArrayEntry(string $key, string $pos): mixed
|
||||||
|
{
|
||||||
|
return $this->table_array[$key][$pos] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set a new value at key with pos
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
* @param string $key
|
||||||
|
* @param string $pos
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setTableArrayEntry(mixed $value, string $key, string $pos): void
|
||||||
|
{
|
||||||
|
$this->table_array[$key][$pos] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* unset entry at key with pos
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @param string $pos
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function unsetTableArrayEntry(string $key, string $pos): void
|
||||||
|
{
|
||||||
|
unset($this->table_array[$key][$pos]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set table name
|
||||||
|
*
|
||||||
|
* @param string $table_name
|
||||||
|
* @return void
|
||||||
|
* @throws \RuntimeException 1998 for empty table name
|
||||||
|
*/
|
||||||
|
public function setTableName(string $table_name): void
|
||||||
|
{
|
||||||
|
$this->table_name = $table_name;
|
||||||
|
if (empty($this->table_name)) {
|
||||||
|
$this->__dbError(1998, false, 'MAJOR ERROR: Core settings missing: table_name');
|
||||||
|
throw new \RuntimeException('MAJOR ERROR: Core settings missing: table_name', 1998);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return table name or empty string if not net
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getTableName(): string
|
||||||
|
{
|
||||||
|
return $this->table_name ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set primary key name
|
||||||
|
*
|
||||||
|
* @param string $pk_name
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setPkName(string $pk_name): void
|
||||||
|
{
|
||||||
|
$this->pk_name = $pk_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get primary key name
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getPkName(): string
|
||||||
|
{
|
||||||
|
return $this->pk_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set primary key id, can be null for not yet set
|
||||||
|
*
|
||||||
|
* @param int|string|null $pk_id
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setPkId(int|string|null $pk_id): void
|
||||||
|
{
|
||||||
|
$this->pk_id = $pk_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return primary key id, or null if not set
|
||||||
|
*
|
||||||
|
* @return int|string|null
|
||||||
|
*/
|
||||||
|
public function getPkId(): int|string|null
|
||||||
|
{
|
||||||
|
return $this->pk_id;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set the base acl level and admin acl flag
|
* set the base acl level and admin acl flag
|
||||||
* This is needed for table array ACL checks
|
* This is needed for table array ACL checks
|
||||||
@@ -198,8 +333,8 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
public function dbCheckPkSet(): bool
|
public function dbCheckPkSet(): bool
|
||||||
{
|
{
|
||||||
// if pk_id is set, overrule ...
|
// if pk_id is set, overrule ...
|
||||||
if (!empty($this->pk_id)) {
|
if (!empty($this->getPkId())) {
|
||||||
$this->table_array[$this->pk_name]['value'] = $this->pk_id;
|
$this->table_array[$this->pk_name]['value'] = $this->getPkId();
|
||||||
}
|
}
|
||||||
// if not set ... produce error
|
// if not set ... produce error
|
||||||
if (!$this->table_array[$this->pk_name]['value']) {
|
if (!$this->table_array[$this->pk_name]['value']) {
|
||||||
@@ -287,7 +422,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
$q .= ' AND ' . $q_where;
|
$q .= ' AND ' . $q_where;
|
||||||
}
|
}
|
||||||
// if 0, error
|
// if 0, error
|
||||||
$this->pk_id = null;
|
$this->setPkId(null);
|
||||||
if (!$this->dbExec($q)) {
|
if (!$this->dbExec($q)) {
|
||||||
$this->__dbError(1022);
|
$this->__dbError(1022);
|
||||||
}
|
}
|
||||||
@@ -374,7 +509,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// possible dbFetchArray errors ...
|
// possible dbFetchArray errors ...
|
||||||
$this->pk_id = $this->table_array[$this->pk_name]['value'];
|
$this->setPkId($this->table_array[$this->pk_name]['value']);
|
||||||
} else {
|
} else {
|
||||||
$this->__dbError(1022);
|
$this->__dbError(1022);
|
||||||
}
|
}
|
||||||
@@ -397,10 +532,6 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
if (count($table_array)) {
|
if (count($table_array)) {
|
||||||
$this->table_array = $table_array;
|
$this->table_array = $table_array;
|
||||||
}
|
}
|
||||||
// PK ID check
|
|
||||||
// if ($this->pk_id && !$this->table_array[$this->pk_name]["value"]) {
|
|
||||||
// $this->table_array[$this->pk_name]["value"]=$this->pk_id;
|
|
||||||
// }
|
|
||||||
// checken ob PKs gesetzt, wenn alle -> update, wenn keiner -> insert, wenn ein paar -> ERROR!
|
// checken ob PKs gesetzt, wenn alle -> update, wenn keiner -> insert, wenn ein paar -> ERROR!
|
||||||
if (!$this->table_array[$this->pk_name]['value']) {
|
if (!$this->table_array[$this->pk_name]['value']) {
|
||||||
$insert = 1;
|
$insert = 1;
|
||||||
@@ -624,16 +755,11 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
$q .= ' AND ' . $q_where;
|
$q .= ' AND ' . $q_where;
|
||||||
}
|
}
|
||||||
// set pk_id ... if it has changed or so
|
// set pk_id ... if it has changed or so
|
||||||
$this->pk_id = $this->table_array[$this->pk_name]['value'];
|
$this->setPkId($this->table_array[$this->pk_name]['value']);
|
||||||
} else {
|
} else {
|
||||||
$q = 'INSERT INTO ' . $this->table_name . ' ';
|
$q = 'INSERT INTO ' . $this->table_name . ' ';
|
||||||
$q .= '(' . $q_vars . ') ';
|
$q .= '(' . $q_vars . ') ';
|
||||||
$q .= 'VALUES (' . $q_data . ')';
|
$q .= 'VALUES (' . $q_data . ')';
|
||||||
// write primary key too
|
|
||||||
// if ($q_data)
|
|
||||||
// $q .= ", ";
|
|
||||||
// $q .= $this->pk_name." = ".$this->table_array[$this->pk_name]['value']." ";
|
|
||||||
// $this->pk_id = $this->table_array[$this->pk_name]['value'];
|
|
||||||
}
|
}
|
||||||
// return success or not
|
// return success or not
|
||||||
if (!$this->dbExec($q)) {
|
if (!$this->dbExec($q)) {
|
||||||
@@ -646,7 +772,7 @@ class ArrayIO extends \CoreLibs\DB\IO
|
|||||||
$insert_id = 0;
|
$insert_id = 0;
|
||||||
}
|
}
|
||||||
$this->table_array[$this->pk_name]['value'] = $insert_id;
|
$this->table_array[$this->pk_name]['value'] = $insert_id;
|
||||||
$this->pk_id = $insert_id;
|
$this->setPkId($insert_id);
|
||||||
}
|
}
|
||||||
// return the table if needed
|
// return the table if needed
|
||||||
return $this->table_array;
|
return $this->table_array;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user