KorespondencjaStorageAcl.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. Lib::loadClass('Core_AclBase');
  3. Lib::loadClass('Core_AclHelper');
  4. Lib::loadClass('FileStorage');
  5. class Schema_KorespondencjaStorageAcl extends Core_AclBase {
  6. public function __construct() {
  7. $this->parentAcl = User::getAcl()->getObjectAcl('default_db', 'IN7_DZIENNIK_KORESP');
  8. // DBG::_(true, true, "parentAcl", $this->parentAcl, __CLASS__, __FUNCTION__, __LINE__);
  9. }
  10. public function getNamespace() { return 'default_objects/' . $this->getName(); }
  11. public function getSourceName() { return 'objects'; }
  12. public function init($force = false) {}
  13. public function isInitialized() { return true; }
  14. public function getName() { return 'Korespondencja'; }
  15. public function getRootTableName() { return 'IN7_DZIENNIK_KORESP'; }
  16. public function getFieldListByIdZasob() { return $this->getRealFieldListByIdZasob(); }
  17. public function getVisibleFieldListByIdZasob() { return $this->getRealFieldListByIdZasob(); }
  18. public function getVirtualFieldListByIdZasob() { return array(); }
  19. public function getRealFieldListByIdZasob($force = false) {
  20. $cols = $this->parentAcl->getRealFieldListByIdZasob();
  21. $cols[100000] = 'File';
  22. return $cols;
  23. }
  24. public function getFieldIdByName($fieldName) {
  25. $fields = $this->getRealFieldListByIdZasob();
  26. if (empty($fieldName)) return null;
  27. foreach ($fields as $idField => $vFieldName) {
  28. if ($vFieldName == $fieldName) return $idField;
  29. }
  30. return null;
  31. }
  32. public function getFieldType($colName) { return null; }
  33. public function isAllowed($idZasob, $taskPerm, $record = null) {
  34. if ($this->parentAcl->hasField($idZasob)) return $this->parentAcl->isAllowed($idZasob, $taskPerm, $record);
  35. $fields = $this->getRealFieldListByIdZasob();
  36. if (array_key_exists($idZasob, $fields)) {
  37. if ('File' == $fields[$idZasob]) {
  38. foreach ($fields as $idFld => $name) {
  39. if ($idFld == $idZasob) continue;
  40. if ($this->parentAcl->isAllowed($idFld, $taskPerm, $record)) return true;
  41. }
  42. }
  43. }
  44. return false;
  45. }
  46. public function hasFieldPerm($idZasob, $taskPerm) {
  47. if ($this->parentAcl->hasField($idZasob)) return $this->parentAcl->hasFieldPerm($idZasob, $taskPerm);
  48. $fields = $this->getRealFieldListByIdZasob();
  49. if (array_key_exists($idZasob, $fields)) {
  50. if ('File' == $fields[$idZasob]) {
  51. foreach ($fields as $idFld => $name) {
  52. if ($idFld == $idZasob) continue;
  53. if ($this->parentAcl->hasFieldPerm($idFld, $taskPerm)) return true;
  54. }
  55. }
  56. }
  57. return false;
  58. }
  59. // TODO: replace legacy functions: isAllowed, hasFieldPerm, getFieldIdByName
  60. public function canCreateField($fieldName) {
  61. if ('File' == $fieldName) return true;
  62. return $this->parentAcl->canCreateField($fieldName);
  63. }
  64. public function canReadField($fieldName) {
  65. if ('File' == $fieldName) return true;
  66. return $this->parentAcl->canReadField($fieldName);
  67. }
  68. public function canReadObjectField($fieldName, $record) {
  69. if ('File' == $fieldName) return true;
  70. return $this->parentAcl->canReadObjectField($fieldName, $record);
  71. }
  72. public function canWriteField($fieldName) {
  73. if ('File' == $fieldName) return true;
  74. return $this->parentAcl->canWriteField($fieldName);
  75. }
  76. public function canWriteObjectField($fieldName, $record) {
  77. if ('File' == $fieldName) return true;
  78. return $this->parentAcl->canWriteObjectField($fieldName, $record);
  79. }
  80. public function getItems($params = array()) {
  81. $DBG = V::get('DBG_DS', 0, $_GET, 'int');
  82. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$params:";print_r($params);echo "\n";}
  83. $items = array();
  84. $rawItems = $this->parentAcl->getItems($params);
  85. foreach ($rawItems as $pk => $item) $items[$pk] = (array)$item;
  86. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$items:";print_r($items);echo "\n";}
  87. if (empty($items)) return $items;
  88. $this->fetchItemRef($items);
  89. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems after fetchItemRef \$items:";print_r($items);echo "\n";}
  90. return $items;
  91. }
  92. public function fetchItemRef(&$items) {
  93. $DBG = V::get('DBG_DS', 0, $_GET, 'int');
  94. $refs = array();// fieldName => xsdType
  95. foreach ($this->getRealFieldListByIdZasob() as $id => $fieldName) {
  96. $fieldType = $this->getXsdFieldType($fieldName);
  97. if ('ref:' == substr($fieldType, 0, 4)) $refs[$fieldName] = substr($fieldType, 4);
  98. else if ('alias_ref:' == substr($fieldType, 0, 10)) $refs[$fieldName] = substr($fieldType, 10);
  99. }
  100. if (empty($refs)) return $items;
  101. $fidList = array_keys($items);
  102. $sqlPk = array(); foreach ($fidList as $pk) { $sqlPk[] = "'{$pk}'"; } $sqlPk = implode(", ", $sqlPk);
  103. $baseRefTableName = $this->getRootTableName() . "__#REF__";
  104. $refRows = array();// $fieldName => [ pk, ... ]
  105. foreach ($refs as $fieldName => $type) {
  106. $acl = Core_AclHelper::getAclByTypeName($type);
  107. $refTableName = $this->getRootTableName() . "__#REF__" . $acl->getRootTableName();
  108. $refRows[$fieldName] = DB::getPDO()->fetchAllByKey("
  109. select r.*
  110. from `{$refTableName}` r
  111. where r.PRIMARY_KEY in({$sqlPk})
  112. -- TODO and r.INSTANCE = '{$refInstanceName}' -- for multiple types based on the same root table
  113. ", $key = 'PRIMARY_KEY');
  114. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems loop(\$fieldName:{$fieldName}) \$refTableName:({$refTableName}), \$refRows[$fieldName]";print_r($refRows[$fieldName]);echo"\n";}
  115. }
  116. foreach ($refRows as $fieldName => $refList) {
  117. foreach ($refList as $pk => $ref) {
  118. $items[ $pk ][ $fieldName ][] = array('xlink' => "{$refs[$fieldName]}.{$ref['REMOTE_PRIMARY_KEY']}");
  119. }
  120. }
  121. }
  122. public function addItem($itemTodo) {
  123. return $this->parentAcl->addItem($itemTodo);
  124. }
  125. public function updateItem($itemPatch) {
  126. return $this->parentAcl->updateItem($itemPatch);
  127. }
  128. public function getGeomFieldType($fieldName) { return null; }
  129. public function getPrimaryKeyField() { return 'ID'; }
  130. public function getID() { return 0; }
  131. public function getAttributesFromZasoby() {
  132. $attributes = array();// fldName => [ 'id_zasob' => int, 'label' => str, 'description' => str ]
  133. // if ($acl->hasFieldPerm($idZasob, 'W')) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_write", "true");
  134. // if ($acl->hasFieldPerm($idZasob, 'C')) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_create", "true");
  135. // if (!$acl->hasFieldPerm($idZasob, 'R')) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_read", "false");
  136. return $attributes;
  137. }
  138. public function isEnumerationField($fieldName) { return false; }
  139. public function getXsdFieldType($fieldName) {
  140. if ('File' == $fieldName) return 'ref:p5_objects:File';
  141. return $this->parentAcl->getXsdFieldType($fieldName);
  142. }
  143. public function isGeomField($fldName) { return $this->parentAcl->isGeomField($fldName); }
  144. }