|
|
@@ -52,14 +52,18 @@ class TableAcl extends Core_AclBase {
|
|
|
if (empty($this->_name)) return null;// throw new Exception("Table name not defined");
|
|
|
if ($this->_rootTableName) return $this->_rootTableName;
|
|
|
if (!$this->_db) return null;// throw new Exception("Database not defined in table {$this->_zasobID}");
|
|
|
- $dbName = DB::getPDO($this->_db)->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) return null;// throw new Exception("Table '{$this->_name}' not exists!");
|
|
|
+ if (DB::getPDO($this->_db)->getZasobId() === DB::getPDO()->getZasobId()) {
|
|
|
+ $dbName = DB::getPDO($this->_db)->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) return null;// throw new Exception("Table '{$this->_name}' not exists!");
|
|
|
+ } else {
|
|
|
+ $this->_rootTableName = $this->_name; // TODO: fix for Postgres
|
|
|
+ }
|
|
|
DBG::log("TableAcl({$this->_zasobID})->getRootTableName (\$this->_name='{$this->_name}', \$this->_rootTableName='{$this->_rootTableName}')");
|
|
|
if ($this->_rootTableName != $this->_name) {
|
|
|
if ($this->_zasobID) {
|
|
|
@@ -74,7 +78,9 @@ class TableAcl extends Core_AclBase {
|
|
|
return $this->_rootTableName;
|
|
|
}
|
|
|
public function getID() { return $this->_zasobID; }
|
|
|
- public function getSqlPrimaryKeyField() { return 'ID'; } // TODO: read from root object schema (_rootTableName)
|
|
|
+ public function getSqlPrimaryKeyField() {
|
|
|
+ return $this->getPrimaryKeyField();
|
|
|
+ } // TODO: read from root object schema (_rootTableName)
|
|
|
public function setName($name) {// TODO: used only by setNameByTableId
|
|
|
DBG::log("setName('{$name}')");
|
|
|
$this->_name = $name;
|
|
|
@@ -1043,7 +1049,7 @@ class TableAcl extends Core_AclBase {
|
|
|
$this->_types = array();// clear _types @see $this->isInitialized
|
|
|
$userAcl = User::getAcl();
|
|
|
$fieldsConfig = $userAcl->getPermsForTable($this->_zasobID);
|
|
|
- // DBG::log(['msg'=>"INIT({$this->_zasobID})::initFieldsFromConfig \$fieldsConfig", '$fieldsConfig'=>$fieldsConfig]);
|
|
|
+ // DBG::log($fieldsConfig, 'array', "INIT({$this->_zasobID})::initFieldsFromConfig \$fieldsConfig");
|
|
|
$this->initFieldsFromConfig($fieldsConfig);
|
|
|
//DBG::_('DBG_SCH', '1', "INIT::\$fieldsConfig({$this->_zasobID}) fields(".count($this->_fields).")", $this, __CLASS__, __FUNCTION__, __LINE__ );
|
|
|
}
|
|
|
@@ -1053,16 +1059,18 @@ class TableAcl extends Core_AclBase {
|
|
|
}
|
|
|
DBG::simpleLog('auth', "TableAcl::init(name: '{$this->_name}')");
|
|
|
|
|
|
- // DBG::log(['msg'=>"INIT({$this->_zasobID}):: \$this", '$this'=>$this, 'name'=>$this->getName()]);
|
|
|
+ // DBG::log(['$this'=>$this, 'name'=>$this->getName()], 'array', "INIT({$this->_zasobID}):: \$this");
|
|
|
$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]);
|
|
|
+ // DBG::log($ds, 'array', "INIT({$this->_zasobID})::getDataSource \$ds");
|
|
|
+ $this->_types = (is_object($this->_schemaClass) && method_exists($this->_schemaClass, 'getLegacyFieldTypes'))
|
|
|
+ ? $this->_schemaClass->getLegacyFieldTypes()
|
|
|
+ : $ds->getFieldTypes();
|
|
|
+ // DBG::log($this->_types, 'array', "INIT({$this->_zasobID})::getFieldTypes \$this->_types");
|
|
|
|
|
|
uasort($this->_fields, array($this, 'sortFieldsCallback'));
|
|
|
|
|
|
$this->_fixTypes();
|
|
|
- // DBG::log(['msg'=>"INIT({$this->_zasobID})::after fixTypes \$this->_types", '$this->_types'=>$this->_types]);
|
|
|
+ // DBG::log($this->_types, 'array', "INIT({$this->_zasobID})::after fixTypes \$this->_types");
|
|
|
|
|
|
$this->save();
|
|
|
}
|
|
|
@@ -1276,16 +1284,17 @@ class TableAcl extends Core_AclBase {
|
|
|
|
|
|
public function getVisibleFieldList() { return $this->getVisibleFieldListByIdZasob(); }
|
|
|
public function getVisibleFieldListByIdZasob() {
|
|
|
+ $primaryKeyField = $this->getSqlPrimaryKeyField();
|
|
|
$cols = array();
|
|
|
$id = 0;
|
|
|
foreach ($this->getFields() as $kFieldID => $vField) {
|
|
|
- if ($vField['name'] == 'ID') {
|
|
|
+ if ($vField['name'] == $primaryKeyField) {
|
|
|
$id = $kFieldID;
|
|
|
}
|
|
|
}
|
|
|
- $cols[$id] = 'ID';
|
|
|
+ $cols[$id] = $primaryKeyField;
|
|
|
foreach ($this->getFields() as $kFieldID => $vField) {
|
|
|
- if ($vField['name'] == 'ID') {
|
|
|
+ if ($vField['name'] == $primaryKeyField) {
|
|
|
continue;
|
|
|
}
|
|
|
$cols[$kFieldID] = $vField['name'];
|
|
|
@@ -1598,6 +1607,13 @@ class TableAcl extends Core_AclBase {
|
|
|
return $geomType;
|
|
|
}
|
|
|
|
|
|
+ public function getSqlTableFrom() {
|
|
|
+ if ($this->loadSchema() && method_exists($this->_schemaClass, 'getSqlTableFrom')) {
|
|
|
+ return $this->_schemaClass->getSqlTableFrom();
|
|
|
+ }
|
|
|
+ return DB::getPDO( $this->getDB() )->tableNameQuote( $this->getRootTableName() );
|
|
|
+ }
|
|
|
+
|
|
|
public function getHistItems($primaryKey) {
|
|
|
if ($this->loadSchema() && method_exists($this->_schemaClass, 'hasGetHistItems') && $this->_schemaClass->hasGetHistItems()) {
|
|
|
return $this->_schemaClass->getHistItems($primaryKey);
|