add searchpattern

This commit is contained in:
stubbfel
2013-09-04 12:15:47 +02:00
parent 2805de2198
commit 2d10c027a2
3 changed files with 59 additions and 8 deletions

View File

@@ -26,6 +26,12 @@ class PisApi extends Api {
*/ */
public static $routeParameterINames = "/iname/:iname+"; public static $routeParameterINames = "/iname/:iname+";
/**
* public string for the patter string parameter
* @var string
*/
public static $routParameterIPatter = "ipatter/:ipatter";
/** /**
* Keyword for pidList arguments * Keyword for pidList arguments
* @var string * @var string
@@ -38,6 +44,12 @@ class PisApi extends Api {
*/ */
public static $keyINameList = "iNameList"; public static $keyINameList = "iNameList";
/**
* Keyword for iNameList arguments
* @var string
*/
public static $keyIPatter = "searchPatter";
/** /**
* max number of pid for each query * max number of pid for each query
* @var int * @var int
@@ -66,22 +78,27 @@ class PisApi extends Api {
* @return query result as xml * @return query result as xml
*/ */
public function sendPisQuery($queryArgs) { 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)) { if (array_key_exists(self::$keyINameList, $queryArgs)) {
$iNameList = \utiliy\ArrayManager::removeEmptyItmes($queryArgs[self::$keyINameList]); $iNameList = \utiliy\ArrayManager::removeEmptyItmes($queryArgs[self::$keyINameList]);
} else { } else {
$iNameList = array(); $iNameList = array();
} }
if (array_key_exists(self::$keyIPatter, $queryArgs)) {
$iPatter = trim($queryArgs[self::$keyIPatter]);
} else {
$iPatter = "*";
}
if (count($pidList) < self::$maxPid) { if (count($pidList) < self::$maxPid) {
$result = $this->sqlManager->sendPisQuery($pidList, $iNameList); $result = $this->sqlManager->sendPisQuery($pidList, $iNameList,$iPatter);
return $this->serialManager->arrayToPis($result); return $this->serialManager->arrayToPis($result);
} }
return NULL; return NULL;
} }
} }
?> ?>

View File

@@ -61,6 +61,12 @@ class PisSqlManager extends SQLManager {
* @var string * @var string
*/ */
private static $orderByTerm = " ORDER BY pid, iName"; 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 * String for the pid part of the query
@@ -74,6 +80,12 @@ class PisSqlManager extends SQLManager {
*/ */
private static $iNameTerm = "iName = "; private static $iNameTerm = "iName = ";
/**
* Variable for the max lenght of an valid pattern string
* @var int
*/
private static $patterMaxLenght = 30;
/** /**
* Default-Constructor * Default-Constructor
*/ */
@@ -93,7 +105,7 @@ class PisSqlManager extends SQLManager {
* @param array $queryArgs * @param array $queryArgs
* @return array [num][assoc] * @return array [num][assoc]
*/ */
public function sendPisQuery($pidList, $iNameList) { public function sendPisQuery($pidList, $iNameList, $iPatter = "*") {
// build query string // build query string
$query = self::$selectTerm; $query = self::$selectTerm;
@@ -114,15 +126,35 @@ class PisSqlManager extends SQLManager {
$query .= self::$closeBracket; $query .= self::$closeBracket;
} }
if ($iPatter != "*" && $this->validIPatter($iPatter)) {
if ($query != self::$selectTerm) {
$query .= self::$andTerm;
}
$query .= self::$iValueLikeTerm ."'%$iPatter%'";
}
if ($query == self::$selectTerm) { if ($query == self::$selectTerm) {
$query = self::$selectAllTerm; $query = self::$selectAllTerm;
} }
$query .= self::$orderByTerm; $query .= self::$orderByTerm;
// send query // send query
return $this->query($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;
}
} }
?> ?>

View File

@@ -10,16 +10,18 @@ $headers = apache_request_headers();
$app = new \api\PisApi($headers); $app = new \api\PisApi($headers);
// HTTP-Get-Method // 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 = array();
$queryArgs[\api\PisApi::$keyPidList] = $pid; $queryArgs[\api\PisApi::$keyPidList] = $pid;
$queryArgs[\api\PisApi::$keyINameList] = $iNames; $queryArgs[\api\PisApi::$keyINameList] = $iNames;
$queryArgs[\api\PisApi::$keyIPatter] = $iPatter;
echo $app->sendPisQuery($queryArgs); 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 = array();
$queryArgs[\api\PisApi::$keyPidList] = $pid; $queryArgs[\api\PisApi::$keyPidList] = $pid;
$queryArgs[\api\PisApi::$keyIPatter] = $iPatter;
echo $app->sendPisQuery($queryArgs); echo $app->sendPisQuery($queryArgs);
}); });