From fbed4b2261828d1a541c574854ce137843fbde3f Mon Sep 17 00:00:00 2001 From: bison Date: Tue, 30 Aug 2016 12:26:22 +0200 Subject: [PATCH] - Added new library ReihungstestLib - Added method isEntitled to FCH_Model - Cleaned the controllers by moving the database related code in the models or libraries --- .../controllers/api/v1/codex/Gemeinde.php | 5 +- .../api/v1/crm/Dokumentstudiengang.php | 38 ++++--------- .../controllers/api/v1/crm/Prestudent.php | 40 ++++++------- .../controllers/api/v1/crm/Reihungstest.php | 36 +++++------- application/core/FHC_Model.php | 30 +++++++--- application/libraries/ReihungstestLib.php | 57 +++++++++++++++++++ application/models/codex/Gemeinde_model.php | 16 ++++-- .../models/crm/Dokumentstudiengang_model.php | 31 ++++++++-- 8 files changed, 160 insertions(+), 93 deletions(-) create mode 100644 application/libraries/ReihungstestLib.php diff --git a/application/controllers/api/v1/codex/Gemeinde.php b/application/controllers/api/v1/codex/Gemeinde.php index 3be4ecb09..52b879598 100644 --- a/application/controllers/api/v1/codex/Gemeinde.php +++ b/application/controllers/api/v1/codex/Gemeinde.php @@ -55,10 +55,7 @@ class Gemeinde extends APIv1_Controller if (is_numeric($plz)) { - $this->GemeindeModel->addSelect("DISTINCT ON (ortschaftsname) ortschaftsname, gemeinde_id, plz, name, ortschaftskennziffer, bulacode, bulabez, kennziffer"); - $this->GemeindeModel->addOrder("ortschaftsname"); - - $result = $this->GemeindeModel->loadWhere(array("plz" => $plz)); + $result = $this->GemeindeModel->getGemeindeByPlz($plz); $this->response($result, REST_Controller::HTTP_OK); } diff --git a/application/controllers/api/v1/crm/Dokumentstudiengang.php b/application/controllers/api/v1/crm/Dokumentstudiengang.php index c30a1704e..2d90c44e7 100644 --- a/application/controllers/api/v1/crm/Dokumentstudiengang.php +++ b/application/controllers/api/v1/crm/Dokumentstudiengang.php @@ -12,7 +12,7 @@ */ // ------------------------------------------------------------------------ -if (!defined('BASEPATH')) exit('No direct script access allowed'); +if (!defined("BASEPATH")) exit("No direct script access allowed"); class Dokumentstudiengang extends APIv1_Controller { @@ -23,9 +23,7 @@ class Dokumentstudiengang extends APIv1_Controller { parent::__construct(); // Load model DokumentstudiengangModel - $this->load->model('crm/dokumentstudiengang_model', 'DokumentstudiengangModel'); - - + $this->load->model("crm/Dokumentstudiengang_model", "DokumentstudiengangModel"); } /** @@ -33,8 +31,8 @@ class Dokumentstudiengang extends APIv1_Controller */ public function getDokumentstudiengang() { - $studiengang_kz = $this->get('studiengang_kz'); - $dokument_kurzbz = $this->get('dokument_kurzbz'); + $studiengang_kz = $this->get("studiengang_kz"); + $dokument_kurzbz = $this->get("dokument_kurzbz"); if (isset($studiengang_kz) && isset($dokument_kurzbz)) { @@ -53,29 +51,13 @@ class Dokumentstudiengang extends APIv1_Controller */ public function getDokumentstudiengangByStudiengang_kz() { - $studiengang_kz = $this->get('studiengang_kz'); - $onlinebewerbung = $this->get('onlinebewerbung'); - $pflicht = $this->get('pflicht'); + $studiengang_kz = $this->get("studiengang_kz"); + $onlinebewerbung = $this->get("onlinebewerbung"); + $pflicht = $this->get("pflicht"); if (isset($studiengang_kz)) { - $result = $this->DokumentstudiengangModel->addJoin("public.tbl_dokument", "dokument_kurzbz"); - if(is_object($result) && $result->error == EXIT_SUCCESS) - { - $parameterArray = array("studiengang_kz" => $studiengang_kz); - - if( isset($onlinebewerbung)) - { - $parameterArray["onlinebewerbung"] = $onlinebewerbung; - } - - if( isset($pflicht)) - { - $parameterArray["pflicht"] = $pflicht; - } - - $result = $this->DokumentstudiengangModel->loadWhere($parameterArray); - } + $result = $this->DokumentstudiengangModel->getDokumentstudiengangByStudiengang_kz($studiengang_kz, $onlinebewerbung, $pflicht); $this->response($result, REST_Controller::HTTP_OK); } @@ -92,9 +74,9 @@ class Dokumentstudiengang extends APIv1_Controller { if ($this->_validate($this->post())) { - if (isset($this->post()['studiengang_kz']) && isset($this->post()['dokument_kurzbz'])) + if (isset($this->post()["studiengang_kz"]) && isset($this->post()["dokument_kurzbz"])) { - $result = $this->DokumentstudiengangModel->update(array($this->post()['studiengang_kz'], $this->post()['dokument_kurzbz']), $this->post()); + $result = $this->DokumentstudiengangModel->update(array($this->post()["studiengang_kz"], $this->post()["dokument_kurzbz"]), $this->post()); } else { diff --git a/application/controllers/api/v1/crm/Prestudent.php b/application/controllers/api/v1/crm/Prestudent.php index b13343009..c41045baf 100644 --- a/application/controllers/api/v1/crm/Prestudent.php +++ b/application/controllers/api/v1/crm/Prestudent.php @@ -12,7 +12,7 @@ */ // ------------------------------------------------------------------------ -if (!defined('BASEPATH')) exit('No direct script access allowed'); +if (!defined("BASEPATH")) exit("No direct script access allowed"); class Prestudent extends APIv1_Controller { @@ -23,7 +23,9 @@ class Prestudent extends APIv1_Controller { parent::__construct(); // Load model PrestudentModel - $this->load->model('crm/prestudent_model', 'PrestudentModel'); + $this->load->model("crm/prestudent_model", "PrestudentModel"); + // Load library ReihungstestLib + $this->load->library("ReihungstestLib"); } /** @@ -31,7 +33,7 @@ class Prestudent extends APIv1_Controller */ public function getPrestudent() { - $prestudentID = $this->get('prestudent_id'); + $prestudentID = $this->get("prestudent_id"); if (isset($prestudentID)) { @@ -50,11 +52,11 @@ class Prestudent extends APIv1_Controller */ public function getPrestudentByPersonID() { - $person_id = $this->get('person_id'); + $person_id = $this->get("person_id"); if (isset($person_id)) { - $result = $this->PrestudentModel->load(array('person_id' => $person_id)); + $result = $this->PrestudentModel->load(array("person_id" => $person_id)); $this->response($result, REST_Controller::HTTP_OK); } @@ -71,9 +73,9 @@ class Prestudent extends APIv1_Controller { if ($this->_validate($this->post())) { - if (isset($this->post()['prestudent_id'])) + if (isset($this->post()["prestudent_id"])) { - $result = $this->PrestudentModel->update($this->post()['prestudent_id'], $this->post()); + $result = $this->PrestudentModel->update($this->post()["prestudent_id"], $this->post()); } else { @@ -95,22 +97,18 @@ class Prestudent extends APIv1_Controller { $ddReihungstest = $this->_parseData($this->post()); - if ($this->_validateAddReihungstest($ddReihungstest)) + if ($this->_validateReihungstest($ddReihungstest)) { - $this->load->model('crm/RtPerson_model', 'RtPersonModel'); - - if(isset($ddReihungstest['new']) && $ddReihungstest['new'] == true) + if(isset($ddReihungstest["new"]) && $ddReihungstest["new"] == true) { // Remove new parameter to avoid DB insert errors - unset($ddReihungstest['new']); + unset($ddReihungstest["new"]); - $result = $this->RtPersonModel->insert($ddReihungstest); + $result = $this->reihungstestlib->insertPersonReihungstest($ddReihungstest); } else { - $pksArray = array($ddReihungstest['person_id'], $ddReihungstest['rt_id']); - - $result = $this->RtPersonModel->update($pksArray, $ddReihungstest); + $result = $this->reihungstestlib->updatePersonReihungstest($ddReihungstest); } $this->response($result, REST_Controller::HTTP_OK); @@ -128,11 +126,9 @@ class Prestudent extends APIv1_Controller { $ddReihungstest = $this->_parseData($this->post()); - if ($this->_validateAddReihungstest($ddReihungstest)) + if (isset($ddReihungstest["rt_person_id"])) { - $this->load->model('crm/RtPerson_model', 'RtPersonModel'); - - $result = $this->RtPersonModel->delete($ddReihungstest['rt_person_id'], $ddReihungstest); + $result = $this->reihungstestlib->deletePersonReihungstest($ddReihungstest); $this->response($result, REST_Controller::HTTP_OK); } @@ -147,9 +143,9 @@ class Prestudent extends APIv1_Controller return true; } - private function _validateAddReihungstest($ddReihungstest = NULL) + private function _validateReihungstest($ddReihungstest = NULL) { - if (!isset($ddReihungstest['person_id']) || !isset($ddReihungstest['rt_id'])) + if (!isset($ddReihungstest["person_id"]) || !isset($ddReihungstest["rt_id"]) || !isset($ddReihungstest["studienplan_id"])) { return false; } diff --git a/application/controllers/api/v1/crm/Reihungstest.php b/application/controllers/api/v1/crm/Reihungstest.php index 514c7ee2a..64c41d159 100644 --- a/application/controllers/api/v1/crm/Reihungstest.php +++ b/application/controllers/api/v1/crm/Reihungstest.php @@ -12,7 +12,7 @@ */ // ------------------------------------------------------------------------ -if (!defined('BASEPATH')) exit('No direct script access allowed'); +if (!defined("BASEPATH")) exit("No direct script access allowed"); class Reihungstest extends APIv1_Controller { @@ -23,7 +23,9 @@ class Reihungstest extends APIv1_Controller { parent::__construct(); // Load model ReihungstestModel - $this->load->model('crm/reihungstest_model', 'ReihungstestModel'); + $this->load->model("crm/reihungstest_model", "ReihungstestModel"); + // Load library ReihungstestLib + $this->load->library("ReihungstestLib"); } /** @@ -31,7 +33,7 @@ class Reihungstest extends APIv1_Controller */ public function getReihungstest() { - $reihungstestID = $this->get('reihungstest_id'); + $reihungstestID = $this->get("reihungstest_id"); if (isset($reihungstestID)) { @@ -50,15 +52,15 @@ class Reihungstest extends APIv1_Controller */ public function getByStudiengangStudiensemester() { - $studiengang_kz = $this->get('studiengang_kz'); - $studiensemester_kurzbz = $this->get('studiensemester_kurzbz'); + $studiengang_kz = $this->get("studiengang_kz"); + $studiensemester_kurzbz = $this->get("studiensemester_kurzbz"); if (isset($studiengang_kz)) { - $parameters = array('studiengang_kz' => $studiengang_kz); + $parameters = array("studiengang_kz" => $studiengang_kz); if (isset($studiensemester_kurzbz)) { - $parameters['studiensemester_kurzbz'] = $studiensemester_kurzbz; + $parameters["studiensemester_kurzbz"] = $studiensemester_kurzbz; } $result = $this->ReihungstestModel->loadWhere($parameters); @@ -75,23 +77,11 @@ class Reihungstest extends APIv1_Controller */ public function getReihungstestByPersonID() { - $person_id = $this->get('person_id'); + $person_id = $this->get("person_id"); if (isset($person_id)) { - $result = $this->ReihungstestModel->addJoin('public.tbl_rt_person', 'reihungstest_id = rt_id'); - if ($result->error == EXIT_SUCCESS) - { - $result = $this->ReihungstestModel->addJoin('public.tbl_person', 'person_id'); - if ($result->error == EXIT_SUCCESS) - { - $result = $this->ReihungstestModel->addJoin('public.tbl_ort', 'tbl_ort.ort_kurzbz = tbl_rt_person.ort_kurzbz', 'LEFT'); - if ($result->error == EXIT_SUCCESS) - { - $result = $this->ReihungstestModel->loadWhere(array('person_id' => $person_id)); - } - } - } + $result = $this->reihungstestlib->getReihungstestByPersonID($person_id); $this->response($result, REST_Controller::HTTP_OK); } @@ -108,9 +98,9 @@ class Reihungstest extends APIv1_Controller { if ($this->_validate($this->post())) { - if (isset($this->post()['reihungstest_id'])) + if (isset($this->post()["reihungstest_id"])) { - $result = $this->ReihungstestModel->update($this->post()['reihungstest_id'], $this->post()); + $result = $this->ReihungstestModel->update($this->post()["reihungstest_id"], $this->post()); } else { diff --git a/application/core/FHC_Model.php b/application/core/FHC_Model.php index e02aa995b..0270f85df 100644 --- a/application/core/FHC_Model.php +++ b/application/core/FHC_Model.php @@ -1,6 +1,6 @@ lang->load('fhc_model'); - $this->lang->load('fhcomplete'); + $this->lang->load("fhc_model"); + $this->lang->load("fhcomplete"); - $this->load->helper('language'); - $this->load->helper('Message'); - $this->load->helper('fhcauth'); + $this->load->helper("language"); + $this->load->helper("Message"); + $this->load->helper("fhcauth"); - $this->load->library('FHC_DB_ACL'); + $this->load->library("FHC_DB_ACL"); - $this->acl = $this->config->item('fhc_acl'); + $this->acl = $this->config->item("fhc_acl"); } /** --------------------------------------------------------------- @@ -54,4 +54,18 @@ class FHC_Model extends CI_Model return null; } } + + protected function isEntitled($sourceName, $accessType, $languageMessageCode, $msgErrorCode) + { + $fhc_acl = $this->getBerechtigungKurzbz($sourceName); + + if (! $this->fhc_db_acl->isBerechtigt($fhc_acl, $accessType)) + { + return $this->_error(lang("fhc_" . $languageMessageCode)." -> " . $fhc_acl . ":" . $accessType, $msgErrorCode); + } + else + { + return true; + } + } } \ No newline at end of file diff --git a/application/libraries/ReihungstestLib.php b/application/libraries/ReihungstestLib.php new file mode 100644 index 000000000..f8ebdf3b9 --- /dev/null +++ b/application/libraries/ReihungstestLib.php @@ -0,0 +1,57 @@ +ci =& get_instance(); + + $this->ci->load->model("crm/RtPerson_model", "RtPersonModel"); + } + + /** + * @return void + */ + public function insertPersonReihungstest($ddReihungstest) + { + return $this->ci->RtPersonModel->insert($ddReihungstest); + } + + /** + * @return void + */ + public function updatePersonReihungstest($ddReihungstest) + { + $pksArray = array($ddReihungstest["person_id"], $ddReihungstest["rt_id"]); + + return $this->ci->RtPersonModel->update($pksArray, $ddReihungstest); + } + + /** + * @return void + */ + public function deletePersonReihungstest($ddReihungstest) + { + return $this->ci->RtPersonModel->delete($ddReihungstest["rt_person_id"], $ddReihungstest); + } + + /** + * @return void + */ + public function getReihungstestByPersonID($person_id) + { + $this->ci->ReihungstestModel->addJoin("public.tbl_rt_person", "reihungstest_id = rt_id"); + $this->ci->ReihungstestModel->addJoin("public.tbl_person", "person_id"); + $this->ci->ReihungstestModel->addJoin("public.tbl_ort", "tbl_ort.ort_kurzbz = tbl_rt_person.ort_kurzbz", "LEFT"); + + return $this->ci->ReihungstestModel->loadWhere(array("person_id" => $person_id)); + } +} \ No newline at end of file diff --git a/application/models/codex/Gemeinde_model.php b/application/models/codex/Gemeinde_model.php index e25d75416..c782346a0 100644 --- a/application/models/codex/Gemeinde_model.php +++ b/application/models/codex/Gemeinde_model.php @@ -1,14 +1,22 @@ dbTable = 'bis.tbl_gemeinde'; - $this->pk = 'gemeinde_id'; + $this->dbTable = "bis.tbl_gemeinde"; + $this->pk = "gemeinde_id"; } -} + + public function getGemeindeByPlz($plz) + { + $this->addSelect("DISTINCT ON (ortschaftsname) ortschaftsname, gemeinde_id, plz, name, ortschaftskennziffer, bulacode, bulabez, kennziffer"); + $this->addOrder("ortschaftsname"); + + return $this->loadWhere(array("plz" => $plz)); + } +} \ No newline at end of file diff --git a/application/models/crm/Dokumentstudiengang_model.php b/application/models/crm/Dokumentstudiengang_model.php index 4be973650..4781a5343 100644 --- a/application/models/crm/Dokumentstudiengang_model.php +++ b/application/models/crm/Dokumentstudiengang_model.php @@ -1,14 +1,37 @@ dbTable = 'public.tbl_dokumentstudiengang'; - $this->pk = array('studiengang_kz', 'dokument_kurzbz'); + $this->dbTable = "public.tbl_dokumentstudiengang"; + $this->pk = array("studiengang_kz", "dokument_kurzbz"); } -} + + public function getDokumentstudiengangByStudiengang_kz($studiengang_kz, $onlinebewerbung, $pflicht) + { + // Checks if the operation is permitted by the API caller + if (($chkRights = $this->isEntitled("public.tbl_dokument", "s", FHC_NORIGHT, FHC_MODEL_ERROR)) !== true) + return $chkRights; + + $this->addJoin("public.tbl_dokument", "dokument_kurzbz"); + + $parameterArray = array("studiengang_kz" => $studiengang_kz); + + if( isset($onlinebewerbung)) + { + $parameterArray["onlinebewerbung"] = $onlinebewerbung; + } + + if( isset($pflicht)) + { + $parameterArray["pflicht"] = $pflicht; + } + + return $this->loadWhere($parameterArray); + } +} \ No newline at end of file