Files
geodb/geoapi/database/PisSqlManager.php
2013-06-26 12:14:43 +02:00

117 lines
2.5 KiB
PHP

<?php
namespace database;
include_once "../../global.inc.php";
include_once PATH_UTILITTY . "/StringManager.php";
require_once PATH_DATABASE . "/SqlManager.php";
/**
* Description of ZisSqlManager
*
* @author stubbfel
* @since 20.06.2013
*/
class PisSqlManager extends SQLManager {
/**
* Fieldname of the placeID
* @var string
*/
public static $placeId = "pid";
/**
* Fieldname of the name of the information
* @var string
*/
public static $infName = "iName";
/**
* Fieldname of the value of the information
* @var string
*/
public static $infValue = "iValue";
/**
* String for the select part of the query
* @var string
*/
private $selectTerm = "SELECT pid, iName, iValue FROM pis WHERE ";
/**
* String for the orderby part of the query
* @var string
*/
private $orderByTerm = " ORDER BY pid";
/**
* String for the pid part of the query
* @var string
*/
private $pidTerm = "pid = ";
/**
* Default-Constructor
*/
public function __construct() {
parent::__construct();
}
/**
* Default-DEConstructor
*/
public function __destruct() {
parent::__destruct();
}
/**
* Methods send an query for the pis-service
* @param array $queryArgs
* @return array [num][assoc]
*/
public function sendPisQuery($queryArgs) {
// build query string
$query = $this->selectTerm;
if ($this->validPidList($queryArgs)) {
$query .= $this->createPidWhereString($queryArgs) . $this->orderByTerm;
} else {
return null;
}
// send query
return $this->query($query);
}
/**
* Method check if all items of the pidlist are orly digits
* @param array $poly
* @return boolean
*/
private function validPidList($pidList) {
foreach ($pidList as $value) {
if (!ctype_digit($value) || PHP_INT_MAX < $value) {
return FALSE;
}
}
return TRUE;
}
/**
* Method convert a pidList to a where-string
* @param array $pidList
* @return string
*/
private function createPidWhereString($pidList) {
$pidListStr = \utiliy\StringManager::$emptyString;
foreach ($pidList as $value) {
$pidListStr .= $this->pidTerm . $value . $this->orTerm;
}
$result = substr($pidListStr, 0, strlen($pidListStr) - strlen($this->orTerm));
return $result;
}
}
?>