ad parent paramter to pis

This commit is contained in:
stubbfel
2013-10-16 11:16:46 +02:00
parent 4494bf9c5c
commit 9f263bc454
5 changed files with 70 additions and 11 deletions

View File

@@ -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;
}
}
?>

View File

@@ -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);
}

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -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;
}
}