| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- Lib::loadClass('Core_AclBase');
- Lib::loadClass('FileStorage');
- class 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 getSourceName() { return 'objects'; }
- public function init($force = false) {}
- public function isInitialized() { return true; }
- public function getName() { return 'TestPerms'; }
- public function getRootTableName() { return 'TEST_PREMS'; }
- public function getRealFieldListByIdZasob($force = false) {
- $cols = $this->parentAcl->getRealFieldListByIdZasob();
- foreach ($cols as $id => $name) {
- if ('ID' == $name) $cols[$id] = 'id';
- }
- $cols[100000] = 'File';
- return $cols;
- }
- public function getFieldIdByName($fieldName) {
- $fields = $this->getRealFieldListByIdZasob();
- if (empty($fieldName)) return null;
- foreach ($fields as $idField => $vFieldName) {
- if ($vFieldName == $fieldName) return $idField;
- }
- return null;
- }
- public function getFieldType($colName) {
- switch ($colName) {
- case 'id': return array(); break;
- }
- return null;
- }
- public function isAllowed($idZasob, $taskPerm, $record = null) {
- if ('C' == $taskPerm && $idZasob > 1 && $idZasob < 7) return true;
- if ('R' == $taskPerm && $idZasob > 0 && $idZasob < 7) return true;
- return false;
- }
- public function hasFieldPerm($idZasob, $taskPerm) {
- if ('C' == $taskPerm && $idZasob > 1 && $idZasob < 7) return true;
- if ('R' == $taskPerm && $idZasob > 0 && $idZasob < 7) return true;
- return false;
- }
- public function getItems($params = array()) {
- $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";}
- if (!empty($params['ogc:Filter'])) $params['ogc:Filter'] = str_replace('<ogc:PropertyName>id</ogc:PropertyName>', '<ogc:PropertyName>ID</ogc:PropertyName>', $params['ogc:Filter']);
- $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);
- 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);
- }
- if (empty($refs)) return $items;
- $fidList = array_keys($items);
- $sqlPk = array(); foreach ($fidList as $pk) { $sqlPk[] = "'{$pk}'"; } $sqlPk = implode(", ", $sqlPk);
- $baseRefTableName = $this->getRootTableName() . "__#REF__";
- $refRows = array();// $fieldName => [ pk, ... ]
- foreach ($refs as $fieldName => $type) {
- $acl = $this->getAclFromTypeName($type);
- $refTableName = $this->getRootTableName() . "__#REF__" . $acl->getRootTableName();
- $refRows[$fieldName] = DB::getPDO()->fetchAllByKey("
- select r.*
- from `{$refTableName}` r
- where r.PRIMARY_KEY in({$sqlPk})
- -- TODO and r.INSTANCE = '{$refInstanceName}' -- for multiple types based on the same root table
- ", $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) {
- $itemPatch['ID'] = $itemPatch['id'];
- unset($itemPatch['id']);
- return $this->parentAcl->updateItem($itemPatch);
- }
- public function getGeomFieldType($fieldName) { return null; }
- public function getPrimaryKeyField() { return 'id'; }
- public function getID() { return 0; }
- public function getAttributesFromZasoby() {
- $attributes = array();// fldName => [ 'id_zasob' => int, 'label' => str, 'description' => str ]
- // if ($acl->hasFieldPerm($idZasob, 'W')) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_write", "true");
- // if ($acl->hasFieldPerm($idZasob, 'C')) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_create", "true");
- // if (!$acl->hasFieldPerm($idZasob, 'R')) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_read", "false");
- return $attributes;
- }
- public function isEnumerationField($fieldName) { return false; }
- public function validateFieldAction($fieldName, $taskPerm, $record = null) {
- if ('File' == $fieldName) {
- // return 'ref:p5_objects:File';
- return true;
- }
- if ('id' == $fieldName) $fieldName = 'ID';
- return $this->parentAcl->isAllowed($fieldID = $this->parentAcl->getFieldIdByName($fieldName), $taskPerm, $record);
- }
- public function getXsdFieldType($fieldName) {
- if ('File' == $fieldName) return 'ref:p5_objects:File';
- return $this->parentAcl->getXsdFieldType($fieldName);
- }
- public function isGeomField($fldName) { return $this->parentAcl->isGeomField($fldName); }
- }
|