ZaliczkaStorageAcl.php 7.9 KB

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