diff --git a/application/controllers/api/v1/organisation/Studiengang2.php b/application/controllers/api/v1/organisation/Studiengang2.php index 18e28ad26..43d43247c 100644 --- a/application/controllers/api/v1/organisation/Studiengang2.php +++ b/application/controllers/api/v1/organisation/Studiengang2.php @@ -15,8 +15,6 @@ if (!defined("BASEPATH")) exit("No direct script access allowed"); class Studiengang2 extends APIv1_Controller { - private static $PROPERTIES_SEPARATOR = "properties_separator"; - /** * Course API constructor. */ diff --git a/application/controllers/api/v1/organisation/Studienplan.php b/application/controllers/api/v1/organisation/Studienplan.php index 1a9d54cf0..68a0a2095 100644 --- a/application/controllers/api/v1/organisation/Studienplan.php +++ b/application/controllers/api/v1/organisation/Studienplan.php @@ -12,7 +12,7 @@ */ // ------------------------------------------------------------------------ -if (!defined('BASEPATH')) exit('No direct script access allowed'); +if (!defined("BASEPATH")) exit("No direct script access allowed"); class Studienplan extends APIv1_Controller { @@ -23,14 +23,12 @@ class Studienplan extends APIv1_Controller { parent::__construct(); // Load model PersonModel - $this->load->model('organisation/studienplan_model', 'StudienplanModel'); - - + $this->load->model("organisation/studienplan_model", "StudienplanModel"); } public function getStudienplan() { - $studienplan_id = $this->get('studienplan_id'); + $studienplan_id = $this->get("studienplan_id"); if (isset($studienplan_id)) { @@ -46,15 +44,11 @@ class Studienplan extends APIv1_Controller public function getStudienplaene() { - $studiengang_kz = $this->get('studiengang_kz'); + $studiengang_kz = $this->get("studiengang_kz"); if (isset($studiengang_kz)) { - $result = $this->StudienplanModel->addJoin('lehre.tbl_studienordnung', 'studienordnung_id'); - if ($result->error == EXIT_SUCCESS) - { - $result = $this->StudienplanModel->loadWhere(array('studiengang_kz' => $this->get('studiengang_kz'))); - } + $result = $this->StudienplanModel->getStudienplaene($studiengang_kz); $this->response($result, REST_Controller::HTTP_OK); } @@ -66,37 +60,19 @@ class Studienplan extends APIv1_Controller public function getStudienplaeneFromSem() { - $studiengang_kz = $this->get('studiengang_kz'); - $studiensemester_kurzbz = $this->get('studiensemester_kurzbz'); - $ausbildungssemester = $this->get('ausbildungssemester'); - $orgform_kurzbz = $this->get('orgform_kurzbz'); + $studiengang_kz = $this->get("studiengang_kz"); + $studiensemester_kurzbz = $this->get("studiensemester_kurzbz"); + $ausbildungssemester = $this->get("ausbildungssemester"); + $orgform_kurzbz = $this->get("orgform_kurzbz"); if (isset($studiengang_kz) && isset($studiensemester_kurzbz)) { - $result = $this->StudienplanModel->addJoin('lehre.tbl_studienordnung', 'studienordnung_id'); - if ($result->error == EXIT_SUCCESS) - { - $result = $this->StudienplanModel->addJoin('lehre.tbl_studienplan_semester', 'studienplan_id'); - if ($result->error == EXIT_SUCCESS) - { - $whereArray = array('tbl_studienplan.aktiv' => 'TRUE', - 'tbl_studienordnung.studiengang_kz' => $studiengang_kz, - 'tbl_studienplan_semester.studiensemester_kurzbz' => $studiensemester_kurzbz - ); - - if(isset($ausbildungssemester)) - { - $whereArray['tbl_studienplan_semester.semester'] = $ausbildungssemester; - } - - if(isset($orgform_kurzbz)) - { - $whereArray['orgform_kurzbz'] = $orgform_kurzbz; - } - - $result = $this->StudienplanModel->loadWhere($whereArray); - } - } + $result = $this->StudienplanModel->getStudienplaeneBySemester( + $studiengang_kz, + $studiensemester_kurzbz, + $ausbildungssemester, + $orgform_kurzbz + ); $this->response($result, REST_Controller::HTTP_OK); } diff --git a/application/controllers/api/v1/person/Kontakt.php b/application/controllers/api/v1/person/Kontakt.php index 20a0b38c5..aa1cc49cb 100644 --- a/application/controllers/api/v1/person/Kontakt.php +++ b/application/controllers/api/v1/person/Kontakt.php @@ -13,7 +13,7 @@ */ // ------------------------------------------------------------------------ -if (! defined('BASEPATH')) exit('No direct script access allowed'); +if (! defined("BASEPATH")) exit("No direct script access allowed"); class Kontakt extends APIv1_Controller { @@ -24,9 +24,7 @@ class Kontakt extends APIv1_Controller { parent::__construct(); // Load model PersonModel - $this->load->model('person/kontakt_model', 'KontaktModel'); - - + $this->load->model("person/kontakt_model", "KontaktModel"); } public function getKontakt() @@ -35,15 +33,7 @@ class Kontakt extends APIv1_Controller if (isset($kontakt_id)) { - $result = $this->KontaktModel->addJoin('public.tbl_standort', 'standort_id', 'LEFT'); - if ($result->error == EXIT_SUCCESS) - { - $result = $this->KontaktModel->addJoin('public.tbl_firma', 'firma_id', 'LEFT'); - if ($result->error == EXIT_SUCCESS) - { - $result = $this->KontaktModel->loadWhere(array('kontakt_id' => $kontakt_id)); - } - } + $result = $this->KontaktModel->getWholeKontakt($kontakt_id); $this->response($result, REST_Controller::HTTP_OK); } @@ -59,7 +49,7 @@ class Kontakt extends APIv1_Controller if (isset($kontakt_id)) { - $result = $this->KontaktModel->loadWhere(array('kontakt_id' => $kontakt_id)); + $result = $this->KontaktModel->load($kontakt_id); $this->response($result, REST_Controller::HTTP_OK); } @@ -75,15 +65,7 @@ class Kontakt extends APIv1_Controller if (isset($person_id)) { - $result = $this->KontaktModel->addJoin('public.tbl_standort', 'standort_id', 'LEFT'); - if ($result->error == EXIT_SUCCESS) - { - $result = $this->KontaktModel->addJoin('public.tbl_firma', 'firma_id', 'LEFT'); - if ($result->error == EXIT_SUCCESS) - { - $result = $this->KontaktModel->loadWhere(array('person_id' => $person_id)); - } - } + $result = $this->KontaktModel->getWholeKontakt(null, $person_id); $this->response($result, REST_Controller::HTTP_OK); } @@ -99,7 +81,7 @@ class Kontakt extends APIv1_Controller if (isset($person_id)) { - $result = $this->KontaktModel->loadWhere(array('person_id' => $person_id)); + $result = $this->KontaktModel->loadWhere(array("person_id" => $person_id)); $this->response($result, REST_Controller::HTTP_OK); } @@ -116,15 +98,7 @@ class Kontakt extends APIv1_Controller if (isset($person_id) && isset($kontakttyp)) { - $result = $this->KontaktModel->addJoin('public.tbl_standort', 'standort_id', 'LEFT'); - if ($result->error == EXIT_SUCCESS) - { - $result = $this->KontaktModel->addJoin('public.tbl_firma', 'firma_id', 'LEFT'); - if ($result->error == EXIT_SUCCESS) - { - $result = $this->KontaktModel->loadWhere(array('person_id' => $person_id, 'kontakttyp' => $kontakttyp)); - } - } + $result = $this->KontaktModel->getWholeKontakt(null, $person_id, $kontakttyp); $this->response($result, REST_Controller::HTTP_OK); } @@ -140,9 +114,9 @@ class Kontakt extends APIv1_Controller if (is_array($post)) { - if (isset($post['kontakt_id'])) + if (isset($post["kontakt_id"])) { - $result = $this->KontaktModel->update($post['kontakt_id'], $post); + $result = $this->KontaktModel->update($post["kontakt_id"], $post); } else { diff --git a/application/controllers/api/v1/person/Person.php b/application/controllers/api/v1/person/Person.php index 7ab6e0d2f..249b7c89f 100644 --- a/application/controllers/api/v1/person/Person.php +++ b/application/controllers/api/v1/person/Person.php @@ -31,27 +31,30 @@ class Person extends APIv1_Controller */ public function getPerson() { - $personID = $this->get("person_id"); + $person_id = $this->get("person_id"); $code = $this->get("code"); $email = $this->get("email"); - if (isset($code) || isset($email) || isset($personID)) + if (isset($code) || isset($email) || isset($person_id)) { if (isset($code) && isset($email)) { - $result = $this->PersonModel->addJoin("public.tbl_kontakt", "person_id"); - if ($result->error == EXIT_SUCCESS) - { - $result = $this->PersonModel->loadWhere(array("zugangscode" => $code, "kontakt" => $email)); - } - } - elseif (isset($code)) - { - $result = $this->PersonModel->loadWhere(array("zugangscode" => $code)); + $result = $this->PersonModel->getPersonKontaktByZugangscode($code, $email); } else { - $result = $this->PersonModel->load($personID); + $parametersArray = array(); + + if (isset($code)) + { + $parametersArray["zugangscode"] = $code; + } + else + { + $parametersArray["person_id"] = $person_id; + } + + $result = $this->PersonModel->loadWhere($parametersArray); } $this->response($result, REST_Controller::HTTP_OK); @@ -61,6 +64,26 @@ class Person extends APIv1_Controller $this->response(); } } + + /** + * @return void + */ + public function getCheckBewerbung() + { + $email = $this->get("email"); + $studiensemester_kurzbz = $this->get("studiensemester_kurzbz"); + + if (isset($email)) + { + $result = $this->PersonModel->checkBewerbung($email, $studiensemester_kurzbz); + + $this->response($result, REST_Controller::HTTP_OK); + } + else + { + $this->response(); + } + } /** * @return void @@ -74,28 +97,7 @@ class Person extends APIv1_Controller { if(isset($person["person_id"]) && !(is_null($person["person_id"])) && ($person["person_id"] != "")) { - if (isset($person["svnr"]) && $person["svnr"] != "") - { - $this->PersonModel->addOrder("svnr", "DESC"); - $result = $this->PersonModel->loadWhere(array( - "person_id != " => $person["person_id"], - "SUBSTRING(svnr FROM 1 FOR 10) = " => $person["svnr"]) - ); - if (is_object($result) && $result->error == EXIT_SUCCESS && - is_array($result->retval) && count($result->retval) > 0) - { - if (count($result->retval) == 1) - { - $person["svnr"] = $person["svnr"] . "v1"; - } - else - { - $person["svnr"] = $person["svnr"] . "v" . ($result->retval[0]->svnr{11} + 1); - } - } - } - - $result = $this->PersonModel->update($person["person_id"], $person); + $result = $this->PersonModel->updatePerson($person); } else { @@ -110,26 +112,6 @@ class Person extends APIv1_Controller } } - /** - * @return void - */ - public function getCheckBewerbung() - { - $email = $this->get("email"); - $studiensemester_kurzbz = $this->get("studiensemester_kurzbz"); - - if (isset($email)) - { - $result = $this->PersonModel->checkBewerbung($email, $studiensemester_kurzbz); - - $this->response($result, REST_Controller::HTTP_OK); - } - else - { - $this->response(); - } - } - private function _validate($person = NULL) { if (!isset($person)) diff --git a/application/controllers/api/v1/ressource/Ort.php b/application/controllers/api/v1/ressource/Ort.php index da05e6c04..bdc695ab0 100644 --- a/application/controllers/api/v1/ressource/Ort.php +++ b/application/controllers/api/v1/ressource/Ort.php @@ -12,7 +12,7 @@ */ // ------------------------------------------------------------------------ -if (!defined('BASEPATH')) exit('No direct script access allowed'); +if (!defined("BASEPATH")) exit("No direct script access allowed"); class Ort extends APIv1_Controller { @@ -23,9 +23,7 @@ class Ort extends APIv1_Controller { parent::__construct(); // Load model OrtModel - $this->load->model('ressource/ort_model', 'OrtModel'); - - + $this->load->model("ressource/ort_model", "OrtModel"); } /** @@ -33,7 +31,7 @@ class Ort extends APIv1_Controller */ public function getOrt() { - $ort_kurzbz = $this->get('ort_kurzbz'); + $ort_kurzbz = $this->get("ort_kurzbz"); if (isset($ort_kurzbz)) { @@ -52,17 +50,11 @@ class Ort extends APIv1_Controller */ public function getAll() { - $raumtyp_kurzbz = $this->get('raumtyp_kurzbz'); + $raumtyp_kurzbz = $this->get("raumtyp_kurzbz"); - $this->OrtModel->addOrder('ort_kurzbz'); - - if (!is_null($raumtyp_kurzbz) && $raumtyp_kurzbz != '') + if (!is_null($raumtyp_kurzbz) && $raumtyp_kurzbz != "") { - $result = $this->OrtModel->addJoin('public.tbl_ortraumtyp', 'ort_kurzbz'); - if ($result->error == EXIT_SUCCESS) - { - $result = $this->OrtModel->loadWhere(array('raumtyp_kurzbz' => $raumtyp_kurzbz)); - } + $result = $this->OrtModel->getAll($raumtyp_kurzbz); } else { @@ -79,9 +71,9 @@ class Ort extends APIv1_Controller { if ($this->_validate($this->post())) { - if (isset($this->post()['ort_kurzbz'])) + if (isset($this->post()["ort_kurzbz"])) { - $result = $this->OrtModel->update($this->post()['ort_kurzbz'], $this->post()); + $result = $this->OrtModel->update($this->post()["ort_kurzbz"], $this->post()); } else { diff --git a/application/libraries/DmsLib.php b/application/libraries/DmsLib.php index 083dab2d4..74181401c 100644 --- a/application/libraries/DmsLib.php +++ b/application/libraries/DmsLib.php @@ -119,7 +119,7 @@ class DmsLib { $filename = uniqid() . "." . pathinfo($dms["name"], PATHINFO_EXTENSION); - return $this->ci->DmsFSModel->write($filename, $dms["file_content"]); + $result = $this->ci->DmsFSModel->write($filename, $dms["file_content"]); if (is_object($result) && $result->error == EXIT_SUCCESS) { $result->retval = $filename; diff --git a/application/models/organisation/Studienplan_model.php b/application/models/organisation/Studienplan_model.php index 9faa61493..5fe7ef44d 100644 --- a/application/models/organisation/Studienplan_model.php +++ b/application/models/organisation/Studienplan_model.php @@ -1,14 +1,45 @@ dbTable = 'lehre.tbl_studienplan'; - $this->pk = 'studienplan_id'; + $this->dbTable = "lehre.tbl_studienplan"; + $this->pk = "studienplan_id"; + } + + public function getStudienplaene($studiengang_kz) + { + $this->addJoin("lehre.tbl_studienordnung", "studienordnung_id"); + + return $this->loadWhere(array("studiengang_kz" => $studiengang_kz)); + } + + public function getStudienplaeneBySemester($studiengang_kz, $studiensemester_kurzbz, $ausbildungssemester = null, $orgform_kurzbz = null) + { + $this->addJoin("lehre.tbl_studienordnung", "studienordnung_id"); + $this->addJoin("lehre.tbl_studienplan_semester", "studienplan_id"); + + $whereArray = array( + "tbl_studienplan.aktiv" => "TRUE", + "tbl_studienordnung.studiengang_kz" => $studiengang_kz, + "tbl_studienplan_semester.studiensemester_kurzbz" => $studiensemester_kurzbz + ); + + if(!is_null($ausbildungssemester)) + { + $whereArray["tbl_studienplan_semester.semester"] = $ausbildungssemester; + } + + if(!is_null($orgform_kurzbz)) + { + $whereArray["orgform_kurzbz"] = $orgform_kurzbz; + } + + return $this->StudienplanModel->loadWhere($whereArray); } } \ No newline at end of file diff --git a/application/models/person/Kontakt_model.php b/application/models/person/Kontakt_model.php index 5c25f563e..88a44cbc8 100644 --- a/application/models/person/Kontakt_model.php +++ b/application/models/person/Kontakt_model.php @@ -1,4 +1,5 @@ dbTable = 'public.tbl_kontakt'; - $this->pk = 'kontakt_id'; + $this->dbTable = "public.tbl_kontakt"; + $this->pk = "kontakt_id"; } + + public function getWholeKontakt($kontakt_id, $person_id = null, $kontakttyp = null) + { + $result = null; + + $this->addJoin("public.tbl_standort", "standort_id", "LEFT"); + $this->addJoin("public.tbl_firma", "firma_id", "LEFT"); + + if (isset($kontakt_id)) + { + $result = $this->load($kontakt_id); + } + else + { + $parametersArray = array(); + + if (!is_null($person_id)) + { + $parametersArray["person_id"] = $person_id; + } + if (!is_null($kontakttyp)) + { + $parametersArray["kontakttyp"] = $kontakttyp; + } + + if (count($parametersArray) > 0) + { + $result = $this->loadWhere($parametersArray); + } + } + + return $result; + } } \ No newline at end of file diff --git a/application/models/person/Person_model.php b/application/models/person/Person_model.php index 7fe986b17..d139788b4 100644 --- a/application/models/person/Person_model.php +++ b/application/models/person/Person_model.php @@ -8,8 +8,15 @@ class Person_model extends DB_Model public function __construct() { parent::__construct(); - $this->dbTable = 'public.tbl_person'; - $this->pk = 'person_id'; + $this->dbTable = "public.tbl_person"; + $this->pk = "person_id"; + } + + public function getPersonKontaktByZugangscode($zugangscode, $email) + { + $this->addJoin("public.tbl_kontakt", "person_id"); + + return $this->loadWhere(array("zugangscode" => $zugangscode, "kontakt" => $email)); } /** @@ -29,6 +36,8 @@ class Person_model extends DB_Model return $chkRights; $result = null; + $checkBewerbungQuery = ""; + $parametersArray = array($email, $email, $email); if (is_null($studiensemester_kurzbz)) { @@ -36,11 +45,9 @@ class Person_model extends DB_Model FROM public.tbl_person p JOIN public.tbl_kontakt k ON p.person_id = k.person_id LEFT JOIN public.tbl_benutzer b ON p.person_id = b.person_id WHERE k.kontakttyp = 'email' - AND (kontakt = ? OR alias || '@technikum-wien.at' = ? OR uid || '@technikum-wien.at' = ?) + AND (kontakt = ? OR alias || '@" . DOMAIN . "' = ? OR uid || '@" . DOMAIN . "' = ?) ORDER BY p.insertamum DESC LIMIT 1"; - - $result = $this->db->query($checkBewerbungQuery, array($email, $email, $email)); } else { @@ -50,17 +57,45 @@ class Person_model extends DB_Model JOIN public.tbl_prestudent ps ON p.person_id = ps.person_id JOIN public.tbl_prestudentstatus pst ON pst.prestudent_id = ps.prestudent_id WHERE k.kontakttyp = 'email' - AND (kontakt = ? OR alias || '@technikum-wien.at' = ? OR uid || '@technikum-wien.at' = ?) + AND (kontakt = ? OR alias || '@" . DOMAIN . "' = ? OR uid || '@" . DOMAIN . "' = ?) AND studiensemester_kurzbz = ? ORDER BY p.insertamum DESC LIMIT 1"; - $result = $this->db->query($checkBewerbungQuery, array($email, $email, $email, $studiensemester_kurzbz)); + array_push($parametersArray, $studiensemester_kurzbz); } + $result = $this->db->query($checkBewerbungQuery, $parametersArray); + if (is_object($result)) return $this->_success($result->result()); else return $this->_error($this->db->error(), FHC_DB_ERROR); } + + public function updatePerson($person) + { + if (isset($person["svnr"]) && $person["svnr"] != "") + { + $this->PersonModel->addOrder("svnr", "DESC"); + $result = $this->PersonModel->loadWhere(array( + "person_id != " => $person["person_id"], + "SUBSTRING(svnr FROM 1 FOR 10) = " => $person["svnr"]) + ); + if (is_object($result) && $result->error == EXIT_SUCCESS && + is_array($result->retval) && count($result->retval) > 0) + { + if (count($result->retval) == 1 && $result->retval[0]->svnr == $person["svnr"]) + { + $person["svnr"] = $person["svnr"] . "v1"; + } + else + { + $person["svnr"] = $person["svnr"] . "v" . ($result->retval[0]->svnr{11} + 1); + } + } + } + + return $this->PersonModel->update($person["person_id"], $person); + } } \ No newline at end of file diff --git a/application/models/ressource/Ort_model.php b/application/models/ressource/Ort_model.php index 3434c6fc0..59b213a54 100644 --- a/application/models/ressource/Ort_model.php +++ b/application/models/ressource/Ort_model.php @@ -1,14 +1,23 @@ dbTable = 'public.tbl_ort'; - $this->pk = 'ort_kurzbz'; + $this->dbTable = "public.tbl_ort"; + $this->pk = "ort_kurzbz"; } -} + + public function getAll($raumtyp_kurzbz) + { + $this->addOrder("ort_kurzbz"); + + $this->addJoin("public.tbl_ortraumtyp", "ort_kurzbz"); + + return $this->OrtModel->loadWhere(array("raumtyp_kurzbz" => $raumtyp_kurzbz)); + } +} \ No newline at end of file