diff --git a/geoapi/api/PisApi.php b/geoapi/api/PisApi.php index 2f81ff2..d4dd5a3 100644 --- a/geoapi/api/PisApi.php +++ b/geoapi/api/PisApi.php @@ -26,6 +26,12 @@ class PisApi extends Api { */ public static $routeParameterINames = "/iname/:iname+"; + /** + * public string for the patter string parameter + * @var string + */ + public static $routParameterIPatter = "ipatter/:ipatter"; + /** * Keyword for pidList arguments * @var string @@ -38,6 +44,12 @@ class PisApi extends Api { */ public static $keyINameList = "iNameList"; + /** + * Keyword for iNameList arguments + * @var string + */ + public static $keyIPatter = "searchPatter"; + /** * max number of pid for each query * @var int @@ -66,22 +78,27 @@ class PisApi extends Api { * @return query result as xml */ public function sendPisQuery($queryArgs) { - $pidList = \utiliy\ArrayManager::removeEmptyItmes($queryArgs[self::$keyPidList]); - + $pidList = \utiliy\ArrayManager::removeEmptyItmes($queryArgs[self::$keyPidList]); + if (array_key_exists(self::$keyINameList, $queryArgs)) { $iNameList = \utiliy\ArrayManager::removeEmptyItmes($queryArgs[self::$keyINameList]); } else { $iNameList = array(); } - + + if (array_key_exists(self::$keyIPatter, $queryArgs)) { + $iPatter = trim($queryArgs[self::$keyIPatter]); + } else { + $iPatter = "*"; + } + if (count($pidList) < self::$maxPid) { - $result = $this->sqlManager->sendPisQuery($pidList, $iNameList); + $result = $this->sqlManager->sendPisQuery($pidList, $iNameList,$iPatter); return $this->serialManager->arrayToPis($result); } return NULL; } - } ?> diff --git a/geoapi/database/PisSqlManager.php b/geoapi/database/PisSqlManager.php index b7b18d4..64e046c 100644 --- a/geoapi/database/PisSqlManager.php +++ b/geoapi/database/PisSqlManager.php @@ -61,6 +61,12 @@ class PisSqlManager extends SQLManager { * @var string */ private static $orderByTerm = " ORDER BY pid, iName"; + + /** + * String for like-Statement fo iValue field + * @var string + */ + private static $iValueLikeTerm = "iValue LIKE "; /** * String for the pid part of the query @@ -74,6 +80,12 @@ class PisSqlManager extends SQLManager { */ private static $iNameTerm = "iName = "; + /** + * Variable for the max lenght of an valid pattern string + * @var int + */ + private static $patterMaxLenght = 30; + /** * Default-Constructor */ @@ -93,7 +105,7 @@ class PisSqlManager extends SQLManager { * @param array $queryArgs * @return array [num][assoc] */ - public function sendPisQuery($pidList, $iNameList) { + public function sendPisQuery($pidList, $iNameList, $iPatter = "*") { // build query string $query = self::$selectTerm; @@ -114,15 +126,35 @@ class PisSqlManager extends SQLManager { $query .= self::$closeBracket; } + if ($iPatter != "*" && $this->validIPatter($iPatter)) { + if ($query != self::$selectTerm) { + $query .= self::$andTerm; + } + $query .= self::$iValueLikeTerm ."'%$iPatter%'"; + } + if ($query == self::$selectTerm) { $query = self::$selectAllTerm; } $query .= self::$orderByTerm; + // send query return $this->query($query); } + /** + * Method check if the input value for pattern string is valid + * @param string $domain + * @return boolean + */ + private function validIPatter($iPatter) { + if (\utiliy\StringManager::validSQLString($iPatter) && ctype_alnum($iPatter) && strlen($iPatter) <= self::$patterMaxLenght) { + return TRUE; + } + return FALSE; + } + } ?> diff --git a/geoapi/service/pis/index.php b/geoapi/service/pis/index.php index d9e3e17..c86b337 100644 --- a/geoapi/service/pis/index.php +++ b/geoapi/service/pis/index.php @@ -10,16 +10,18 @@ $headers = apache_request_headers(); $app = new \api\PisApi($headers); // HTTP-Get-Method -$app->get(\api\PisApi::$routeParameterPids . \api\PisApi::$routeParameterINames, function ($pid, $iNames = array()) use ($app) { +$app->get(\api\PisApi::$routeParameterPids . \api\PisApi::$routeParameterINames . \api\PisApi::$routParameterIPatter, function ($pid, $iNames = array(), $iPatter = "*") use ($app) { $queryArgs = array(); $queryArgs[\api\PisApi::$keyPidList] = $pid; $queryArgs[\api\PisApi::$keyINameList] = $iNames; + $queryArgs[\api\PisApi::$keyIPatter] = $iPatter; echo $app->sendPisQuery($queryArgs); }); -$app->get(\api\PisApi::$routeParameterPids, function ($pid) use ($app) { +$app->get(\api\PisApi::$routeParameterPids . \api\PisApi::$routParameterIPatter, function ($pid, $iPatter = "*") use ($app) { $queryArgs = array(); $queryArgs[\api\PisApi::$keyPidList] = $pid; + $queryArgs[\api\PisApi::$keyIPatter] = $iPatter; echo $app->sendPisQuery($queryArgs); });