From d7771da74e34673d37ecbf245c289e3dc55200f2 Mon Sep 17 00:00:00 2001 From: Paolo Date: Fri, 5 May 2017 11:06:35 +0200 Subject: [PATCH] - Added utility function var_dump_to_error_log to the fhc_helper - Added method checkAvailability to model Reihungstest_model - Added method checkAvailability to library ReihungstestLib - Added a validation for the test in the method insertPersonReihungstest of the library ReihungstestLib --- application/helpers/fhc_helper.php | 14 ++++++++++ application/libraries/ReihungstestLib.php | 24 ++++++++++++++++- application/models/crm/Reihungstest_model.php | 27 +++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/application/helpers/fhc_helper.php b/application/helpers/fhc_helper.php index b76e2041d..c2832d55d 100644 --- a/application/helpers/fhc_helper.php +++ b/application/helpers/fhc_helper.php @@ -62,3 +62,17 @@ function generateToken($length = 64) $token .= $characters[mt_rand(0, $charactersLength)]; return $token; } + +/** + * var_dump_to_error_log() + * Gets the output of the var_dump function and print it out + * via the error log. It also removes the end line characters + */ +function var_dump_to_error_log($parameter) +{ + ob_start(); + var_dump($parameter); + $ob_get_contents = ob_get_contents(); + ob_end_clean(); + error_log(str_replace("\n", '', $ob_get_contents)); +} \ No newline at end of file diff --git a/application/libraries/ReihungstestLib.php b/application/libraries/ReihungstestLib.php index 6d6960240..4030e50c3 100644 --- a/application/libraries/ReihungstestLib.php +++ b/application/libraries/ReihungstestLib.php @@ -23,7 +23,14 @@ class ReihungstestLib */ public function insertPersonReihungstest($ddReihungstest) { - return $this->ci->RtPersonModel->insert($ddReihungstest); + if (isset($ddReihungstest['rt_id']) && $this->checkAvailability($ddReihungstest['rt_id'])) + { + return $this->ci->RtPersonModel->insert($ddReihungstest); + } + else + { + return error('This test is not more available'); + } } /** @@ -62,4 +69,19 @@ class ReihungstestLib return $this->ci->ReihungstestModel->loadWhere($parametersArray); } + + /** + * It checks if the test is available + */ + public function checkAvailability($reihungstest_id) + { + $result = $this->ci->ReihungstestModel->checkAvailability($reihungstest_id); + + if (hasData($result)) + { + return true; + } + + return false; + } } \ No newline at end of file diff --git a/application/models/crm/Reihungstest_model.php b/application/models/crm/Reihungstest_model.php index 46e8702cc..a8d048463 100644 --- a/application/models/crm/Reihungstest_model.php +++ b/application/models/crm/Reihungstest_model.php @@ -11,4 +11,31 @@ class Reihungstest_model extends DB_Model $this->dbTable = 'public.tbl_reihungstest'; $this->pk = 'reihungstest_id'; } + + /** + * Gets a test from a test id only if it is available + */ + public function checkAvailability($reihungstest_id) + { + $query = 'SELECT public.tbl_reihungstest.* + FROM public.tbl_reihungstest LEFT JOIN public.tbl_rt_studienplan USING(reihungstest_id) + WHERE tbl_reihungstest.oeffentlich = TRUE + AND tbl_reihungstest.datum > NOW() + AND tbl_reihungstest.anmeldefrist >= NOW() + AND COALESCE ( + tbl_reihungstest.max_teilnehmer, + ( + SELECT SUM(arbeitsplaetze) + FROM public.tbl_ort JOIN public.tbl_rt_ort USING(ort_kurzbz) + WHERE rt_id = tbl_reihungstest.reihungstest_id + ) + ) - ( + SELECT COUNT(*) + FROM public.tbl_rt_person + WHERE rt_id = tbl_reihungstest.reihungstest_id + ) > 0 + AND reihungstest_id = ?'; + + return $this->execQuery($query, array($reihungstest_id)); + } } \ No newline at end of file