TestPermsStorageAcl.php 7.7 KB

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