TestPermsStorageAcl.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. Lib::loadClass('Core_AclBase');
  3. Lib::loadClass('FileStorage');
  4. class 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 getRealFieldListByIdZasob($force = false) {
  15. $cols = $this->parentAcl->getRealFieldListByIdZasob();
  16. $cols[100000] = 'File';
  17. // $cols[100001] = 'NestedObjectTest';
  18. return $cols;
  19. }
  20. public function getFieldIdByName($fieldName) {
  21. $fields = $this->getRealFieldListByIdZasob();
  22. if (empty($fieldName)) return null;
  23. foreach ($fields as $idField => $vFieldName) {
  24. if ($vFieldName == $fieldName) return $idField;
  25. }
  26. return null;
  27. }
  28. public function getFieldType($colName) {
  29. return null;
  30. }
  31. public function isAllowed($idZasob, $taskPerm, $record = null) {
  32. if ('C' == $taskPerm && $idZasob > 1 && $idZasob < 7) return true;
  33. if ('R' == $taskPerm && $idZasob > 0 && $idZasob < 7) return true;
  34. return false;
  35. }
  36. public function hasFieldPerm($idZasob, $taskPerm) {
  37. if ('C' == $taskPerm && $idZasob > 1 && $idZasob < 7) return true;
  38. if ('R' == $taskPerm && $idZasob > 0 && $idZasob < 7) return true;
  39. return false;
  40. }
  41. public function getItems($params = array()) {
  42. $DBG = V::get('DBG_DS', 0, $_GET, 'int');
  43. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$params:";print_r($params);echo "\n";}
  44. $items = array();
  45. $rawItems = $this->parentAcl->getItems($params);
  46. foreach ($rawItems as $pk => $item) $items[$pk] = (array)$item;
  47. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems \$items:";print_r($items);echo "\n";}
  48. if (empty($items)) return $items;
  49. $this->fetchItemRef($items);
  50. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems after fetchItemRef \$items:";print_r($items);echo "\n";}
  51. return $items;
  52. }
  53. public function fetchItemRef(&$items) {
  54. $DBG = V::get('DBG_DS', 0, $_GET, 'int');
  55. $refs = array();// fieldName => xsdType
  56. foreach ($this->getRealFieldListByIdZasob() as $id => $fieldName) {
  57. $fieldType = $this->getXsdFieldType($fieldName);
  58. if ('ref:' == substr($fieldType, 0, 4)) $refs[$fieldName] = substr($fieldType, 4);
  59. }
  60. if (empty($refs)) return $items;
  61. $fidList = array_keys($items);
  62. $sqlPk = array(); foreach ($fidList as $pk) { $sqlPk[] = "'{$pk}'"; } $sqlPk = implode(", ", $sqlPk);
  63. $baseRefTableName = $this->getRootTableName() . "__#REF__";
  64. $refRows = array();// $fieldName => [ pk, ... ]
  65. foreach ($refs as $fieldName => $type) {
  66. $acl = $this->getAclFromTypeName($type);
  67. $refTableName = $this->getRootTableName() . "__#REF__" . $acl->getRootTableName();
  68. $refRows[$fieldName] = DB::getPDO()->fetchAllByKey("
  69. select r.*
  70. from `{$refTableName}` r
  71. where r.PRIMARY_KEY in({$sqlPk})
  72. -- TODO and r.INSTANCE = '{$refInstanceName}' -- for multiple types based on the same root table
  73. ", $key = 'PRIMARY_KEY');
  74. if($DBG>2){echo 'C.'.get_class($this).' L.' . __LINE__ . " getItems loop(\$fieldName:{$fieldName}) \$refTableName:({$refTableName}), \$refRows[$fieldName]";print_r($refRows[$fieldName]);echo"\n";}
  75. }
  76. foreach ($refRows as $fieldName => $refList) {
  77. foreach ($refList as $pk => $ref) {
  78. $items[ $pk ][ $fieldName ][] = array('xlink' => "{$refs[$fieldName]}.{$ref['REMOTE_PRIMARY_KEY']}");
  79. }
  80. }
  81. }
  82. public function addItem($itemTodo) {
  83. return $this->parentAcl->addItem($itemTodo);
  84. }
  85. public function updateItem($itemPatch) {
  86. return $this->parentAcl->updateItem($itemPatch);
  87. }
  88. public function getGeomFieldType($fieldName) { return null; }
  89. public function getPrimaryKeyField() { return 'ID'; }
  90. public function getID() { return 0; }
  91. public function getAttributesFromZasoby() {
  92. $attributes = array();// fldName => [ 'id_zasob' => int, 'label' => str, 'description' => str ]
  93. // if ($acl->hasFieldPerm($idZasob, 'W')) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_write", "true");
  94. // if ($acl->hasFieldPerm($idZasob, 'C')) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_create", "true");
  95. // if (!$acl->hasFieldPerm($idZasob, 'R')) $elNode->setAttributeNS($rootWfsNsUri, "{$rootWfsNs}:allow_read", "false");
  96. return $attributes;
  97. }
  98. public function isEnumerationField($fieldName) {
  99. if ('A_STATUS' == $fieldName) return true;
  100. return false;
  101. }
  102. public function getEnumerations($fieldName) {
  103. if ('A_STATUS' == $fieldName) return $this->parentAcl->getEnumerations($fieldName);
  104. return null;
  105. }
  106. public function validateFieldAction($fieldName, $taskPerm, $record = null) {
  107. if ('File' == $fieldName) {
  108. // return 'ref:p5_objects:File';
  109. return true;
  110. }
  111. // if ('NestedObjectTest' == $fieldName) {
  112. // // return 'ref:p5_objects:NestedObjectTest';
  113. // return true;
  114. // }
  115. return $this->parentAcl->isAllowed($fieldID = $this->parentAcl->getFieldIdByName($fieldName), $taskPerm, $record);
  116. }
  117. public function getXsdFieldType($fieldName) {
  118. if ('File' == $fieldName) return 'ref:p5_objects:File';
  119. // if ('NestedObjectTest' == $fieldName) return 'local_ref:p5_objects:NestedObjectTest';
  120. return $this->parentAcl->getXsdFieldType($fieldName);
  121. }
  122. public function isGeomField($fldName) {
  123. if ('File' == $fieldName) return false;
  124. // if ('NestedObjectTest' == $fieldName) return false;
  125. return $this->parentAcl->isGeomField($fldName);
  126. }
  127. }