mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-20 00:12:15 +00:00
Added a workaround to convert pgsql arrays into php arrays
Affected controllers: Dokument and Dokumentstudiengang
This commit is contained in:
@@ -61,4 +61,54 @@ class APIv1_Controller extends REST_Controller
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** ----------------------------------------------------------------------------------------------------------------------------------
|
||||
* 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;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------------------------------------------------------
|
||||
}
|
||||
Reference in New Issue
Block a user