parentAcl = User::getAcl()->getObjectAcl('default_db', 'TEST_PERMS'); // DBG::_(true, true, "parentAcl", $this->parentAcl, __CLASS__, __FUNCTION__, __LINE__); } public function getNamespace() { return 'default_objects/' . $this->getName(); } public function getSourceName() { return 'default_objects'; } public function init($force = false) {} public function isInitialized() { return true; } public function getName() { return 'TestPerms'; } public function getRootTableName() { return 'TEST_PREMS'; } public function getFieldListByIdZasob() { return $this->getRealFieldListByIdZasob(); } public function getVisibleFieldListByIdZasob() { return $this->getRealFieldListByIdZasob(); } public function getVirtualFieldListByIdZasob() { return array(); } public function getRealFieldListByIdZasob($force = false) { $cols = $this->parentAcl->getRealFieldListByIdZasob(); $cols[100000] = 'File'; // $cols[100010] = 'File1'; // $cols[100011] = 'File2'; // $cols[100001] = 'NestedObjectTest'; $cols[100002] = 'AccessGroupRead'; $cols[100003] = 'AccessGroupWrite'; $cols[100004] = 'AccessOwner'; return $cols; } public function getFields() {// @returns array - $this->_fields $fields = $this->parentAcl->getFields(); $fields[100000] = ['name'=>'File', 'perms'=>'RWXC', 'opis'=>'Plik', 'sort_prio'=>999, 'label'=>'Plik']; // $fields[100001] = 'NestedObjectTest'; $fields[100002] = ['name'=>'AccessGroupRead', 'perms'=>'RWXC', 'opis'=>'Odczyt dla', 'sort_prio'=>999, 'label'=>'Odczyt dla']; $fields[100003] = ['name'=>'AccessGroupWrite', 'perms'=>'RWXC', 'opis'=>'Zapis dla', 'sort_prio'=>999, 'label'=>'Zapis dla']; $fields[100004] = ['name'=>'AccessOwner', 'perms'=>'RWXC', 'opis'=>'Osoba odpowiedzialna', 'sort_prio'=>999, 'label'=>'Osoba odp.']; return $fields; } public function getFieldType($fieldName) { foreach ($this->getFields() as $field) { if ($fieldName == $field['name']) return $field; } return null; } // TODO: replace legacy functions: isAllowed, hasFieldPerm, getFieldIdByName public function canCreateField($fieldName) { if ('File' == $fieldName) return true; if ('AccessGroupRead' == $fieldName) return true; if ('AccessGroupWrite' == $fieldName) return true; if ('AccessOwner' == $fieldName) return true; return $this->parentAcl->canCreateField($fieldName); } public function canReadField($fieldName) { if ('File' == $fieldName) return true; if ('AccessGroupRead' == $fieldName) return true; if ('AccessGroupWrite' == $fieldName) return true; if ('AccessOwner' == $fieldName) return true; return $this->parentAcl->canReadField($fieldName); } public function canReadObjectField($fieldName, $record) { if ('File' == $fieldName) return true; if ('AccessGroupRead' == $fieldName) return true; if ('AccessGroupWrite' == $fieldName) return true; if ('AccessOwner' == $fieldName) return true; return $this->parentAcl->canReadObjectField($fieldName, $record); } public function canWriteField($fieldName) { if ('File' == $fieldName) return true; if ('AccessGroupRead' == $fieldName) return true; if ('AccessGroupWrite' == $fieldName) return true; if ('AccessOwner' == $fieldName) return true; return $this->parentAcl->canWriteField($fieldName); } public function canWriteObjectField($fieldName, $record) { if ('File' == $fieldName) return true; if ('AccessGroupRead' == $fieldName) return true; if ('AccessGroupWrite' == $fieldName) return true; if ('AccessOwner' == $fieldName) return true; return $this->parentAcl->canWriteObjectField($fieldName, $record); } public function getTotal($params = array()) {// TODO: use ParseOgcQuery $DBG = V::get('DBG_DS', 0, $_GET, 'int'); if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getTotal \$params:";print_r($params);echo "\n";} return $this->parentAcl->getTotal($params); } public function getItem($primaryKey) { $items = $this->getItems(['primaryKey'=>$primaryKey]); return (!empty($items[$primaryKey])) ? $items[$primaryKey] : null; } public function getItems($params = array()) {// TODO: use ParseOgcQuery $DBG = V::get('DBG_DS', 0, $_GET, 'int'); if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$params:";print_r($params);echo "\n";} $items = array(); $rawItems = $this->parentAcl->getItems($params); foreach ($rawItems as $pk => $item) $items[$pk] = (array)$item; if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$items:";print_r($items);echo "\n";} if (empty($items)) return $items; $this->fetchItemRef($items);// TODO: only fields from request if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems after fetchItemRef \$items:";print_r($items);echo "\n";} return $items; } public function fetchItemRef(&$items) { $DBG = V::get('DBG_DS', 0, $_GET, 'int'); $refs = array();// fieldName => xsdType foreach ($this->getRealFieldListByIdZasob() as $id => $fieldName) { $fieldType = $this->getXsdFieldType($fieldName); if ('ref:' == substr($fieldType, 0, 4)) $refs[$fieldName] = substr($fieldType, 4); else if ('alias_ref:' == substr($fieldType, 0, 10)) { $refs[$fieldName] = substr($fieldType, 10); } } if (empty($refs)) return $items; $pkList = array_keys($items); $sqlPk = array(); foreach ($pkList as $pk) { $sqlPk[] = DB::getPDO()->quote($pk, PDO::PARAM_STR); } $sqlPk = implode(", ", $sqlPk); $refRows = array();// $fieldName => [ pk, ... ] foreach ($refs as $fieldName => $type) { $acl = Core_AclHelper::getAclByTypeName($type); // TODO: Core_AclBase->fetchRefs($fieldName, $pkList = array());// $refPk[$fieldName] = $this->fetchRefs($fieldName, $pkList); $refTableName = $this->createRefTable($fieldName); if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems loop(\$fieldName:{$fieldName}) \$refTableName:({$refTableName})";echo"\n";} $refRows[$fieldName] = DB::getPDO()->fetchAllByKey(" select r.* from `{$refTableName}` r where r.PRIMARY_KEY in({$sqlPk}) ", $key = 'PRIMARY_KEY'); if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems loop(\$fieldName:{$fieldName}) \$refTableName:({$refTableName}), \$refRows[$fieldName]";print_r($refRows[$fieldName]);echo"\n";} } foreach ($refRows as $fieldName => $refList) { foreach ($refList as $pk => $ref) { $items[ $pk ][ $fieldName ][] = array('xlink' => "{$refs[$fieldName]}.{$ref['REMOTE_PRIMARY_KEY']}"); } } } public function addItem($itemTodo) { return $this->parentAcl->addItem($itemTodo); } public function updateItem($itemPatch) { return $this->parentAcl->updateItem($itemPatch); } public function getGeomFieldType($fieldName) { return null; } public function getPrimaryKeyField() { return 'ID'; } public function getID() { return 0; } public function getAttributesFromZasoby() { return array(); } public function isEnumerationField($fieldName) { if ('A_STATUS' == $fieldName) return true; return false; } public function getEnumerations($fieldName) { if ('A_STATUS' == $fieldName) return $this->parentAcl->getEnumerations($fieldName); return null; } public function getXsdFieldType($fieldName) { if ('File' == $fieldName) return 'ref:p5_objects:File'; // if ('File1' == $fieldName) return 'alias_ref:p5_objects:File'; // if ('File2' == $fieldName) return 'alias_ref:p5_objects:File'; // if ('NestedObjectTest' == $fieldName) return 'local_ref:p5_objects:NestedObjectTest'; if ('AccessGroupRead' == $fieldName) return 'ref:default_objects:AccessGroupRead'; if ('AccessGroupWrite' == $fieldName) return 'ref:default_objects:AccessGroupWrite'; if ('AccessOwner' == $fieldName) return 'ref:default_objects:AccessOwner'; return $this->parentAcl->getXsdFieldType($fieldName); } public function isGeomField($fldName) { if ('File' == $fieldName) return false; if ('AccessGroupRead' == $fieldName) return false; if ('AccessGroupWrite' == $fieldName) return false; if ('AccessOwner' == $fieldName) return false; // if ('NestedObjectTest' == $fieldName) return false; return $this->parentAcl->isGeomField($fldName); } }