SystemProcessStorageAcl.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. if ('nazwa' == $currSortCol) $currSortCol = 'DESC';// TODO: @see attribute '@alias' for field 'nazwa'
  42. $aliasMap = array();
  43. foreach ($this->_simpleSchema['root'] as $key => $field) {
  44. if ('@' === substr($key, 0, 1)) continue;
  45. $aliasMap[ $key ] = (!empty($field['@alias'])) ? $field['@alias'] : $key;
  46. }
  47. // TODO: if (!array_key_exists($currSortCol, $aliasMap)) throw new Exception("field name not allowed to sort");
  48. $currSortCol = (array_key_exists($currSortCol, $aliasMap)) ? $aliasMap[$currSortCol] : null;
  49. if (!empty($currSortCol) && ('asc' == $currSortFlip || 'desc' == $currSortFlip)) {
  50. $sqlOrderBy = "order by p.`{$currSortCol}` {$currSortFlip}";
  51. }
  52. $limit = V::get('limit', 0, $params);
  53. $limit = ($limit < 0) ? 0 : $limit;
  54. $offset = V::get('limitstart', 0, $params);
  55. $offset = ($offset < 0) ? 0 : $offset;
  56. if ($limit > 0) $sqlLimitOffset = "limit {$limit} offset {$offset}";
  57. return DB::getPDO()->fetchAllByKey("
  58. select p.ID
  59. , p.`DESC` as nazwa
  60. , p.`OPIS` as opis
  61. , p.A_RECORD_CREATE_AUTHOR as `autor`
  62. , p.A_RECORD_CREATE_DATE as `utworzono`
  63. , p.A_RECORD_UPDATE_AUTHOR as `zaktualizował`
  64. , p.A_RECORD_UPDATE_DATE as `zaktualizowano`
  65. from `CRM_PROCES` p
  66. where p.`TYPE` = 'PROCES_INIT'
  67. and p.`A_STATUS` not in('DELETED', 'OFF_HARD', 'OFF_SOFT')
  68. {$sqlWhereAnd}
  69. {$sqlOrderBy}
  70. {$sqlLimitOffset}
  71. ", 'ID');
  72. }
  73. }