Jelajahi Sumber

added wps api methods for selected features

Piotr Labudda 8 tahun lalu
induk
melakukan
70adb93b87

+ 28 - 0
SE/se-lib/Api/Process/P5/GetSelectedFeatures.php

@@ -0,0 +1,28 @@
+<?php
+
+Lib::loadClass('FeatureAttrSelected');
+
+class Api_Process_P5_GetSelectedFeatures { // TODO: extends Api_ProcessBase
+
+	static function run($args, $responseForm) {
+		$typeName = (!empty($args['typeName'][0])) ? $args['typeName'][0] : '';
+		if (!$typeName) throw new Api_OwsException("Missing value for 'typeName'", 501, null, 'MissingParameterValue', 'request');
+		$listPrimaryKeys = (!empty($args['primaryKey'])) ? $args['primaryKey'] : [];
+		if (empty($listPrimaryKeys)) throw new Api_OwsException("Missing value for 'primaryKey'", 501, null, 'MissingParameterValue', 'request');
+
+		$listSelectedState = FeatureAttrSelected::getSelectState($typeName, $listPrimaryKeys);
+		$totalSelected = FeatureAttrSelected::getTotalSelected($typeName);
+
+		header('Content-Type: application/json');
+		echo json_encode([
+			'type' => "success",
+			'msg' => "done",
+			'body' => [
+				'selected' => $listSelectedState,
+				'totalSelected' => $totalSelected,
+			]
+		]);
+		exit;
+	}
+
+}

+ 4 - 2
SE/se-lib/Api/Process/P5/SelectFeature.php

