| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- <?php
- Lib::loadClass('Core_AclBase');
- Lib::loadClass('Core_AclHelper');
- Lib::loadClass('FileStorage');
- class Schema_TestPermsStorageAcl extends Core_AclBase {
- public function __construct() {
- $this->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})
- and r.A_STATUS != 'DELETED'
- ", $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);
- }
- }
|