SystemProcessStorageAcl.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. Lib::loadClass('Core_AclSimpleSchemaBase');
  3. Lib::loadClass('ParseOgcFilter');
  4. class Schema_SystemProcessStorageAcl extends Core_AclSimpleSchemaBase {
  5. public $_simpleSchema = [
  6. 'root' => [
  7. '@namespace' => 'default_objects/SystemProcess',
  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. return DB::getPDO()->fetchValue("
  21. select count(1) as total
  22. from `CRM_PROCES` p
  23. where p.`TYPE` = 'PROCES_INIT'
  24. and p.`A_STATUS` not in('DELETED', 'OFF_HARD', 'OFF_SOFT')
  25. {$sqlWhereAnd}
  26. ");
  27. }
  28. public function _parseSqlWhere($params = []) {
  29. $sqlWhereAnd = "";
  30. // TODO: parse where/ogc, etc.
  31. return $sqlWhereAnd;
  32. }
  33. public function getItems($params = []) {
  34. $sqlOrderBy = "";
  35. $sqlLimitOffset = "";
  36. $sqlWhereAnd = $this->_parseSqlWhere($params);
  37. $currSortCol = V::get('order_by', 'ID', $params);
  38. $currSortFlip = strtolower(V::get('order_dir', 'desc', $params));
  39. // TODO: validate $currSortCol is in field list
  40. // TODO: validate $currSortFlip ('asc' or 'desc')
  41. $aliasMap = array();
  42. foreach ($this->_simpleSchema['root'] as $key => $field) {
  43. if ('@' === substr($key, 0, 1)) continue;
  44. $aliasMap[ $key ] = (!empty($field['@alias'])) ? $field['@alias'] : $key;
  45. }
  46. // TODO: if (!array_key_exists($currSortCol, $aliasMap)) throw new Exception("field name not allowed to sort");
  47. $currSortCol = (array_key_exists($currSortCol, $aliasMap)) ? $aliasMap[$currSortCol] : null;
  48. if (!empty($currSortCol) && ('asc' == $currSortFlip || 'desc' == $currSortFlip)) {
  49. $sqlOrderBy = "order by p.`{$currSortCol}` {$currSortFlip}";
  50. }
  51. $limit = V::get('limit', 0, $params);
  52. $limit = ($limit < 0) ? 0 : $limit;
  53. $offset = V::get('limitstart', 0, $params);
  54. $offset = ($offset < 0) ? 0 : $offset;
  55. if ($limit > 0) $sqlLimitOffset = "limit {$limit} offset {$offset}";
  56. return DB::getPDO()->fetchAllByKey("
  57. select p.ID
  58. , p.`DESC` as nazwa
  59. , p.`OPIS` as opis
  60. , p.A_RECORD_CREATE_AUTHOR as `autor`
  61. , p.A_RECORD_CREATE_DATE as `utworzono`
  62. , p.A_RECORD_UPDATE_AUTHOR as `zaktualizował`
  63. , p.A_RECORD_UPDATE_DATE as `zaktualizowano`
  64. from `CRM_PROCES` p
  65. where p.`TYPE` = 'PROCES_INIT'
  66. and p.`A_STATUS` not in('DELETED', 'OFF_HARD', 'OFF_SOFT')
  67. {$sqlWhereAnd}
  68. {$sqlOrderBy}
  69. {$sqlLimitOffset}
  70. ", 'ID');
  71. }
  72. }