- 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
This commit is contained in:
Paolo
2017-05-05 11:06:35 +02:00
parent b3c03aaa76
commit d7771da74e
3 changed files with 64 additions and 1 deletions
+14
View File
@@ -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));
}
+23 -1
View File
@@ -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;
}
}
@@ -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));
}
}