|
|
@@ -30,23 +30,50 @@ Lib::loadClass('DataSourceFactory');
|
|
|
*/
|
|
|
class TableAcl extends Core_AclBase {
|
|
|
|
|
|
- private $_zasobID = '';
|
|
|
- private $_db = '';
|
|
|
- private $_name = '';
|
|
|
- private $_label = '';
|
|
|
- private $_opis = '';
|
|
|
- private $_fields = array();
|
|
|
- private $_types = array();
|
|
|
- private $_virtualFieldsIdList = array();
|
|
|
- private $_schemaLoaded = false;
|
|
|
+ public $_rootTableName = null;
|
|
|
+ public $_zasobID = '';
|
|
|
+ public $_db = '';
|
|
|
+ public $_name = '';
|
|
|
+ public $_label = '';
|
|
|
+ public $_opis = '';
|
|
|
+ public $_fields = array();
|
|
|
+ public $_types = array();
|
|
|
+ public $_virtualFieldsIdList = array();
|
|
|
+ public $_schemaLoaded = false;
|
|
|
|
|
|
public function __construct($zasobID) { $this->_zasobID = $zasobID; }
|
|
|
public function getNamespace() { return 'default_db/' . $this->getName(); }
|
|
|
public function getSourceName() { return 'default_db'; }
|
|
|
public function getName() { return $this->_name; }
|
|
|
- public function getRootTableName() { return $this->_name; }
|
|
|
+ public function getRootTableName() {
|
|
|
+ if (empty($this->_name)) throw new Exception("Table name not defined");
|
|
|
+ if ($this->_rootTableName) return $this->_rootTableName;
|
|
|
+ $dbName = DB::getPDO()->getDatabaseName();
|
|
|
+ $this->_rootTableName = DB::getPDO()->fetchValue("
|
|
|
+ select t.TABLE_NAME
|
|
|
+ from `information_schema`.`TABLES` t
|
|
|
+ where t.TABLE_SCHEMA = '{$dbName}'
|
|
|
+ and t.TABLE_NAME LIKE '{$this->_name}'
|
|
|
+ ");
|
|
|
+ if (!$this->_rootTableName) throw new Exception("Table '{$this->_name}' not exists!");
|
|
|
+ DBG::log("TableAcl({$this->_zasobID})->getRootTableName (\$this->_name='{$this->_name}', \$this->_rootTableName='{$this->_rootTableName}')");
|
|
|
+ if ($this->_rootTableName != $this->_name) {
|
|
|
+ if ($this->_zasobID) {
|
|
|
+ $affected = DB::getPDO()->update('CRM_LISTA_ZASOBOW', 'ID', $this->_zasobID, [
|
|
|
+ 'DESC' => $this->_rootTableName
|
|
|
+ ]);
|
|
|
+ DBG::log("TableAcl({$this->_zasobID})->getRootTableName fixed zasob table name (\$affected={$affected})");
|
|
|
+ }
|
|
|
+ $this->_name = $this->_rootTableName;
|
|
|
+ $this->save();
|
|
|
+ }
|
|
|
+ return $this->_rootTableName;
|
|
|
+ }
|
|
|
public function getID() { return $this->_zasobID; }
|
|
|
- public function setName($name) { $this->_name = $name; }
|
|
|
+ public function setName($name) {// TODO: used only by setNameByTableId
|
|
|
+ DBG::log("setName('{$name}')");
|
|
|
+ $this->_name = $name;
|
|
|
+ }
|
|
|
public function setOpis($opis) { $this->_opis = $opis; }
|
|
|
public function getOpis() { return $this->_opis; }
|
|
|
public function setLabel($label) { $this->_label = $label; }
|
|
|
@@ -939,6 +966,7 @@ class TableAcl extends Core_AclBase {
|
|
|
}
|
|
|
$obj = new TableAcl($idTable);
|
|
|
$obj->fromArray($tableConfig);
|
|
|
+ $obj->getRootTableName();
|
|
|
$obj->save();
|
|
|
$_cache[$idTable] = $obj;
|
|
|
return $_cache[$idTable];
|
|
|
@@ -957,7 +985,7 @@ class TableAcl extends Core_AclBase {
|
|
|
$this->_types = array();// clear _types @see $this->isInitialized
|
|
|
$userAcl = User::getAcl();
|
|
|
$fieldsConfig = $userAcl->getPermsForTable($this->_zasobID);
|
|
|
- DBG::_('DBG_SCH', '>1', "INIT::\$fieldsConfig({$this->_zasobID}) fields(".count($this->_fields).")", $fieldsConfig, __CLASS__, __FUNCTION__, __LINE__ );
|
|
|
+ DBG::log(['msg'=>"INIT({$this->_zasobID})::initFieldsFromConfig \$fieldsConfig", '$fieldsConfig'=>$fieldsConfig]);
|
|
|
$this->initFieldsFromConfig($fieldsConfig);
|
|
|
//DBG::_('DBG_SCH', '1', "INIT::\$fieldsConfig({$this->_zasobID}) fields(".count($this->_fields).")", $this, __CLASS__, __FUNCTION__, __LINE__ );
|
|
|
}
|
|
|
@@ -966,13 +994,16 @@ class TableAcl extends Core_AclBase {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ DBG::log(['msg'=>"INIT({$this->_zasobID}):: \$this", '$this'=>$this, 'name'=>$this->getName()]);
|
|
|
$ds = $this->getDataSource();
|
|
|
+ DBG::log(['msg'=>"INIT({$this->_zasobID})::getDataSource \$ds", '$ds'=>$ds]);
|
|
|
$this->_types = $ds->getFieldTypes();
|
|
|
+ DBG::log(['msg'=>"INIT({$this->_zasobID})::getFieldTypes \$this->_types", '$this->_types'=>$this->_types]);
|
|
|
|
|
|
uasort($this->_fields, array($this, 'sortFieldsCallback'));
|
|
|
|
|
|
$this->_fixTypes();
|
|
|
- DBG::_('DBG_SCH', '>1', "INIT::after fixTypes({$this->_zasobID})", $this->_types, __CLASS__, __FUNCTION__, __LINE__ );
|
|
|
+ DBG::log(['msg'=>"INIT({$this->_zasobID})::after fixTypes \$this->_types", '$this->_types'=>$this->_types]);
|
|
|
|
|
|
$this->save();
|
|
|
}
|
|
|
@@ -1164,6 +1195,7 @@ class TableAcl extends Core_AclBase {
|
|
|
*/
|
|
|
function save() {
|
|
|
$_SESSION['TableAcl_cache'][$this->_zasobID] = $this->toArray();
|
|
|
+ DBG::log("save(name='{$_SESSION['TableAcl_cache'][$this->_zasobID]['name']}')");
|
|
|
}
|
|
|
|
|
|
public function getFieldTypeById($fieldID) {
|
|
|
@@ -1338,8 +1370,10 @@ class TableAcl extends Core_AclBase {
|
|
|
}
|
|
|
|
|
|
public function fromArray($arr) {
|
|
|
+ DBG::log("fromArray(name='{$arr['name']}')");
|
|
|
$this->_db = $arr['db'];
|
|
|
$this->_name = $arr['name'];
|
|
|
+ $this->_rootTableName = V::get('_rootTableName', null, $arr);
|
|
|
$this->_label = $arr['label'];
|
|
|
$this->_opis = $arr['opis'];
|
|
|
$this->_fields = V::get('fields', array(), $arr);
|
|
|
@@ -1351,6 +1385,7 @@ class TableAcl extends Core_AclBase {
|
|
|
$arr = array();
|
|
|
$arr['db'] = $this->_db;
|
|
|
$arr['name'] = $this->_name;
|
|
|
+ $arr['_rootTableName'] = $this->_rootTableName;
|
|
|
$arr['label'] = $this->_label;
|
|
|
$arr['opis'] = $this->_opis;
|
|
|
$arr['fields'] = $this->_fields;
|
|
|
@@ -1587,7 +1622,7 @@ class TableAcl extends Core_AclBase {
|
|
|
private function _getDataSource($cols) {
|
|
|
$dsConfig = array();
|
|
|
$dsConfig['source_id'] = $this->getDB();
|
|
|
- $dsConfig['object_name'] = $this->getName();
|
|
|
+ $dsConfig['object_name'] = $this->getRootTableName();
|
|
|
$dsConfig['fields'] = $cols;
|
|
|
$dsConfig['field_types'] = $this->getTypes();
|
|
|
$dsConfig['fields_virtual'] = $this->getVirtualFieldListByIdZasob();
|