From e871e30a0967deeb347d01bf56cd49be2e1b61a9 Mon Sep 17 00:00:00 2001 From: adisposkofh Date: Tue, 11 Aug 2026 15:00:18 +0200 Subject: [PATCH] removed direct use of retval in all coodle-related models --- .../api/frontend/v1/coodle/CoodleSurvey.php | 100 ++++++++++++------ .../CoodleSurveyExternalParticipant_model.php | 17 +-- .../CoodleSurveyParticipant_model.php | 10 +- .../ressource/CoodleSurveyTimeslot_model.php | 8 +- .../models/ressource/CoodleSurvey_model.php | 4 +- 5 files changed, 86 insertions(+), 53 deletions(-) diff --git a/application/controllers/api/frontend/v1/coodle/CoodleSurvey.php b/application/controllers/api/frontend/v1/coodle/CoodleSurvey.php index 24e5d1009..ab7fb9d7d 100644 --- a/application/controllers/api/frontend/v1/coodle/CoodleSurvey.php +++ b/application/controllers/api/frontend/v1/coodle/CoodleSurvey.php @@ -79,15 +79,17 @@ class CoodleSurvey extends FHCAPI_Controller $surveyId = $this->input->post("surveyId"); $surveyResult = $this->CoodleSurveyModel->getSurvey($surveyId); $survey = $this->getDataOrTerminateWithError($surveyResult); - $survey = count($survey) ? $survey[0] : null; + $survey = $survey && count($survey) ? $survey[0] : null; if (!$survey) { $this->terminateWithError("Survey not found!"); } - $timeslots = $this->CoodleSurveyTimeslotModel->getTimeslots($surveyId); + $timeslotsResult = $this->CoodleSurveyTimeslotModel->getTimeslots($surveyId); + $timeslots = $this->getDataOrTerminateWithError($timeslotsResult); $survey->timeslots = $timeslots; - $participants = $this->CoodleSurveyParticipantModel->getParticipants($surveyId); + $participantsResult = $this->CoodleSurveyParticipantModel->getParticipants($surveyId); + $participants = $this->getDataOrTerminateWithError($participantsResult); $participants = $this->parseParticipantSelections($participants); $authUserUID = getAuthUID(); @@ -105,7 +107,8 @@ class CoodleSurvey extends FHCAPI_Controller $this->terminateWithError("You are not authorized to view this survey!"); } - $externalParticipants = $this->CoodleSurveyExternalParticipantModel->getExternalParticipants($surveyId); + $externalParticipantsResult = $this->CoodleSurveyExternalParticipantModel->getExternalParticipants($surveyId); + $externalParticipants = $this->getDataOrTerminateWithError($externalParticipantsResult); $externalParticipants = $this->parseParticipantSelections($externalParticipants); $survey->participants = $participants; @@ -134,14 +137,17 @@ class CoodleSurvey extends FHCAPI_Controller $survey = $validatedAccessKey["survey"]; $externalParticipant = $validatedAccessKey["externalParticipant"]; - $timeslots = $this->CoodleSurveyTimeslotModel->getTimeslots($survey->id); + $timeslotsResult = $this->CoodleSurveyTimeslotModel->getTimeslots($survey->id); + $timeslots = $this->getDataOrTerminateWithError($timeslotsResult); $survey->timeslots = $timeslots; - $participants = $this->CoodleSurveyParticipantModel->getParticipants($survey->id); + $participantsResult = $this->CoodleSurveyParticipantModel->getParticipants($survey->id); + $participants = $this->getDataOrTerminateWithError($participantsResult); $participants = $this->parseParticipantSelections($participants); $survey->participants = $participants; - $externalParticipants = $this->CoodleSurveyExternalParticipantModel->getExternalParticipants($survey->id); + $externalParticipantsResult = $this->CoodleSurveyExternalParticipantModel->getExternalParticipants($survey->id); + $externalParticipants = $this->getDataOrTerminateWithError($externalParticipantsResult); $externalParticipants = $this->parseParticipantSelections($externalParticipants); $survey->external_participants = $externalParticipants; @@ -219,7 +225,8 @@ class CoodleSurvey extends FHCAPI_Controller $surveyId = $this->getDataOrTerminateWithError($this->CoodleSurveyModel->createSurvey($surveyData, getAuthUID())); $this->CoodleSurveyTimeslotModel->updateTimeslots($surveyId, $surveyData["timeslots"]); - $timeslots = $this->CoodleSurveyTimeslotModel->getTimeslots($surveyId); + $timeslotsResult = $this->CoodleSurveyTimeslotModel->getTimeslots($surveyId); + $timeslots = $this->getDataOrTerminateWithError($timeslotsResult); $this->CoodleSurveyParticipantModel->updateParticipants($surveyId, $surveyData["participants"], $timeslots); $this->CoodleSurveyExternalParticipantModel->updateExternalParticipants($surveyId, $surveyData["externalParticipants"], $timeslots); @@ -252,7 +259,7 @@ class CoodleSurvey extends FHCAPI_Controller $surveyResult = $this->CoodleSurveyModel->getSurvey($surveyId); $survey = $this->getDataOrTerminateWithError($surveyResult); - $survey = count($survey) ? $survey[0] : null; + $survey = $survey && count($survey) ? $survey[0] : null; if (!$survey) $this->terminateWithError("Survey not found!"); @@ -261,7 +268,8 @@ class CoodleSurvey extends FHCAPI_Controller $this->CoodleSurveyModel->updateSurvey($surveyId, $surveyData); $this->CoodleSurveyTimeslotModel->updateTimeslots($surveyId, $surveyData["timeslots"]); - $timeslots = $this->CoodleSurveyTimeslotModel->getTimeslots($surveyId); + $timeslotsResult = $this->CoodleSurveyTimeslotModel->getTimeslots($surveyId); + $timeslots = $this->getDataOrTerminateWithError($timeslotsResult); $this->CoodleSurveyParticipantModel->updateParticipants($surveyId, $surveyData["participants"], $timeslots); $this->CoodleSurveyExternalParticipantModel->updateExternalParticipants($surveyId, $surveyData["externalParticipants"], $timeslots); @@ -292,7 +300,7 @@ class CoodleSurvey extends FHCAPI_Controller $surveyResult = $this->CoodleSurveyModel->getSurvey($surveyId); $survey = $this->getDataOrTerminateWithError($surveyResult); - $survey = count($survey) ? $survey[0] : null; + $survey = $survey && count($survey) ? $survey[0] : null; if (!$survey) { $this->terminateWithError("Survey not found!"); } @@ -301,7 +309,8 @@ class CoodleSurvey extends FHCAPI_Controller $this->terminateWithError("You can no longer vote in this survey!"); } - $participants = $this->CoodleSurveyParticipantModel->getParticipants($surveyId); + $participantsResult = $this->CoodleSurveyParticipantModel->getParticipants($surveyId); + $participants = $this->getDataOrTerminateWithError($participantsResult); $participantUids = array_map( function ($participant) { return $participant->uid; @@ -313,7 +322,8 @@ class CoodleSurvey extends FHCAPI_Controller } if ($selection && count($selection)) { - $timeslots = $this->CoodleSurveyTimeslotModel->getTimeslots($surveyId); + $timeslotsResult = $this->CoodleSurveyTimeslotModel->getTimeslots($surveyId); + $timeslots = $this->getDataOrTerminateWithError($timeslotsResult); $timeslotIds = array_map( function ($timeslot) { return $timeslot->id; @@ -352,7 +362,8 @@ class CoodleSurvey extends FHCAPI_Controller } if ($selection && count($selection)) { - $timeslots = $this->CoodleSurveyTimeslotModel->getTimeslots($survey->id); + $timeslotsResult = $this->CoodleSurveyTimeslotModel->getTimeslots($survey->id); + $timeslots = $this->getDataOrTerminateWithError($timeslotsResult); $timeslotIds = array_map( function ($timeslot) { return $timeslot->id; @@ -378,7 +389,7 @@ class CoodleSurvey extends FHCAPI_Controller $surveyId = $this->input->post("surveyId"); $surveyResult = $this->CoodleSurveyModel->getSurvey($surveyId); $survey = $this->getDataOrTerminateWithError($surveyResult); - $survey = count($survey) ? $survey[0] : null; + $survey = $survey && count($survey) ? $survey[0] : null; if (!$survey) { $this->terminateWithError("Survey not found!"); @@ -402,7 +413,7 @@ class CoodleSurvey extends FHCAPI_Controller $surveyResult = $this->CoodleSurveyModel->getSurvey($surveyId); $survey = $this->getDataOrTerminateWithError($surveyResult); - $survey = count($survey) ? $survey[0] : null; + $survey = $survey && count($survey) ? $survey[0] : null; if (!$survey) { $this->terminateWithError("Survey not found!"); } else if ($survey->creator_uid !== getAuthUID()) { @@ -415,7 +426,9 @@ class CoodleSurvey extends FHCAPI_Controller $selectedTimeslot = null; if ($selectedTimeslotId) { - $selectedTimeslot = $this->CoodleSurveyTimeslotModel->getTimeslot($selectedTimeslotId); + $selectedTimeslotResult = $this->CoodleSurveyTimeslotModel->getTimeslot($survey->selected_timeslot_id); + $selectedTimeslot = $this->getDataOrTerminateWithError($selectedTimeslotResult); + $selectedTimeslot = $selectedTimeslot && (count($selectedTimeslot)) ? $selectedTimeslot[0] : null; if (!$selectedTimeslot) { $this->terminateWithError("Selected timeslot not found!"); } else if ($selectedTimeslot->survey_id !== $surveyId) { @@ -449,7 +462,7 @@ class CoodleSurvey extends FHCAPI_Controller $surveyId = $this->input->post("surveyId"); $surveyResult = $this->CoodleSurveyModel->getSurvey($surveyId); $survey = $this->getDataOrTerminateWithError($surveyResult); - $survey = count($survey) ? $survey[0] : null; + $survey = $survey && count($survey) ? $survey[0] : null; if (!$survey) { $this->terminateWithError("Survey not found!"); } else if ($survey->creator_uid !== getAuthUID()) { @@ -507,7 +520,7 @@ class CoodleSurvey extends FHCAPI_Controller $surveyResult = $this->CoodleSurveyModel->getSurvey($surveyId); $survey = $this->getDataOrTerminateWithError($surveyResult); - $survey = count($survey) ? $survey[0] : null; + $survey = $survey && count($survey) ? $survey[0] : null; if (!$survey) $this->terminateWithError("Survey not found!"); @@ -713,7 +726,8 @@ class CoodleSurvey extends FHCAPI_Controller private function generateCoodleIcal($uid, $shouldIncludeIdentifyingInformation) { - $activeParticipantEntries = $this->CoodleSurveyParticipantModel->getActiveParticipantEntriesByUid($uid); + $activeParticipantEntriesResult = $this->CoodleSurveyParticipantModel->getActiveParticipantEntriesByUid($uid); + $activeParticipantEntries = $this->getDataOrTerminateWithError($activeParticipantEntriesResult); $selectedTimeslotIds = []; foreach ($activeParticipantEntries as $participantEntry) { if ($participantEntry->selection === null) @@ -726,13 +740,15 @@ class CoodleSurvey extends FHCAPI_Controller $localTimezone = new DateTimeZone("Europe/Vienna"); $utcTimezone = new DateTimeZone("UTC"); foreach ($selectedTimeslotIds as $timeslotId) { - $timeslot = $this->CoodleSurveyTimeslotModel->getTimeslot($timeslotId); + $timeslotResult = $this->CoodleSurveyTimeslotModel->getTimeslot($timeslotId); + $timeslot = $this->getDataOrTerminateWithError($timeslotResult); + $timeslot = $timeslot && (count($timeslot)) ? $timeslot[0] : null; if (!$timeslot) continue; $surveyResult = $this->CoodleSurveyModel->getSurvey($timeslot->survey_id); $survey = $this->getDataOrTerminateWithError($surveyResult); - $survey = count($survey) ? $survey[0] : null; + $survey = $survey && count($survey) ? $survey[0] : null; if (!$survey) continue; @@ -814,8 +830,10 @@ class CoodleSurvey extends FHCAPI_Controller $surveyResult = $this->CoodleSurveyModel->getSurvey($surveyId); $survey = $this->getDataOrTerminateWithError($surveyResult); - $survey = count($survey) ? $survey[0] : null; - $externalParticipant = $this->CoodleSurveyExternalParticipantModel->getExternalParticipantByAccessKey($surveyId, $accessKey); + $survey = $survey && count($survey) ? $survey[0] : null; + $externalParticipantResult = $this->CoodleSurveyExternalParticipantModel->getExternalParticipantByAccessKey($surveyId, $accessKey); + $externalParticipant = $this->getDataOrTerminateWithError($externalParticipantResult); + $externalParticipant = $externalParticipant && count($externalParticipant) ? $externalParticipant[0] : null; if (!$survey || !$externalParticipant) return null; @@ -828,8 +846,10 @@ class CoodleSurvey extends FHCAPI_Controller private function sendSurveyCreationEmail($survey) { - $participants = $this->CoodleSurveyParticipantModel->getParticipants($survey->id); - $externalParticipants = $this->CoodleSurveyExternalParticipantModel->getExternalParticipants($survey->id, true); + $participantsResult = $this->CoodleSurveyParticipantModel->getParticipants($survey->id); + $participants = $this->getDataOrTerminateWithError($participantsResult); + $externalParticipantsResult = $this->CoodleSurveyExternalParticipantModel->getExternalParticipants($survey->id, true); + $externalParticipants = $this->getDataOrTerminateWithError($externalParticipantsResult); $creatorFullName = getData($this->PersonModel->getFullName($survey->creator_uid)); foreach ($participants as $participant) { @@ -864,8 +884,10 @@ class CoodleSurvey extends FHCAPI_Controller private function sendSurveyUpdateEmail($survey) { - $participants = $this->CoodleSurveyParticipantModel->getParticipants($survey->id); - $externalParticipants = $this->CoodleSurveyExternalParticipantModel->getExternalParticipants($survey->id, true); + $participantsResult = $this->CoodleSurveyParticipantModel->getParticipants($survey->id); + $participants = $this->getDataOrTerminateWithError($participantsResult); + $externalParticipantsResult = $this->CoodleSurveyExternalParticipantModel->getExternalParticipants($survey->id, true); + $externalParticipants = $this->getDataOrTerminateWithError($externalParticipantsResult); $creatorFullName = getData($this->PersonModel->getFullName($survey->creator_uid)); foreach ($participants as $participant) { @@ -900,7 +922,8 @@ class CoodleSurvey extends FHCAPI_Controller private function sendSurveyReminderEmail($survey) { - $participants = $this->CoodleSurveyParticipantModel->getParticipants($survey->id); + $participantsResult = $this->CoodleSurveyParticipantModel->getParticipants($survey->id); + $participants = $this->getDataOrTerminateWithError($participantsResult); $participantsWithoutVote = array_filter( $participants, function ($participant) { @@ -908,7 +931,8 @@ class CoodleSurvey extends FHCAPI_Controller } ); - $externalParticipants = $this->CoodleSurveyExternalParticipantModel->getExternalParticipants($survey->id, true); + $externalParticipantsResult = $this->CoodleSurveyExternalParticipantModel->getExternalParticipants($survey->id, true); + $externalParticipants = $this->getDataOrTerminateWithError($externalParticipantsResult); $externalParticipantsWithoutVote = array_filter( $externalParticipants, function ($externalParticipant) { @@ -955,8 +979,10 @@ class CoodleSurvey extends FHCAPI_Controller private function sendSurveyCancellationEmail($survey) { - $participants = $this->CoodleSurveyParticipantModel->getParticipants($survey->id); - $externalParticipants = $this->CoodleSurveyExternalParticipantModel->getExternalParticipants($survey->id, true); + $participantsResult = $this->CoodleSurveyParticipantModel->getParticipants($survey->id); + $participants = $this->getDataOrTerminateWithError($participantsResult); + $externalParticipantsResult = $this->CoodleSurveyExternalParticipantModel->getExternalParticipants($survey->id, true); + $externalParticipants = $this->getDataOrTerminateWithError($externalParticipantsResult); $creatorFullName = getData($this->PersonModel->getFullName($survey->creator_uid)); foreach ($participants as $participant) { @@ -991,13 +1017,17 @@ class CoodleSurvey extends FHCAPI_Controller private function sendSurveyCompletionEmail($survey, $selectedRoomId) { - $participants = $this->CoodleSurveyParticipantModel->getParticipants($survey->id); - $externalParticipants = $this->CoodleSurveyExternalParticipantModel->getExternalParticipants($survey->id, true); + $participantsResult = $this->CoodleSurveyParticipantModel->getParticipants($survey->id); + $participants = $this->getDataOrTerminateWithError($participantsResult); + $externalParticipantsResult = $this->CoodleSurveyExternalParticipantModel->getExternalParticipants($survey->id, true); + $externalParticipants = $this->getDataOrTerminateWithError($externalParticipantsResult); $creatorFullName = getData($this->PersonModel->getFullName($survey->creator_uid)); $selectedTimeslot = null; if ($survey->selected_timeslot_id) { - $selectedTimeslot = $this->CoodleSurveyTimeslotModel->getTimeslot($survey->selected_timeslot_id); + $selectedTimeslotResult = $this->CoodleSurveyTimeslotModel->getTimeslot($survey->selected_timeslot_id); + $selectedTimeslot = $this->getDataOrTerminateWithError($selectedTimeslotResult); + $selectedTimeslot = $selectedTimeslot && (count($selectedTimeslot)) ? $selectedTimeslot[0] : null; } if ($selectedTimeslot) { diff --git a/application/models/ressource/CoodleSurveyExternalParticipant_model.php b/application/models/ressource/CoodleSurveyExternalParticipant_model.php index cd6ba9906..1bd475172 100644 --- a/application/models/ressource/CoodleSurveyExternalParticipant_model.php +++ b/application/models/ressource/CoodleSurveyExternalParticipant_model.php @@ -12,7 +12,7 @@ class CoodleSurveyExternalParticipant_model extends DB_Model parent::__construct(); $this->dbTable = 'campus.tbl_coodle_survey_external_participants'; $this->pk = 'id'; - + $this->_ci =& get_instance(); } @@ -23,7 +23,7 @@ class CoodleSurveyExternalParticipant_model extends DB_Model FROM $this->dbTable WHERE survey_id = $surveyId "; - return $this->execQuery($query)->retval; + return $this->execQuery($query); } public function getExternalParticipant($externalParticipantId, $includeAccessKey = false) @@ -34,7 +34,7 @@ class CoodleSurveyExternalParticipant_model extends DB_Model WHERE id = $externalParticipantId LIMIT 1 "; - return $this->execQuery($query)->retval[0]; + return $this->execQuery($query); } public function getExternalParticipantByAccessKey($surveyId, $accessKey) @@ -44,12 +44,16 @@ class CoodleSurveyExternalParticipant_model extends DB_Model WHERE survey_id = $surveyId AND access_key = '$accessKey' LIMIT 1 "; - return $this->execQuery($query)->retval[0]; + return $this->execQuery($query); } public function updateExternalParticipants($surveyId, $externalParticipants, $timeslots) { - $oldExternalParticipants = $this->getExternalParticipants($surveyId); + $participantsQuery = "SELECT * + FROM $this->dbTable + WHERE survey_id = $surveyId + "; + $oldExternalParticipants = getData($this->execQuery($participantsQuery)); $oldExternalParticipantIds = array_map( function ($oldExternalParticipant) { return $oldExternalParticipant->id; @@ -104,8 +108,7 @@ class CoodleSurveyExternalParticipant_model extends DB_Model $this->execQuery($insertQuery); } - - $updatedExternalParticipants = $this->getExternalParticipants($surveyId); + $updatedExternalParticipants = getData($this->execQuery($participantsQuery)); $timeslotIds = array_map( function ($timeslot) { return $timeslot->id; diff --git a/application/models/ressource/CoodleSurveyParticipant_model.php b/application/models/ressource/CoodleSurveyParticipant_model.php index da8bc910e..8c3c4c815 100644 --- a/application/models/ressource/CoodleSurveyParticipant_model.php +++ b/application/models/ressource/CoodleSurveyParticipant_model.php @@ -23,13 +23,13 @@ class CoodleSurveyParticipant_model extends DB_Model JOIN public.tbl_person person ON(person.person_id = benutzer.person_id) WHERE survey_id = $surveyId "; - return $this->execQuery($query)->retval; + return $this->execQuery($query); } public function getParticipantEntriesByUid($uid) { $query = "SELECT * FROM $this->dbTable WHERE participant_uid = '$uid'"; - return $this->execQuery($query)->retval; + return $this->execQuery($query); } public function getActiveParticipantEntriesByUid($uid) @@ -43,7 +43,7 @@ class CoodleSurveyParticipant_model extends DB_Model WHERE surveyParticipant.participant_uid = '$uid' AND survey.completed_at IS NULL AND survey.canceled_at IS NULL"; - return $this->execQuery($query)->retval; + return $this->execQuery($query); } public function updateParticipants($surveyId, $participants, $timeslots) @@ -53,7 +53,7 @@ class CoodleSurveyParticipant_model extends DB_Model }, $participants); $existingParticipantsQuery = "SELECT * FROM " . $this->dbTable . " WHERE survey_id = " . $surveyId; - $existingParticipants = $this->execQuery($existingParticipantsQuery)->retval; + $existingParticipants = getData($this->execQuery($existingParticipantsQuery)); $existingParticipantUids = array_map( function ($existingParticipant) { return $existingParticipant->participant_uid; @@ -101,7 +101,7 @@ class CoodleSurveyParticipant_model extends DB_Model $timeslots ); - $updatedExistingParticipants = $this->execQuery($existingParticipantsQuery)->retval; + $updatedExistingParticipants = getData($this->execQuery($existingParticipantsQuery)); foreach ($updatedExistingParticipants as $participant) { if (!$participant->selection) continue; diff --git a/application/models/ressource/CoodleSurveyTimeslot_model.php b/application/models/ressource/CoodleSurveyTimeslot_model.php index d21345e85..13720c730 100644 --- a/application/models/ressource/CoodleSurveyTimeslot_model.php +++ b/application/models/ressource/CoodleSurveyTimeslot_model.php @@ -18,7 +18,7 @@ class CoodleSurveyTimeslot_model extends DB_Model FROM $this->dbTable WHERE survey_id = $surveyId "; - return $this->execQuery($query)->retval; + return $this->execQuery($query); } public function getTimeslotsForMultipleSurveys($surveyIds) @@ -30,7 +30,7 @@ class CoodleSurveyTimeslot_model extends DB_Model FROM $this->dbTable WHERE survey_id IN $surveyIds "; - return $this->execQuery($query)->retval; + return $this->execQuery($query); } public function getTimeslot($timeslotId) @@ -40,7 +40,7 @@ class CoodleSurveyTimeslot_model extends DB_Model WHERE id = $timeslotId LIMIT 1 "; - return $this->execQuery($query)->retval[0]; + return $this->execQuery($query); } public function updateTimeslots($surveyId, $timeslots) @@ -68,7 +68,7 @@ class CoodleSurveyTimeslot_model extends DB_Model FROM $this->dbTable WHERE survey_id = $surveyId "; - $existingTimeslots = $this->execQuery($existingTimeslotsQuery)->retval; + $existingTimeslots = getData($this->execQuery($existingTimeslotsQuery)); $existingTimeslotIds = array_map( function ($existingTimeslot) { return $existingTimeslot->id; diff --git a/application/models/ressource/CoodleSurvey_model.php b/application/models/ressource/CoodleSurvey_model.php index 991dabaae..c400209fb 100644 --- a/application/models/ressource/CoodleSurvey_model.php +++ b/application/models/ressource/CoodleSurvey_model.php @@ -38,7 +38,7 @@ class CoodleSurvey_model extends DB_Model public function getActiveSurveys($uid) { - $userParticipantEntries = $this->CoodleSurveyParticipantModel->getParticipantEntriesByUid($uid); + $userParticipantEntries = getData($this->CoodleSurveyParticipantModel->getParticipantEntriesByUid($uid)); $surveyIdsWhereUserIsParticipant = array_map( function ($userParticipantEntry) { return $userParticipantEntry->survey_id; @@ -70,7 +70,7 @@ class CoodleSurvey_model extends DB_Model public function getInactiveSurveys($uid) { - $userParticipantEntries = $this->CoodleSurveyParticipantModel->getParticipantEntriesByUid($uid); + $userParticipantEntries = getData($this->CoodleSurveyParticipantModel->getParticipantEntriesByUid($uid)); $surveyIdsWhereUserIsParticipant = array_map( function ($userParticipantEntry) { return $userParticipantEntry->survey_id;