TestPermsStorageAcl.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. Lib::loadClass('Core_AclBase');
  3. Lib::loadClass('FileStorage');
  4. class Schema_TestPermsStorageAcl extends Core_AclBase {
  5. public function __construct() {
  6. $this->parentAcl = User::getAcl()->getObjectAcl('default_db', 'TEST_PERMS');
  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 'TestPerms'; }
  14. public function getRootTableName() { return 'TEST_PREMS'; }
  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. // $cols[100010] = 'File1';
  22. // $cols[100011] = 'File2';
  23. // $cols[100001] = 'NestedObjectTest';
  24. $cols[100002] = 'AccessGroupRead';
  25. $cols[100003] = 'AccessGroupWrite';
  26. $cols[100004] = 'AccessOwner';
  27. return $cols;
  28. }
  29. public function getFields() {// @returns array - $this->_fields
  30. $fields = $this->parentAcl->getFields();
  31. $fields[100000] = ['name'=>'File', 'perms'=>'RWXC', 'opis'=>'Plik', 'sort_prio'=>999, 'label'=>'Plik'];
  32. // $fields[100001] = 'NestedObjectTest';
  33. $fields[100002] = ['name'=>'AccessGroupRead', 'perms'=>'RWXC', 'opis'=>'Odczyt dla', 'sort_prio'=>999, 'label'=>'Odczyt dla'];
  34. $fields[100003] = ['name'=>'AccessGroupWrite', 'perms'=>'RWXC', 'opis'=>'Zapis dla', 'sort_prio'=>999, 'label'=>'Zapis dla'];
  35. $fields[100004] = ['name'=>'AccessOwner', 'perms'=>'RWXC', 'opis'=>'Osoba odpowiedzialna', 'sort_prio'=>999, 'label'=>'Osoba odp.'];
  36. return $fields;
  37. }
  38. public function getFieldType($fieldName) {
  39. foreach ($this->getFields() as $field) {
  40. if ($fieldName == $field['name']) return $field;
  41. }
  42. return null;
  43. }
  44. // TODO: replace legacy functions: isAllowed, hasFieldPerm, getFieldIdByName
  45. public function canCreateField($fieldName) {
  46. if ('File' == $fieldName) return true;
  47. if ('AccessGroupRead' == $fieldName) return true;
  48. if ('AccessGroupWrite' == $fieldName) return true;
  49. if ('AccessOwner' == $fieldName) return true;
  50. return $this->parentAcl->canCreateField($fieldName);
  51. }
  52. public function canReadField($fieldName) {
  53. if ('File' == $fieldName) return true;
  54. if ('AccessGroupRead' == $fieldName) return true;
  55. if ('AccessGroupWrite' == $fieldName) return true;
  56. if ('AccessOwner' == $fieldName) return true;
  57. return $this->parentAcl->canReadField($fieldName);
  58. }
  59. public function canReadObjectField($fieldName, $record) {
  60. if ('File' == $fieldName) return true;
  61. if ('AccessGroupRead' == $fieldName) return true;
  62. if ('AccessGroupWrite' == $fieldName) return true;
  63. if ('AccessOwner' == $fieldName) return true;
  64. return $this->parentAcl->canReadObjectField($fieldName, $record);
  65. }
  66. public function canWriteField($fieldName) {
  67. if ('File' == $fieldName) return true;
  68. if ('AccessGroupRead' == $fieldName) return true;
  69. if ('AccessGroupWrite' == $fieldName) return true;
  70. if ('AccessOwner' == $fieldName) return true;
  71. return $this->parentAcl->canWriteField($fieldName);
  72. }
  73. public function canWriteObjectField($fieldName, $record) {
  74. if ('File' == $fieldName) return true;
  75. if ('AccessGroupRead' == $fieldName) return true;
  76. if ('AccessGroupWrite' == $fieldName) return true;
  77. if ('AccessOwner' == $fieldName) return true;
  78. return $this->parentAcl->canWriteObjectField($fieldName, $record);
  79. }
  80. public function getTotal($params = array()) {// TODO: use ParseOgcQuery
  81. $DBG = V::get('DBG_DS', 0, $_GET, 'int');
  82. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getTotal \$params:";print_r($params);echo "\n";}
  83. return $this->parentAcl->getTotal($params);
  84. }
  85. public function getItems($params = array()) {// TODO: use ParseOgcQuery
  86. $DBG = V::get('DBG_DS', 0, $_GET, 'int');
  87. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$params:";print_r($params);echo "\n";}
  88. $items = array();
  89. $rawItems = $this->parentAcl->getItems($params);
  90. foreach ($rawItems as $pk => $item) $items[$pk] = (array)$item;
  91. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$items:";print_r($items);echo "\n";}
  92. if (empty($items)) return $items;
  93. $this->fetchItemRef($items);// TODO: only fields from request
  94. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems after fetchItemRef \$items:";print_r($items);echo "\n";}
  95. return $items;
  96. }
  97. public function fetchItemRef(&$items) {
  98. $DBG = V::get('DBG_DS', 0, $_GET, 'int');
  99. $refs = array();// fieldName => xsdType
  100. foreach ($this->getRealFieldListByIdZasob() as $id => $fieldName) {
  101. $fieldType = $this->getXsdFieldType($fieldName);
  102. if ('ref:' == substr($fieldType, 0, 4)) $refs[$fieldName] = substr($fieldType, 4);
  103. else if ('alias_ref:' == substr($fieldType, 0, 10)) {
  104. $refs[$fieldName] = substr($fieldType, 10);
  105. }
  106. }
  107. if (empty($refs)) return $items;
  108. $pkList = array_keys($items);
  109. $sqlPk = array(); foreach ($pkList as $pk) { $sqlPk[] = DB::getPDO()->quote($pk, PDO::PARAM_STR); } $sqlPk = implode(", ", $sqlPk);
  110. $refRows = array();// $fieldName => [ pk, ... ]
  111. foreach ($refs as $fieldName => $type) {
  112. $acl = $this->getAclFromTypeName($type);
  113. // TODO: Core_AclBase->fetchRefs($fieldName, $pkList = array());// $refPk[$fieldName] = $this->fetchRefs($fieldName, $pkList);
  114. $refTableName = $this->createRefTable($fieldName);
  115. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems loop(\$fieldName:{$fieldName}) \$refTableName:({$refTableName})";echo"\n";}
  116. $refRows[$fieldName] = DB::getPDO()->fetchAllByKey("
  117. select r.*
  118. from `{$refTableName}` r
  119. where r.PRIMARY_KEY in({$sqlPk})
  120. ", $key = 'PRIMARY_KEY');
  121. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems loop(\$fieldName:{$fieldName}) \$refTableName:({$refTableName}), \$refRows[$fieldName]";print_r($refRows[$fieldName]);echo"\n";}
  122. }
  123. foreach ($refRows as $fieldName => $refList) {
  124. foreach ($refList as $pk => $ref) {
  125. $items[ $pk ][ $fieldName ][] = array('xlink' => "{$refs[$fieldName]}.{$ref['REMOTE_PRIMARY_KEY']}");
  126. }
  127. }
  128. }
  129. public function addItem($itemTodo) {
  130. return $this->parentAcl->addItem($itemTodo);
  131. }
  132. public function updateItem($itemPatch) {
  133. return $this->parentAcl->updateItem($itemPatch);
  134. }
  135. public function getGeomFieldType($fieldName) { return null; }
  136. public function getPrimaryKeyField() { return 'ID'; }
  137. public function getID() { return 0; }
  138. public function getAttributesFromZasoby() { return array(); }
  139. public function isEnumerationField($fieldName) {
  140. if ('A_STATUS' == $fieldName) return true;
  141. return false;
  142. }
  143. public function getEnumerations($fieldName) {
  144. if ('A_STATUS' == $fieldName) return $this->parentAcl->getEnumerations($fieldName);
  145. return null;
  146. }
  147. public function getXsdFieldType($fieldName) {
  148. if ('File' == $fieldName) return 'ref:p5_objects:File';
  149. // if ('File1' == $fieldName) return 'alias_ref:p5_objects:File';
  150. // if ('File2' == $fieldName) return 'alias_ref:p5_objects:File';
  151. // if ('NestedObjectTest' == $fieldName) return 'local_ref:p5_objects:NestedObjectTest';
  152. if ('AccessGroupRead' == $fieldName) return 'alias_ref:p5_objects:AccessGroup';
  153. if ('AccessGroupWrite' == $fieldName) return 'alias_ref:p5_objects:AccessGroup';
  154. if ('AccessOwner' == $fieldName) return 'ref:p5_objects:AccessOwner';
  155. return $this->parentAcl->getXsdFieldType($fieldName);
  156. }
  157. public function isGeomField($fldName) {
  158. if ('File' == $fieldName) return false;
  159. if ('AccessGroupRead' == $fieldName) return false;
  160. if ('AccessGroupWrite' == $fieldName) return false;
  161. if ('AccessOwner' == $fieldName) return false;
  162. // if ('NestedObjectTest' == $fieldName) return false;
  163. return $this->parentAcl->isGeomField($fldName);
  164. }
  165. }