TestPermsStorageAcl.php 7.6 KB

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