From 219113bc7320c5c70a58e266977e961ef917b3cb Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Mon, 6 Nov 2023 14:25:38 +0100 Subject: [PATCH] InteressentIn anlegen: check + getGeschlechter return value --- .../controllers/components/stv/Student.php | 48 +++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/application/controllers/components/stv/Student.php b/application/controllers/components/stv/Student.php index 0acc37c64..823b22b50 100644 --- a/application/controllers/components/stv/Student.php +++ b/application/controllers/components/stv/Student.php @@ -100,9 +100,9 @@ class Student extends FHC_Controller $result = $this->GeschlechtModel->load(); if (isError($result)) { $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); - $this->outputJson(getError($result)); + $this->outputJson($result); } else { - $this->outputJson(getData($result) ?: []); + $this->outputJsonSuccess(getData($result) ?: []); } } @@ -254,6 +254,49 @@ class Student extends FHC_Controller $this->outputJsonSuccess(true); } + public function check() + { + $this->load->library('form_validation'); + + $this->form_validation->set_rules('gebdatum', 'Geburtsdatum', 'callback_isValidDate', [ + 'isValidDate' => $this->p->t('ui', 'error_invalid_date') + ]); + + if ($this->form_validation->run() == false) { + $this->output->set_status_header(REST_Controller::HTTP_BAD_REQUEST); + return $this->outputJsonError($this->form_validation->error_array()); + } + + $vorname = $this->input->post('vorname'); + $nachname = $this->input->post('nachname'); + $gebdatum = $this->input->post('gebdatum'); + + if (!$vorname && !$nachname && !$gebdatum) { + return $this->outputJsonSuccess([]); + } + + $this->load->model('person/Person_model', 'PersonModel'); + + if ($gebdatum) + $this->PersonModel->db->where('gebdatum', (new DateTime($gebdatum))->format('Y-m-d')); + if ($vorname && $nachname) { + $this->PersonModel->db->or_group_start(); + $this->PersonModel->db->where('LOWER(nachname)', 'LOWER(' . $this->PersonModel->db->escape($nachname) . ')', false); + $this->PersonModel->db->where('LOWER(vorname)', 'LOWER(' . $this->PersonModel->db->escape($vorname) . ')', false); + $this->PersonModel->db->group_end(); + } elseif ($nachname) { + $this->PersonModel->db->or_where('LOWER(nachname)', 'LOWER(' . $this->PersonModel->escape($nachname) . ')', false); + } + + $result = $this->PersonModel->load(); + + if (isError($result)) { + $this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR); + } + + $this->outputJson($result); + } + public function isValidDate($date) { try { @@ -263,5 +306,4 @@ class Student extends FHC_Controller } return true; } - }