Просмотр исходного кода

working wps function select / unselect Feature

Piotr Labudda 8 лет назад
Родитель
Сommit
604f3e5cf8

+ 23 - 0
SE/se-lib/Api/Process/P5/SelectFeature.php

@@ -0,0 +1,23 @@
+<?php
+
+Lib::loadClass('FeatureAttrSelected');
+
+class Api_Process_P5_SelectFeature { // 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::select($typeName, $listPrimaryKeys);
+
+		header('Content-Type: application/json');
+		echo json_encode([
+			'type' => "success",
+			'msg' => "done",
+		]);
+		exit;
+	}
+
+}

+ 23 - 0
SE/se-lib/Api/Process/P5/UnselectFeature.php

@@ -0,0 +1,23 @@
+<?php
+
+Lib::loadClass('FeatureAttrSelected');
+
+class Api_Process_P5_UnselectFeature { // 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::unselect($typeName, $listPrimaryKeys);
+
+		header('Content-Type: application/json');
+		echo json_encode([
+			'type' => "success",
+			'msg' => "done",
+		]);
+		exit;
+	}
+
+}

+ 13 - 0
SE/se-lib/Api/WpsHelper.php

@@ -89,4 +89,17 @@ class Api_WpsHelper {
 		}
 	}
 
+	static function executeProcess($wpsProcess, $args, $responseForm = 'json') {
+		$className = implode("_", array_merge(
+			[
+				'Api',
+				'Process',
+			], array_map('ucfirst', explode(':', $wpsProcess->identifier))
+		) );
+		if (!Lib::tryLoadClass($className)) {
+			throw new Api_OwsException("Api Process not found '{$wpsProcess->identifier}'", 500, null, 'ApiProcessNotFound', 'request');
+		}
+		$className::run($args, $responseForm);
+	}
+
 }

+ 2 - 1
SE/se-lib/Api/WpsV1/Server.php

@@ -72,13 +72,14 @@ class Api_WpsV1_Server extends Api_WpsV1_ServerBase {
 	}
 	function _runExecute($xml) {
 		$funInfo = self::_parseExecuteXmlArray($xml);
-		print_r($funInfo);
 		$identifier = V::get('identifier', '', $funInfo);
 		$args = V::get('args', [], $funInfo, 'array');
 		if (empty($identifier)) throw new Exception("Parse xml request error - missing identifier");
 		Lib::loadClass('Api_WpsHelper');
 		$wpsProcess = Api_WpsHelper::getUserWpsProcess($identifier);
 		Api_WpsHelper::validateProcessArgs($wpsProcess, $args);
+		Api_WpsHelper::executeProcess($wpsProcess, $args);
+		exit;
 	}
 
 	function describeProcessAction() {

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

@@ -0,0 +1,57 @@
+<?php
+
+class FeatureAttrSelected {
+
+	static function select($typeName, array $listPrimaryKeys) {
+		$idUser = User::getID();
+		self::prepareUserTable($typeName, $idUser);
+		$tableName = self::getAttributeTableName($typeName, $idUser);
+		foreach ($listPrimaryKeys as $pk) {
+			DB::getPDO()->execSql(" insert ignore `{$tableName}` (`primaryKey`) values ( :pk ) ", [ ':pk' => $pk ]);
+		}
+	}
+
+	static function unselect($typeName, array $listPrimaryKeys) {
+		$idUser = User::getID();
+		self::prepareUserTable($typeName, $idUser);
+		$tableName = self::getAttributeTableName($typeName, $idUser);
+		foreach ($listPrimaryKeys as $pk) {
+			DB::getPDO()->execSql(" delete from `{$tableName}` where `primaryKey` = :pk ", [ ':pk' => $pk ]);
+		}
+	}
+
+	static function prepareUserTable($typeName, $idUser) {
+		static $_created = [];
+		$key = "{$typeName}-{$idUser}";
+		if (!array_key_exists($key, $_created)) {
+			self::_prepareUserTable($typeName, $idUser);
+			$_created[$key] = true;
+		}
+	}
+	static function _prepareUserTable($typeName, $idUser) {
+		$tableName = self::getAttributeTableName($typeName, $idUser);
+		// DB::getPDO()->execSql(" DROP TABLE IF EXISTS `{$tableName}` ");
+		// TODO: primaryKey type from $acl
+		DB::getPDO()->execSql("
+			CREATE TABLE IF NOT EXISTS `{$tableName}` (
+				`primaryKey` int(11) NOT NULL,
+				UNIQUE KEY `primaryKey` (`primaryKey`)
+			) ENGINE=MyISAM DEFAULT CHARSET=latin2;
+		");
+	}
+
+	static function getAttributeTableName($typeName, $idUser) {
+		static $_created = [];
+		$key = "{$typeName}-{$idUser}";
+		if (!array_key_exists($key, $_created)) {
+			$_created[$key] = self::_getAttributeTableName($typeName, $idUser);
+		}
+		return $_created[$key];
+	}
+	static function _getAttributeTableName($typeName, $idUser) {
+		$acl = ACL::getAclByTypeName($typeName);
+		$rootTableName = $acl->getRootTableName();
+		return "{$rootTableName}__@selected_{$idUser}";
+	}
+
+}