|
|
@@ -249,10 +249,26 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
|
|
|
public function canWriteObjectField($fieldName, $record) { return false; }// TODO: perms from Procesy
|
|
|
|
|
|
public function getTotal($params = array()) { throw new Exception("Unimplemented - TODO: F." . __FUNCTION__); }// TODO: use ParseOgcQuery
|
|
|
- public function getItem($primaryKey) { throw new Exception("Unimplemented - TODO: F." . __FUNCTION__); }
|
|
|
+ public function getItem($primaryKey, $params = []) { throw new Exception("Unimplemented - TODO: F." . __FUNCTION__); }
|
|
|
public function getItems($params = array()) { throw new Exception("Unimplemented - TODO: F." . __FUNCTION__); }// TODO: use ParseOgcQuery
|
|
|
public function fetchItemRef(&$items) { throw new Exception("Unimplemented - TODO: F." . __FUNCTION__); }// TODO: , $fieldName = ''
|
|
|
- public function fetchItemFieldRefs($primaryKey, $fieldName) { throw new Exception("Unimplemented - TODO: F." . __FUNCTION__); }
|
|
|
+ public function fetchItemFieldRefs($primaryKey, $fieldName) {
|
|
|
+ $refTable = Core_AclHelper::getRefTable($this->getName(), $fieldName);
|
|
|
+ $sqlPk = DB::getPDO()->quote($primaryKey, PDO::PARAM_STR);
|
|
|
+ return array_map(
|
|
|
+ function ($row) {
|
|
|
+ return [
|
|
|
+ 'xlink' => "{$row['REMOTE_TYPENAME']}.{$row['REMOTE_PRIMARY_KEY']}" // TODO:
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ , DB::getPDO()->fetchAll("
|
|
|
+ select r.REMOTE_PRIMARY_KEY, r.REMOTE_TYPENAME
|
|
|
+ from `{$refTable}` r
|
|
|
+ where r.PRIMARY_KEY = {$sqlPk}
|
|
|
+ and r.A_STATUS != 'DELETED'
|
|
|
+ ")
|
|
|
+ );
|
|
|
+ }
|
|
|
public function addItem($itemTodo) { throw new Exception("Unimplemented - TODO: " . get_class($this) . "::" . __FUNCTION__); }
|
|
|
public function updateItem($itemPatch) { throw new Exception("Unimplemented - TODO: F." . __FUNCTION__); }
|
|
|
|
|
|
@@ -307,7 +323,7 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
|
|
|
return $this->_simpleSchema['root'][$fieldName]['@@params'][$paramKey];
|
|
|
}
|
|
|
|
|
|
- public function addP5Types(&$item, $key) {
|
|
|
+ public function addP5Types(&$item) {
|
|
|
DBG::_('DBG_ACL', '>1', "\$item", $item, __CLASS__, __FUNCTION__, __LINE__);
|
|
|
$sqlSelect = [];
|
|
|
foreach ($this->_simpleSchema['root'] as $key => $field) {
|
|
|
@@ -341,4 +357,56 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public function fixParams(&$params) {// validate and fix params for getItem, getItems, etc. @see Api_WfsServerBase::parseGetFeatureArgsFromRequest()
|
|
|
+ $params['cols'] = $this->parseParamCols($params['cols']);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function parseParamCols($filterCols = []) {
|
|
|
+ V::get('cols', [], $params);// wfs:propertyName
|
|
|
+ if (empty($filterCols)) {// set default filter cols
|
|
|
+ foreach ($this->_simpleSchema['root'] as $fieldName => $field) {
|
|
|
+ if ('@' == substr($fieldName, 0, 1)) continue;
|
|
|
+ if ('unbounded' == V::get('maxOccurs', '', $field)) continue;// TODO:?: default load only single value fields (skip maxOccurs="unbounded")?
|
|
|
+ if (!empty($field['@type'])) {
|
|
|
+ if ('xsd:' === substr($field['@type'], 0, 4)) $filterCols[$fieldName] = true;
|
|
|
+ else if ('p5:' === substr($field['@type'], 0, 3)) $filterCols[$fieldName] = true;
|
|
|
+ } else if (!empty($field['@ref'])) {
|
|
|
+ $filterCols[$fieldName] = true;
|
|
|
+ } else throw new Exception("Schema error for field '{$fieldName}' ns({$this->_namespace})");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ {// fix xpath for ref fields
|
|
|
+ foreach ($filterCols as $fieldName => $bool) {
|
|
|
+ $field = $this->_simpleSchema['root'][$fieldName];
|
|
|
+ if (!empty($field['@ref'])) {
|
|
|
+ $filterCols[$fieldName] = [];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return $filterCols;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function buildFromSqlRow($row, $params = []) {
|
|
|
+ $object = [];
|
|
|
+ $filterCols = $this->parseParamCols($params['cols']);
|
|
|
+ $object['_raw'] = $row;
|
|
|
+ foreach ($this->_simpleSchema['root'] as $fieldName => $field) {
|
|
|
+ if ('@' == substr($fieldName, 0, 1)) continue;
|
|
|
+ if (!array_key_exists($fieldName, $filterCols)) continue;// only filter cols
|
|
|
+ if (!empty($field['@type'])) {
|
|
|
+ // UI::alert('warning', "TODO: field({$fieldName}) type({$field['@type']})");
|
|
|
+ if ('xsd:' === substr($field['@type'], 0, 4)) {
|
|
|
+ $sqlFieldName = (!empty($field['@alias'])) ? $field['@alias'] : $fieldName;
|
|
|
+ $object[$fieldName] = V::get($sqlFieldName, '', $row);
|
|
|
+ } else if ('p5:' === substr($field['@type'], 0, 3)) {
|
|
|
+ $object[$fieldName] = "TODO: generate value for type {$field['@type']} - field '{$fieldName}' ns({$this->_namespace})";// TODO: single field method like addP5Types
|
|
|
+ } else throw new Exception("Not Implemented type for field '{$fieldName}' ns({$this->_namespace})");
|
|
|
+ } else if (!empty($field['@ref'])) {
|
|
|
+ $object[$fieldName] = $this->fetchItemFieldRefs($primaryKey, $fieldName);
|
|
|
+ } else throw new Exception("Schema error for field '{$fieldName}' ns({$this->_namespace})");
|
|
|
+ }
|
|
|
+ return $object;
|
|
|
+ }
|
|
|
+
|
|
|
}
|