From ccb9daffaaaa47c4a8d381376541e6e479e202e8 Mon Sep 17 00:00:00 2001 From: bison-paolo Date: Wed, 12 Oct 2016 15:39:37 +0200 Subject: [PATCH] Automatically set as accepted all the uploaded documents - Added migration script 019_dokumentprestudent.php - Added method postSetAccepted to controller Dokumentprestudent - Added method setAccepted to model Dokumentprestudent_model --- .../api/v1/crm/Dokumentprestudent.php | 21 ++++++++++-- .../migrations/019_dokumentprestudent.php | 33 +++++++++++++++++++ .../models/crm/Dokumentprestudent_model.php | 31 +++++++++++++++-- 3 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 application/migrations/019_dokumentprestudent.php diff --git a/application/controllers/api/v1/crm/Dokumentprestudent.php b/application/controllers/api/v1/crm/Dokumentprestudent.php index 46aa8186c..f498e969a 100644 --- a/application/controllers/api/v1/crm/Dokumentprestudent.php +++ b/application/controllers/api/v1/crm/Dokumentprestudent.php @@ -24,8 +24,6 @@ class Dokumentprestudent extends APIv1_Controller parent::__construct(); // Load model DokumentprestudentModel $this->load->model('crm/dokumentprestudent_model', 'DokumentprestudentModel'); - - } /** @@ -72,7 +70,24 @@ class Dokumentprestudent extends APIv1_Controller } } - private function _validate($dokumentprestudent = NULL) + /** + * @return void + */ + public function postSetAccepted() + { + if (isset($this->post()['prestudent_id']) && isset($this->post()['studiengang_kz'])) + { + $result = $this->DokumentprestudentModel->setAccepted($this->post()['prestudent_id'], $this->post()['studiengang_kz']); + + $this->response($result, REST_Controller::HTTP_OK); + } + else + { + $this->response(); + } + } + + private function _validate($dokumentprestudent = null) { return true; } diff --git a/application/migrations/019_dokumentprestudent.php b/application/migrations/019_dokumentprestudent.php new file mode 100644 index 000000000..15d2f046d --- /dev/null +++ b/application/migrations/019_dokumentprestudent.php @@ -0,0 +1,33 @@ +startUP(); + + // Change mitarbeiter_uid could be null + $this->execQuery('ALTER TABLE public.tbl_dokumentprestudent ALTER mitarbeiter_uid DROP NOT NULL'); + + $this->endUP(); + } + + public function down() + { + $this->startDown(); + + // Change mitarbeiter_uid could not be null + $this->execQuery('ALTER TABLE public.tbl_dokumentprestudent ALTER mitarbeiter_uid SET NOT NULL'); + + $this->endDown(); + } +} \ No newline at end of file diff --git a/application/models/crm/Dokumentprestudent_model.php b/application/models/crm/Dokumentprestudent_model.php index e5cebe31f..3478e9cc9 100644 --- a/application/models/crm/Dokumentprestudent_model.php +++ b/application/models/crm/Dokumentprestudent_model.php @@ -1,7 +1,7 @@ dbTable = 'public.tbl_dokumentprestudent'; $this->pk = array('prestudent_id', 'dokument_kurzbz'); } -} + + public function setAccepted($prestudent_id, $studiengang_kz) + { + if (($chkRights = $this->isEntitled("public.tbl_dokumentprestudent", "i", FHC_NORIGHT, FHC_MODEL_ERROR)) !== true) + return $chkRights; + + $query = 'INSERT INTO public.tbl_dokumentprestudent (dokument_kurzbz, prestudent_id, insertamum) ( + SELECT ds.dokument_kurzbz, + p.prestudent_id, + NOW() AS insertamum + FROM (SELECT DISTINCT person_id, dokument_kurzbz FROM public.tbl_akte) a + INNER JOIN public.tbl_prestudent p USING(person_id) + INNER JOIN public.tbl_dokumentstudiengang ds USING(dokument_kurzbz, studiengang_kz) + LEFT JOIN public.tbl_dokumentprestudent dp USING(dokument_kurzbz, prestudent_id) + WHERE ds.onlinebewerbung IS TRUE + AND (dp.dokument_kurzbz IS NULL AND dp.prestudent_id IS NULL) + AND p.prestudent_id = ? + AND ds.studiengang_kz = ? + )'; + + $result = $this->db->query($query, array($prestudent_id, $studiengang_kz)); + + if ($result) + return $this->_success($result); + else + return $this->_error($this->db->error(), FHC_DB_ERROR); + } +} \ No newline at end of file