From 0a19cbfba45b7a10f5d6ae5e2168f9ef506a5f88 Mon Sep 17 00:00:00 2001 From: bison-paolo Date: Fri, 25 Nov 2016 15:09:19 +0100 Subject: [PATCH] - Changed the routes used to call the controllers, now accept also capital names - Now method getStudiengangBewerbung of controller Studiengang returns also data relative to the table lehre.tbl_akadgrad - Fixes and enhancements of method loadTree of DB_Model. --- application/config/routes.php | 12 +++--- application/core/DB_Model.php | 37 ++++++++++++------- .../models/organisation/Studiengang_model.php | 8 +++- 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/application/config/routes.php b/application/config/routes.php index 80f82e274..791b6d03c 100755 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -54,9 +54,9 @@ $route['404_override'] = ''; $route['translate_uri_dashes'] = FALSE; // Class name conflicts -$route['api/v1/organisation/studiengang/(:any)'] = 'api/v1/organisation/studiengang2/$1'; -$route['api/v1/ressource/betriebsmittelperson/(:any)'] = 'api/v1/ressource/betriebsmittelperson2/$1'; -$route['api/v1/organisation/fachbereich/(:any)'] = 'api/v1/organisation/fachbereich2/$1'; -$route['api/v1/organisation/geschaeftsjahr/(:any)'] = 'api/v1/organisation/geschaeftsjahr2/$1'; -$route['api/v1/organisation/organisationseinheit/(:any)'] = 'api/v1/organisation/organisationseinheit2/$1'; -$route['api/v1/system/sprache/(:any)'] = 'api/v1/system/sprache2/$1'; \ No newline at end of file +$route['api/v1/organisation/[S|s]tudiengang/(:any)'] = 'api/v1/organisation/studiengang2/$1'; +$route['api/v1/organisation/[F|f]achbereich/(:any)'] = 'api/v1/organisation/fachbereich2/$1'; +$route['api/v1/organisation/[G|g]eschaeftsjahr/(:any)'] = 'api/v1/organisation/geschaeftsjahr2/$1'; +$route['api/v1/organisation/[O|o]rganisationseinheit/(:any)'] = 'api/v1/organisation/organisationseinheit2/$1'; +$route['api/v1/ressource/[B|b]etriebsmittelperson/(:any)'] = 'api/v1/ressource/betriebsmittelperson2/$1'; +$route['api/v1/system/[S|s]prache/(:any)'] = 'api/v1/system/sprache2/$1'; \ No newline at end of file diff --git a/application/core/DB_Model.php b/application/core/DB_Model.php index 1b93c864d..afb055f03 100644 --- a/application/core/DB_Model.php +++ b/application/core/DB_Model.php @@ -266,13 +266,12 @@ class DB_Model extends FHC_Model // Execute the query $resultDB = $this->db->get_where($this->dbTable, $where); - // If everything went ok... if ($resultDB) { // Converts the object that contains data, from the returned CI's object to an array // with the postgresql array and boolean types converterd - $resultArray = $this->toPhp($resultDB); + $resultArray = $this->toPhp($resultDB);//var_dump($resultArray); // Array that will contain all the mainTable records, and to each record the linked data // of a side table $returnArray = array(); @@ -286,15 +285,18 @@ class DB_Model extends FHC_Model // Temporary array that will contain a representation of every records returned from DB // every element is an associative array that contains all the data of each table $objTmpArray = array(); - + $tableColumnsCountArrayOffset = 0; // Columns offset // Gets all the data of a single table from the returned record, and creates an object filled with these data for ($f = 0; $f < count($tableColumnsCountArray); $f++) { $objTmpArray[$f] = new stdClass(); // Object that will represent a data set of a table - foreach (array_slice($objectVars, $f == 0 ? 0 : $tableColumnsCountArray[$f - 1], $tableColumnsCountArray[$f]) as $key => $value) + + foreach (array_slice($objectVars, $tableColumnsCountArrayOffset, $tableColumnsCountArray[$f]) as $key => $value) { $objTmpArray[$f]->{str_replace($tables[$f] . '_', '', $key)} = $value; } + + $tableColumnsCountArrayOffset += $tableColumnsCountArray[$f]; // Increasing the offset } // Object that represents data of the main table @@ -304,23 +306,30 @@ class DB_Model extends FHC_Model { // Object that represents data of the side table $sideTableObj = $objTmpArray[$t]; - $sideTableProperty = $tables[$t]; if (is_array($sideTablesAliases)) { - $sideTableProperty = $sideTablesAliases[$t -1]; + $sideTableProperty = $sideTablesAliases[$t - 1]; } - if (($k = $this->findMainTable($mainTableObj, $returnArray)) === false) + // If the side table has data. If it was used a left join all the properties could be null + if (!empty(array_filter(get_object_vars($sideTableObj)))) { - $mainTableObj->{$sideTableProperty} = array($sideTableObj); - $returnArray[$returnArrayCounter++] = $mainTableObj; - } - else - { - if (array_search($sideTableObj, $returnArray[$k]->{$sideTableProperty}) === false) + if (($k = $this->findMainTable($mainTableObj, $returnArray)) === false) { - array_push($returnArray[$k]->{$sideTableProperty}, $sideTableObj); + $mainTableObj->{$sideTableProperty} = array($sideTableObj); + $returnArray[$returnArrayCounter++] = $mainTableObj; + } + else + { + if (!isset($returnArray[$k]->{$sideTableProperty})) + { + $returnArray[$k]->{$sideTableProperty} = array($sideTableObj); + } + else if (array_search($sideTableObj, $returnArray[$k]->{$sideTableProperty}) === false) + { + array_push($returnArray[$k]->{$sideTableProperty}, $sideTableObj); + } } } } diff --git a/application/models/organisation/Studiengang_model.php b/application/models/organisation/Studiengang_model.php index f33e531b4..b5b0fb435 100644 --- a/application/models/organisation/Studiengang_model.php +++ b/application/models/organisation/Studiengang_model.php @@ -141,6 +141,8 @@ class Studiengang_model extends DB_Model { // Join table public.tbl_studiengang with table lehre.tbl_studienordnung on column studiengang_kz $this->addJoin('lehre.tbl_studienordnung', 'studiengang_kz'); + // Join table lehre.tbl_studienordnung with table lehre.tbl_akadgrad on column akadgrad_id + $this->addJoin('lehre.tbl_akadgrad', 'akadgrad_id', 'LEFT'); // Then join with table lehre.tbl_studienplan on column studienordnung_id $this->addJoin('lehre.tbl_studienplan', 'studienordnung_id'); // Then join with table lehre.tbl_studienplan_semester on column studienplan_id @@ -158,7 +160,8 @@ class Studiengang_model extends DB_Model $result = $this->loadTree( 'tbl_studiengang', array( - 'tbl_studienplan' + 'tbl_studienplan', + 'tbl_akadgrad' ), 'public.tbl_studiengang.aktiv = TRUE AND public.tbl_studiengang.onlinebewerbung = TRUE @@ -168,7 +171,8 @@ class Studiengang_model extends DB_Model AND lehre.tbl_studienplan.aktiv = TRUE' , array( - 'studienplaene' + 'studienplaene', + 'akadgrad' ) );