diff --git a/geoapi/api/PisApi.php b/geoapi/api/PisApi.php index 5b17f8a..9f7fecc 100644 --- a/geoapi/api/PisApi.php +++ b/geoapi/api/PisApi.php @@ -19,6 +19,12 @@ class PisApi extends Api { * @var string */ public static $routeParameterPids = "/pid/:pid+"; + + /** + * Route string for the parent paramter + * @var string + */ + public static $routeParameterParent = "/parent/:parent"; /** * Route string for the iNames paramter @@ -50,6 +56,12 @@ class PisApi extends Api { */ public static $keyIPatter = "searchPatter"; + /** + * Keyword for parendId arguments + * @var string + */ + public static $keyParentId = "parendId"; + /** * max number of pid for each query * @var int @@ -85,20 +97,26 @@ class PisApi extends Api { } else { $iNameList = array(); } - if (array_key_exists(self::$keyIPatter, $queryArgs)) { $iPatter = trim($queryArgs[self::$keyIPatter]); } else { $iPatter = "*"; } + if (array_key_exists(self::$keyParentId, $queryArgs)) { + $parentId = trim($queryArgs[self::$keyParentId]); + } else { + $parentId = "*"; + } + if (count($pidList) < self::$maxPid) { - $result = $this->sqlManager->sendPisQuery($pidList, $iNameList,$iPatter); + $result = $this->sqlManager->sendPisQuery($pidList, $parentId, $iNameList, $iPatter); return $this->serialManager->arrayToPis($result); } return NULL; } + } ?> diff --git a/geoapi/database/PisSqlManager.php b/geoapi/database/PisSqlManager.php index 9a89d61..9ccefaa 100644 --- a/geoapi/database/PisSqlManager.php +++ b/geoapi/database/PisSqlManager.php @@ -61,7 +61,7 @@ class PisSqlManager extends SQLManager { * @var string */ private static $orderByTerm = " ORDER BY pid, iName"; - + /** * String for like-Statement fo iValue field * @var string @@ -74,6 +74,12 @@ class PisSqlManager extends SQLManager { */ private static $pidTerm = "pid = "; + /** + * String for the parent part of the query + * @var string + */ + private static $parentTerm = "parent = "; + /** * String for the iName part of the query * @var string @@ -105,7 +111,7 @@ class PisSqlManager extends SQLManager { * @param array $queryArgs * @return array [num][assoc] */ - public function sendPisQuery($pidList, $iNameList, $iPatter = "*") { + public function sendPisQuery($pidList, $parentId, $iNameList, $iPatter = "*") { // build query string $query = self::$selectTerm; @@ -117,6 +123,13 @@ class PisSqlManager extends SQLManager { return null; } + if ($parentId != "*" && \utiliy\StringManager::validInt($parentId)) { + if ($query != self::$selectTerm) { + $query .= self::$andTerm; + } + $query .= self::$parentTerm . "$parentId"; + } + if (count($iNameList) > 0 && \utiliy\ArrayManager::validAlphaNumList($iNameList)) { if ($query != self::$selectTerm) { $query .= self::$andTerm; @@ -130,15 +143,15 @@ class PisSqlManager extends SQLManager { if ($query != self::$selectTerm) { $query .= self::$andTerm; } - $query .= self::$iValueLikeTerm ."'%$iPatter%'"; + $query .= self::$iValueLikeTerm . "'%$iPatter%'"; } - + if ($query == self::$selectTerm) { $query = self::$selectAllTerm; } $query .= self::$orderByTerm; - + // send query return $this->query($query); } diff --git a/geoapi/service/pis/index.php b/geoapi/service/pis/index.php index 61dd975..506d039 100644 --- a/geoapi/service/pis/index.php +++ b/geoapi/service/pis/index.php @@ -10,21 +10,31 @@ $headers = apache_request_headers(); $app = new \api\PisApi($headers); // HTTP-Get-Method -$app->get(\api\PisApi::$routeParameterPids . \api\PisApi::$routeParameterINames . \api\PisApi::$routParameterIPatter, function ($pid, $iNames = array(), $iPatter = "*") use ($app) { +$app->get(\api\PisApi::$routeParameterPids . \api\PisApi::$routeParameterINames . \api\PisApi::$routParameterIPatter . "(" . \api\PisApi::$routeParameterParent .")", function ($pid, $iNames = array(), $iPatter = "*",$parent = "*") use ($app) { $queryArgs = array(); $queryArgs[\api\PisApi::$keyPidList] = $pid; $queryArgs[\api\PisApi::$keyINameList] = $iNames; $queryArgs[\api\PisApi::$keyIPatter] = $iPatter; + $queryArgs[\api\PisApi::$keyParentId] = $parent; echo $app->sendPisQuery($queryArgs); }); -$app->get(\api\PisApi::$routeParameterPids . \api\PisApi::$routParameterIPatter, function ($pid, $iPatter = "*") use ($app) { +$app->get(\api\PisApi::$routeParameterPids . \api\PisApi::$routParameterIPatter . "(" . \api\PisApi::$routeParameterParent .")", function ($pid, $iPatter = "*",$parent = "*") use ($app) { $queryArgs = array(); $queryArgs[\api\PisApi::$keyPidList] = $pid; $queryArgs[\api\PisApi::$keyIPatter] = $iPatter; + $queryArgs[\api\PisApi::$keyParentId] = $parent; echo $app->sendPisQuery($queryArgs); }); +$app->get(\api\PisApi::$routeParameterPids . \api\PisApi::$routeParameterINames . \api\PisApi::$routeParameterParent, function ($pid, $iNames = array(), $parent = "*") use ($app) { + $queryArgs = array(); + $queryArgs[\api\PisApi::$keyPidList] = $pid; + $queryArgs[\api\PisApi::$keyINameList] = $iNames; + $queryArgs[\api\PisApi::$keyParentId] = $parent; + echo $app->sendPisQuery($queryArgs); + }); + $app->get(\api\PisApi::$routeParameterPids . \api\PisApi::$routeParameterINames, function ($pid, $iNames = array()) use ($app) { $queryArgs = array(); $queryArgs[\api\PisApi::$keyPidList] = $pid; @@ -32,6 +42,13 @@ $app->get(\api\PisApi::$routeParameterPids . \api\PisApi::$routeParameterINames, echo $app->sendPisQuery($queryArgs); }); +$app->get(\api\PisApi::$routeParameterPids . \api\PisApi::$routeParameterParent, function ($pid, $parent = "*") use ($app) { + $queryArgs = array(); + $queryArgs[\api\PisApi::$keyPidList] = $pid; + $queryArgs[\api\PisApi::$keyParentId] = $parent; + echo $app->sendPisQuery($queryArgs); + }); + $app->get(\api\PisApi::$routeParameterPids, function ($pid) use ($app) { $queryArgs = array(); $queryArgs[\api\PisApi::$keyPidList] = $pid; diff --git a/geoapi/utility/ArrayManager.php b/geoapi/utility/ArrayManager.php index ff76b62..c270310 100644 --- a/geoapi/utility/ArrayManager.php +++ b/geoapi/utility/ArrayManager.php @@ -47,8 +47,7 @@ class ArrayManager { */ public static function validIntList($list) { foreach ($list as $value) { - - if (!ctype_digit($value) || PHP_INT_MAX < $value) { + if (!StringManager::validInt($value)) { return FALSE; } } diff --git a/geoapi/utility/StringManager.php b/geoapi/utility/StringManager.php index a424cb8..e178ff0 100644 --- a/geoapi/utility/StringManager.php +++ b/geoapi/utility/StringManager.php @@ -54,6 +54,18 @@ class StringManager { } return FALSE; } + + /** + * Method if the string is in integor + * @param string $value + * @return boolean + */ + public static function validInt($value) { + if (!ctype_digit($value) || PHP_INT_MAX < $value) { + return FALSE; + } + return TRUE; + } }