| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- <?php
- Lib::loadClass('Core_AclBase');
- Lib::loadClass('Core_AclHelper');
- Lib::loadClass('FileStorage');
- class Schema_KorespondencjaStorageAcl extends Core_AclBase {
- public function __construct() {
- $this->parentAcl = User::getAcl()->getObjectAcl('default_db', 'IN7_DZIENNIK_KORESP');
- // DBG::_(true, true, "parentAcl", $this->parentAcl, __CLASS__, __FUNCTION__, __LINE__);
- }
- public function getNamespace() { return 'default_objects/' . $this->getName(); }
- public function getSourceName() { return 'objects'; }
- public function init($force = false) {}
- public function isInitialized() { return true; }
- public function getName() { return 'Korespondencja'; }
- public function getRootTableName() { return 'IN7_DZIENNIK_KORESP'; }
- 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';
- 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) { return null; }
- public function isAllowed($idZasob, $taskPerm, $record = null) {
- if ($this->parentAcl->hasField($idZasob)) return $this->parentAcl->isAllowed($idZasob, $taskPerm, $record);
- $fields = $this->getRealFieldListByIdZasob();
- if (array_key_exists($idZasob, $fields)) {
- if ('File' == $fields[$idZasob]) {
- foreach ($fields as $idFld => $name) {
- if ($idFld == $idZasob) continue;
- if ($this->parentAcl->isAllowed($idFld, $taskPerm, $record)) return true;
- }
- }
- }
- return false;
- }
- public function hasFieldPerm($idZasob, $taskPerm) {
- if ($this->parentAcl->hasField($idZasob)) return $this->parentAcl->hasFieldPerm($idZasob, $taskPerm);
- $fields = $this->getRealFieldListByIdZasob();
- if (array_key_exists($idZasob, $fields)) {
- if ('File' == $fields[$idZasob]) {
- foreach ($fields as $idFld => $name) {
- if ($idFld == $idZasob) continue;
- if ($this->parentAcl->hasFieldPerm($idFld, $taskPerm)) return true;
- }
- }
- }
- return false;
- }
- // TODO: replace legacy functions: isAllowed, hasFieldPerm, getFieldIdByName
- public function canCreateField($fieldName) {
- if ('File' == $fieldName) return true;
- return $this->parentAcl->canCreateField($fieldName);
- }
- public function canReadField($fieldName) {
- if ('File' == $fieldName) return true;
- return $this->parentAcl->canReadField($fieldName);
- }
- public function canReadObjectField($fieldName, $record) {
- if ('File' == $fieldName) return true;
- return $this->parentAcl->canReadObjectField($fieldName, $record);
- }
- public function canWriteField($fieldName) {
- if ('File' == $fieldName) return true;
- return $this->parentAcl->canWriteField($fieldName);
- }
- public function canWriteObjectField($fieldName, $record) {
- if ('File' == $fieldName) return true;
- return $this->parentAcl->canWriteObjectField($fieldName, $record);
- }
- 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";}
- $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);
- else if ('alias_ref:' == substr($fieldType, 0, 10)) $refs[$fieldName] = substr($fieldType, 10);
- }
- 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 = Core_AclHelper::getAclByTypeName($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) {
- 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 getXsdFieldType($fieldName) {
- if ('File' == $fieldName) return 'ref:p5_objects:File';
- return $this->parentAcl->getXsdFieldType($fieldName);
- }
- public function isGeomField($fldName) { return $this->parentAcl->isGeomField($fldName); }
- }
|