KorespondencjaStorageAcl.php 6.8 KB

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