- Added method loadList to model DB_model

- Added method getStudienplan to model Studiengang_model
- Changes in method getStudiengangStudienplan of controller Studiengang2
This commit is contained in:
bison
2016-08-26 14:21:04 +02:00
parent 59b5d76e44
commit 7e71681d26
3 changed files with 170 additions and 130 deletions
@@ -62,121 +62,11 @@ class Studiengang2 extends APIv1_Controller
// If $studiensemester_kurzbz and $ausbildungssemester are present
if (isset($studiensemester_kurzbz) && isset($ausbildungssemester))
{
$result = null; // return variable
// Check & set
if (!isset($aktiv)) $aktiv = "TRUE";
if (!isset($onlinebewerbung)) $onlinebewerbung = "TRUE";
// Join table public.tbl_studiengang with table lehre.tbl_studienordnung on column studiengang_kz
$result = $this->StudiengangModel->addJoin("lehre.tbl_studienordnung", "studiengang_kz");
if ($result->error == EXIT_SUCCESS) // If the API caller has the rights
{
// Then join with table lehre.tbl_studienplan on column studienordnung_id
$result = $this->StudiengangModel->addJoin("lehre.tbl_studienplan", "studienordnung_id");
if ($result->error == EXIT_SUCCESS) // If the API caller has the rights
{
// Then join with table lehre.tbl_studienplan_semester on column studienplan_id
$result = $this->StudiengangModel->addJoin("lehre.tbl_studienplan_semester", "studienplan_id");
if ($result->error == EXIT_SUCCESS) // If the API caller has the rights
{
// Select all fields from table public.tbl_studiengang and table lehre.tbl_studienplan
// The separator is used to keep data separated between table public.tbl_studiengang
// and table lehre.tbl_studienplan (keep 'em separated!)
$this->StudiengangModel->addSelect(
"public.tbl_studiengang.*,
'' as " . Studiengang2::$PROPERTIES_SEPARATOR . ",
lehre.tbl_studienplan.studienplan_id as tbl_sp_studienplan_id,
lehre.tbl_studienplan.studienordnung_id as tbl_sp_studienordnung_id,
lehre.tbl_studienplan.orgform_kurzbz as tbl_sp_orgform_kurzbz,
lehre.tbl_studienplan.version as tbl_sp_version,
lehre.tbl_studienplan.bezeichnung as tbl_sp_bezeichnung,
lehre.tbl_studienplan.regelstudiendauer as tbl_sp_regelstudiendauer,
lehre.tbl_studienplan.sprache as tbl_sp_sprache,
lehre.tbl_studienplan.aktiv as tbl_sp_aktiv,
lehre.tbl_studienplan.semesterwochen as tbl_sp_semesterwochen,
lehre.tbl_studienplan.testtool_sprachwahl as tbl_sp_testtool_sprachwahl,
lehre.tbl_studienplan.insertamum as tbl_sp_insertamum,
lehre.tbl_studienplan.insertvon as tbl_sp_insertvon,
lehre.tbl_studienplan.updateamum as tbl_sp_updateamum,
lehre.tbl_studienplan.updatevon as tbl_sp_updatevon,
lehre.tbl_studienplan.ext_id as tbl_sp_ext_id,
lehre.tbl_studienplan.ects_stpl as tbl_sp_ects_stpl,
lehre.tbl_studienplan.pflicht_sws as tbl_sp_pflicht_sws,
lehre.tbl_studienplan.pflicht_lvs as tbl_sp_pflicht_lvs"
);
// Ordering by studiengang_kz and studienplan_id
$this->StudiengangModel->addOrder("public.tbl_studiengang.studiengang_kz");
$this->StudiengangModel->addOrder("lehre.tbl_studienplan.studienplan_id");
// Execute the query
$result = $this->StudiengangModel->loadWhere(array(
"lehre.tbl_studienplan_semester.studiensemester_kurzbz" => $studiensemester_kurzbz,
"lehre.tbl_studienplan_semester.semester" => $ausbildungssemester,
"public.tbl_studiengang.aktiv" => $aktiv,
"public.tbl_studiengang.onlinebewerbung" => $onlinebewerbung
));
}
}
}
// If everything went ok...
if (is_object($result) && $result->error == EXIT_SUCCESS &&
is_array($result->retval) && count($result->retval) > 0)
{
$studiengangArray = array(); // Array that will contain all the studiengang
$countReturnArray = 0; // Array counter
$prevStudiengang_kz = null; // Previous studiengang key
// Iterates the array that contains data from database
for ($i = 0; $i < count($result->retval); $i++)
{
$objStudiengang = new stdClass(); // New object that represent a studiengang
$objStudienplan = new stdClass(); // New object that represent a studienplan
$separator = false;
// Getting all the properties as an array, of an element of the array that
// represents a single studiengang with its own studienplan
foreach (get_object_vars($result->retval[$i]) as $key => $value)
{
// If the current element is the separator then ignore it!
if ($key != Studiengang2::$PROPERTIES_SEPARATOR)
{
// Before the separator: studiengang
if (!$separator)
{
$objStudiengang->{$key} = $value;
}
else // After the separator: studienplan
{
$objStudienplan->{str_replace("tbl_sp_", "", $key)} = $value;
}
}
else
{
$separator = true;
}
}
// If the current studiengang is the same as before, adds to it the studienplan
if ($prevStudiengang_kz == $objStudiengang->studiengang_kz)
{
array_push($studiengangArray[$countReturnArray - 1]->studienplaene, $objStudienplan);
}
// Otherwise creates the property studienplaene and adds the first studienplan,
// then adds the new studiengang to studiengangArray and sets prevStudiengang_kz
else
{
$objStudiengang->studienplaene = array($objStudienplan);
$studiengangArray[$countReturnArray++] = $objStudiengang;
$prevStudiengang_kz = $objStudiengang->studiengang_kz;
}
}
// Sets result with the standard success object that contains all the studiengang
$result = $this->_success($studiengangArray);
}
$result = $this->StudiengangModel->getStudienplan($studiensemester_kurzbz, $ausbildungssemester, $aktiv, $onlinebewerbung);
$this->response($result, REST_Controller::HTTP_OK);
}