finish #70
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user