UserProcessStorageAcl.php 4.3 KB

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