SystemObjectStorageAcl.php 4.6 KB

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