- Added method chkRights to DB_Model

- Added method toPhp to DB_Model to convert array and boolean types from PostgresSQL to php
- Added method execQuery to DB_Model to execute a query (it calls toPhp)
- Added method pgsqlArrayToPhpArray to convert a pgsql array to php
- Updated DB_Model methods to using chkRights (and toPhp where it is needed)
- Removed methods escapeArray and _pgsqlArrayToPhpArray from controller APIv1_Controller
- Removed escapeArray from controllers Dokumentstudiengang and Dokument
- Updated models to use execQuery (and chkRights where it is needed)
This commit is contained in:
bison-paolo
2016-10-17 17:07:51 +02:00
parent 19ff69110d
commit f3b79cd731
17 changed files with 327 additions and 318 deletions
+3 -53
View File
@@ -9,7 +9,7 @@ class APIv1_Controller extends REST_Controller
parent::__construct();
// Loads return messages
$this->load->helper('message');
$this->load->helper('Message');
}
/**
@@ -23,7 +23,7 @@ class APIv1_Controller extends REST_Controller
{
foreach($data as $key=>$value)
{
if($value === "")
if($value === '')
{
$data[$key] = NULL;
}
@@ -36,60 +36,10 @@ class APIv1_Controller extends REST_Controller
}
else
{
if($data == "")
if($data == '')
{
return NULL;
}
}
}
/** ----------------------------------------------------------------------------------------------------------------------------------
* Workaround for converting a pgsql array to a php array
* To be dropped as soon as possible :D
*/
protected function escapeArrays($result, $fields_names)
{
if (is_object($result) && isset($result->retval) && is_array($result->retval))
{
for ($i = 0; $i < count($result->retval); $i++)
{
foreach($fields_names as $field_name)
{
if (isset($result->retval[$i]->{$field_name}))
{
$result->retval[$i]->{$field_name} = $this->_pgsqlArrayToPhpArray($result->retval[$i]->{$field_name});
}
}
}
}
return $result;
}
/**
* To be moved to DB_model
*/
private function _pgsqlArrayToPhpArray($string)
{
$result = array();
if (!empty($string))
{
preg_match_all(
'/(?<=^\{|,)(([^,"{]*)|\s*"((?:[^"\\\\]|\\\\(?:.|[0-9]+|x[0-9a-f]+))*)"\s*)(,|(?<!^\{)(?=\}$))/i',
$string,
$matches,
PREG_SET_ORDER
);
foreach ($matches as $match)
{
$result[] = $match[3] != '' ? stripcslashes($match[3]) : (strtolower($match[2]) == 'null' ? null : $match[2]);
}
}
return $result;
}
// --------------------------------------------------------------------------------------------------------------------------------------------
}