KorespondencjaStorageAcl.php 6.5 KB

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