| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531 |
- <?php
- Lib::loadClass('Core_AclSimpleSchemaBase');
- Lib::loadClass('ParseOgcFilter');
- Lib::loadClass('Router');
- Lib::loadClass('SchemaVersionUpgrade');
- class Schema_SystemObjectFieldStorageAcl extends Core_AclSimpleSchemaBase {
- public $_simpleSchema = [
- 'root' => [
- '@namespace' => 'default_objects/SystemObjectField',
- '@primaryKey' => 'namespace',
- 'idZasob' => [ '@type' => 'xsd:integer' ],
- 'idDatabase' => [ '@type' => 'xsd:integer' ],
- '_rootTableName' => [ '@type' => 'xsd:string' ],
- 'namespace' => [ '@type' => 'xsd:string' ],
- 'objectNamespace' => [ '@type' => 'xsd:string' ],
- 'fieldNamespace' => [ '@type' => 'xsd:string' ],
- 'xsdType' => [ '@type' => 'xsd:string' ],
- 'xsdRestrictions' => [ '@type' => 'xsd:string' ],
- 'appInfo' => [ '@type' => 'xsd:string' ],
- 'minOccurs' => [ '@type' => 'xsd:string' ],
- 'maxOccurs' => [ '@type' => 'xsd:string' ], // '0..unbounded',
- 'isActive' => [ '@type' => 'xsd:integer' ], // installed
- 'description' => [ '@type' => 'xsd:string' ],
- 'isLocal' => [ '@type' => 'xsd:integer', '@comment' => "is in _rootTableName" ],
- 'sortPrio' => [ '@type' => 'xsd:integer' ],
- // '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ł' ],
- // 'A_RECORD_UPDATE_DATE' => [ '@type' => 'xsd:date', '@label' => 'zaktualizowano' ],
- ]
- ];
- // public $_rootTableName = 'CRM_LISTA_ZASOBOW';
- public $_rootTableName = 'CRM_#CACHE_ACL_OBJECT_FIELD';
- public $_enumRootTableName = 'CRM_#CACHE_ACL_OBJECT_FIELD_enum';
- public $_version = '3';
- public function __construct($simpleSchema = null) {
- parent::__construct($simpleSchema);
- SchemaVersionUpgrade::upgradeSchema();
- }
- public static function getAntAclXsdBasePath($typeName) {
- if (!$typeName) throw new Exception("Missing typeName");
- $antAclPath = null;
- if ($activeProject = Config::getProjectPath()) {
- $tryProjectSchemaPath = "{$activeProject}/schema/ant-object/" . str_replace(['__x3A__', ':'], ['.', '/'], $typeName);
- if (file_exists($tryProjectSchemaPath)) {
- $antAclPath = $tryProjectSchemaPath;
- }
- }
- if (!$antAclPath) {
- $antAclPath = APP_PATH_SCHEMA . DS . 'ant-object' . DS . str_replace(['__x3A__', ':'], ['.', '/'], $typeName);
- }
- return $antAclPath;
- }
- public function updateCache($namespace = null) {
- DBG::log("SystemObjectField::updateCache({$namespace})...");
- if (!$namespace) return;
- DB::getPDO()->update($this->_rootTableName, 'objectNamespace', $namespace, ['isActive' => 0]);
- DB::getPDO()->execSql("
- DELETE from `{$this->_enumRootTableName}`
- where isActive = 0
- and objectNamespace = :objectNamespace
- ", [
- ':objectNamespace' => $namespace,
- ]);
- DB::getPDO()->update($this->_enumRootTableName, 'objectNamespace', $namespace, ['isActive' => 0]);
- if (!$namespace) throw new Exception("Missing namespace '{$namespace}'");
- $objectItem = SchemaFactory::loadDefaultObject('SystemObject')->getItem($namespace);
- DBG::nicePrint($objectItem, '$objectItem');
- DBG::log($objectItem, 'array', '$objectItem');
- switch ($objectItem['_type']) {
- case 'AntAcl': $this->updateCacheAntAcl($objectItem); break;
- case 'TableAcl': $this->updateCacheTableAcl($objectItem); break;
- case 'StorageAcl': $this->updateCacheStorageAcl($objectItem); break;
- default: throw new Exception("TODO: Not Implemented type '{$objectItem['_type']}'");
- }
- // TODO: mv from methods: SchemaFactory::loadDefaultObject('SystemObject')->updateItem([
- // 'namespace' => $item['namespace'],
- // 'isStructInstalled' => 1
- // ]);
- $dbName = DB::getPDO()->getDatabaseName();
- DB::getPDO()->execSql("
- update `{$this->_rootTableName}` t
- set t.isLocal = IF(
- ( select c.COLUMN_NAME
- from information_schema.COLUMNS c
- where c.COLUMN_NAME = t.fieldNamespace
- and c.TABLE_SCHEMA = '{$dbName}'
- and c.TABLE_NAME = '{$objectItem['_rootTableName']}'
- limit 1
- ) is null
- , 0, 1)
- where t.objectNamespace = '{$objectItem['namespace']}'
- and t._rootTableName = '{$objectItem['_rootTableName']}'
- ");
- DB::getPDO()->execSql("
- UPDATE `{$this->_rootTableName}` t
- LEFT JOIN `CRM_LISTA_ZASOBOW` z on ( z.ID = t.idZasob )
- SET t.sortPrio = IF(z.ID is not null, z.SORT_PRIO, 0)
- WHERE t.objectNamespace = '{$objectItem['namespace']}'
- ");
- }
- public function updateCacheAntAcl($item) {
- Lib::loadClass('AntAclBase');
- $antAclPath = Schema_SystemObjectFieldStorageAcl::getAntAclXsdBasePath($item['typeName']);
- DBG::log(['typeName'=>$item['typeName'], 'antAclPath'=>$antAclPath], 'array', "AntAcl build.xml path");
- if (!file_exists("{$antAclPath}/build.xml")) throw new Exception("Ant build file not exists");
- Lib::loadClass('XML');
- $xsdType = XML::getXsdTypeFromXsdSchema("{$antAclPath}/{$item['name']}.xsd", $namespace = $item['namespace'], $name = $item['name']);
- DBG::nicePrint($xsdType, '$xsdType');
- if (empty($xsdType['struct'])) throw new Exception("Field list not found for '{$item['namespace']}'");
- foreach ($xsdType['struct'] as $fieldName => $x) {
- $listEnum = [];
- if (!empty($x['restrictions']['enumeration'])) {
- $listEnum = $x['restrictions']['enumeration'];
- unset($x['restrictions']['enumeration']);
- }
- DB::getPDO()->insertOrUpdate($this->_rootTableName, [
- 'namespace' => "{$item['namespace']}/{$fieldName}",
- 'objectNamespace' => $item['namespace'],
- 'idDatabase' => $item['idDatabase'],
- '_rootTableName' => $item['_rootTableName'],
- 'fieldNamespace' => $fieldName,
- 'xsdType' => $x['type'],
- 'xsdRestrictions' => json_encode($x['restrictions']),
- 'appInfo' => json_encode($x['appInfo']),
- 'minOccurs' => $x['minOccurs'],
- 'maxOccurs' => $x['maxOccurs'],
- 'isActive' => 1
- ]);
- if (!empty($listEnum)) {
- DBG::nicePrint($listEnum, '$listEnum');
- $sortPrio = count($listEnum);
- foreach ($listEnum as $value => $label) {
- DB::getPDO()->insertOrUpdate("{$this->_enumRootTableName}", [
- 'namespace' => "{$item['namespace']}/{$fieldName}/@{$value}",
- 'fieldNamespace' => $fieldName,
- 'objectNamespace' => $item['namespace'],
- 'value' => $value,
- 'label' => $label,
- 'isActive' => 1,
- 'sortPrio' => $sortPrio--
- ]);
- }
- }
- }
- SchemaFactory::loadDefaultObject('SystemObject')->updateItem([
- 'namespace' => $item['namespace'],
- 'isStructInstalled' => 1,
- 'primaryKey' => $xsdType['primaryKey'],
- 'appInfo' => json_encode($xsdType['appInfo']),
- ]);
- DB::getPDO()->execSql("
- DELETE from `{$this->_enumRootTableName}`
- where isActive = 0
- and objectNamespace = :objectNamespace
- ", [
- ':objectNamespace' => $item['namespace'],
- ]);
- $zasobTableName = substr($item['objectNamespace'], strlen('default_db/'));
- $zasobTableName = (false !== strpos($zasobTableName, '/'))
- ? $item['objectNamespace']
- : $zasobTableName;
- DB::getPDO()->execSql("
- update `{$this->_rootTableName}` t
- join CRM_LISTA_ZASOBOW zp on(zp.PARENT_ID = {$item['idDatabase']} and zp.`DESC` = '{$zasobTableName}')
- join CRM_LISTA_ZASOBOW z on(z.PARENT_ID = zp.ID and z.`DESC` = t.fieldNamespace)
- set t.idZasob = z.ID
- where t.objectNamespace = '{$item['namespace']}'
- ");
- UI::alert('success', "Gotowe");
- }
- public function updateCacheStorageAcl($item) {
- Lib::loadClass('SchemaFactory');
- $aclName = substr($item['namespace'], strlen('default_objects/'));
- DBG::log($aclName, 'array', "\$aclName");
- $fvAcl = SchemaFactory::loadDefaultObject($aclName);
- DBG::log($fvAcl->getFields(), 'array', "\$fvAcl->getFields()");
- foreach ($fvAcl->getFields() as $field) {
- // 'name' => 'id',
- // 'perms' => '',
- // 'idZasob' => 10000,
- // 'xsdType' => 'xsd:integer',
- // 'label' => 'id',
- $fieldName = $field['name'];
- $xsdType = $field['xsdType'];
- DB::getPDO()->insertOrUpdate($this->_rootTableName, [
- 'namespace' => "{$item['namespace']}/{$fieldName}",
- 'objectNamespace' => $item['namespace'],
- 'idDatabase' => $item['idDatabase'],
- '_rootTableName' => $item['_rootTableName'],
- 'fieldNamespace' => $fieldName,
- 'xsdType' => $xsdType,
- // 'xsdRestrictions' => '',
- // 'appInfo' => '',
- // 'minOccurs' => '',
- // 'maxOccurs' => '',
- 'isActive' => 1
- ]);
- $listEnum = [];
- if (!empty($listEnum)) {
- DBG::nicePrint($listEnum, '$listEnum');
- foreach ($listEnum as $value => $label) {
- DB::getPDO()->insertOrUpdate("{$this->_enumRootTableName}", [
- 'namespace' => "{$item['namespace']}/{$fieldName}/@{$value}",
- 'fieldNamespace' => $fieldName,
- 'objectNamespace' => $item['namespace'],
- 'value' => $value,
- 'label' => $label,
- 'isActive' => 1
- ]);
- }
- }
- }
- SchemaFactory::loadDefaultObject('SystemObject')->updateItem([
- 'namespace' => $item['namespace'],
- 'isStructInstalled' => 1,
- 'primaryKey' => $fvAcl->getPrimaryKeyField(),
- ]);
- // $zasobTableName = substr($item['objectNamespace'], strlen('default_db/'));
- // $zasobTableName = (false !== strpos($zasobTableName, '/'))
- // ? $item['objectNamespace']
- // : $zasobTableName;
- // DB::getPDO()->execSql("
- // update `{$this->_rootTableName}` t
- // join CRM_LISTA_ZASOBOW zp on(zp.PARENT_ID = {$item['idDatabase']} and zp.`DESC` = '{$zasobTableName}')
- // join CRM_LISTA_ZASOBOW z on(z.PARENT_ID = zp.ID and z.`DESC` = t.fieldNamespace)
- // set t.idZasob = z.ID
- // where t.objectNamespace = '{$item['namespace']}'
- // ");
- }
- public function updateCacheTableAcl($item) {
- // TODO: xsdType - convert mysql type to xsdType, xsdRestrictions
- $xsdInfo = [];
- Lib::loadClass('SchemaHelper');
- $dbName = DB::getPDO()->getDatabaseName();
- $mysqlTypes = DB::getPDO()->fetchAll("
- select c.COLUMN_NAME, c.COLUMN_TYPE, c.DATA_TYPE, c.IS_NULLABLE, c.CHARACTER_MAXIMUM_LENGTH, c.NUMERIC_PRECISION, c.NUMERIC_SCALE
- from `information_schema`.`COLUMNS` c
- where c.TABLE_SCHEMA = '{$dbName}'
- and c.TABLE_NAME = '{$item['_rootTableName']}'
- ");
- foreach ($mysqlTypes as $mysqlType) {
- $xsdInfo[ $mysqlType['COLUMN_NAME'] ] = SchemaHelper::convertMysqlTypeToSchemaXsd($mysqlType);
- }
- DBG::nicePrint($xsdInfo, '$xsdInfo');
- foreach ($xsdInfo as $fieldName => $x) {
- $listEnum = [];
- if (!empty($x['restrictions']['enumeration'])) {
- $listEnum = $x['restrictions']['enumeration'];
- unset($x['restrictions']['enumeration']);
- }
- DB::getPDO()->insertOrUpdate($this->_rootTableName, [
- 'namespace' => "{$item['namespace']}/{$fieldName}",
- 'fieldNamespace' => $fieldName,
- 'isActive' => 1,
- 'idDatabase' => $item['idDatabase'],
- '_rootTableName' => $item['_rootTableName'],
- 'objectNamespace' => $item['namespace'],
- 'xsdType' => $x['type'],
- 'xsdRestrictions' => json_encode($x['restrictions']),
- 'appInfo' => json_encode([]),
- ]);
- if (!empty($listEnum)) {
- DBG::nicePrint($listEnum, '$listEnum');
- foreach ($listEnum as $value => $label) {
- DB::getPDO()->insertOrUpdate("{$this->_enumRootTableName}", [
- 'namespace' => "{$item['namespace']}/{$fieldName}/@{$value}",
- 'fieldNamespace' => $fieldName,
- 'objectNamespace' => $item['namespace'],
- 'value' => $value,
- 'label' => $label,
- 'isActive' => 1
- ]);
- }
- }
- }
- SchemaFactory::loadDefaultObject('SystemObject')->updateItem([
- 'namespace' => $item['namespace'],
- 'isStructInstalled' => 1
- ]);
- $zasobTableName = substr($item['namespace'], strlen('default_db/'));
- $zasobTableName = (false !== strpos($zasobTableName, '/'))
- ? $item['namespace']
- : $zasobTableName;
- DB::getPDO()->execSql("
- update `{$this->_rootTableName}` t
- join CRM_LISTA_ZASOBOW zp on(zp.PARENT_ID = {$item['idDatabase']} and zp.`DESC` = '{$zasobTableName}' and zp.PARENT_ID = {$item['idDatabase']})
- join CRM_LISTA_ZASOBOW z on(z.PARENT_ID = zp.ID and z.`DESC` = t.fieldNamespace)
- set t.idZasob = z.ID
- where t.objectNamespace = '{$item['namespace']}'
- ");
- $struct = $this->getItems([
- '__backRef' => [
- 'namespace' => 'default_objects/SystemObject',
- 'primaryKey' => $item['namespace']
- ]
- ]);
- DBG::nicePrint($struct, '$struct');
- {// TODO: DBG
- $schema = ['xsd:schema', [
- 'xmlns:xsd' => "http://www.w3.org/2001/XMLSchema",
- 'xmlns:gml' => "http://www.opengis.net/gml",
- 'xmlns:p5' => "https://biuro.biall-net.pl/wfs",
- 'xmlns:default_db' => "https://biuro.biall-net.pl/wfs/default_db",
- 'xmlns:default_objects' => "https://biuro.biall-net.pl/wfs/default_objects",
- 'elementFormDefault' => "qualified",
- 'version' => "1.0.0",
- ], []];
- Lib::loadClass('Api_WfsNs');
- $tnsUri = Api_WfsNs::getNsUri($item['nsPrefix']);
- $schema[1]['xmlns:' . Api_WfsNs::getNsPrefix($tnsUri)] = $tnsUri;
- $schema[1]['targetNamespace'] = $tnsUri;
- $schema[2][] = ['xsd:import', ['namespace'=>"http://www.opengis.net/gml", 'schemaLocation'=>"https://biuro.biall-net.pl/dev-pl/se-master/schema/gml/2.1.2/feature.xsd"], null];
- $schema[2][] = ['xsd:complexType', [ 'name'=> $item['name'] . "Type" ], [
- [ 'xsd:complexContent', [], [
- [ 'xsd:extension', ['base'=>"gml:AbstractFeatureType"], [
- [ 'xsd:sequence', [], array_map(function ($field) {
- $attrs = [
- 'name' => $field['fieldNamespace'],
- // <xsd:element minOccurs="1" maxOccurs="1" name="ID" type="xsd:integer" nillable="true"/>
- 'minOccurs' => $field['minOccurs'],
- 'maxOccurs' => $field['maxOccurs'],
- ];
- $childrens = null;
- $restrictions = [];
- foreach (self::getXsdRestrictionsValue($field) as $k => $v) {
- if ('enumeration' == $k) {
- foreach ($v as $enumValue) {
- $restrictions[] = [ 'xsd:enumeration', [ 'value' => $enumValue ], null ];
- }
- } else if ('maxLength' == $k) {
- $restrictions[] = [ 'xsd:maxLength', [ 'value' => $v ], null ];
- } else if ('totalDigits' == $k) {
- $restrictions[] = [ 'xsd:totalDigits', [ 'value' => $v ], null ];
- } else if ('fractionDigits' == $k) {
- $restrictions[] = [ 'xsd:fractionDigits', [ 'value' => $v ], null ];
- } else if ('nillable' == $k) {
- if ($v) $attrs['nillable'] = "true";
- } else {
- DBG::log(['TODO' => $k, $v]);
- }
- }
- if (!empty($restrictions)) {
- $childrens = [
- [ 'xsd:simpleType', [], [
- [ 'xsd:restriction', [ 'base' => $field['xsdType'] ], $restrictions ]
- ] ]
- ];
- } else {
- $attrs['type'] = $field['xsdType'];
- }
- return [ 'xsd:element', $attrs, $childrens ];
- }, $struct) ]
- ] ]
- ] ]
- ] ];
- $schema[2][] = ['xsd:element', [ 'name' => $item['name'], 'type' => "{$item['nsPrefix']}:{$item['name']}Type", 'substitutionGroup' => "gml:_Feature" ], null];
- DBG::nicePrint($schema, '$schema');
- Lib::loadClass('Core_XmlWriter');
- ob_start();
- $xmlWriter = new Core_XmlWriter();
- $xmlWriter->openUri('php://output');
- $xmlWriter->setIndent(true);
- $xmlWriter->startDocument('1.0','UTF-8');
- $xmlWriter->h($schema[0], $schema[1], $schema[2]);
- $xmlWriter->endDocument();
- echo UI::h('pre', ['style' => 'max-height:400px; overflow:scroll'], htmlspecialchars(ob_get_clean()));
- }
- }
- public function _parseWhere($params = []) {
- $sqlWhere = [];
- DBG::log($params, 'array', "SystemObject::_parseWhere");
- if (!empty($params['__backRef'])) {
- // '__backRef' => [
- // 'namespace' => 'default_objects/SystemObject',
- // 'primaryKey' => 'default_db/TEST_PERMS',
- // ),
- if (empty($params['__backRef']['namespace'])) throw new Exception("Missing refFrom/namespace");
- if (empty($params['__backRef']['primaryKey'])) throw new Exception("Missing refFrom/primaryKey");
- if ('default_objects/SystemObject' != $params['__backRef']['namespace']) throw new Exception("Unsupported refFrom/namespace '{$params['__backRef']['namespace']}'");
- $sqlWhere[] = "t.objectNamespace = " . DB::getPDO()->quote($params['__backRef']['primaryKey'], PDO::PARAM_INT);
- }
- {
- $filterParams = [];
- $xsdFields = $this->getXsdTypes();
- DBG::log($xsdFields);
- foreach ($params as $k => $v) {
- if ('f_' != substr($k, 0, 2)) continue;
- $fieldName = substr($k, 2);
- if (!array_key_exists($fieldName, $xsdFields)) {
- // TODO: check query by xpath or use different param prefix
- throw new Exception("Field '{$fieldName}' not found in '{$this->_namespace}'");
- }
- if ('p5:' == substr($xsdFields[$fieldName], 0, 3)) {
- continue;
- }
- $filterParams[$fieldName] = $v;
- }
- }
- if (!empty($filterParams)) {
- DBG::log($filterParams, 'array', "SystemObject::_parseWhere TODO \$filterParams");
- foreach ($filterParams as $fieldName => $value) {
- if (is_array($value)) {
- DBG::log($value, 'array', "TODO SystemObject::_parseWhere array value for \$filterParams[{$fieldName}]");
- } else if (is_scalar($value)) {
- 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}]");
- }
- }
- }
- return (!empty($sqlWhere)) ? "where " . implode(" and ", $sqlWhere) : '';
- }
- public function getTotal($params = []) {
- $sqlWhere = $this->_parseWhere($params);
- return DB::getPDO()->fetchValue("
- select count(1) as cnt
- from `{$this->_rootTableName}` t
- {$sqlWhere}
- ");
- }
- public function getItem($pk, $params = []) {
- if (!$pk) throw new Exception("Missing primary key '{$this->_namespace}'");
- $pkField = $this->getSqlPrimaryKeyField();
- if (!$pkField) throw new Exception("Missing primary key field defined in '{$this->_namespace}'");
- $sqlPk = DB::getPDO()->quote($pk, PDO::PARAM_STR);
- $item = DB::getPDO()->fetchFirst("
- select t.*
- from `{$this->_rootTableName}` t
- where t.`{$pkField}` = {$sqlPk}
- ");
- if (!$item) throw new Exception("Item '{$pk}' not exists - type '{$this->_namespace}'");
- return $this->buildFeatureFromSqlRow($item, $params);
- }
- public function getItems($params = []) {
- $sqlWhere = $this->_parseWhere($params);
- $currSortCol = V::get('order_by', 'idZasob', $params);
- $currSortFlip = strtolower(V::get('order_dir', 'desc', $params));
- // TODO: validate $currSortCol is in field list
- // TODO: validate $currSortFlip ('asc' or 'desc')
- $xsdFields = $this->getXsdTypes();
- if (!array_key_exists($currSortCol, $xsdFields)) throw new Exception("Field '{$currSortCol}' not found in '{$this->_namespace}'");
- if (!in_array($currSortFlip, ['asc', 'desc'])) throw new Exception("Sort dir not allowed");
- $sqlOrderBy = "order by t.`{$currSortCol}` {$currSortFlip}";
- $limit = V::get('limit', 0, $params, 'int');
- $limit = ($limit < 0) ? 0 : $limit;
- $offset = V::get('limitstart', 0, $params, 'int');
- $offset = ($offset < 0) ? 0 : $offset;
- $sqlLimit = ($limit > 0)
- ? "limit {$limit} offset {$offset}"
- : '';
- return array_map(array($this, 'buildFeatureFromSqlRow'), DB::getPDO()->fetchAll("
- select t.*
- from `{$this->_rootTableName}` t
- {$sqlWhere}
- {$sqlOrderBy}
- {$sqlLimit}
- "));
- }
- static function getXsdRestrictionsValue($fieldInfo) {
- $xsdRestrictions = @json_decode($fieldInfo['xsdRestrictions'], $assoc = true);
- if (empty($xsdRestrictions)) $xsdRestrictions = [];
- if (array_key_exists('__DBG__', $xsdRestrictions)) unset($xsdRestrictions['__DBG__']);
- return $xsdRestrictions;
- }
- public function buildFeatureFromSqlRow($item) {
- if ('p5:enum' == V::get('xsdType', '', $item)) {
- $xsdRestrictions = @json_decode($item['xsdRestrictions'], $assoc = true);
- $xsdRestrictions['enumeration'] = [];
- foreach (DB::getPDO()->fetchAll("
- select t.value, t.label
- from `{$this->_enumRootTableName}` t
- where t.objectNamespace = '{$item['objectNamespace']}'
- and t.fieldNamespace = '{$item['fieldNamespace']}'
- and t.isActive = 1
- order by sortPrio DESC
- ") as $enum) {
- $xsdRestrictions['enumeration'][ $enum['value'] ] = $enum['label'];
- }
- $item['xsdRestrictions'] = json_encode($xsdRestrictions);
- }
- return $item;
- }
- public function updateItem($itemPatch) {
- SchemaFactory::loadDefaultObject('SystemObject')->clearGetItemCache();
- $pkField = $this->getPrimaryKeyField();
- $pk = V::get($pkField, null, $itemPatch);
- if (null === $pk) throw new Exception("BUG missing primary key field for '{$this->_namespace}' updateItem");
- DBG::log(['updateItem $itemPatch', $itemPatch]);
- unset($itemPatch[$pkField]);
- if (empty($itemPatch)) return 0;
- foreach ($itemPatch as $fieldName => $value) {
- if ('idZasob' == $fieldName) continue;
- throw new Exception("Update field '{$fieldName}' not allowed for '{$this->_namespace}'");
- }
- return DB::getPDO()->update($this->_rootTableName, $pkField, $pk, $itemPatch);
- }
- }
|