SystemObjectStorageAcl.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. Lib::loadClass('Core_AclSimpleSchemaBase');
  3. Lib::loadClass('ParseOgcFilter');
  4. class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
  5. public $_simpleSchema = [
  6. 'root' => [
  7. '@namespace' => 'default_objects/SystemObject',
  8. 'ID' => [ '@type' => 'xsd:integer' ],
  9. 'namespace' => [ '@type' => 'xsd:string' ],
  10. 'tabela' => [ '@type' => 'xsd:string', '@alias' => 'DESC' ],
  11. 'nazwa' => [ '@type' => 'xsd:string', '@alias' => 'DESC' ],
  12. 'opis' => [ '@type' => 'xsd:string', '@alias' => 'OPIS' ],
  13. 'id_zasob' => [ '@type' => 'xsd:integer' ],
  14. 'A_RECORD_CREATE_AUTHOR' => [ '@type' => 'xsd:string' ],
  15. 'A_RECORD_CREATE_DATE' => [ '@type' => 'xsd:date' ],
  16. 'A_RECORD_UPDATE_AUTHOR' => [ '@type' => 'xsd:string' ],
  17. 'A_RECORD_UPDATE_DATE' => [ '@type' => 'xsd:date' ],
  18. ]
  19. ];
  20. public $_rootTableName = 'CRM_LISTA_ZASOBOW';
  21. public function getTotal($params = []) {
  22. return count($this->_getAllItems());
  23. }
  24. public function getItems($params = []) {
  25. $items = $this->_getAllItems();
  26. $currSortCol = V::get('order_by', 'ID', $params);
  27. $currSortFlip = strtolower(V::get('order_dir', 'desc', $params));
  28. // TODO: validate $currSortCol is in field list
  29. // TODO: validate $currSortFlip ('asc' or 'desc')
  30. if (!empty($currSortCol) && ('asc' == $currSortFlip || 'desc' == $currSortFlip)) {
  31. usort($items, function ($itemA, $itemB) use ($currSortCol, $currSortFlip) {
  32. $a = strtolower(V::get($currSortCol, '', $itemA));
  33. $b = strtolower(V::get($currSortCol, '', $itemB));
  34. if ($a == $b) return 0;
  35. else if ('asc' == $currSortFlip) return ($a < $b) ? -1 : 1;
  36. else if ('desc' == $currSortFlip) return ($a > $b) ? -1 : 1;
  37. throw new Exception("BUG - Wrong sort param - order dir");
  38. });
  39. }
  40. $limit = V::get('limit', 0, $params);
  41. $limit = ($limit < 0) ? 0 : $limit;
  42. $offset = V::get('limitstart', 0, $params);
  43. $offset = ($offset < 0) ? 0 : $offset;
  44. return ($limit > 0)
  45. ? $this->_fixKeyItems(array_splice($items, $offset, $limit))
  46. : $this->_fixKeyItems(array_splice($items, $offset));
  47. }
  48. public function _fixKeyItems($items) {
  49. $fixed = array();
  50. foreach ($items as $item) {
  51. $fixed[ $this->_generateUniqueKeyFromNamespace($item['namespace']) ] = $item;
  52. }
  53. return $fixed;
  54. }
  55. public function _generateUniqueKeyFromNamespace($namespace) {
  56. return str_replace('/', '__x3A__', $namespace);
  57. }
  58. public function _getAllItems($params = []) {
  59. static $_cacheAllItems = null;
  60. if (null !== $_cacheAllItems) return $_cacheAllItems;
  61. $idMainDatabase = DB::getPDO()->getZasobId();
  62. $_cacheAllItems = array_filter(
  63. array_merge(
  64. array_map(
  65. function ($row) {
  66. $row['namespace'] = "default_db/{$row['tabela']}";
  67. $row['ID'] = $this->_generateUniqueKeyFromNamespace($row['namespace']);
  68. return $row;
  69. }
  70. , DB::getPDO()->fetchAll("
  71. select z.ID as id_zasob
  72. , z.`DESC` as tabela
  73. , IF(z.`DESC_PL` != '', z.`DESC_PL`, z.`DESC`) as nazwa
  74. , z.`OPIS` as opis
  75. , z.A_RECORD_CREATE_AUTHOR
  76. , z.A_RECORD_CREATE_DATE
  77. , z.A_RECORD_UPDATE_AUTHOR
  78. , z.A_RECORD_UPDATE_DATE
  79. from `CRM_LISTA_ZASOBOW` z
  80. where z.PARENT_ID = {$idMainDatabase}
  81. and z.`TYPE` = 'TABELA'
  82. and z.`A_STATUS` not in('DELETED', 'OFF_HARD', 'OFF_SOFT')
  83. ")
  84. )
  85. , array_map(
  86. function ($typeName) {
  87. $namespace = str_replace(':', '/', $typeName);
  88. $namespace = str_replace('__x3A__', '/', $namespace);
  89. return [
  90. 'ID' => $this->_generateUniqueKeyFromNamespace($namespace),
  91. 'namespace' => $namespace,
  92. 'tabela' => '', // TODO: $acl->getRootTableName(),
  93. 'nazwa' => substr($typeName, strrpos($typeName, ':') + 1),
  94. 'opis' => '...',
  95. 'A_RECORD_CREATE_AUTHOR' => '',
  96. 'A_RECORD_CREATE_DATE' => '',
  97. 'A_RECORD_UPDATE_AUTHOR' => '',
  98. 'A_RECORD_UPDATE_DATE' => ''
  99. ];
  100. }
  101. , Core_AclHelper::getAclList()
  102. )
  103. )
  104. , function ($item) use ($params) {
  105. return true;
  106. }
  107. );
  108. return $_cacheAllItems;
  109. }
  110. }