diff --git a/application/controllers/api/frontend/v1/Ampeln.php b/application/controllers/api/frontend/v1/Ampeln.php index bc2bca597..037996009 100644 --- a/application/controllers/api/frontend/v1/Ampeln.php +++ b/application/controllers/api/frontend/v1/Ampeln.php @@ -73,18 +73,14 @@ class Ampeln extends FHCAPI_Controller $userAmpeln = array(); // fetch active ampeln - $activeAmpeln = $this->AmpelModel->active(); + $activeAmpeln = $this->AmpelModel->active(false, $this->uid); $activeAmpeln = $this->getDataOrTerminateWithError($activeAmpeln); foreach($activeAmpeln as $ampel){ - // check if ampel is confirmed by user - $confirmedByUser = $this->AmpelModel->isConfirmed($ampel->ampel_id,$this->uid); - $ampel->bestaetigt = $confirmedByUser; - // only include non confirmed active ampeln in the result - if(!$confirmedByUser){ + if(!$ampel->bestaetigt){ // check if the user was assigned to the ampel $zugeteilt = $this->AmpelModel->isZugeteilt($this->uid, $ampel->benutzer_select); @@ -107,13 +103,11 @@ class Ampeln extends FHCAPI_Controller { $userAmpeln = array(); - $ampel_result = $this->AmpelModel->active(); + $ampel_result = $this->AmpelModel->active(false, $this->uid); $ampel_result = $this->getDataOrTerminateWithError($ampel_result); foreach($ampel_result as $ampel){ - $confirmedByUser = $this->AmpelModel->isConfirmed($ampel->ampel_id,$this->uid); - $ampel->bestaetigt = $confirmedByUser; // check if the ampel was assigned to the user $zugeteilt = $this->AmpelModel->isZugeteilt($this->uid, $ampel->benutzer_select); diff --git a/application/models/content/Ampel_model.php b/application/models/content/Ampel_model.php index 33de9fbbe..9a8b211b8 100755 --- a/application/models/content/Ampel_model.php +++ b/application/models/content/Ampel_model.php @@ -18,15 +18,27 @@ class Ampel_model extends DB_Model * @param bool $email If true, then only ampeln are retrieved that are marked to be sent by mail. * @return stdClass Returns array of objects. */ - public function active($email = false) + public function active($email = false, $uid = null) { $userLanguage = getUserLanguage(); + $bestaetigt = ''; + if($uid != null){ + $bestaetigt = ', + COALESCE(( + SELECT true + FROM public.tbl_ampel_benutzer_bestaetigt a + WHERE a.ampel_id = ampel_id + AND uid = ' . $this->escape($uid) . ' LIMIT 1), false) as bestaetigt'; + } + $parametersArray = []; $query = ' SELECT *, beschreibung[('.$this->getLanguageIndex($this->escape($userLanguage)).')] as beschreibung_trans, buttontext[('.$this->getLanguageIndex($this->escape($userLanguage)).')] as buttontext_trans - FROM public.tbl_ampel - WHERE'; + '.$bestaetigt + .' + FROM public.tbl_ampel + WHERE'; if ($email === true) {