diff --git a/application/controllers/api/frontend/v1/studstatus/Unterbrechung.php b/application/controllers/api/frontend/v1/studstatus/Unterbrechung.php index abf58cf4f..72d5dbccc 100644 --- a/application/controllers/api/frontend/v1/studstatus/Unterbrechung.php +++ b/application/controllers/api/frontend/v1/studstatus/Unterbrechung.php @@ -127,9 +127,9 @@ class Unterbrechung extends FHCAPI_Controller $this->form_validation->set_rules( 'datum_wiedereinstieg', 'Datum Wiedereinstieg', - 'required|callback_isValidDate|callback_isDateInFuture', + 'required|is_valid_date|callback_isDateInFuture', [ - 'isValidDate' => $this->p->t('ui', 'error_invalid_date'), + 'is_valid_date' => $this->p->t('ui', 'error_invalid_date'), 'isDateInFuture' => $this->p->t('ui', 'error_invalid_date') ] ); @@ -209,18 +209,9 @@ class Unterbrechung extends FHCAPI_Controller $this->terminateWithSuccess(getData($result)); } - public function isValidDate($date) - { - try { - new DateTime($date); - } catch (Exception $e) { - return false; - } - return true; - } - public function isDateInFuture($date) { return new DateTime() < new DateTime($date); } } + diff --git a/application/controllers/api/frontend/v1/stv/Student.php b/application/controllers/api/frontend/v1/stv/Student.php index 2721bbd6f..2fb354f0c 100644 --- a/application/controllers/api/frontend/v1/stv/Student.php +++ b/application/controllers/api/frontend/v1/stv/Student.php @@ -542,6 +542,7 @@ class Student extends FHCAPI_Controller $this->_validate(); + // TODO(chris): This should be in a library $this->load->model('crm/Student_model', 'StudentModel'); $this->load->model('crm/Prestudent_model', 'PrestudentModel'); $this->load->model('crm/Prestudentstatus_model', 'PrestudentstatusModel'); @@ -793,8 +794,8 @@ class Student extends FHCAPI_Controller $this->form_validation->set_rules('geschlecht', 'Geschlecht', 'callback_requiredIfNotPersonId', [ 'requiredIfNotPersonId' => $this->p->t('ui', 'error_fieldRequired', ['field' => $this->p->t('person', 'geschlecht')]) ]); - $this->form_validation->set_rules('gebdatum', 'Geburtsdatum', ['isValidDate', function($value) { return isValidDate($value); }], [ - 'isValidDate' => $this->p->t('ui', 'error_invalid_date') + $this->form_validation->set_rules('gebdatum', 'Geburtsdatum', 'is_valid_date', [ + 'is_valid_date' => $this->p->t('ui', 'error_invalid_date') ]); //$this->form_validation->set_rules('address[checked]', 'Address', 'required'); $this->form_validation->set_rules('address[plz]', 'PLZ', 'callback_requiredIfAddressFunc', [ diff --git a/application/helpers/hlp_common_helper.php b/application/helpers/hlp_common_helper.php index b13d9d44d..51d520a80 100644 --- a/application/helpers/hlp_common_helper.php +++ b/application/helpers/hlp_common_helper.php @@ -408,22 +408,6 @@ function findResource($path, $resource, $subdir = false, $extraDir = null) return null; } -/** - * check if String can be converted to a date - */ -function isValidDate($dateString) -{ - try - { - return (new DateTime($dateString)) !== false; - } - catch(Exception $e) - { - return false; - } -} - - // ------------------------------------------------------------------------ // PHP functions that don't exist in older versions // ------------------------------------------------------------------------ @@ -446,7 +430,8 @@ if (!function_exists('array_is_list')) { // ------------------------------------------------------------------------ /** - * check if string can be converted to a date + * Check if the provided parameter is a string containing a valid date + * NOTE: the name is in the "snake case" format because othewise the CI form validation _cannot_ use it */ function is_valid_date($dateString) {