|
|
@@ -0,0 +1,138 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+Lib::loadClass('Core_AclBase');
|
|
|
+Lib::loadClass('FileStorage');
|
|
|
+
|
|
|
+class 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 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 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;
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ 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) {
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ 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); }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+CREATE TABLE IF NOT EXISTS `IN7_DZIENNIK_KORESP__#REF__CRM_FILES` (
|
|
|
+ `PRIMARY_KEY` int(11) NOT NULL,
|
|
|
+ `REMOTE_PRIMARY_KEY` int(11) NOT NULL,
|
|
|
+ KEY `PRIMARY_KEY` (`PRIMARY_KEY`),
|
|
|
+ KEY `REMOTE_PRIMARY_KEY` (`REMOTE_PRIMARY_KEY`)
|
|
|
+) ENGINE=MyISAM DEFAULT CHARSET=latin2;
|
|
|
+*/
|