UserProcessStorageAcl.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. Lib::loadClass('Core_AclSimpleSchemaBase');
  3. Lib::loadClass('ParseOgcFilter');
  4. class Schema_UserProcessStorageAcl extends Core_AclSimpleSchemaBase {
  5. public $_simpleSchema = [
  6. 'root' => [
  7. '@namespace' => 'default_objects/UserProcess',
  8. 'ID' => [ '@type' => 'xsd:integer' ],
  9. 'nazwa' => [ '@type' => 'xsd:string', '@alias' => 'DESC' ],
  10. 'opis' => [ '@type' => 'xsd:string', '@alias' => 'OPIS' ],
  11. 'link_uruchom_filtr_procesu' => [ '@type' => 'p5:www_link' ],
  12. 'autor' => [ '@type' => 'xsd:string' , '@alias' => 'A_RECORD_CREATE_AUTHOR' ],
  13. 'utworzono' => [ '@type' => 'xsd:date' , '@alias' => 'A_RECORD_CREATE_DATE' ],
  14. 'zaktualizował' => [ '@type' => 'xsd:string' , '@alias' => 'A_RECORD_UPDATE_AUTHOR' ],
  15. 'zaktualizowano' => [ '@type' => 'xsd:date', '@alias' => 'A_RECORD_UPDATE_DATE' ]
  16. ]
  17. ];
  18. public $_rootTableName = 'CRM_PROCES';
  19. public function getTotal($params = []) {
  20. $sqlWhereAnd = $this->_parseSqlWhere($params);
  21. $idGroupList = $this->_getUserIdGroupList();
  22. if (empty($idGroupList)) throw new Exception("Brak przyipsanych grup do użytwkonika");
  23. $sqlIdGroupCsv = implode(",", $idGroupList);
  24. return DB::getPDO()->fetchValue("
  25. select count(1) as total
  26. from `CRM_PROCES` p
  27. where p.`TYPE` = 'PROCES_INIT'
  28. and p.`A_STATUS` not in('DELETED', 'OFF_HARD', 'OFF_SOFT')
  29. and p.ID in (
  30. select gi.ID_PROCES_INIT
  31. from `CRM_PROCES_idx_GROUP_to_INIT_VIEW` as gi
  32. where gi.ID_GROUP in({$sqlIdGroupCsv})
  33. )
  34. {$sqlWhereAnd}
  35. ");
  36. }
  37. public function _parseSqlWhere($params = []) {
  38. $sqlWhereAnd = "";
  39. // TODO: parse where/ogc, etc.
  40. return $sqlWhereAnd;
  41. }
  42. public function getItems($params = []) {
  43. $sqlOrderBy = "";
  44. $sqlLimitOffset = "";
  45. $sqlWhereAnd = $this->_parseSqlWhere($params);
  46. $currSortCol = V::get('order_by', 'ID', $params);
  47. $currSortFlip = strtolower(V::get('order_dir', 'desc', $params));
  48. // TODO: validate $currSortCol is in field list
  49. // TODO: validate $currSortFlip ('asc' or 'desc')
  50. $aliasMap = array();
  51. foreach ($this->_simpleSchema['root'] as $key => $field) {
  52. if ('@' === substr($key, 0, 1)) continue;
  53. $aliasMap[ $key ] = (!empty($field['@alias'])) ? $field['@alias'] : $key;
  54. }
  55. // TODO: if (!array_key_exists($currSortCol, $aliasMap)) throw new Exception("field name not allowed to sort");
  56. $currSortCol = (array_key_exists($currSortCol, $aliasMap)) ? $aliasMap[$currSortCol] : null;
  57. if (!empty($currSortCol) && ('asc' == $currSortFlip || 'desc' == $currSortFlip)) {
  58. $sqlOrderBy = "order by p.`{$currSortCol}` {$currSortFlip}";
  59. }
  60. $limit = V::get('limit', 0, $params);
  61. $limit = ($limit < 0) ? 0 : $limit;
  62. $offset = V::get('limitstart', 0, $params);
  63. $offset = ($offset < 0) ? 0 : $offset;
  64. if ($limit > 0) $sqlLimitOffset = "limit {$limit} offset {$offset}";
  65. $idGroupList = $this->_getUserIdGroupList();
  66. if (empty($idGroupList)) throw new Exception("Brak przyipsanych grup do użytwkonika");
  67. $sqlIdGroupCsv = implode(",", $idGroupList);
  68. $items = DB::getPDO()->fetchAllByKey("
  69. select p.ID
  70. , p.`DESC` as nazwa
  71. , p.`OPIS` as opis
  72. , p.A_RECORD_CREATE_AUTHOR as `autor`
  73. , p.A_RECORD_CREATE_DATE as `utworzono`
  74. , p.A_RECORD_UPDATE_AUTHOR as `zaktualizował`
  75. , p.A_RECORD_UPDATE_DATE as `zaktualizowano`
  76. from `CRM_PROCES` p
  77. where p.`TYPE` = 'PROCES_INIT'
  78. and p.`A_STATUS` not in('DELETED', 'OFF_HARD', 'OFF_SOFT')
  79. and p.ID in (
  80. select gi.ID_PROCES_INIT
  81. from `CRM_PROCES_idx_GROUP_to_INIT_VIEW` as gi
  82. where gi.ID_GROUP in({$sqlIdGroupCsv})
  83. )
  84. {$sqlWhereAnd}
  85. group by p.ID
  86. {$sqlOrderBy}
  87. {$sqlLimitOffset}
  88. ", 'ID');
  89. array_walk($items, function (&$item, $key) {
  90. $item['link_uruchom_filtr_procesu'] = Request::getPathUri() . "index.php?FUNCTION_INIT=MENU_SELECT_PROCES&_action=setPermsByProces&id_proces={$item['ID']}";
  91. });
  92. return $items;
  93. }
  94. public function _getUserIdGroupList() {
  95. $idUser = User::getID();
  96. return array_map(
  97. function ($row) {
  98. return $row['ID'];
  99. }
  100. , DB::getPDO()->fetchAll("
  101. select z.ID
  102. from `CRM_AUTH_PROFILE` as up
  103. left join `CRM_LISTA_ZASOBOW` as z on(z.`ID`=up.`ID_ZASOB`)
  104. where
  105. up.`REMOTE_ID`='{$idUser}'
  106. and up.`A_STATUS` in('WAITING', 'NORMAL')
  107. and up.`REMOTE_TABLE`='ADMIN_USERS'
  108. and z.`ID` is not null
  109. and z.`TYPE` in('STANOWISKO','PODMIOT','DZIAL')
  110. ")
  111. );
  112. }
  113. }