|
|
@@ -0,0 +1,121 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+Lib::loadClass('Core_AclSimpleSchemaBase');
|
|
|
+Lib::loadClass('ParseOgcFilter');
|
|
|
+
|
|
|
+class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
|
|
|
+
|
|
|
+ public $_simpleSchema = [
|
|
|
+ 'root' => [
|
|
|
+ '@namespace' => 'default_objects/SystemObject',
|
|
|
+ 'ID' => [ '@type' => 'xsd:integer' ],
|
|
|
+ 'namespace' => [ '@type' => 'xsd:string' ],
|
|
|
+ 'tabela' => [ '@type' => 'xsd:string', '@alias' => 'DESC' ],
|
|
|
+ 'nazwa' => [ '@type' => 'xsd:string', '@alias' => 'DESC' ],
|
|
|
+ 'opis' => [ '@type' => 'xsd:string', '@alias' => 'OPIS' ],
|
|
|
+ 'id_zasob' => [ '@type' => 'xsd:integer' ],
|
|
|
+ 'A_RECORD_CREATE_AUTHOR' => [ '@type' => 'xsd:string' ],
|
|
|
+ 'A_RECORD_CREATE_DATE' => [ '@type' => 'xsd:date' ],
|
|
|
+ 'A_RECORD_UPDATE_AUTHOR' => [ '@type' => 'xsd:string' ],
|
|
|
+ 'A_RECORD_UPDATE_DATE' => [ '@type' => 'xsd:date' ],
|
|
|
+ ]
|
|
|
+ ];
|
|
|
+ public $_rootTableName = 'CRM_LISTA_ZASOBOW';
|
|
|
+
|
|
|
+ public function getTotal($params = []) {
|
|
|
+ return count($this->_getAllItems());
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getItems($params = []) {
|
|
|
+ $items = $this->_getAllItems();
|
|
|
+ $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')
|
|
|
+ if (!empty($currSortCol) && ('asc' == $currSortFlip || 'desc' == $currSortFlip)) {
|
|
|
+ usort($items, function ($itemA, $itemB) use ($currSortCol, $currSortFlip) {
|
|
|
+ $a = strtolower(V::get($currSortCol, '', $itemA));
|
|
|
+ $b = strtolower(V::get($currSortCol, '', $itemB));
|
|
|
+
|
|
|
+ if ($a == $b) return 0;
|
|
|
+ else if ('asc' == $currSortFlip) return ($a < $b) ? -1 : 1;
|
|
|
+ else if ('desc' == $currSortFlip) return ($a > $b) ? -1 : 1;
|
|
|
+ throw new Exception("BUG - Wrong sort param - order dir");
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ $limit = V::get('limit', 0, $params);
|
|
|
+ $limit = ($limit < 0) ? 0 : $limit;
|
|
|
+ $offset = V::get('limitstart', 0, $params);
|
|
|
+ $offset = ($offset < 0) ? 0 : $offset;
|
|
|
+ return ($limit > 0)
|
|
|
+ ? $this->_fixKeyItems(array_splice($items, $offset, $limit))
|
|
|
+ : $this->_fixKeyItems(array_splice($items, $offset));
|
|
|
+ }
|
|
|
+
|
|
|
+ public function _fixKeyItems($items) {
|
|
|
+ $fixed = array();
|
|
|
+ foreach ($items as $item) {
|
|
|
+ $fixed[ $this->_generateUniqueKeyFromNamespace($item['namespace']) ] = $item;
|
|
|
+ }
|
|
|
+ return $fixed;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function _generateUniqueKeyFromNamespace($namespace) {
|
|
|
+ return str_replace('/', '__x3A__', $namespace);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function _getAllItems($params = []) {
|
|
|
+ static $_cacheAllItems = null;
|
|
|
+ if (null !== $_cacheAllItems) return $_cacheAllItems;
|
|
|
+ $idMainDatabase = DB::getPDO()->getZasobId();
|
|
|
+ $_cacheAllItems = array_filter(
|
|
|
+ array_merge(
|
|
|
+ array_map(
|
|
|
+ function ($row) {
|
|
|
+ $row['namespace'] = "default_db/{$row['tabela']}";
|
|
|
+ $row['ID'] = $this->_generateUniqueKeyFromNamespace($row['namespace']);
|
|
|
+ return $row;
|
|
|
+ }
|
|
|
+ , DB::getPDO()->fetchAll("
|
|
|
+ select z.ID as id_zasob
|
|
|
+ , z.`DESC` as tabela
|
|
|
+ , IF(z.`DESC_PL` != '', z.`DESC_PL`, z.`DESC`) as nazwa
|
|
|
+ , z.`OPIS` as opis
|
|
|
+ , z.A_RECORD_CREATE_AUTHOR
|
|
|
+ , z.A_RECORD_CREATE_DATE
|
|
|
+ , z.A_RECORD_UPDATE_AUTHOR
|
|
|
+ , z.A_RECORD_UPDATE_DATE
|
|
|
+ from `CRM_LISTA_ZASOBOW` z
|
|
|
+ where z.PARENT_ID = {$idMainDatabase}
|
|
|
+ and z.`TYPE` = 'TABELA'
|
|
|
+ and z.`A_STATUS` not in('DELETED', 'OFF_HARD', 'OFF_SOFT')
|
|
|
+ ")
|
|
|
+ )
|
|
|
+ , array_map(
|
|
|
+ function ($typeName) {
|
|
|
+ $namespace = str_replace(':', '/', $typeName);
|
|
|
+ $namespace = str_replace('__x3A__', '/', $namespace);
|
|
|
+ return [
|
|
|
+ 'ID' => $this->_generateUniqueKeyFromNamespace($namespace),
|
|
|
+ 'namespace' => $namespace,
|
|
|
+ 'tabela' => '', // TODO: $acl->getRootTableName(),
|
|
|
+ 'nazwa' => substr($typeName, strrpos($typeName, ':') + 1),
|
|
|
+ 'opis' => '...',
|
|
|
+ 'A_RECORD_CREATE_AUTHOR' => '',
|
|
|
+ 'A_RECORD_CREATE_DATE' => '',
|
|
|
+ 'A_RECORD_UPDATE_AUTHOR' => '',
|
|
|
+ 'A_RECORD_UPDATE_DATE' => ''
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ , Core_AclHelper::getAclList()
|
|
|
+ )
|
|
|
+ )
|
|
|
+ , function ($item) use ($params) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ );
|
|
|
+ return $_cacheAllItems;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|