فهرست منبع

fixed missing ref links in WFS when more then 10 refs child found

Piotr Labudda 8 سال پیش
والد
کامیت
88a8ee63c6
1فایلهای تغییر یافته به همراه29 افزوده شده و 20 حذف شده
  1. 29 20
      SE/se-lib/AclQueryFeatures.php

+ 29 - 20
SE/se-lib/AclQueryFeatures.php

@@ -595,13 +595,6 @@ class AclQueryFeatures {
 		}, $rows));
 		DBG::log($this->_foundFeatures, 'array', "_foundFeatures");
 		return array_map([ $this, 'fetchRowRefs' ], $rows);
-		// if (!empty($rows) && !empty($rows[0])) {
-		//	 $rows[0]['default_db__x3A__CRM_WSKAZNIK:CRM_WSKAZNIK'] = [
-		//		 [ 'xlink' => 'default_db__x3A__CRM_WSKAZNIK:CRM_WSKAZNIK.999' ],
-		//		 [ 'xlink' => 'default_db__x3A__CRM_WSKAZNIK:CRM_WSKAZNIK.998' ],
-		//	 ];
-		// }
-		return $rows;
 	}
 
 	public function fetchRowRefs($row) {
@@ -610,11 +603,10 @@ class AclQueryFeatures {
 		$primaryKey = $row[$sqlPk];
 		DBG::log($row, 'array', "DBG primaryKey '{$primaryKey}'");
 		if (!$primaryKey) throw new Exception("Missing primaryKey");
+		$defaultRefLimit = 10; // TODO: get from $this->_params and pass to nested buildQuery
+		$refLimitPlus1 = $defaultRefLimit + 1;
 		foreach ($this->getSelectRemote() as $fieldName => $cols) {
 			DBG::log($cols, 'array', "add select remote '{$fieldName}' \$cols");
-
-			$refLimit = 10; // TODO: get from $this->_params and pass to nested buildQuery
-			$refLimitPlus1 = $refLimit + 1;
 			$xsdType = $this->_acl->getXsdFieldType($fieldName);
 			if ('ref:' === substr($xsdType, 0, 4) && empty($cols)) {
 				DBG::log("add remote xlink's '{$fieldName}' \$items[{$primaryKey}] ...");
@@ -635,32 +627,49 @@ class AclQueryFeatures {
 							'xlink' => "{$ns['url']}#{$ns['name']}.{$refInfo['REMOTE_PRIMARY_KEY']}",
 						];
 					}, $xlinks);
-					if (count($xlinks) > $refLimit) DBG::log('TODO: xlink FETCH MORE DATA...');
-					if (count($xlinks) > $refLimit) $row[$fieldName][] = [ 'p5:links' => [
+					if (count($xlinks) > $defaultRefLimit) DBG::log('TODO: xlink FETCH MORE DATA...');
+					if (count($xlinks) > $defaultRefLimit) $row[$fieldName][] = [ 'p5:links' => [
 						'p5:next' => [
 							'@typeName' => $fieldName,
 							'@backRefNS' => $this->_acl->getNamespace(),
 							'@backRefPK' => $primaryKey,
-							'@startIndex' => $refLimit,
-							'value' => Request::getScriptUri() . "?SERVICE=WFS&VERSION=1.0.0&TYPENAME={$fieldName}&REQUEST=GetFeature&backRefNS=".$this->_acl->getNamespace()."&backRefPK={$primaryKey}&backRefField={$fieldName}&startIndex={$refLimit}",
+							'@startIndex' => $defaultRefLimit,
+							'value' => Request::getScriptUri() . "?SERVICE=WFS&VERSION=1.0.0&TYPENAME={$fieldName}&REQUEST=GetFeature&backRefNS=".$this->_acl->getNamespace()."&backRefPK={$primaryKey}&backRefField={$fieldName}&startIndex={$defaultRefLimit}",
 						],
 					] ];
 					DBG::log($row[$fieldName], 'array', "remote xlinks for \$items[{$primaryKey}][{$fieldName}]");
 				}
 			} else if ('ref:' === substr($xsdType, 0, 4) && !empty($cols)) {
 				$refAcl = ACL::getAclByTypeName($fieldName);
-				$items = $refAcl->buildQuery([
+				$refQuery = $refAcl->buildQuery([
 					'cols' => $cols,
 					'__backRef' => [
 						'namespace' => $this->_acl->getNamespace(),
 						'primaryKey' => $primaryKey,
 						'fieldName' => $fieldName,
 					],
+					'limit' => $refLimitPlus1,
 					'skipFeaturesAsXlink' => $this->_foundFeatures
-					// TODO: add $refLimit + 1
-				])->getItems();
-				// TODO: if (count($items) > $refLimit) // TODO: add item for GUI - has more data + wfs link to fetch more (offset)
-				DBG::log($items, 'array', "add remote items '{$fieldName}' \$items");
+					// TODO: add $defaultRefLimit + 1
+				]);
+				$totalRefs = $refQuery->getTotal();
+				$items = $refQuery->getItems([ 'limit' => $defaultRefLimit ]);
+				// TODO: if (count($items) > $defaultRefLimit) // TODO: add item for GUI - has more data + wfs link to fetch more (offset)
+				DBG::log($items, 'array', "add remote items '{$fieldName}' \$items[{$primaryKey}][{$fieldName}] total({$totalRefs})");
+				if ($totalRefs > $defaultRefLimit) {
+					DBG::log('TODO: resolve recurse fetch more data link');
+					array_pop($items); // remove last item
+					$items[] = [ 'p5:links' => [
+						'p5:next' => [
+							'@typeName' => $fieldName,
+							'@backRefNS' => $this->_acl->getNamespace(),
+							'@backRefPK' => $primaryKey,
+							'@startIndex' => $defaultRefLimit,
+							'value' => Request::getScriptUri() . "?SERVICE=WFS&VERSION=1.0.0&TYPENAME={$fieldName}&REQUEST=GetFeature&backRefNS=".$this->_acl->getNamespace()."&backRefPK={$primaryKey}&backRefField={$fieldName}&startIndex={$defaultRefLimit}",
+						],
+					] ];
+				}
+
 				$refNs = $refAcl->getNamespace();
 				$refPk = $refAcl->getPrimaryKeyField();
 				$this__hasFeatureId = [ $this, 'hasFeatureId' ];
@@ -690,7 +699,7 @@ class AclQueryFeatures {
 	}
 	public function addFeatureId($featureId) {
 		$this->_foundFeatures[] = $featureId;
-		DBG::log($this->_foundFeatures, 'array', "TODO: addFeatureId({$featureId})");
+		DBG::log($this->_foundFeatures, 'array', "addFeatureId({$featureId})");
 	}
 
 	public function getAclSqlPrimaryKeyField() {