SystemFunctionStorageAcl.php 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. Lib::loadClass('Core_AclSimpleSchemaBase');
  3. Lib::loadClass('ParseOgcFilter');
  4. class Schema_SystemFunctionStorageAcl extends Core_AclSimpleSchemaBase {
  5. public $_simpleSchema = [
  6. 'root' => [
  7. '@namespace' => 'default_objects/SystemFunction',
  8. '@primaryKey' => 'name',
  9. 'name' => [ '@type' => 'xsd:string' ],
  10. 'description' => [ '@type' => 'xsd:string', '@label' => "Opis" ],
  11. 'param' => [ '@type' => 'xsd:string', '@label' => "Parametry", '@macOccurs' => 'unbounded' ],
  12. // 'autor' => [ '@type' => 'xsd:string' ],
  13. // 'utworzono' => [ '@type' => 'xsd:date' ],
  14. // 'zaktualizował' => [ '@type' => 'xsd:string' ],
  15. // 'zaktualizowano' => [ '@type' => 'xsd:date' ]
  16. ]
  17. ];
  18. public $_rootTableName = 'CRM_LISTA_ZASOBOW';
  19. public function getTotal($params = []) {
  20. return count($this->_getAllItems());
  21. }
  22. public function getItems($params = []) {
  23. $items = $this->_getAllItems();
  24. $currSortCol = V::get('order_by', 'ID', $params);
  25. $currSortFlip = strtolower(V::get('order_dir', 'desc', $params));
  26. // TODO: validate $currSortCol is in field list
  27. // TODO: validate $currSortFlip ('asc' or 'desc')
  28. $aliasMap = array();
  29. foreach ($this->_simpleSchema['root'] as $key => $field) {
  30. if ('@' === substr($key, 0, 1)) continue;
  31. $aliasMap[ $key ] = $key;// (!empty($field['@alias'])) ? $field['@alias'] : $key;
  32. }
  33. // TODO: if (!array_key_exists($currSortCol, $aliasMap)) throw new Exception("field name not allowed to sort");
  34. $currSortCol = (array_key_exists($currSortCol, $aliasMap)) ? $aliasMap[$currSortCol] : null;
  35. if (!empty($currSortCol) && ('asc' == $currSortFlip || 'desc' == $currSortFlip)) {
  36. usort($items, function ($itemA, $itemB) use ($currSortCol, $currSortFlip) {
  37. $a = strtolower(V::get($currSortCol, '', $itemA));
  38. $b = strtolower(V::get($currSortCol, '', $itemB));
  39. if ($a == $b) return 0;
  40. else if ('asc' == $currSortFlip) return ($a < $b) ? -1 : 1;
  41. else if ('desc' == $currSortFlip) return ($a > $b) ? -1 : 1;
  42. throw new Exception("BUG - Wrong sort param - order dir");
  43. });
  44. }
  45. $limit = V::get('limit', 0, $params);
  46. $limit = ($limit < 0) ? 0 : $limit;
  47. $offset = V::get('limitstart', 0, $params);
  48. $offset = ($offset < 0) ? 0 : $offset;
  49. return array_slice($items, $offset, ($limit > 0) ? $limit : null, $preserve_keys = true);
  50. }
  51. public function _getAllItems($params = []) {
  52. static $_cacheAllItems = null;
  53. if (null !== $_cacheAllItems) return $_cacheAllItems;
  54. $_cacheAllItems = [];
  55. $_cacheAllItems[] = [ 'name' => "Calendar", 'description' => "Calendar" ];
  56. $_cacheAllItems[] = [ 'name' => "ProcesEditor", 'description' => "ProcesEditor" ];
  57. $_cacheAllItems[] = [ 'name' => "ProcesView", 'description' => "ProcesView" ];
  58. $_cacheAllItems[] = [ 'name' => "ProjektyKosztorys", 'description' => "ProjektyKosztorys" ];
  59. $_cacheAllItems[] = [ 'name' => "ProjektyKosztyWstepnychRobot", 'description' => "ProjektyKosztyWstepnychRobot" ];
  60. $_cacheAllItems[] = [ 'name' => "ProjektyOdbiorKosztorys", 'description' => "ProjektyOdbiorKosztorys" ];
  61. $_cacheAllItems[] = [ 'name' => "ProjektyOfertaAdminKosztorys", 'description' => "ProjektyOfertaAdminKosztorys" ];
  62. $_cacheAllItems[] = [ 'name' => "ProjektyOfertaKosztorys", 'description' => "ProjektyOfertaKosztorys" ];
  63. $_cacheAllItems[] = [ 'name' => "ProjektyProNetMediaApproveZam", 'description' => "ProjektyProNetMediaApproveZam" ];
  64. $_cacheAllItems[] = [ 'name' => "ProjektyProNetMediaBudget", 'description' => "ProjektyProNetMediaBudget" ];
  65. $_cacheAllItems[] = [ 'name' => "ProjektyProNetMediaFinalApproveZam", 'description' => "ProjektyProNetMediaFinalApproveZam" ];
  66. $_cacheAllItems[] = [ 'name' => "ProjektyProNetMediaRequestApproveZam", 'description' => "ProjektyProNetMediaRequestApproveZam" ];
  67. $_cacheAllItems[] = [ 'name' => "ProjektyProNetMediaZamZlec", 'description' => "ProjektyProNetMediaZamZlec" ];
  68. $_cacheAllItems[] = [ 'name' => "ProjektyPrzedmiarKosztorys", 'description' => "ProjektyPrzedmiarKosztorys" ];
  69. $_cacheAllItems[] = [ 'name' => "ProjektyZamowieniaKosztorys", 'description' => "ProjektyZamowieniaKosztorys" ];
  70. $_cacheAllItems[] = [ 'name' => "ProjektyZestawienieSwMikRurKosztorys", 'description' => "ProjektyZestawienieSwMikRurKosztorys" ];
  71. $_cacheAllItems[] = [ 'name' => "RaportyKasowe", 'description' => "RaportyKasowe" ];
  72. $_cacheAllItems[] = [ 'name' => "UserProNetMediaZaliczka", 'description' => "UserProNetMediaZaliczka" ];
  73. $_cacheAllItems[] = [ 'name' => "WmsGenerate", 'description' => "WmsGenerate" ];
  74. return $_cacheAllItems;
  75. }
  76. }