@@ -11,14 +11,16 @@ class Api_Process_P5_SelectFeature { // TODO: extends Api_ProcessBase
 		if (empty($listPrimaryKeys)) throw new Api_OwsException("Missing value for 'primaryKey'", 501, null, 'MissingParameterValue', 'request');
 		if (empty($listPrimaryKeys)) throw new Api_OwsException("Missing value for 'primaryKey'", 501, null, 'MissingParameterValue', 'request');
 
 
 		FeatureAttrSelected::select($typeName, $listPrimaryKeys);
 		FeatureAttrSelected::select($typeName, $listPrimaryKeys);
-		$lsistSelectedState = FeatureAttrSelected::getSelectState($typeName, $listPrimaryKeys);
+		$listSelectedState = FeatureAttrSelected::getSelectState($typeName, $listPrimaryKeys);
+		$totalSelected = FeatureAttrSelected::getTotalSelected($typeName);
 
 
 		header('Content-Type: application/json');
 		header('Content-Type: application/json');
 		echo json_encode([
 		echo json_encode([
 			'type' => "success",
 			'type' => "success",
 			'msg' => "done",
 			'msg' => "done",
 			'body' => [
 			'body' => [
-				'selected' => $lsistSelectedState
+				'selected' => $listSelectedState,
+				'totalSelected' => $totalSelected,
 			]
 			]
 		]);
 		]);
 		exit;
 		exit;

+ 29 - 0
SE/se-lib/Api/Process/P5/UnselectAllFeatures.php

@@ -0,0 +1,29 @@
+<?php
+
+Lib::loadClass('FeatureAttrSelected');
+
+class Api_Process_P5_UnselectAllFeatures { // TODO: extends Api_ProcessBase
+
+	static function run($args, $responseForm) {
+		$typeName = (!empty($args['typeName'][0])) ? $args['typeName'][0] : '';
+		if (!$typeName) throw new Api_OwsException("Missing value for 'typeName'", 501, null, 'MissingParameterValue', 'request');
+		// $listPrimaryKeys = (!empty($args['primaryKey'])) ? $args['primaryKey'] : [];
+		// if (empty($listPrimaryKeys)) throw new Api_OwsException("Missing value for 'primaryKey'", 501, null, 'MissingParameterValue', 'request');
+
+		FeatureAttrSelected::unselectAll($typeName);
+		// $listSelectedState = FeatureAttrSelected::getSelectState($typeName, $listPrimaryKeys);
+		// $totalSelected = FeatureAttrSelected::getTotalSelected($typeName);
+
+		header('Content-Type: application/json');
+		echo json_encode([
+			'type' => "success",
+			'msg' => "done",
+			'body' => [
+				'selected' => [], // $listSelectedState,
+				'totalSelected' => 0, // $totalSelected,
+			]
+		]);
+		exit;
+	}
+
+}

+ 4 - 2
SE/se-lib/Api/Process/P5/UnselectFeature.php

@@ -11,14 +11,16 @@ class Api_Process_P5_UnselectFeature { // TODO: extends Api_ProcessBase
 		if (empty($listPrimaryKeys)) throw new Api_OwsException("Missing value for 'primaryKey'", 501, null, 'MissingParameterValue', 'request');
 		if (empty($listPrimaryKeys)) throw new Api_OwsException("Missing value for 'primaryKey'", 501, null, 'MissingParameterValue', 'request');
 
 
 		FeatureAttrSelected::unselect($typeName, $listPrimaryKeys);
 		FeatureAttrSelected::unselect($typeName, $listPrimaryKeys);
-		$lsistSelectedState = FeatureAttrSelected::getSelectState($typeName, $listPrimaryKeys);
+		$listSelectedState = FeatureAttrSelected::getSelectState($typeName, $listPrimaryKeys);
+		$totalSelected = FeatureAttrSelected::getTotalSelected($typeName);
 
 
 		header('Content-Type: application/json');
 		header('Content-Type: application/json');
 		echo json_encode([
 		echo json_encode([
 			'type' => "success",
 			'type' => "success",
 			'msg' => "done",
 			'msg' => "done",
 			'body' => [
 			'body' => [
-				'selected' => $lsistSelectedState
+				'selected' => $listSelectedState,
+				'totalSelected' => $totalSelected,
 			]
 			]
 		]);
 		]);
 		exit;
 		exit;

+ 24 - 16
SE/se-lib/Api/WpsHelper.php

@@ -34,24 +34,26 @@ class Api_WpsHelper {
 		$defaultWpsProcessList = [];
 		$defaultWpsProcessList = [];
 
 
 		{
 		{
+			$selectFeatureArgTypeName = [
+				'maxOccurs' => "1",
+				'minOccurs' => "1",
+				'identifier' => 'typeName',
+				'title' => "Feature typeName",
+				'description' => "Feature typeName eg. default_db/PROBLEMS",
+				'type' => 'literal',
+			];
+			$selectFeatureArgPrimaryKey = [
+				'maxOccurs' => "unbounded",
+				'minOccurs' => "1",
+				'identifier' => 'primaryKey',
+				'title' => "Feature primaryKey",
+				'description' => "Feature primaryKey",
+				'type' => 'literal',
+			];
 			$selectFeatureBase = [
 			$selectFeatureBase = [
 				'dataInputs' => [
 				'dataInputs' => [
-					[
-						'maxOccurs' => "1",
-						'minOccurs' => "1",
-						'identifier' => 'typeName',
-						'title' => "Feature typeName",
-						'description' => "Feature typeName eg. default_db/PROBLEMS",
-						'type' => 'literal',
-					],
-					[
-						'maxOccurs' => "unbounded",
-						'minOccurs' => "1",
-						'identifier' => 'primaryKey',
-						'title' => "Feature primaryKey",
-						'description' => "Feature primaryKey",
-						'type' => 'literal',
-					],
+					$selectFeatureArgTypeName,
+					$selectFeatureArgPrimaryKey,
 				],
 				],
 				// 'MimeType' => text/xml, 'Encoding' => base64, 'Schema' => http://foo.bar/gml/3.1.0/polygon.xsd
 				// 'MimeType' => text/xml, 'Encoding' => base64, 'Schema' => http://foo.bar/gml/3.1.0/polygon.xsd
 				'defaultOutput' => [ 'MimeType' => "application/json" ], // TODO: result type - like Insert Wfs Transaction result - list of: Success (primaryKey = 123), ...
 				'defaultOutput' => [ 'MimeType' => "application/json" ], // TODO: result type - like Insert Wfs Transaction result - list of: Success (primaryKey = 123), ...
@@ -66,6 +68,12 @@ class Api_WpsHelper {
 			];
 			];
 			$defaultWpsProcessList['p5:selectFeature']   = array_merge([ 'title' => "Select feature", 'descriptin' => "Select feature (set attribute @selected to true)" ], $selectFeatureBase);
 			$defaultWpsProcessList['p5:selectFeature']   = array_merge([ 'title' => "Select feature", 'descriptin' => "Select feature (set attribute @selected to true)" ], $selectFeatureBase);
 			$defaultWpsProcessList['p5:unselectFeature'] = array_merge([ 'title' => "Unselect feature", 'descriptin' => "Unselect feature (set attribute @selected to false)" ], $selectFeatureBase);
 			$defaultWpsProcessList['p5:unselectFeature'] = array_merge([ 'title' => "Unselect feature", 'descriptin' => "Unselect feature (set attribute @selected to false)" ], $selectFeatureBase);
+			$defaultWpsProcessList['p5:getSelectedFeatures'] = array_merge([ 'title' => "Get selected features", 'descriptin' => "Get list of selected features (with attribute @selected = true)" ], $selectFeatureBase);
+			$defaultWpsProcessList['p5:unselectAllFeatures'] = array_merge([ 'title' => "Unselect all features", 'descriptin' => "Unselect all features (set attribute @selected to false)" ], $selectFeatureBase, [
+				'dataInputs' => [
+					$selectFeatureArgTypeName
+				]
+			]);
 		}
 		}
 
 
 		array_walk($defaultWpsProcessList, function (&$wpsFunction, $identifier) {
 		array_walk($defaultWpsProcessList, function (&$wpsFunction, $identifier) {

+ 17 - 0
SE/se-lib/FeatureAttrSelected.php

@@ -2,6 +2,16 @@
 
 
 class FeatureAttrSelected {
 class FeatureAttrSelected {
 
 
+	static function getTotalSelected($typeName) {
+		$idUser = User::getID();
+		self::prepareUserTable($typeName, $idUser);
+		$tableName = self::getAttributeTableName($typeName, $idUser);
+		return (int)DB::getPDO()->fetchValue("
+			select count(*) as total
+			from `{$tableName}`
+		");
+	}
+
 	static function getSelectState($typeName, array $listPrimaryKeys) {
 	static function getSelectState($typeName, array $listPrimaryKeys) {
 		$idUser = User::getID();
 		$idUser = User::getID();
 		self::prepareUserTable($typeName, $idUser);
 		self::prepareUserTable($typeName, $idUser);
@@ -39,6 +49,13 @@ class FeatureAttrSelected {
 		}
 		}
 	}
 	}
 
 
+	static function unselectAll($typeName) {
+		$idUser = User::getID();
+		self::prepareUserTable($typeName, $idUser);
+		$tableName = self::getAttributeTableName($typeName, $idUser);
+		DB::getPDO()->execSql(" truncate table `{$tableName}` ");
+	}
+
 	static function prepareUserTable($typeName, $idUser) {
 	static function prepareUserTable($typeName, $idUser) {
 		static $_created = [];
 		static $_created = [];
 		$key = "{$typeName}-{$idUser}";
 		$key = "{$typeName}-{$idUser}";

+ 1 - 0
SE/wps.php

@@ -60,6 +60,7 @@ try {
 	$api->setBaseUri($apiBaseUri);// TODO: RMME - replaced with Api_WfsNs::getBaseWfsUri();
 	$api->setBaseUri($apiBaseUri);// TODO: RMME - replaced with Api_WfsNs::getBaseWfsUri();
 	$api->execute($taskPath);
 	$api->execute($taskPath);
 }
 }
+// TODO: catch Api_WfsException, Api_OwsException?
 catch (HttpException $e) {
 catch (HttpException $e) {
 	DBG::log($e);
 	DBG::log($e);
 	Http::sendHeaderByCode($e->getCode());
 	Http::sendHeaderByCode($e->getCode());