diff --git a/application/controllers/api/frontend/v1/Ampeln.php b/application/controllers/api/frontend/v1/Ampeln.php index 62f061e82..23aa239a4 100644 --- a/application/controllers/api/frontend/v1/Ampeln.php +++ b/application/controllers/api/frontend/v1/Ampeln.php @@ -31,6 +31,7 @@ class Ampeln extends FHCAPI_Controller 'getAllActiveAmpeln' => self::PERM_LOGGED, 'getConfirmedActiveAmpeln' => self::PERM_LOGGED, 'confirmAmpel' => self::PERM_LOGGED, + 'alleAmpeln' => self::PERM_LOGGED, ]); @@ -128,6 +129,18 @@ class Ampeln extends FHCAPI_Controller $this->terminateWithSuccess($userAmpeln); } + + public function alleAmpeln(){ + + $alle_ampeln = $this->AmpelModel->alleAmpeln($this->uid); + + if(isError($alle_ampeln)) $this->terminateWithError(getError($alle_ampeln)); + + $alle_ampeln = $this->getDataOrTerminateWithError($alle_ampeln); + + $this->terminateWithSuccess($alle_ampeln); + + } diff --git a/application/models/content/Ampel_model.php b/application/models/content/Ampel_model.php index c4e32e21b..0bb500c55 100755 --- a/application/models/content/Ampel_model.php +++ b/application/models/content/Ampel_model.php @@ -104,4 +104,65 @@ class Ampel_model extends DB_Model } } + + + function alleAmpeln($uid){ + + $datum = new datum(); + $now = $datum->mktime_fromdate(date('Y-m-d')); + + // start date of user + $benutzerStartDate = $this->execReadOnlyQuery(" + SELECT insertamum FROM public.tbl_benutzer WHERE uid = ?", [$uid]); + $benutzerStartDate = $datum->mktime_fromdate(date(current(getData($benutzerStartDate))->insertamum)); + + // user language + $userLanguage = getUserLanguage(); + $this->load->model('system/Sprache_model','SpracheModel'); + $this->SpracheModel->addSelect(["index"]); + $userLanguage = $this->SpracheModel->loadWhere(["sprache" => $userLanguage]); + //checking for error + if(isError($userLanguage)) return error(getError($userLanguage)); + $userLanguage = getData($userLanguage)[0]->index - 1; // why does the index start at 1? + + $zugeteile_ampeln = []; + + $allAmpeln = $this->execReadOnlyQuery(" + SELECT * FROM + public.tbl_ampel"); + + if(isError($allAmpeln)) return error(getError($allAmpeln)); + + $allAmpeln = getData($allAmpeln); + + foreach($allAmpeln as $ampel){ + $zugeteilt = $this->execReadOnlyQuery(" + SELECT + CASE WHEN ? IN (?) + THEN true + ELSE false + END as zugeteilt + ", [$uid, $ampel->benutzer_select]); + + if(isError($zugeteilt)) return error(getError($zugeteilt)); + + if($zugeteilt + // datum der Ampel liegt nicht vor der Vorlaufzeit + && (isset($ampel->vorlaufzeit) && !($now < strtotime('-' . $ampel->vorlaufzeit . ' day', $datum->mktime_fromdate($ampel->deadline)) )) + // verfallszeit nicht vor dem start Datum des Benutzers abgelaufen + && isset($ampel->verfallszeit) && $benutzerStartDate < strtotime('+' . $ampel->verfallszeit . ' day', $datum->mktime_fromdate($ampel->deadline)) + + // verfallszeit ist abgelaufen + //&& $now > strtotime('+' . $ampel->verfallszeit . ' day', $ampel->deadline) + + ){ + $ampel->beschreibung = $ampel->beschreibung[$userLanguage]; + $ampel->buttontext = $ampel->buttontext[$userLanguage]; + $zugeteile_ampeln[] = $ampel; + } + } + + return success($zugeteile_ampeln); + } + } diff --git a/public/js/api/ampeln.js b/public/js/api/ampeln.js index 85cd08df2..248903415 100644 --- a/public/js/api/ampeln.js +++ b/public/js/api/ampeln.js @@ -23,4 +23,11 @@ export default { `/api/frontend/v1/Ampeln/confirmAmpel/${ampel_id}`,{}); }, + alleAmpeln: function () { + return this.$fhcApi.get( + FHC_JS_DATA_STORAGE_OBJECT.app_root + + FHC_JS_DATA_STORAGE_OBJECT.ci_router + + `/api/frontend/v1/Ampeln/alleAmpeln`,{}); + }, + } \ No newline at end of file