[ '@namespace' => 'default_objects/SystemProcess', 'ID' => [ '@type' => 'xsd:integer' ], 'nazwa' => [ '@type' => 'xsd:string', '@alias' => 'DESC' ], 'opis' => [ '@type' => 'xsd:string', '@alias' => 'OPIS' ], 'autor' => [ '@type' => 'xsd:string' , '@alias' => 'A_RECORD_CREATE_AUTHOR' ], 'utworzono' => [ '@type' => 'xsd:date' , '@alias' => 'A_RECORD_CREATE_DATE' ], 'zaktualizowaƂ' => [ '@type' => 'xsd:string' , '@alias' => 'A_RECORD_UPDATE_AUTHOR' ], 'zaktualizowano' => [ '@type' => 'xsd:date', '@alias' => 'A_RECORD_UPDATE_DATE' ] ] ]; public $_rootTableName = 'CRM_PROCES'; public function getTotal($params = []) { $sqlWhereAnd = $this->_parseSqlWhere($params); return DB::getPDO()->fetchValue(" select count(1) as total from `CRM_PROCES` p where p.`TYPE` = 'PROCES_INIT' and p.`A_STATUS` not in('DELETED', 'OFF_HARD', 'OFF_SOFT') {$sqlWhereAnd} "); } public function _parseSqlWhere($params = []) { $sqlWhereAnd = ""; // TODO: parse where/ogc, etc. return $sqlWhereAnd; } public function getItems($params = []) { $sqlOrderBy = ""; $sqlLimitOffset = ""; $sqlWhereAnd = $this->_parseSqlWhere($params); $currSortCol = V::get('order_by', 'ID', $params); $currSortFlip = strtolower(V::get('order_dir', 'desc', $params)); // TODO: validate $currSortCol is in field list // TODO: validate $currSortFlip ('asc' or 'desc') $aliasMap = array(); foreach ($this->_simpleSchema['root'] as $key => $field) { if ('@' === substr($key, 0, 1)) continue; $aliasMap[ $key ] = (!empty($field['@alias'])) ? $field['@alias'] : $key; } // TODO: if (!array_key_exists($currSortCol, $aliasMap)) throw new Exception("field name not allowed to sort"); $currSortCol = (array_key_exists($currSortCol, $aliasMap)) ? $aliasMap[$currSortCol] : null; if (!empty($currSortCol) && ('asc' == $currSortFlip || 'desc' == $currSortFlip)) { $sqlOrderBy = "order by p.`{$currSortCol}` {$currSortFlip}"; } $limit = V::get('limit', 0, $params); $limit = ($limit < 0) ? 0 : $limit; $offset = V::get('limitstart', 0, $params); $offset = ($offset < 0) ? 0 : $offset; if ($limit > 0) $sqlLimitOffset = "limit {$limit} offset {$offset}"; return DB::getPDO()->fetchAllByKey(" select p.ID , p.`DESC` as nazwa , p.`OPIS` as opis , p.A_RECORD_CREATE_AUTHOR as `autor` , p.A_RECORD_CREATE_DATE as `utworzono` , p.A_RECORD_UPDATE_AUTHOR as `zaktualizowaƂ` , p.A_RECORD_UPDATE_DATE as `zaktualizowano` from `CRM_PROCES` p where p.`TYPE` = 'PROCES_INIT' and p.`A_STATUS` not in('DELETED', 'OFF_HARD', 'OFF_SOFT') {$sqlWhereAnd} {$sqlOrderBy} {$sqlLimitOffset} ", 'ID'); } }