From 9cce095e9b35e35734a865ab1577beb385ca2c1a Mon Sep 17 00:00:00 2001 From: paolo Date: Fri, 1 Jul 2016 10:50:37 +0200 Subject: [PATCH] - Added permissions for table public.tbl_rt_person - Added method postAddReihungstest to controller Prestudent - Added method getReihungstestByPersonID to controller Reihungstest - Fixed tables structure in the migration script 011_reihungstest.php - Added model RtPerson_model --- application/config/fhcomplete.php | 1 + .../controllers/api/v1/crm/Prestudent.php | 46 ++++++++++++++++++- .../controllers/api/v1/crm/Reihungstest.php | 33 ++++++++++++- application/migrations/011_reihungstest.php | 6 +-- application/models/crm/RtPerson_model.php | 15 ++++++ 5 files changed, 94 insertions(+), 7 deletions(-) create mode 100644 application/models/crm/RtPerson_model.php diff --git a/application/config/fhcomplete.php b/application/config/fhcomplete.php index 00ed49d65..992737b60 100755 --- a/application/config/fhcomplete.php +++ b/application/config/fhcomplete.php @@ -191,6 +191,7 @@ $config['fhc_acl'] = array 'public.tbl_variable' => 'basis/variable', 'public.tbl_vorlage' => 'system/vorlage', 'public.tbl_vorlagestudiengang' => 'system/vorlagestudiengang', + 'public.tbl_rt_person' => 'basis/person', 'public.vw_studiensemester' => 'basis/vw_studiensemester', 'system.tbl_app' => 'system/app', 'system.tbl_appdaten' => 'system/appdaten', diff --git a/application/controllers/api/v1/crm/Prestudent.php b/application/controllers/api/v1/crm/Prestudent.php index bf1ada78c..3a3412db0 100644 --- a/application/controllers/api/v1/crm/Prestudent.php +++ b/application/controllers/api/v1/crm/Prestudent.php @@ -24,8 +24,6 @@ class Prestudent extends APIv1_Controller parent::__construct(); // Load model PrestudentModel $this->load->model('crm/prestudent_model', 'PrestudentModel'); - - } /** @@ -111,8 +109,52 @@ class Prestudent extends APIv1_Controller } } + /** + * @return void + */ + public function postAddReihungstest() + { + $ddReihungstest = $this->_parseData($this->post()); + + if ($this->_validateAddReihungstest($ddReihungstest)) + { + $this->load->model('crm/RtPerson_model', 'RtPersonModel'); + + if(isset($ddReihungstest['new']) && $ddReihungstest['new'] === true) + { + // Remove new parameter to avoid DB insert errors + unset($ddReihungstest['new']); + + $result = $this->RtPersonModel->insert($ddReihungstest); + } + else + { + $pksArray = array($ddReihungstest['person_id'], $ddReihungstest['rt_id']); + + $result = $this->RtPersonModel->update($pksArray, $ddReihungstest); + } + + $this->response($result, REST_Controller::HTTP_OK); + } + else + { + $this->response(); + } + } + private function _validate($prestudent = NULL) { return true; } + + private function _validateAddReihungstest($ddReihungstest = NULL) + { + if (!isset($ddReihungstest['person_id']) || !isset($ddReihungstest['rt_id']) || + !isset($ddReihungstest['ort_kurzbz'])) + { + return false; + } + + return true; + } } \ No newline at end of file diff --git a/application/controllers/api/v1/crm/Reihungstest.php b/application/controllers/api/v1/crm/Reihungstest.php index f04ab7119..3ab4575ef 100644 --- a/application/controllers/api/v1/crm/Reihungstest.php +++ b/application/controllers/api/v1/crm/Reihungstest.php @@ -24,8 +24,6 @@ class Reihungstest extends APIv1_Controller parent::__construct(); // Load model ReihungstestModel $this->load->model('crm/reihungstest_model', 'ReihungstestModel'); - - } /** @@ -71,6 +69,37 @@ class Reihungstest extends APIv1_Controller $this->response(); } } + + /** + * @return void + */ + public function getReihungstestByPersonID() + { + $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'); + if ($result->error == EXIT_SUCCESS) + { + $result = $this->ReihungstestModel->loadWhere(array('person_id' => $person_id)); + } + } + } + + $this->response($result, REST_Controller::HTTP_OK); + } + else + { + $this->response(); + } + } /** * @return void diff --git a/application/migrations/011_reihungstest.php b/application/migrations/011_reihungstest.php index 66e00d883..237d1bc28 100644 --- a/application/migrations/011_reihungstest.php +++ b/application/migrations/011_reihungstest.php @@ -42,7 +42,7 @@ class Migration_Reihungstest extends CI_Migration { $query= "CREATE TABLE public.tbl_rt_studienplan ( reihungstest_id integer, stundenplan_id integer, - PRIMARY KEY (reihungstest_id, stundenplan_id), + CONSTRAINT pk_tbl_rt_studienplan PRIMARY KEY (reihungstest_id, stundenplan_id), CONSTRAINT fk_rt_studienplan_reihungstest_id FOREIGN KEY (reihungstest_id) REFERENCES public.tbl_reihungstest(reihungstest_id) ON UPDATE CASCADE ON DELETE RESTRICT, CONSTRAINT fk_rt_studienplan_stundenplan_id FOREIGN KEY (stundenplan_id) REFERENCES lehre.tbl_stundenplan(stundenplan_id) ON UPDATE CASCADE ON DELETE RESTRICT ); @@ -62,9 +62,9 @@ class Migration_Reihungstest extends CI_Migration { $query= "CREATE TABLE public.tbl_rt_person ( person_id integer, rt_id integer, - anmeldedatum date DEFAULT NOW(), + anmeldedatum date, teilgenommen boolean DEFAULT FALSE, - ort_kurzbz varchar(16), + ort_kurzbz varchar(16) NOT NULL, CONSTRAINT pk_tbl_rt_person PRIMARY KEY (person_id, rt_id), CONSTRAINT fk_rt_person_ort_kurzbz FOREIGN KEY (ort_kurzbz) REFERENCES public.tbl_ort(ort_kurzbz) ON UPDATE CASCADE ON DELETE RESTRICT, CONSTRAINT fk_rt_person_reihungstest_id FOREIGN KEY (rt_id) REFERENCES public.tbl_reihungstest(reihungstest_id) ON UPDATE CASCADE ON DELETE RESTRICT diff --git a/application/models/crm/RtPerson_model.php b/application/models/crm/RtPerson_model.php new file mode 100644 index 000000000..dc9b7e18f --- /dev/null +++ b/application/models/crm/RtPerson_model.php @@ -0,0 +1,15 @@ +dbTable = 'public.tbl_rt_person'; + $this->pk = array('person_id', 'rt_id'); + $this->hasSequence = false; + } +} \ No newline at end of file