TestPermsStorageAcl.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. Lib::loadClass('Core_AclBase');
  3. Lib::loadClass('Core_AclHelper');
  4. Lib::loadClass('FileStorage');
  5. class Schema_TestPermsStorageAcl extends Core_AclBase {
  6. public function __construct() {
  7. $this->parentAcl = User::getAcl()->getObjectAcl('default_db', 'TEST_PERMS');
  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 'TestPerms'; }
  15. public function getRootTableName() { return 'TEST_PREMS'; }
  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. // $cols[100010] = 'File1';
  23. // $cols[100011] = 'File2';
  24. // $cols[100001] = 'NestedObjectTest';
  25. $cols[100002] = 'AccessGroupRead';
  26. $cols[100003] = 'AccessGroupWrite';
  27. $cols[100004] = 'AccessOwner';
  28. return $cols;
  29. }
  30. public function getFields() {// @returns array - $this->_fields
  31. $fields = $this->parentAcl->getFields();
  32. $fields[100000] = ['name'=>'File', 'perms'=>'RWXC', 'opis'=>'Plik', 'sort_prio'=>999, 'label'=>'Plik'];
  33. // $fields[100001] = 'NestedObjectTest';
  34. $fields[100002] = ['name'=>'AccessGroupRead', 'perms'=>'RWXC', 'opis'=>'Odczyt dla', 'sort_prio'=>999, 'label'=>'Odczyt dla'];
  35. $fields[100003] = ['name'=>'AccessGroupWrite', 'perms'=>'RWXC', 'opis'=>'Zapis dla', 'sort_prio'=>999, 'label'=>'Zapis dla'];
  36. $fields[100004] = ['name'=>'AccessOwner', 'perms'=>'RWXC', 'opis'=>'Osoba odpowiedzialna', 'sort_prio'=>999, 'label'=>'Osoba odp.'];
  37. return $fields;
  38. }
  39. public function getFieldType($fieldName) {
  40. foreach ($this->getFields() as $field) {
  41. if ($fieldName == $field['name']) return $field;
  42. }
  43. return null;
  44. }
  45. // TODO: replace legacy functions: isAllowed, hasFieldPerm, getFieldIdByName
  46. public function canCreateField($fieldName) {
  47. if ('File' == $fieldName) return true;
  48. if ('AccessGroupRead' == $fieldName) return true;
  49. if ('AccessGroupWrite' == $fieldName) return true;
  50. if ('AccessOwner' == $fieldName) return true;
  51. return $this->parentAcl->canCreateField($fieldName);
  52. }
  53. public function canReadField($fieldName) {
  54. if ('File' == $fieldName) return true;
  55. if ('AccessGroupRead' == $fieldName) return true;
  56. if ('AccessGroupWrite' == $fieldName) return true;
  57. if ('AccessOwner' == $fieldName) return true;
  58. return $this->parentAcl->canReadField($fieldName);
  59. }
  60. public function canReadObjectField($fieldName, $record) {
  61. if ('File' == $fieldName) return true;
  62. if ('AccessGroupRead' == $fieldName) return true;
  63. if ('AccessGroupWrite' == $fieldName) return true;
  64. if ('AccessOwner' == $fieldName) return true;
  65. return $this->parentAcl->canReadObjectField($fieldName, $record);
  66. }
  67. public function canWriteField($fieldName) {
  68. if ('File' == $fieldName) return true;
  69. if ('AccessGroupRead' == $fieldName) return true;
  70. if ('AccessGroupWrite' == $fieldName) return true;
  71. if ('AccessOwner' == $fieldName) return true;
  72. return $this->parentAcl->canWriteField($fieldName);
  73. }
  74. public function canWriteObjectField($fieldName, $record) {
  75. if ('File' == $fieldName) return true;
  76. if ('AccessGroupRead' == $fieldName) return true;
  77. if ('AccessGroupWrite' == $fieldName) return true;
  78. if ('AccessOwner' == $fieldName) return true;
  79. return $this->parentAcl->canWriteObjectField($fieldName, $record);
  80. }
  81. public function getTotal($params = array()) {// TODO: use ParseOgcQuery
  82. $DBG = V::get('DBG_DS', 0, $_GET, 'int');
  83. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getTotal \$params:";print_r($params);echo "\n";}
  84. return $this->parentAcl->getTotal($params);
  85. }
  86. public function getItem($primaryKey, $params = []) {
  87. $items = $this->getItems(['primaryKey'=>$primaryKey]);
  88. return (!empty($items[$primaryKey])) ? $items[$primaryKey] : null;
  89. }
  90. public function getItems($params = array()) {// TODO: use ParseOgcQuery
  91. $DBG = V::get('DBG_DS', 0, $_GET, 'int');
  92. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$params:";print_r($params);echo "\n";}
  93. $items = array();
  94. $rawItems = $this->parentAcl->getItems($params);
  95. foreach ($rawItems as $pk => $item) $items[$pk] = (array)$item;
  96. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$items:";print_r($items);echo "\n";}
  97. if (empty($items)) return $items;
  98. $this->itemsFetchRefs($items);// TODO: only fields from request
  99. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems after itemsFetchRefs \$items:";print_r($items);echo "\n";}
  100. return $items;
  101. }
  102. public function addItem($itemTodo) {
  103. return $this->parentAcl->addItem($itemTodo);
  104. }
  105. public function updateItem($itemPatch) {
  106. return $this->parentAcl->updateItem($itemPatch);
  107. }
  108. public function getGeomFieldType($fieldName) { return ('the_geom' == $fieldName) ? 'polygon' : null; }
  109. public function getPrimaryKeyField() { return 'ID'; }
  110. public function getID() { return 0; }
  111. public function getAttributesFromZasoby() { return array(); }
  112. public function isEnumerationField($fieldName) {
  113. if ('A_STATUS' == $fieldName) return true;
  114. return false;
  115. }
  116. public function getEnumerations($fieldName) {
  117. if ('A_STATUS' == $fieldName) return $this->parentAcl->getEnumerations($fieldName);
  118. return null;
  119. }
  120. public function getXsdFieldType($fieldName) {
  121. if ('File' == $fieldName) return 'ref:default_objects:File';
  122. // if ('File1' == $fieldName) return 'alias_ref:p5_objects:File';
  123. // if ('File2' == $fieldName) return 'alias_ref:p5_objects:File';
  124. // if ('NestedObjectTest' == $fieldName) return 'local_ref:p5_objects:NestedObjectTest';
  125. if ('AccessGroupRead' == $fieldName) return 'ref:default_objects:AccessGroupRead';
  126. if ('AccessGroupWrite' == $fieldName) return 'ref:default_objects:AccessGroupWrite';
  127. if ('AccessOwner' == $fieldName) return 'ref:default_objects:AccessOwner';
  128. return $this->parentAcl->getXsdFieldType($fieldName);
  129. }
  130. public function isGeomField($fldName) {
  131. if ('File' == $fieldName) return false;
  132. if ('AccessGroupRead' == $fieldName) return false;
  133. if ('AccessGroupWrite' == $fieldName) return false;
  134. if ('AccessOwner' == $fieldName) return false;
  135. // if ('NestedObjectTest' == $fieldName) return false;
  136. return $this->parentAcl->isGeomField($fldName);
  137. }
  138. }