|
|
@@ -0,0 +1,124 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+Lib::loadClass('Core_AclSimpleSchemaBase');
|
|
|
+Lib::loadClass('ParseOgcFilter');
|
|
|
+
|
|
|
+class Schema_UserProcessStorageAcl extends Core_AclSimpleSchemaBase {
|
|
|
+
|
|
|
+ public $_simpleSchema = [
|
|
|
+ 'root' => [
|
|
|
+ '@namespace' => 'default_objects/UserProcess',
|
|
|
+ '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);
|
|
|
+
|
|
|
+ $idGroupList = $this->_getUserIdGroupList();
|
|
|
+ if (empty($idGroupList)) throw new Exception("Brak przyipsanych grup do użytwkonika");
|
|
|
+ $sqlIdGroupCsv = implode(",", $idGroupList);
|
|
|
+
|
|
|
+ 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')
|
|
|
+ and p.ID in (
|
|
|
+ select gi.ID_PROCES_INIT
|
|
|
+ from `CRM_PROCES_idx_GROUP_to_INIT_VIEW` as gi
|
|
|
+ where gi.ID_GROUP in({$sqlIdGroupCsv})
|
|
|
+ )
|
|
|
+ {$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}";
|
|
|
+
|
|
|
+ $idGroupList = $this->_getUserIdGroupList();
|
|
|
+ if (empty($idGroupList)) throw new Exception("Brak przyipsanych grup do użytwkonika");
|
|
|
+ $sqlIdGroupCsv = implode(",", $idGroupList);
|
|
|
+
|
|
|
+ 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')
|
|
|
+ and p.ID in (
|
|
|
+ select gi.ID_PROCES_INIT
|
|
|
+ from `CRM_PROCES_idx_GROUP_to_INIT_VIEW` as gi
|
|
|
+ where gi.ID_GROUP in({$sqlIdGroupCsv})
|
|
|
+ )
|
|
|
+ {$sqlWhereAnd}
|
|
|
+ group by p.ID
|
|
|
+ {$sqlOrderBy}
|
|
|
+ {$sqlLimitOffset}
|
|
|
+ ", 'ID');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function _getUserIdGroupList() {
|
|
|
+ $idUser = User::getID();
|
|
|
+ return array_map(
|
|
|
+ function ($row) {
|
|
|
+ return $row['ID'];
|
|
|
+ }
|
|
|
+ , DB::getPDO()->fetchAll("
|
|
|
+ select z.ID
|
|
|
+ from `CRM_AUTH_PROFILE` as up
|
|
|
+ left join `CRM_LISTA_ZASOBOW` as z on(z.`ID`=up.`ID_ZASOB`)
|
|
|
+ where
|
|
|
+ up.`REMOTE_ID`='{$idUser}'
|
|
|
+ and up.`A_STATUS` in('WAITING', 'NORMAL')
|
|
|
+ and up.`REMOTE_TABLE`='ADMIN_USERS'
|
|
|
+ and z.`ID` is not null
|
|
|
+ and z.`TYPE` in('STANOWISKO','PODMIOT','DZIAL')
|
|
|
+ ")
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+}
|