finish #69
This commit is contained in:
@@ -15,11 +15,29 @@ require_once PATH_API . "/Api.php";
|
||||
class PisApi extends Api {
|
||||
|
||||
/**
|
||||
* Route string for the alias paramter
|
||||
* Route string for the pids paramter
|
||||
* @var string
|
||||
*/
|
||||
public static $routeParameterPids = "/pid/:pid+";
|
||||
|
||||
/**
|
||||
* Route string for the iNames paramter
|
||||
* @var string
|
||||
*/
|
||||
public static $routeParameterINames = "/iname/:iname+";
|
||||
|
||||
/**
|
||||
* Keyword for pidList arguments
|
||||
* @var string
|
||||
*/
|
||||
public static $keyPidList = "pidList";
|
||||
|
||||
/**
|
||||
* Keyword for iNameList arguments
|
||||
* @var string
|
||||
*/
|
||||
public static $keyINameList = "iNameList";
|
||||
|
||||
/**
|
||||
* max number of pid for each query
|
||||
* @var int
|
||||
@@ -48,14 +66,22 @@ class PisApi extends Api {
|
||||
* @return query result as xml
|
||||
*/
|
||||
public function sendPisQuery($queryArgs) {
|
||||
$pidList = \utiliy\ArrayManager::removeEmptyItmes($queryArgs);
|
||||
$pidList = \utiliy\ArrayManager::removeEmptyItmes($queryArgs[self::$keyPidList]);
|
||||
|
||||
if (array_key_exists(self::$keyINameList, $queryArgs)) {
|
||||
$iNameList = \utiliy\ArrayManager::removeEmptyItmes($queryArgs[self::$keyINameList]);
|
||||
} else {
|
||||
$iNameList = array();
|
||||
}
|
||||
|
||||
if (count($pidList) < self::$maxPid) {
|
||||
$result = $this->sqlManager->sendPisQuery($pidList);
|
||||
|
||||
$result = $this->sqlManager->sendPisQuery($pidList, $iNameList);
|
||||
|
||||
return $this->serialManager->arrayToPis($result);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace database;
|
||||
|
||||
include_once "../../global.inc.php";
|
||||
include_once PATH_UTILITTY . "/StringManager.php";
|
||||
include_once PATH_UTILITTY . "/ArrayManager.php";
|
||||
require_once PATH_DATABASE . "/SqlManager.php";
|
||||
|
||||
/**
|
||||
@@ -50,6 +50,12 @@ class PisSqlManager extends SQLManager {
|
||||
*/
|
||||
private static $pidTerm = "pid = ";
|
||||
|
||||
/**
|
||||
* String for the iName part of the query
|
||||
* @var string
|
||||
*/
|
||||
private static $iNameTerm = "iName = ";
|
||||
|
||||
/**
|
||||
* Default-Constructor
|
||||
*/
|
||||
@@ -69,19 +75,31 @@ class PisSqlManager extends SQLManager {
|
||||
* @param array $queryArgs
|
||||
* @return array [num][assoc]
|
||||
*/
|
||||
public function sendPisQuery($queryArgs) {
|
||||
public function sendPisQuery($pidList, $iNameList) {
|
||||
|
||||
// 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($iNameList) > 0 && \utiliy\ArrayManager::validAlphaNumList($iNameList)) {
|
||||
$query .= self::$andTerm;
|
||||
$query .= self::$openBracket;
|
||||
$query .= \utiliy\ArrayManager::toSqlWhereString($iNameList, self::$orTerm, self::$iNameTerm);
|
||||
$query .= self::$closeBracket;
|
||||
}
|
||||
|
||||
$query .= self::$orderByTerm;
|
||||
|
||||
// send query
|
||||
return $this->query($query);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -60,6 +60,18 @@ abstract class SqlManager {
|
||||
*/
|
||||
protected static $quoteTerm = "\"";
|
||||
|
||||
/**
|
||||
* String for open Bracket in a query
|
||||
* @var string
|
||||
*/
|
||||
protected static $openBracket = "(";
|
||||
|
||||
/**
|
||||
* String for close Bracket in a query
|
||||
* @var string
|
||||
*/
|
||||
protected static $closeBracket = ")";
|
||||
|
||||
/**
|
||||
* Default-Constructor
|
||||
*/
|
||||
@@ -67,7 +79,9 @@ abstract class SqlManager {
|
||||
$this->serverAddress = \config\DBConfig::$sqlServer;
|
||||
$this->dbName = \config\DBConfig::$sqlDBName;
|
||||
$this->userName = \config\DBConfig::$sqlDBUser;
|
||||
$this->userPw = \config\DBConfig::$sqlDBUserPW;
|
||||
$this->userPw = \config\DBConfig::$sqlDBUserPW
|
||||
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,18 +96,20 @@ abstract class SqlManager {
|
||||
unset($this->serverAddress);
|
||||
unset($this->dbName);
|
||||
unset($this->userName);
|
||||
unset($this->userPW);
|
||||
unset($this->userPW
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method setup the connection to the Database
|
||||
*/
|
||||
public function connect() {
|
||||
$this->link = mysql_connect($this->serverAddress, $this->userName, $this->userPw);
|
||||
$this->link = mysql_connect($this->serverAddress , $this->userName , $this->userPw);
|
||||
if (!$this->link) {
|
||||
exit("No Connection: " . mysql_error());
|
||||
}
|
||||
$selected = mysql_select_db($this->dbName, $this->link);
|
||||
$selected = mysql_select_db($this->dbName , $this->link);
|
||||
if (!$selected) {
|
||||
exit("No DB: " . mysql_error());
|
||||
}
|
||||
@@ -103,7 +119,9 @@ abstract class SqlManager {
|
||||
* Method close the connection
|
||||
*/
|
||||
public function closeConnection() {
|
||||
if ($this->link) {
|
||||
if (
|
||||
|
||||
$this->link) {
|
||||
mysql_close($this->link);
|
||||
unset($this->link);
|
||||
$this->link = null;
|
||||
@@ -113,20 +131,23 @@ abstract class SqlManager {
|
||||
/**
|
||||
* Method send a query to the Datebase and return the result
|
||||
* @param string $query
|
||||
|
||||
|
||||
* @return result[num][assoc]
|
||||
*/
|
||||
protected function query($query) {
|
||||
|
||||
// send error
|
||||
$mysqlResult = mysql_query($query, $this->link);
|
||||
$mysqlResult = mysql_query($query, $this->link );
|
||||
if (!$mysqlResult) {
|
||||
// echo $query;
|
||||
exit("Query error: " . mysql_error());
|
||||
}
|
||||
|
||||
// fetch result
|
||||
$rowNums = mysql_num_rows($mysqlResult);
|
||||
$result = array();
|
||||
for ($i = 0; $i < $rowNums; $i++) {
|
||||
for ($i = 0; $i < $rowNums; $i++) {
|
||||
$row = mysql_fetch_assoc($mysqlResult);
|
||||
$result[$i] = $row;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
include_once "../../global.inc.php";
|
||||
require_once PATH_API . "/PisApi.php";
|
||||
include_once PATH_UTILITTY . "/ArrayManager.php";
|
||||
|
||||
// get reguest header
|
||||
$headers = apache_request_headers();
|
||||
@@ -9,8 +10,17 @@ $headers = apache_request_headers();
|
||||
$app = new \api\PisApi($headers);
|
||||
|
||||
// HTTP-Get-Method
|
||||
$app->get(\api\PisApi::$routeParameterPids . \api\PisApi::$routeParameterINames, function ($pid, $iNames = array()) use ($app) {
|
||||
$queryArgs = array();
|
||||
$queryArgs[\api\PisApi::$keyPidList] = $pid;
|
||||
$queryArgs[\api\PisApi::$keyINameList] = $iNames;
|
||||
echo $app->sendPisQuery($queryArgs);
|
||||
});
|
||||
|
||||
$app->get(\api\PisApi::$routeParameterPids, function ($pid) use ($app) {
|
||||
echo $app->sendPisQuery($pid);
|
||||
$queryArgs = array();
|
||||
$queryArgs[\api\PisApi::$keyPidList] = $pid;
|
||||
echo $app->sendPisQuery($queryArgs);
|
||||
});
|
||||
|
||||
$app->run();
|
||||
|
||||
@@ -34,7 +34,7 @@ class ArrayManager {
|
||||
public static function toSqlWhereString($array, $operator = "", $fieldname = "") {
|
||||
$arrayStr = StringManager::$emptyString;
|
||||
foreach ($array as $value) {
|
||||
$arrayStr .= $fieldname . $value . $operator;
|
||||
$arrayStr .= $fieldname . StringManager::$quotes . $value . StringManager::$quotes . $operator;
|
||||
}
|
||||
$result = substr($arrayStr, 0, strlen($arrayStr) - strlen($operator));
|
||||
return $result;
|
||||
@@ -55,6 +55,21 @@ class ArrayManager {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method check if all items of the array are only digits and < PHP_INT_MAX
|
||||
* @param array $poly
|
||||
* @return boolean
|
||||
*/
|
||||
public static function validAlphaNumList($list) {
|
||||
foreach ($list as $value) {
|
||||
|
||||
if (!ctype_alnum($value) || !\utiliy\StringManager::validSQLString($value)) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -12,10 +12,16 @@ include_once "../../global.inc.php";
|
||||
class StringManager {
|
||||
|
||||
/**
|
||||
* A Constant vor an emptystring like ""
|
||||
* A Constant for an emptystring like ""
|
||||
* @var string
|
||||
*/
|
||||
public static $emptyString = "";
|
||||
|
||||
/**
|
||||
* A Constant for an quotechars like "
|
||||
* @var string
|
||||
*/
|
||||
public static $quotes = "\"";
|
||||
|
||||
/**
|
||||
* Method check if a certain string start with a certain substring
|
||||
|
||||
Reference in New Issue
Block a user