diff --git a/geoapi/api/PssApi.php b/geoapi/api/PssApi.php index a1a071c..72d5e04 100644 --- a/geoapi/api/PssApi.php +++ b/geoapi/api/PssApi.php @@ -20,6 +20,24 @@ class PssApi extends Api { * @var string */ public static $routeParameterPids = "/pid/:pid+"; + + /** + * Route string for the iNames paramter + * @var string + */ + public static $routeParameterSNames = "/sname/:sname+"; + + /** + * Keyword for pidList arguments + * @var string + */ + public static $keyPidList = "pidList"; + + /** + * Keyword for iNameList arguments + * @var string + */ + public static $keySNameList = "sNameList"; /** * max number of pid for each query @@ -49,11 +67,18 @@ class PssApi extends Api { * @return query result as xml */ public function sendPssQuery($queryArgs) { - $pidList = \utiliy\ArrayManager::removeEmptyItmes($queryArgs); - + $pidList = \utiliy\ArrayManager::removeEmptyItmes($queryArgs[self::$keyPidList]); + + if (array_key_exists(self::$keySNameList, $queryArgs)) { + $sNameList = \utiliy\ArrayManager::removeEmptyItmes($queryArgs[self::$keySNameList]); + } else { + $sNameList = array(); + } + if (count($pidList) < self::$maxPid) { - $result = $this->sqlManager->sendPssQuery($pidList); - return $this->serialManager->arrayTopis($result); + $result = $this->sqlManager->sendPssQuery($pidList, $sNameList); + + return $this->serialManager->arrayToPss($result); } return NULL; } diff --git a/geoapi/database/PssSqlManager.php b/geoapi/database/PssSqlManager.php index eac7745..5360547 100644 --- a/geoapi/database/PssSqlManager.php +++ b/geoapi/database/PssSqlManager.php @@ -56,6 +56,12 @@ class PssSqlManager extends SQLManager { */ private static $pidTerm = "pid = "; + /** + * String for the iName part of the query + * @var string + */ + private static $sNameTerm = "sName = "; + /** * Default-Constructor */ @@ -75,16 +81,26 @@ class PssSqlManager extends SQLManager { * @param array $queryArgs * @return array [num][assoc] */ - public function sendPssQuery($queryArgs) { + public function sendPssQuery($pidList, $sNameList) { // build query string $query = self::$selectTerm; - - if (\utiliy\ArrayManager::validIntList($queryArgs)) { - $query .= \utiliy\ArrayManager::toSqlWhereString($queryArgs, self::$orTerm, self::$pidTerm) . self::$orderByTerm; + if (\utiliy\ArrayManager::validIntList($pidList)) { + $query .= self::$openBracket; + $query .= \utiliy\ArrayManager::toSqlWhereString($pidList, self::$orTerm, self::$pidTerm); + $query .= self::$closeBracket; } else { return null; - }; + } + + if (count($sNameList) > 0 && \utiliy\ArrayManager::validAlphaNumList($sNameList)) { + $query .= self::$andTerm; + $query .= self::$openBracket; + $query .= \utiliy\ArrayManager::toSqlWhereString($sNameList, self::$orTerm, self::$sNameTerm); + $query .= self::$closeBracket; + } + + $query .= self::$orderByTerm; // send query return $this->query($query); diff --git a/geoapi/service/pss/index.php b/geoapi/service/pss/index.php index c6e55cc..9368884 100644 --- a/geoapi/service/pss/index.php +++ b/geoapi/service/pss/index.php @@ -9,8 +9,17 @@ $headers = apache_request_headers(); $app = new \api\PssApi($headers); // HTTP-Get-Method +$app->get(\api\PssApi::$routeParameterPids . \api\PssApi::$routeParameterSNames, function ($pid, $sNames = array()) use ($app) { + $queryArgs = array(); + $queryArgs[\api\PssApi::$keyPidList] = $pid; + $queryArgs[\api\PssApi::$keySNameList] = $sNames; + echo $app->sendPssQuery($queryArgs); + }); + $app->get(\api\PssApi::$routeParameterPids, function ($pid) use ($app) { - echo $app->sendPssQuery($pid); + $queryArgs = array(); + $queryArgs[\api\PssApi::$keyPidList] = $pid; + echo $app->sendPssQuery($queryArgs); }); $app->run();