From 40f51d035f97382dd9bef46c2430a94f78b590cf Mon Sep 17 00:00:00 2001 From: bison-paolo Date: Thu, 13 Oct 2016 14:35:39 +0200 Subject: [PATCH] - Added method postSetAcceptedDocuments to controller Dokumentprestudent - Added method setAcceptedDocuments to model Dokumentprestudent_model --- .../api/v1/crm/Dokumentprestudent.php | 17 +++++ .../models/crm/Dokumentprestudent_model.php | 66 ++++++++++++++----- 2 files changed, 68 insertions(+), 15 deletions(-) diff --git a/application/controllers/api/v1/crm/Dokumentprestudent.php b/application/controllers/api/v1/crm/Dokumentprestudent.php index f498e969a..9b7977ab0 100644 --- a/application/controllers/api/v1/crm/Dokumentprestudent.php +++ b/application/controllers/api/v1/crm/Dokumentprestudent.php @@ -87,6 +87,23 @@ class Dokumentprestudent extends APIv1_Controller } } + /** + * @return void + */ + public function postSetAcceptedDocuments() + { + if (isset($this->post()['prestudent_id']) && is_array($this->post()['dokument_kurzbz'])) + { + $result = $this->DokumentprestudentModel->setAcceptedDocuments($this->post()['prestudent_id'], $this->post()['dokument_kurzbz']); + + $this->response($result, REST_Controller::HTTP_OK); + } + else + { + $this->response(); + } + } + private function _validate($dokumentprestudent = null) { return true; diff --git a/application/models/crm/Dokumentprestudent_model.php b/application/models/crm/Dokumentprestudent_model.php index 3478e9cc9..9254c1e72 100644 --- a/application/models/crm/Dokumentprestudent_model.php +++ b/application/models/crm/Dokumentprestudent_model.php @@ -14,24 +14,60 @@ class Dokumentprestudent_model extends DB_Model public function setAccepted($prestudent_id, $studiengang_kz) { - if (($chkRights = $this->isEntitled("public.tbl_dokumentprestudent", "i", FHC_NORIGHT, FHC_MODEL_ERROR)) !== true) + 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 = null; - $result = $this->db->query($query, array($prestudent_id, $studiengang_kz)); + if (is_numeric($prestudent_id) && is_numeric($studiengang_kz)) + { + $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); + } + + public function setAcceptedDocuments($prestudent_id, $dokument_kurzbz) + { + if (($chkRights = $this->isEntitled('public.tbl_dokumentprestudent', 'i', FHC_NORIGHT, FHC_MODEL_ERROR)) !== true) + return $chkRights; + + $result = null; + + if (is_numeric($prestudent_id) && is_array($dokument_kurzbz) && count($dokument_kurzbz) > 0) + { + $query = 'INSERT INTO public.tbl_dokumentprestudent (dokument_kurzbz, prestudent_id, insertamum) ( + SELECT d.dokument_kurzbz, + ? AS prestudent_id, + NOW() AS insertamum + FROM public.tbl_dokument d + WHERE d.dokument_kurzbz IN ? + AND d.dokument_kurzbz NOT IN ( + SELECT dokument_kurzbz + FROM public.tbl_dokumentprestudent + WHERE prestudent_id = ? + ) + )'; + + $result = $this->db->query($query, array($prestudent_id, $dokument_kurzbz, $prestudent_id)); + } if ($result) return $this->_success($result);