From 9ed193d9b8f55377ad4aba0db8d327712cf95e25 Mon Sep 17 00:00:00 2001 From: paolo Date: Wed, 27 Jul 2016 14:28:10 +0200 Subject: [PATCH] Moved methods getLastStatus from Prestudent to Prestudentstatus --- .../controllers/api/v1/crm/Prestudent.php | 21 --------- .../api/v1/crm/Prestudentstatus.php | 4 +- application/models/crm/Prestudent_model.php | 46 ------------------- .../models/crm/Prestudentstatus_model.php | 46 +++++++++++++++++++ 4 files changed, 47 insertions(+), 70 deletions(-) diff --git a/application/controllers/api/v1/crm/Prestudent.php b/application/controllers/api/v1/crm/Prestudent.php index e067a3894..e3498e9cd 100644 --- a/application/controllers/api/v1/crm/Prestudent.php +++ b/application/controllers/api/v1/crm/Prestudent.php @@ -63,27 +63,6 @@ class Prestudent extends APIv1_Controller $this->response(); } } - - /** - * @return void - */ - public function getLastStatus() - { - $prestudent_id = $this->get('prestudent_id'); - $studiensemester_kurzbz = $this->get('studiensemester_kurzbz'); - $status_kurzbz = $this->get('status_kurzbz'); - - if (isset($prestudent_id)) - { - $result = $this->PrestudentModel->getLastStatus($prestudent_id, $studiensemester_kurzbz, $status_kurzbz); - - $this->response($result, REST_Controller::HTTP_OK); - } - else - { - $this->response(); - } - } /** * @return void diff --git a/application/controllers/api/v1/crm/Prestudentstatus.php b/application/controllers/api/v1/crm/Prestudentstatus.php index 721e6ca8c..7d5bc84f9 100644 --- a/application/controllers/api/v1/crm/Prestudentstatus.php +++ b/application/controllers/api/v1/crm/Prestudentstatus.php @@ -24,8 +24,6 @@ class Prestudentstatus extends APIv1_Controller parent::__construct(); // Load model PrestudentstatusModel $this->load->model('crm/prestudentstatus_model', 'PrestudentstatusModel'); - - } /** @@ -110,4 +108,4 @@ class Prestudentstatus extends APIv1_Controller { return true; } -} +} \ No newline at end of file diff --git a/application/models/crm/Prestudent_model.php b/application/models/crm/Prestudent_model.php index c5896da64..9353444cd 100644 --- a/application/models/crm/Prestudent_model.php +++ b/application/models/crm/Prestudent_model.php @@ -11,50 +11,4 @@ class Prestudent_model extends DB_Model $this->dbTable = 'public.tbl_prestudent'; $this->pk = 'prestudent_id'; } - - /** - * @return void - */ - public function getLastStatus($prestudent_id, $studiensemester_kurzbz = '', $status_kurzbz = '') - { - // Checks if the operation is permitted by the API caller - if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz('public.tbl_prestudentstatus'), 's')) - return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->getBerechtigungKurzbz('public.tbl_prestudentstatus'), FHC_MODEL_ERROR); - - if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz('lehre.tbl_studienplan'), 's')) - return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->getBerechtigungKurzbz('lehre.tbl_studienplan'), FHC_MODEL_ERROR); - - if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz('public.tbl_status'), 's')) - return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->getBerechtigungKurzbz('public.tbl_status'), FHC_MODEL_ERROR); - - $query = "SELECT tbl_prestudentstatus.*, - bezeichnung AS studienplan_bezeichnung, - tbl_status.bezeichnung_mehrsprachig - FROM public.tbl_prestudentstatus LEFT JOIN lehre.tbl_studienplan USING (studienplan_id) - JOIN public.tbl_status USING (status_kurzbz) - WHERE tbl_status.status_kurzbz = tbl_prestudentstatus.status_kurzbz - AND prestudent_id = ?"; - - $parametersArray = array($prestudent_id); - - if ($studiensemester_kurzbz != '') - { - array_push($parametersArray, $studiensemester_kurzbz); - $query .= ' AND studiensemester_kurzbz = ?'; - } - if ($status_kurzbz != '') - { - array_push($parametersArray, $status_kurzbz); - $query .= ' AND status_kurzbz = ?'; - } - - $query .= ' ORDER BY datum DESC, insertamum DESC, ext_id DESC LIMIT 1'; - - $result = $this->db->query($query, $parametersArray); - - if (is_object($result)) - return $this->_success($result->result()); - else - return $this->_error($this->db->error(), FHC_DB_ERROR); - } } \ No newline at end of file diff --git a/application/models/crm/Prestudentstatus_model.php b/application/models/crm/Prestudentstatus_model.php index 8f6b57a41..6d960a07b 100644 --- a/application/models/crm/Prestudentstatus_model.php +++ b/application/models/crm/Prestudentstatus_model.php @@ -12,4 +12,50 @@ class Prestudentstatus_model extends DB_Model $this->pk = array('ausbildungssemester', 'studiensemester_kurzbz', 'status_kurzbz', 'prestudent_id'); $this->hasSequence = false; } + + /** + * @return void + */ + public function getLastStatus($prestudent_id, $studiensemester_kurzbz = '', $status_kurzbz = '') + { + // Checks if the operation is permitted by the API caller + if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz('public.tbl_prestudentstatus'), 's')) + return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->getBerechtigungKurzbz('public.tbl_prestudentstatus'), FHC_MODEL_ERROR); + + if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz('lehre.tbl_studienplan'), 's')) + return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->getBerechtigungKurzbz('lehre.tbl_studienplan'), FHC_MODEL_ERROR); + + if (! $this->fhc_db_acl->isBerechtigt($this->getBerechtigungKurzbz('public.tbl_status'), 's')) + return $this->_error(lang('fhc_'.FHC_NORIGHT).' -> '.$this->getBerechtigungKurzbz('public.tbl_status'), FHC_MODEL_ERROR); + + $query = "SELECT tbl_prestudentstatus.*, + bezeichnung AS studienplan_bezeichnung, + tbl_status.bezeichnung_mehrsprachig + FROM public.tbl_prestudentstatus LEFT JOIN lehre.tbl_studienplan USING (studienplan_id) + JOIN public.tbl_status USING (status_kurzbz) + WHERE tbl_status.status_kurzbz = tbl_prestudentstatus.status_kurzbz + AND prestudent_id = ?"; + + $parametersArray = array($prestudent_id); + + if ($studiensemester_kurzbz != '') + { + array_push($parametersArray, $studiensemester_kurzbz); + $query .= ' AND studiensemester_kurzbz = ?'; + } + if ($status_kurzbz != '') + { + array_push($parametersArray, $status_kurzbz); + $query .= ' AND status_kurzbz = ?'; + } + + $query .= ' ORDER BY datum DESC, insertamum DESC, ext_id DESC LIMIT 1'; + + $result = $this->db->query($query, $parametersArray); + + if (is_object($result)) + return $this->_success($result->result()); + else + return $this->_error($this->db->error(), FHC_DB_ERROR); + } } \ No newline at end of file