|
|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
Lib::loadClass('Core_AclSimpleSchemaBase');
|
|
|
Lib::loadClass('ParseOgcFilter');
|
|
|
+Lib::loadClass('Router');
|
|
|
|
|
|
class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
|
|
|
|
|
|
@@ -17,6 +18,8 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
|
|
|
'_type' => [ '@type' => 'xsd:string' ],
|
|
|
'isActive' => [ '@type' => 'xsd:integer' ], // installed
|
|
|
'description' => [ '@type' => 'xsd:string' ],
|
|
|
+ 'namespace' => [ '@type' => 'xsd:string' ],
|
|
|
+ 'reinstallLink' => [ '@type' => 'p5:www_link' ],
|
|
|
// 'A_RECORD_CREATE_AUTHOR' => [ '@type' => 'xsd:string' , '@label' => 'autor' ],
|
|
|
// 'A_RECORD_CREATE_DATE' => [ '@type' => 'xsd:date' , '@label' => 'utworzono' ],
|
|
|
// 'A_RECORD_UPDATE_AUTHOR' => [ '@type' => 'xsd:string' , '@label' => 'zaktualizował' ],
|
|
|
@@ -221,18 +224,20 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
|
|
|
// $acl = SchemaFactory::loadDefaultObject($clsName);
|
|
|
// $namespace = $acl->getNamespace();
|
|
|
// $name = $acl->getName();
|
|
|
+ $idDatabase = DB::getPDO($sourceName)->getZasobId();
|
|
|
$sqlNsPrefix = "{$sourceName}__x3A__{$rootTableName}";
|
|
|
$sqlName = $name;
|
|
|
DB::getPDO()->execSql("
|
|
|
- insert ignore into `{$this->_rootTableName}` (nsPrefix, idDatabase, _type, name, description, isActive)
|
|
|
+ insert into `{$this->_rootTableName}` (nsPrefix, idDatabase, _type, name, description, isActive)
|
|
|
values (
|
|
|
'{$sqlNsPrefix}'
|
|
|
- , '0'
|
|
|
+ , '{$idDatabase}'
|
|
|
, 'AntAcl'
|
|
|
, '{$sqlName}'
|
|
|
, ''
|
|
|
, '1'
|
|
|
)
|
|
|
+ on duplicate key update idDatabase = '{$idDatabase}'
|
|
|
");
|
|
|
} catch (Exception $e) {
|
|
|
UI::alert('danger', $e->getMessage());
|
|
|
@@ -275,6 +280,9 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
|
|
|
// TODO: check query by xpath or use different param prefix
|
|
|
throw new Exception("Field '{$fieldName}' not found in '{$this->_namespace}'");
|
|
|
}
|
|
|
+ if ('p5:www_link' == $xsdFields[$fieldName]) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
$filterParams[$fieldName] = $v;
|
|
|
}
|
|
|
}
|
|
|
@@ -284,7 +292,11 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
|
|
|
if (is_array($value)) {
|
|
|
DBG::log($value, 'array', "TODO SystemObject::_parseWhere array value for \$filterParams[{$fieldName}]");
|
|
|
} else if (is_scalar($value)) {
|
|
|
- $sqlWhere[] = "t.{$fieldName} like " . DB::getPDO()->quote("%{$value}%", PDO::PARAM_STR);
|
|
|
+ if ('=' == substr($value, 0, 1)) {
|
|
|
+ $sqlWhere[] = "t.{$fieldName} = " . DB::getPDO()->quote(substr($value, 1), PDO::PARAM_STR);
|
|
|
+ } else {
|
|
|
+ $sqlWhere[] = "t.{$fieldName} like " . DB::getPDO()->quote("%{$value}%", PDO::PARAM_STR);
|
|
|
+ }
|
|
|
} else {
|
|
|
DBG::log($value, 'array', "BUG SystemObject::_parseWhere unknown type for \$filterParams[{$fieldName}]");
|
|
|
}
|
|
|
@@ -322,131 +334,20 @@ class Schema_SystemObjectStorageAcl extends Core_AclSimpleSchemaBase {
|
|
|
? "limit {$limit} offset {$offset}"
|
|
|
: '';
|
|
|
|
|
|
- return DB::getPDO()->fetchAll("
|
|
|
+ return array_map(array($this, 'buildFeatureFromSqlRow'), DB::getPDO()->fetchAll("
|
|
|
select t.*
|
|
|
from `{$this->_rootTableName}` t
|
|
|
{$sqlWhere}
|
|
|
{$sqlOrderBy}
|
|
|
{$sqlLimit}
|
|
|
- ");
|
|
|
-
|
|
|
- $items = $this->_getAllItems();
|
|
|
-
|
|
|
- $aliasMap = array();
|
|
|
- foreach ($this->_simpleSchema['root'] as $key => $field) {
|
|
|
- if ('@' === substr($key, 0, 1)) continue;
|
|
|
- $aliasMap[ $key ] = $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)) {
|
|
|
- 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 array_slice($items, $offset, ($limit > 0) ? $limit : null, $preserve_keys = true);
|
|
|
- }
|
|
|
-
|
|
|
- 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();
|
|
|
- $listFromZasoby = array_map(
|
|
|
- function ($row) {
|
|
|
- $row['ID'] = $row['id_zasob'];
|
|
|
- if (false !== strpos($row['tabela'], '/')) {
|
|
|
- $ns = Core_AclHelper::parseNamespaceUrl($row['tabela']);
|
|
|
- $row['namespace'] = "{$row['tabela']}";
|
|
|
- $row['typeName'] = "{$ns['prefix']}:{$ns['name']}";
|
|
|
- $row['nazwa'] = $ns['name'];
|
|
|
- } else {
|
|
|
- $row['namespace'] = "default_db/{$row['tabela']}";
|
|
|
- $row['typeName'] = "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 as `autor`
|
|
|
- , z.A_RECORD_CREATE_DATE as `utworzono`
|
|
|
- , z.A_RECORD_UPDATE_AUTHOR as `zaktualizował`
|
|
|
- , z.A_RECORD_UPDATE_DATE as `zaktualizowano`
|
|
|
- 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')
|
|
|
- ")
|
|
|
- );
|
|
|
- $notRawTables = array_filter(
|
|
|
- array_map(
|
|
|
- function ($item) {
|
|
|
- return $item['typeName'];
|
|
|
- }
|
|
|
- , $listFromZasoby
|
|
|
- )
|
|
|
- , function ($typeName) {
|
|
|
- return 'default_db:' !== substr($typeName, 0, strlen('default_db:'));
|
|
|
- }
|
|
|
- );
|
|
|
- $_cacheAllItems = array_filter(
|
|
|
- array_merge(
|
|
|
- $listFromZasoby
|
|
|
- , array_map(
|
|
|
- function ($typeName) {
|
|
|
- list($prefix, $objectName) = explode(':', $typeName);
|
|
|
- $namespace = str_replace([':', '__x3A__'], '/', $typeName);
|
|
|
- $id = 0;
|
|
|
- if ('objects' == $prefix) {
|
|
|
- $id = SchemaFactory::loadDefaultObject($objectName)->getID();
|
|
|
- } else if ('default_objects' == $prefix) {
|
|
|
- $id = SchemaFactory::loadDefaultObject($objectName)->getID();
|
|
|
- } else if ('default_db__x3A__' == substr($prefix, 0, 17)) {
|
|
|
- $rootTableName = strtolower(substr($prefix, 17));
|
|
|
- $id = SchemaFactory::loadTableObject($rootTableName, $objectName)->getID();
|
|
|
- }
|
|
|
- if (!$id) $id = $this->_generateUniqueKeyFromNamespace($namespace);
|
|
|
- return [
|
|
|
- 'ID' => $id,
|
|
|
- 'id_zasob' => $id,
|
|
|
- 'namespace' => $namespace,
|
|
|
- 'typeName' => $typeName,
|
|
|
- 'tabela' => '', // TODO: $acl->getRootTableName(),
|
|
|
- 'nazwa' => substr($typeName, strrpos($typeName, ':') + 1),
|
|
|
- 'opis' => '...',
|
|
|
- 'autor' => '',
|
|
|
- 'utworzono' => '',
|
|
|
- 'zaktualizował' => '',
|
|
|
- 'zaktualizowano' => ''
|
|
|
- ];
|
|
|
- }
|
|
|
- , array_filter(Core_AclHelper::getAclList(), function ($typeName) use ($notRawTables) { return !in_array($typeName, $notRawTables); })
|
|
|
- )
|
|
|
- )
|
|
|
- , function ($item) use ($params) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- );
|
|
|
- return $_cacheAllItems;
|
|
|
+ public function buildFeatureFromSqlRow($item) {
|
|
|
+ $namespace = str_replace('__x3A__', '/', $item['nsPrefix']) . '/' . $item['name'];
|
|
|
+ $item['namespace'] = $namespace;
|
|
|
+ $item['reinstallLink'] = Router::getRoute('Storage')->getLink('objectReinstall', [ 'namespace' => $namespace ]);
|
|
|
+ return $item;
|
|
|
}
|
|
|
|
|
|
}
|