KorespondencjaStorageAcl.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 'default_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->itemsFetchRefs($items);
  89. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems after itemsFetchRefs \$items:";print_r($items);echo "\n";}
  90. return $items;
  91. }
  92. public function addItem($itemTodo) {
  93. return $this->parentAcl->addItem($itemTodo);
  94. }
  95. public function updateItem($itemPatch) {
  96. return $this->parentAcl->updateItem($itemPatch);
  97. }
  98. public function getGeomFieldType($fieldName) { return null; }
  99. public function getPrimaryKeyField() { return 'ID'; }
  100. public function getAttributesFromZasoby() {
  101. $attributes = array();// fldName => [ 'id_zasob' => int, 'label' => str, 'description' => str ]
  102. // if ($acl->hasFieldPerm($idZasob, 'W')) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_write", "true");
  103. // if ($acl->hasFieldPerm($idZasob, 'C')) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_create", "true");
  104. // if (!$acl->hasFieldPerm($idZasob, 'R')) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_read", "false");
  105. return $attributes;
  106. }
  107. public function isEnumerationField($fieldName) { return false; }
  108. public function getXsdFieldType($fieldName) {
  109. if ('File' == $fieldName) return 'ref:default_objects:File';
  110. return $this->parentAcl->getXsdFieldType($fieldName);
  111. }
  112. public function isGeomField($fldName) { return $this->parentAcl->isGeomField($fldName); }
  113. }