This commit is contained in:
stubbfel
2013-07-10 11:34:07 +02:00
parent 5c11441ef5
commit fe6e6eaaf4
7 changed files with 163 additions and 67 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -4,10 +4,10 @@
<mapcanvas>
<units>degrees</units>
<extent>
<xmin>14.101601</xmin>
<ymin>51.518800</ymin>
<xmax>14.676288</xmax>
<ymax>51.809110</ymax>
<xmin>14.191382</xmin>
<ymin>51.659713</ymin>
<xmax>14.478726</xmax>
<ymax>51.804868</ymax>
</extent>
<projections>0</projections>
<destinationsrs>
@@ -49,29 +49,29 @@
<legendlayerfile isInOverview="0" layerid="roads20130709105652660" visible="0"/>
</filegroup>
</legendlayer>
<legendlayer drawingOrder="-1" open="false" checked="Qt::Unchecked" name="campus-cottbus-mitte-gebäude" showFeatureCount="0">
<legendlayer drawingOrder="-1" open="false" checked="Qt::Checked" name="campus-cottbus-mitte-gebäude" showFeatureCount="0">
<filegroup open="false" hidden="false">
<legendlayerfile isInOverview="0" layerid="campus_cottbus_mitte_gebäude20130709104921649" visible="0"/>
<legendlayerfile isInOverview="0" layerid="campus_cottbus_mitte_gebäude20130709104921649" visible="1"/>
</filegroup>
</legendlayer>
<legendlayer drawingOrder="-1" open="false" checked="Qt::Unchecked" name="campus-cottbus-süd-gebäude" showFeatureCount="0">
<legendlayer drawingOrder="-1" open="false" checked="Qt::Checked" name="campus-cottbus-süd-gebäude" showFeatureCount="0">
<filegroup open="false" hidden="false">
<legendlayerfile isInOverview="0" layerid="campus_cottbus_süd_gebäude20130709114420373" visible="0"/>
<legendlayerfile isInOverview="0" layerid="campus_cottbus_süd_gebäude20130709114420373" visible="1"/>
</filegroup>
</legendlayer>
<legendlayer drawingOrder="-1" open="false" checked="Qt::Checked" name="campuse" showFeatureCount="0">
<legendlayer drawingOrder="-1" open="false" checked="Qt::Checked" name="campus-senftenberg-gebäude" showFeatureCount="0">
<filegroup open="false" hidden="false">
<legendlayerfile isInOverview="0" layerid="campuse20130709122450377" visible="1"/>
<legendlayerfile isInOverview="0" layerid="campus_senftenberg_gebäude20130709121511731" visible="1"/>
</filegroup>
</legendlayer>
<legendlayer drawingOrder="-1" open="false" checked="Qt::Unchecked" name="campus-senftenberg-gebäude" showFeatureCount="0">
<filegroup open="false" hidden="false">
<legendlayerfile isInOverview="0" layerid="campus_senftenberg_gebäude20130709121511731" visible="0"/>
</filegroup>
</legendlayer>
<legendlayer drawingOrder="-1" open="true" checked="Qt::Unchecked" name="campus-cottbus-nord-gebäude" showFeatureCount="0">
<legendlayer drawingOrder="-1" open="true" checked="Qt::Checked" name="campus-cottbus-nord-gebäude" showFeatureCount="0">
<filegroup open="true" hidden="false">
<legendlayerfile isInOverview="0" layerid="campus_cottbus_nord_gebäude20130709130745659" visible="0"/>
<legendlayerfile isInOverview="0" layerid="campus_cottbus_nord_gebäude20130709130745659" visible="1"/>
</filegroup>
</legendlayer>
<legendlayer drawingOrder="-1" open="true" checked="Qt::Checked" name="campuse" showFeatureCount="0">
<filegroup open="true" hidden="false">
<legendlayerfile isInOverview="0" layerid="campuse20130709122450377" visible="1"/>
</filegroup>
</legendlayer>
<legendlayer drawingOrder="-1" open="false" checked="Qt::Unchecked" name="buildings" showFeatureCount="0">
@@ -119,7 +119,7 @@
<sizescale field=""/>
</renderer-v2>
<customproperties/>
<displayfield></displayfield>
<displayfield>name</displayfield>
<label>0</label>
<labelattributes>
<label fieldname="" text="Beschriftung"/>
@@ -141,9 +141,9 @@
<multilineenabled fieldname="" on=""/>
<selectedonly on=""/>
</labelattributes>
<editform></editform>
<editform>.</editform>
<editforminit></editforminit>
<annotationform></annotationform>
<annotationform>.</annotationform>
<attributeactions/>
</maplayer>
<maplayer minimumScale="0" maximumScale="1e+08" geometry="Polygon" type="vector" hasScaleBasedVisibilityFlag="0">
@@ -184,7 +184,7 @@
<sizescale field=""/>
</renderer-v2>
<customproperties/>
<displayfield></displayfield>
<displayfield>name</displayfield>
<label>0</label>
<labelattributes>
<label fieldname="" text="Beschriftung"/>
@@ -206,9 +206,9 @@
<multilineenabled fieldname="" on=""/>
<selectedonly on=""/>
</labelattributes>
<editform></editform>
<editform>.</editform>
<editforminit></editforminit>
<annotationform></annotationform>
<annotationform>.</annotationform>
<attributeactions/>
</maplayer>
<maplayer minimumScale="0" maximumScale="1e+08" geometry="Line" type="vector" hasScaleBasedVisibilityFlag="0">
@@ -251,7 +251,7 @@
<sizescale field=""/>
</renderer-v2>
<customproperties/>
<displayfield></displayfield>
<displayfield>name</displayfield>
<label>0</label>
<labelattributes>
<label fieldname="" text="Beschriftung"/>
@@ -273,9 +273,9 @@
<multilineenabled fieldname="" on=""/>
<selectedonly on=""/>
</labelattributes>
<editform></editform>
<editform>.</editform>
<editforminit></editforminit>
<annotationform></annotationform>
<annotationform>.</annotationform>
<attributeactions/>
</maplayer>
<maplayer minimumScale="0" maximumScale="1e+08" geometry="Polygon" type="vector" hasScaleBasedVisibilityFlag="0">
@@ -316,7 +316,7 @@
<sizescale field=""/>
</renderer-v2>
<customproperties/>
<displayfield></displayfield>
<displayfield>name</displayfield>
<label>0</label>
<labelattributes>
<label fieldname="" text="Beschriftung"/>
@@ -338,9 +338,9 @@
<multilineenabled fieldname="" on=""/>
<selectedonly on=""/>
</labelattributes>
<editform></editform>
<editform>.</editform>
<editforminit></editforminit>
<annotationform></annotationform>
<annotationform>.</annotationform>
<attributeactions/>
</maplayer>
<maplayer minimumScale="0" maximumScale="1e+08" geometry="Line" type="vector" hasScaleBasedVisibilityFlag="0">
@@ -383,7 +383,7 @@
<sizescale field=""/>
</renderer-v2>
<customproperties/>
<displayfield></displayfield>
<displayfield>name</displayfield>
<label>0</label>
<labelattributes>
<label fieldname="" text="Beschriftung"/>
@@ -405,9 +405,9 @@
<multilineenabled fieldname="" on=""/>
<selectedonly on=""/>
</labelattributes>
<editform></editform>
<editform>.</editform>
<editforminit></editforminit>
<annotationform></annotationform>
<annotationform>.</annotationform>
<attributeactions/>
</maplayer>
<maplayer minimumScale="0" maximumScale="1e+08" geometry="Polygon" type="vector" hasScaleBasedVisibilityFlag="0">
@@ -448,7 +448,7 @@
<sizescale field=""/>
</renderer-v2>
<customproperties/>
<displayfield></displayfield>
<displayfield>name</displayfield>
<label>0</label>
<labelattributes>
<label fieldname="" text="Beschriftung"/>
@@ -470,9 +470,9 @@
<multilineenabled fieldname="" on=""/>
<selectedonly on=""/>
</labelattributes>
<editform></editform>
<editform>.</editform>
<editforminit></editforminit>
<annotationform></annotationform>
<annotationform>.</annotationform>
<attributeactions/>
</maplayer>
<maplayer minimumScale="0" maximumScale="1e+08" geometry="Line" type="vector" hasScaleBasedVisibilityFlag="0">
@@ -515,7 +515,7 @@
<sizescale field=""/>
</renderer-v2>
<customproperties/>
<displayfield></displayfield>
<displayfield>name</displayfield>
<label>0</label>
<labelattributes>
<label fieldname="" text="Beschriftung"/>
@@ -537,9 +537,9 @@
<multilineenabled fieldname="" on=""/>
<selectedonly on=""/>
</labelattributes>
<editform></editform>
<editform>.</editform>
<editforminit></editforminit>
<annotationform></annotationform>
<annotationform>.</annotationform>
<attributeactions/>
</maplayer>
<maplayer minimumScale="0" maximumScale="1e+08" geometry="Polygon" type="vector" hasScaleBasedVisibilityFlag="0">
@@ -580,7 +580,7 @@
<sizescale field=""/>
</renderer-v2>
<customproperties/>
<displayfield></displayfield>
<displayfield>name</displayfield>
<label>0</label>
<labelattributes>
<label fieldname="" text="Beschriftung"/>
@@ -602,9 +602,9 @@
<multilineenabled fieldname="" on=""/>
<selectedonly on=""/>
</labelattributes>
<editform></editform>
<editform>.</editform>
<editforminit></editforminit>
<annotationform></annotationform>
<annotationform>.</annotationform>
<attributeactions/>
</maplayer>
<maplayer minimumScale="0" maximumScale="1e+08" geometry="Line" type="vector" hasScaleBasedVisibilityFlag="0">
@@ -647,7 +647,7 @@
<sizescale field=""/>
</renderer-v2>
<customproperties/>
<displayfield></displayfield>
<displayfield>name</displayfield>
<label>0</label>
<labelattributes>
<label fieldname="" text="Beschriftung"/>
@@ -669,9 +669,9 @@
<multilineenabled fieldname="" on=""/>
<selectedonly on=""/>
</labelattributes>
<editform></editform>
<editform>.</editform>
<editforminit></editforminit>
<annotationform></annotationform>
<annotationform>.</annotationform>
<attributeactions/>
</maplayer>
<maplayer minimumScale="0" maximumScale="1e+08" geometry="Polygon" type="vector" hasScaleBasedVisibilityFlag="0">
@@ -739,9 +739,9 @@
<edittype type="0" name="osm_id"/>
<edittype type="0" name="type"/>
</edittypes>
<editform></editform>
<editform>.</editform>
<editforminit></editforminit>
<annotationform></annotationform>
<annotationform>.</annotationform>
<attributeactions/>
<overlay display="false" type="diagram">
<renderer item_interpretation="linear">
@@ -795,7 +795,7 @@
<sizescale field=""/>
</renderer-v2>
<customproperties/>
<displayfield></displayfield>
<displayfield>name</displayfield>
<label>0</label>
<labelattributes>
<label fieldname="" text="Beschriftung"/>
@@ -817,9 +817,9 @@
<multilineenabled fieldname="" on=""/>
<selectedonly on=""/>
</labelattributes>
<editform></editform>
<editform>.</editform>
<editforminit></editforminit>
<annotationform></annotationform>
<annotationform>.</annotationform>
<attributeactions/>
</maplayer>
</projectlayers>