From 24d74dd332a23944208d15e862f082e6e8424137 Mon Sep 17 00:00:00 2001 From: cgfhtw Date: Wed, 7 Aug 2024 15:51:19 +0200 Subject: [PATCH] correct student check --- .../api/frontend/v1/stv/Status.php | 6 +-- .../libraries/PrestudentstatusCheckLib.php | 27 +++--------- application/models/crm/Student_model.php | 42 ------------------- 3 files changed, 9 insertions(+), 66 deletions(-) diff --git a/application/controllers/api/frontend/v1/stv/Status.php b/application/controllers/api/frontend/v1/stv/Status.php index 8a7588897..b14c38eb8 100644 --- a/application/controllers/api/frontend/v1/stv/Status.php +++ b/application/controllers/api/frontend/v1/stv/Status.php @@ -254,7 +254,7 @@ class Status extends FHCAPI_Controller ) return true; // Only test if new status is Student - $result = $this->prestudentstatuschecklib->checkIfExistingStudentRolle($prestudent_id); + $result = $this->prestudentstatuschecklib->checkIfExistingStudent($prestudent_id); return $this->getDataOrTerminateWithError($result); }], @@ -1059,7 +1059,7 @@ class Status extends FHCAPI_Controller if ($value != Prestudentstatus_model::STATUS_STUDENT) return true; // Only test if new status is Student - $result = $this->prestudentstatuschecklib->checkIfExistingStudentRolle($prestudent_id); + $result = $this->prestudentstatuschecklib->checkIfExistingStudent($prestudent_id); return $this->getDataOrTerminateWithError($result); }] @@ -1600,7 +1600,7 @@ class Status extends FHCAPI_Controller if ($value != Prestudentstatus_model::STATUS_STUDENT) return true; - $result = $this->prestudentstatuschecklib->checkIfExistingStudentRolle($prestudent_id); + $result = $this->prestudentstatuschecklib->checkIfExistingStudent($prestudent_id); return $this->getDataOrTerminateWithError($result); }] diff --git a/application/libraries/PrestudentstatusCheckLib.php b/application/libraries/PrestudentstatusCheckLib.php index b14542e8f..e3320de7e 100644 --- a/application/libraries/PrestudentstatusCheckLib.php +++ b/application/libraries/PrestudentstatusCheckLib.php @@ -127,20 +127,22 @@ class PrestudentstatusCheckLib } /** - * Checks if a student role already exists. + * Checks if a student already exists. * * @param integer $prestudent_id * * @return stdClass */ - public function checkIfExistingStudentRolle($prestudent_id) + public function checkIfExistingStudent($prestudent_id) { - $result = $this->_ci->StudentModel->checkIfExistingStudentRolle($prestudent_id); + $result = $this->_ci->StudentModel->loadWhere([ + 'prestudent_id' => $prestudent_id + ]); if (isError($result)) return $result; - return success(getData($result) != '0'); + return success(hasData($result)); } /** @@ -229,23 +231,6 @@ class PrestudentstatusCheckLib return success(hasData($result)); } - /** - * Checks if is the first student Status - * - * @param integer $prestudent_id - * - * @return stdClass - */ - public function checkIfIsErsterStudent($prestudent_id) - { - $result = $this->_ci->StudentModel->checkIfExistingStudentRolle($prestudent_id); - - if (isError($result)) - return $result; - - return success(getData($result) == '0'); - } - /** * Check if Bismeldestichtag erreicht * diff --git a/application/models/crm/Student_model.php b/application/models/crm/Student_model.php index 023751f7c..fec72cbfc 100644 --- a/application/models/crm/Student_model.php +++ b/application/models/crm/Student_model.php @@ -230,46 +230,4 @@ class Student_model extends DB_Model { return $student_uid . '@' . DOMAIN; } - - /** - * Check if StudentenRolle already exists - * @param integer $prestudent_id - * @return 0 if not exists, count(rollen) if it does - * Copy from studentDBDML.php - */ - public function checkIfExistingStudentRolle($prestudent_id) - { - $qry = "SELECT - count(*) as anzahl - FROM - public.tbl_student - WHERE - prestudent_id = ? "; - - $result = $this->execQuery($qry, array($prestudent_id)); - - if (isError($result)) - { - return error($result); - } - else - { - $resultObject = current(getData($result)); - - if (property_exists($resultObject, 'anzahl')) { - $resultValue = (int)$resultObject->anzahl; - - if ($resultValue > 0) - { - return success($resultValue, $resultValue . " vorhandene Rollen"); - } - else - { - return success("0"); - } - } else { - return error("StudentModel: Error During Check if Existing Student Rolle."); - } - } - } }