UserProcessStorageAcl.php 4.9 KB

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