ad parent paramter to pis
This commit is contained in:
@@ -20,6 +20,12 @@ class PisApi extends Api {
|
||||
*/
|
||||
public static $routeParameterPids = "/pid/:pid+";
|
||||
|
||||
/**
|
||||
* Route string for the parent paramter
|
||||
* @var string
|
||||
*/
|
||||
public static $routeParameterParent = "/parent/:parent";
|
||||
|
||||
/**
|
||||
* Route string for the iNames paramter
|
||||
* @var string
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -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,7 +143,7 @@ class PisSqlManager extends SQLManager {
|
||||
if ($query != self::$selectTerm) {
|
||||
$query .= self::$andTerm;
|
||||
}
|
||||
$query .= self::$iValueLikeTerm ."'%$iPatter%'";
|
||||
$query .= self::$iValueLikeTerm . "'%$iPatter%'";
|
||||
}
|
||||
|
||||
if ($query == self::$selectTerm) {
|
||||
|
||||
@@ -10,18 +10,28 @@ $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);
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +55,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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user