Parcourir la source

added '@instance' for search params['cols']

Piotr Labudda il y a 9 ans
Parent
commit
0c76bb802d

+ 19 - 1
SE/se-lib/Core/AclSimpleSchemaBase.php

@@ -385,7 +385,13 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
       }
     } else {
       foreach ($cols as $fieldXPath) {
-        if (false === strpos($fieldXPath, '/')) {// not xpath - field name
+        if ('@' == substr($fieldXPath, 0, 1)) {// attr
+          if ('@instance' === $fieldXPath) {
+            $filterCols['@instance'] = true;
+          } else {
+            throw new Exception("Not implemented attribute name '{$fieldXPath}' in '{$this->_namespace}'");
+          }
+        } else if (false === strpos($fieldXPath, '/')) {// not xpath - field name
           if (!array_key_exists($fieldXPath, $this->_simpleSchema['root'])) throw new Exception("Field name '{$fieldXPath}' not exists in '{$this->_namespace}'");
           $field = $this->_simpleSchema['root'][$fieldXPath];
           if (!empty($field['@type'])) {
@@ -406,6 +412,18 @@ class Core_AclSimpleSchemaBase extends Core_AclBase {
     $object = [];
     $filterCols = $this->getParamCols($params);
     $object['_raw'] = $row;
+    if (in_array('@instance', $filterCols)) {
+      $instanceTable = Core_AclHelper::getInstanceTable($this->getRootTableName());
+      $sqlPkFieldName = $this->getSqlPrimaryKeyField();
+      if (empty($row[$sqlPkFieldName])) throw new Exception("Missing primary key in ({$this->_namespace})");
+      $sqlPk = DB::getPDO()->quote($row[$sqlPkFieldName], PDO::PARAM_STR);
+      $object['@instance'] = DB::getPDO()->fetchValue("
+        select i.INSTANCE_NAME
+        from `{$instanceTable}` i
+        where i.PRIMARY_KEY = {$sqlPk}
+      ");// TODO: where i.`INSTANCE_TYPE` = 'instance' -- (i.`INSTANCE_TYPE` != 'derived')
+    }
+
     foreach ($this->_simpleSchema['root'] as $fieldName => $field) {
       if ('@' == substr($fieldName, 0, 1)) continue;
       if (!array_key_exists($fieldName, $filterCols)) continue;// only filter cols

+ 2 - 4
SE/se-lib/Route/UrlAction/UserProNetMediaZaliczka.php

@@ -68,6 +68,7 @@ class Route_UrlAction_UserProNetMediaZaliczka extends RouteBase {// TODO: UrlAct
 
 		$zaliczkaData = $acl->getItem($args['idZaliczka'], [
 			'cols' => [
+				'@instance',
 				'id',
 				'created',
 				'kwota',
@@ -365,10 +366,7 @@ window.location.href='{$redirectUrl}';
 
 		$acl = Core_AclHelper::getAclByNamespace("default_db/ZALICZKA/Zaliczka");
 		$schema = $acl->getSimpleSchemaTree();
-		DBG::nicePrint($schema, '$schema');
-		$zaliczkaData = $this->fetchDataBySchema($schema, $idUser);
-
-		// DBG::nicePrint($zaliczkaData, '$zaliczkaData');// TODO: DBG
+		// DBG::nicePrint($schema, '$schema');
 
 		UI::inlineJS(__FILE__ . '.fetchData.js', [
 			'SYNC_URL' => Request::getPathUri() . "index.php?_route=UrlAction_UserProNetMediaZaliczka&_task=fetchDataAjax&idUser={$idUser}&idZaliczka={$idZaliczka}",

+ 0 - 1
SE/se-lib/Schema/DefaultDb/zaliczka/ZaliczkaStorageAcl.php

@@ -193,7 +193,6 @@ class Schema_DefaultDb_zaliczka_ZaliczkaStorageAcl extends Core_AclSimpleSchemaB
     $zaliczkaRaw = (!empty($zaliczkaRaw)) ? reset($zaliczkaRaw) : null;
     // DBG::nicePrint($zaliczkaRaw, '$zaliczkaRaw');
     if (!$zaliczkaRaw) return null;
-    $filterCols = $this->getParamCols($params);
     return $this->buildFromSqlRow($zaliczkaRaw, $params);
   }