|
|
@@ -8,231 +8,231 @@ Lib::loadClass('Core_AclBase');
|
|
|
*/
|
|
|
class AntAclBase extends Core_AclBase {
|
|
|
|
|
|
- public function __construct($zasobID = 0) {
|
|
|
- $this->_zasobID = (int)$zasobID;
|
|
|
- $this->_name = '';
|
|
|
- $this->_namespace = '';
|
|
|
- $this->_rootTableName = '';
|
|
|
- $this->_db = 0; // database id zasobu
|
|
|
- $this->_rootNamespace = '';
|
|
|
- $this->_primaryKey = '';
|
|
|
- $this->_fields = [];
|
|
|
- }
|
|
|
- public function getDB() { return $this->_db; }
|
|
|
- public function getName() { return $this->_name; }
|
|
|
- public function getNamespace() { return $this->_namespace; }
|
|
|
- public function getRootNamespace() { return $this->_rootNamespace; }
|
|
|
- public function getSourceName() { return 'default_db'; } // TODO: ?
|
|
|
- public function getRootTableName() { return $this->_rootTableName; }
|
|
|
- public function getPrimaryKeyField() { return $this->_primaryKey; }
|
|
|
- public function getFieldListByIdZasob() { return $this->getRealFieldListByIdZasob(); }
|
|
|
- public function getVirtualFieldListByIdZasob() { return []; }
|
|
|
- // public function getVisibleFieldListByIdZasob() { return $this->getRealFieldListByIdZasob(); } // TODO: get visible fields
|
|
|
- public function getVisibleFieldListByIdZasob() {
|
|
|
- $fields = $this->getRealFieldListByIdZasob();
|
|
|
- $pkField = $this->getPrimaryKeyField();
|
|
|
+ public function __construct($zasobID = 0) {
|
|
|
+ $this->_zasobID = (int)$zasobID;
|
|
|
+ $this->_name = '';
|
|
|
+ $this->_namespace = '';
|
|
|
+ $this->_rootTableName = '';
|
|
|
+ $this->_db = 0; // database id zasobu
|
|
|
+ $this->_rootNamespace = '';
|
|
|
+ $this->_primaryKey = '';
|
|
|
+ $this->_fields = [];
|
|
|
+ }
|
|
|
+ public function getDB() { return $this->_db; }
|
|
|
+ public function getName() { return $this->_name; }
|
|
|
+ public function getNamespace() { return $this->_namespace; }
|
|
|
+ public function getRootNamespace() { return $this->_rootNamespace; }
|
|
|
+ public function getSourceName() { return 'default_db'; } // TODO: ?
|
|
|
+ public function getRootTableName() { return $this->_rootTableName; }
|
|
|
+ public function getPrimaryKeyField() { return $this->_primaryKey; }
|
|
|
+ public function getFieldListByIdZasob() { return $this->getRealFieldListByIdZasob(); }
|
|
|
+ public function getVirtualFieldListByIdZasob() { return []; }
|
|
|
+ // public function getVisibleFieldListByIdZasob() { return $this->getRealFieldListByIdZasob(); } // TODO: get visible fields
|
|
|
+ public function getVisibleFieldListByIdZasob() {
|
|
|
+ $fields = $this->getRealFieldListByIdZasob();
|
|
|
+ $pkField = $this->getPrimaryKeyField();
|
|
|
$cols = array();
|
|
|
foreach ($fields as $kFieldID => $fieldName) {
|
|
|
if ($pkField === $fieldName) {
|
|
|
$id = $kFieldID;
|
|
|
- break;
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
$cols[$id] = 'ID';
|
|
|
foreach ($fields as $kFieldID => $fieldName) {
|
|
|
- if ($pkField === $fieldName) continue;
|
|
|
+ if ($pkField === $fieldName) continue;
|
|
|
$cols[$kFieldID] = $fieldName;
|
|
|
}
|
|
|
return $cols;
|
|
|
}
|
|
|
- public function getRealFieldListByIdZasob() {
|
|
|
- $cols = array();
|
|
|
- $fakeZasobId = 1000000;
|
|
|
- foreach ($this->getFields() as $field) {
|
|
|
- $idZasobField = ($field['idZasob']) ? $field['idZasob'] : $fakeZasobId++;
|
|
|
- $cols[$idZasobField] = $field['fieldNamespace'];
|
|
|
- }
|
|
|
- return $cols;
|
|
|
- }
|
|
|
- public function getFieldType($fieldName) { return null; }
|
|
|
- // try {
|
|
|
- // throw new Exception("TODO: AntAclBase::getFieldType({$fieldName})");
|
|
|
- // } catch (Exception $e) {
|
|
|
- // DBG::log($e);
|
|
|
- // }
|
|
|
- // $field = $this->_getField($fieldName);
|
|
|
- // return $field['xsdType'];
|
|
|
- // }
|
|
|
- public function getXsdFieldType($fieldName) {
|
|
|
- $field = $this->_getField($fieldName);
|
|
|
- return $field['xsdType'];
|
|
|
- }
|
|
|
- public function getXsdMaxOccurs($fieldName) {
|
|
|
- $field = $this->_getField($fieldName);
|
|
|
- return $field['maxOccurs'];
|
|
|
- }
|
|
|
- public function getXsdMinOccurs($fieldName) {
|
|
|
- $field = $this->_getField($fieldName);
|
|
|
- return $field['minOccurs'];
|
|
|
- }
|
|
|
- public function getAttributesFromZasoby() {
|
|
|
- return [];// TODO: ...
|
|
|
- }
|
|
|
- public function getXsdFieldParam($fieldName, $paramKey) { // TODO: fetch from db
|
|
|
- return null;
|
|
|
- }
|
|
|
- // public function getXsdFieldParam($fieldName, $paramKey) { // TableAcl
|
|
|
+ public function getRealFieldListByIdZasob() {
|
|
|
+ $cols = array();
|
|
|
+ $fakeZasobId = 1000000;
|
|
|
+ foreach ($this->getFields() as $field) {
|
|
|
+ $idZasobField = ($field['idZasob']) ? $field['idZasob'] : $fakeZasobId++;
|
|
|
+ $cols[$idZasobField] = $field['fieldNamespace'];
|
|
|
+ }
|
|
|
+ return $cols;
|
|
|
+ }
|
|
|
+ public function getFieldType($fieldName) { return null; }
|
|
|
+ // try {
|
|
|
+ // throw new Exception("TODO: AntAclBase::getFieldType({$fieldName})");
|
|
|
+ // } catch (Exception $e) {
|
|
|
+ // DBG::log($e);
|
|
|
+ // }
|
|
|
+ // $field = $this->_getField($fieldName);
|
|
|
+ // return $field['xsdType'];
|
|
|
+ // }
|
|
|
+ public function getXsdFieldType($fieldName) {
|
|
|
+ $field = $this->_getField($fieldName);
|
|
|
+ return $field['xsdType'];
|
|
|
+ }
|
|
|
+ public function getXsdMaxOccurs($fieldName) {
|
|
|
+ $field = $this->_getField($fieldName);
|
|
|
+ return $field['maxOccurs'];
|
|
|
+ }
|
|
|
+ public function getXsdMinOccurs($fieldName) {
|
|
|
+ $field = $this->_getField($fieldName);
|
|
|
+ return $field['minOccurs'];
|
|
|
+ }
|
|
|
+ public function getAttributesFromZasoby() {
|
|
|
+ return [];// TODO: ...
|
|
|
+ }
|
|
|
+ public function getXsdFieldParam($fieldName, $paramKey) { // TODO: fetch from db
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ // public function getXsdFieldParam($fieldName, $paramKey) { // TableAcl
|
|
|
// return ($this->_schemaClass)
|
|
|
// ? $this->_schemaClass->getFieldParam($fieldName, $paramKey)
|
|
|
// : null
|
|
|
// ;
|
|
|
// }
|
|
|
// public function getXsdFieldParam($fieldName, $paramKey) { // SimpleSchema
|
|
|
- // if (empty($this->_simpleSchema['root'][$fieldName])) return null;
|
|
|
- // if (empty($this->_simpleSchema['root'][$fieldName]['@@params'])) return null;
|
|
|
- // if (empty($this->_simpleSchema['root'][$fieldName]['@@params'][$paramKey])) return null;
|
|
|
- // return $this->_simpleSchema['root'][$fieldName]['@@params'][$paramKey];
|
|
|
+ // if (empty($this->_simpleSchema['root'][$fieldName])) return null;
|
|
|
+ // if (empty($this->_simpleSchema['root'][$fieldName]['@@params'])) return null;
|
|
|
+ // if (empty($this->_simpleSchema['root'][$fieldName]['@@params'][$paramKey])) return null;
|
|
|
+ // return $this->_simpleSchema['root'][$fieldName]['@@params'][$paramKey];
|
|
|
// }
|
|
|
|
|
|
- public function isGeomField($fieldName) {
|
|
|
- return ('the_geom' === $fieldName); // TODO: check by xsdType
|
|
|
- }
|
|
|
- public function isEnumerationField($fieldName) {
|
|
|
- return false; // TODO: ...
|
|
|
- }
|
|
|
-
|
|
|
- public function canWriteField($fieldName) {
|
|
|
- return false; // TODO: return $this->getPerms($fieldName)->canWrite()
|
|
|
- }
|
|
|
- public function canCreateField($fieldName) {
|
|
|
- return false; // TODO: return $this->getPerms($fieldName)->canCreate()
|
|
|
- }
|
|
|
- public function canReadField($fieldName) {
|
|
|
- return true; // TODO: return $this->getPerms($fieldName)->canRead()
|
|
|
- }
|
|
|
- public function canReadObjectField($fieldName, $object) {
|
|
|
- return true; // TODO: return $this->getPerms($fieldName, $object)->canRead()
|
|
|
- }
|
|
|
- public function canWriteObjectField($fieldName, $record) {
|
|
|
- return false; // TODO: return $this->getPerms($fieldName, $object)->canWrite()
|
|
|
- }
|
|
|
-
|
|
|
- public function getFields() { // TODO: conflict return structure with TableAcl
|
|
|
- if (empty($this->_fields)) {
|
|
|
- // TODO: fetch fields from DB
|
|
|
- // Lib::loadClass('SchemaFactory');
|
|
|
- // $objectStorage = SchemaFactory::loadDefaultObject('SystemObject');
|
|
|
- // $item = $objectStorage->getItem($namespace, [
|
|
|
- // 'propertyName' => '*,field'
|
|
|
- // ]);
|
|
|
- }
|
|
|
- return $this->_fields;
|
|
|
- }
|
|
|
- public function _getField($fieldName) {
|
|
|
- foreach ($this->getFields() as $field) {
|
|
|
- if ($fieldName === $field['fieldNamespace']) return $field;
|
|
|
- }
|
|
|
- throw new Exception("Field not found '{$this->_namespace}/{$fieldName}'");
|
|
|
- }
|
|
|
-
|
|
|
- public function getSqlPrimaryKeyField() { return 'ID'; } // TODO: read from root object schema (_rootTableName)
|
|
|
-
|
|
|
- public function getTotal($params = []) {
|
|
|
- DBG::log($params, 'array', "AntAclBase::getTotal params");
|
|
|
- $idInstance = ACL::getInstanceId($this->_namespace);
|
|
|
- $instanceTable = ACL::getInstanceTable($this->_namespace);
|
|
|
- $sqlPrimaryKey = $this->getSqlPrimaryKeyField();
|
|
|
- return DB::getPDO()->fetchValue(" -- getTotal({$this->_namespace})
|
|
|
- select count(1)
|
|
|
- from `{$this->_rootTableName}` t
|
|
|
- join `{$instanceTable}` i on(i.pk = t.{$sqlPrimaryKey} and i.idInstance = {$idInstance})
|
|
|
- ");
|
|
|
- }
|
|
|
- public function getItems($params = []) {
|
|
|
- DBG::log($params, 'array', "AntAclBase::getItems params");
|
|
|
-
|
|
|
- // $sql->limit = V::get('limit', 10, $params, 'int');
|
|
|
- // $sql->offset = V::get('limitstart', 0, $params, 'int');
|
|
|
- $limit = V::get('limit', 0, $params, 'int');
|
|
|
- $limit = ($limit < 0) ? 0 : $limit;
|
|
|
- $offset = V::get('limitstart', 0, $params, 'int');
|
|
|
- $offset = ($offset < 0) ? 0 : $offset;
|
|
|
- $sqlLimit = ($limit > 0)
|
|
|
- ? "limit {$limit} offset {$offset}"
|
|
|
- : '';
|
|
|
-
|
|
|
- $idInstance = ACL::getInstanceId($this->_namespace);
|
|
|
- $instanceTable = ACL::getInstanceTable($this->_namespace);
|
|
|
- $sqlPrimaryKey = $this->getSqlPrimaryKeyField();
|
|
|
-
|
|
|
- {
|
|
|
- $filtrIsInstance = [$this->_namespace];
|
|
|
- $filtrIsNotInstance = [];
|
|
|
- if (!empty($params['f_is_instance'])) $filtrIsInstance = $params['f_is_instance'];
|
|
|
- if (!empty($params['f_is_not_instance'])) $filtrIsNotInstance = $params['f_is_not_instance'];
|
|
|
- }
|
|
|
-
|
|
|
- return ACL::query($this)
|
|
|
- ->isInstance($filtrIsInstance)
|
|
|
- ->isNotInstance($filtrIsNotInstance)
|
|
|
- ->select('*') // TODO: fields
|
|
|
- ->select(!empty($params['@instances']) ? '@instances' : '')
|
|
|
- // ->join($instanceTable, 'i', [ 'rawJoin' => "i.pk = t.{$sqlPrimaryKey} and i.idInstance = {$idInstance}" ])
|
|
|
- ->limit($limit)
|
|
|
- ->offset($offset)
|
|
|
- ->execute();
|
|
|
- }
|
|
|
-
|
|
|
- public static function buildInstance($idZasob, $conf = []) {
|
|
|
- static $_cache;
|
|
|
- if (!$_cache) $_cache = array();
|
|
|
- if (array_key_exists($idZasob, $_cache)) {
|
|
|
- return $_cache[$idZasob];
|
|
|
- }
|
|
|
-
|
|
|
- if (empty($conf)) throw new Exception("Brak danych konfiguracyjnych do obiektu ant nr {$idZasob}");
|
|
|
- DBG::log($conf, 'array', 'AntAclBase::buildInstance $conf');
|
|
|
- $acl = new AntAclBase($idZasob);
|
|
|
- $acl->_name = $conf['name'];
|
|
|
- $acl->_rootTableName = $conf['_rootTableName'];
|
|
|
- $acl->_db = $conf['idDatabase'];
|
|
|
- $acl->_namespace = $conf['namespace'];
|
|
|
- $acl->_rootNamespace = str_replace('__x3A__', '/', $conf['nsPrefix']);
|
|
|
- $acl->_fields = $conf['field']; // TODO: lazyLoading - use getFields() in all functions - TODO: use ACL::getObjectFields
|
|
|
- $acl->_primaryKey = 'ID'; // $conf['primaryKey'];
|
|
|
-
|
|
|
- $_cache[$idZasob] = $acl;
|
|
|
- return $_cache[$idZasob];
|
|
|
- }
|
|
|
-
|
|
|
- public function buildQuery($params = array()) {
|
|
|
- Lib::loadClass('AclQueryFeatures');
|
|
|
+ public function isGeomField($fieldName) {
|
|
|
+ return ('the_geom' === $fieldName); // TODO: check by xsdType
|
|
|
+ }
|
|
|
+ public function isEnumerationField($fieldName) {
|
|
|
+ return false; // TODO: ...
|
|
|
+ }
|
|
|
+
|
|
|
+ public function canWriteField($fieldName) {
|
|
|
+ return false; // TODO: return $this->getPerms($fieldName)->canWrite()
|
|
|
+ }
|
|
|
+ public function canCreateField($fieldName) {
|
|
|
+ return false; // TODO: return $this->getPerms($fieldName)->canCreate()
|
|
|
+ }
|
|
|
+ public function canReadField($fieldName) {
|
|
|
+ return true; // TODO: return $this->getPerms($fieldName)->canRead()
|
|
|
+ }
|
|
|
+ public function canReadObjectField($fieldName, $object) {
|
|
|
+ return true; // TODO: return $this->getPerms($fieldName, $object)->canRead()
|
|
|
+ }
|
|
|
+ public function canWriteObjectField($fieldName, $record) {
|
|
|
+ return false; // TODO: return $this->getPerms($fieldName, $object)->canWrite()
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getFields() { // TODO: conflict return structure with TableAcl
|
|
|
+ if (empty($this->_fields)) {
|
|
|
+ // TODO: fetch fields from DB
|
|
|
+ // Lib::loadClass('SchemaFactory');
|
|
|
+ // $objectStorage = SchemaFactory::loadDefaultObject('SystemObject');
|
|
|
+ // $item = $objectStorage->getItem($namespace, [
|
|
|
+ // 'propertyName' => '*,field'
|
|
|
+ // ]);
|
|
|
+ }
|
|
|
+ return $this->_fields;
|
|
|
+ }
|
|
|
+ public function _getField($fieldName) {
|
|
|
+ foreach ($this->getFields() as $field) {
|
|
|
+ if ($fieldName === $field['fieldNamespace']) return $field;
|
|
|
+ }
|
|
|
+ throw new Exception("Field not found '{$this->_namespace}/{$fieldName}'");
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getSqlPrimaryKeyField() { return 'ID'; } // TODO: read from root object schema (_rootTableName)
|
|
|
+
|
|
|
+ public function getTotal($params = []) {
|
|
|
+ DBG::log($params, 'array', "AntAclBase::getTotal params");
|
|
|
+ $idInstance = ACL::getInstanceId($this->_namespace);
|
|
|
+ $instanceTable = ACL::getInstanceTable($this->_namespace);
|
|
|
+ $sqlPrimaryKey = $this->getSqlPrimaryKeyField();
|
|
|
+ return DB::getPDO()->fetchValue(" -- getTotal({$this->_namespace})
|
|
|
+ select count(1)
|
|
|
+ from `{$this->_rootTableName}` t
|
|
|
+ join `{$instanceTable}` i on(i.pk = t.{$sqlPrimaryKey} and i.idInstance = {$idInstance})
|
|
|
+ ");
|
|
|
+ }
|
|
|
+ public function getItems($params = []) {
|
|
|
+ DBG::log($params, 'array', "AntAclBase::getItems params");
|
|
|
+
|
|
|
+ // $sql->limit = V::get('limit', 10, $params, 'int');
|
|
|
+ // $sql->offset = V::get('limitstart', 0, $params, 'int');
|
|
|
+ $limit = V::get('limit', 0, $params, 'int');
|
|
|
+ $limit = ($limit < 0) ? 0 : $limit;
|
|
|
+ $offset = V::get('limitstart', 0, $params, 'int');
|
|
|
+ $offset = ($offset < 0) ? 0 : $offset;
|
|
|
+ $sqlLimit = ($limit > 0)
|
|
|
+ ? "limit {$limit} offset {$offset}"
|
|
|
+ : '';
|
|
|
+
|
|
|
+ $idInstance = ACL::getInstanceId($this->_namespace);
|
|
|
+ $instanceTable = ACL::getInstanceTable($this->_namespace);
|
|
|
+ $sqlPrimaryKey = $this->getSqlPrimaryKeyField();
|
|
|
+
|
|
|
+ {
|
|
|
+ $filtrIsInstance = [$this->_namespace];
|
|
|
+ $filtrIsNotInstance = [];
|
|
|
+ if (!empty($params['f_is_instance'])) $filtrIsInstance = $params['f_is_instance'];
|
|
|
+ if (!empty($params['f_is_not_instance'])) $filtrIsNotInstance = $params['f_is_not_instance'];
|
|
|
+ }
|
|
|
+
|
|
|
+ return ACL::query($this)
|
|
|
+ ->isInstance($filtrIsInstance)
|
|
|
+ ->isNotInstance($filtrIsNotInstance)
|
|
|
+ ->select('*') // TODO: fields
|
|
|
+ ->select(!empty($params['@instances']) ? '@instances' : '')
|
|
|
+ // ->join($instanceTable, 'i', [ 'rawJoin' => "i.pk = t.{$sqlPrimaryKey} and i.idInstance = {$idInstance}" ])
|
|
|
+ ->limit($limit)
|
|
|
+ ->offset($offset)
|
|
|
+ ->execute();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function buildInstance($idZasob, $conf = []) {
|
|
|
+ static $_cache;
|
|
|
+ if (!$_cache) $_cache = array();
|
|
|
+ if (array_key_exists($idZasob, $_cache)) {
|
|
|
+ return $_cache[$idZasob];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (empty($conf)) throw new Exception("Brak danych konfiguracyjnych do obiektu ant nr {$idZasob}");
|
|
|
+ DBG::log($conf, 'array', 'AntAclBase::buildInstance $conf');
|
|
|
+ $acl = new AntAclBase($idZasob);
|
|
|
+ $acl->_name = $conf['name'];
|
|
|
+ $acl->_rootTableName = $conf['_rootTableName'];
|
|
|
+ $acl->_db = $conf['idDatabase'];
|
|
|
+ $acl->_namespace = $conf['namespace'];
|
|
|
+ $acl->_rootNamespace = str_replace('__x3A__', '/', $conf['nsPrefix']);
|
|
|
+ $acl->_fields = $conf['field']; // TODO: lazyLoading - use getFields() in all functions - TODO: use ACL::getObjectFields
|
|
|
+ $acl->_primaryKey = 'ID'; // $conf['primaryKey'];
|
|
|
+
|
|
|
+ $_cache[$idZasob] = $acl;
|
|
|
+ return $_cache[$idZasob];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function buildQuery($params = array()) {
|
|
|
+ Lib::loadClass('AclQueryFeatures');
|
|
|
return new AclQueryFeatures($this, $params, $legacyMode = false);
|
|
|
- }
|
|
|
-
|
|
|
- public function getInstanceList() {
|
|
|
- $rootTableName = $this->_rootTableName;
|
|
|
- return array_map(function ($row) use ($rootTableName) {
|
|
|
- return $row['name'];
|
|
|
- }, SchemaFactory::loadDefaultObject('SystemObject')->getItems([
|
|
|
- 'propertyName' => 'name', // TODO: SystemObject fix propertyName
|
|
|
- 'f__rootTableName' => "={$rootTableName}",
|
|
|
- 'f__type' => "=AntAcl",
|
|
|
- 'f_isObjectActive' => "=1",
|
|
|
- ])
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- public function getLocalFieldList() {
|
|
|
- return array_map(function ($field) {
|
|
|
- return $field['fieldNamespace'];
|
|
|
- }, array_filter($this->getFields(), function ($field) {
|
|
|
- return ($field['isLocal']);
|
|
|
- }));
|
|
|
- }
|
|
|
-
|
|
|
- public function isLocalField($fieldName) {
|
|
|
- return $this->_getField($fieldName)['isLocal'];
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getInstanceList() {
|
|
|
+ $rootTableName = $this->_rootTableName;
|
|
|
+ return array_map(function ($row) use ($rootTableName) {
|
|
|
+ return $row['name'];
|
|
|
+ }, SchemaFactory::loadDefaultObject('SystemObject')->getItems([
|
|
|
+ 'propertyName' => 'name', // TODO: SystemObject fix propertyName
|
|
|
+ 'f__rootTableName' => "={$rootTableName}",
|
|
|
+ 'f__type' => "=AntAcl",
|
|
|
+ 'f_isObjectActive' => "=1",
|
|
|
+ ])
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getLocalFieldList() {
|
|
|
+ return array_map(function ($field) {
|
|
|
+ return $field['fieldNamespace'];
|
|
|
+ }, array_filter($this->getFields(), function ($field) {
|
|
|
+ return ($field['isLocal']);
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ public function isLocalField($fieldName) {
|
|
|
+ return $this->_getField($fieldName)['isLocal'];
|
|
|
+ }
|
|
|
|
|
|
}
|