diff --git a/application/controllers/api/frontend/v1/Ampeln.php b/application/controllers/api/frontend/v1/Ampeln.php index 2e64ba8b6..debdb917d 100644 --- a/application/controllers/api/frontend/v1/Ampeln.php +++ b/application/controllers/api/frontend/v1/Ampeln.php @@ -27,20 +27,15 @@ class Ampeln extends FHCAPI_Controller public function __construct() { parent::__construct([ - 'getNonConfirmedActiveAmpeln' => self::PERM_LOGGED, - 'getAllActiveAmpeln' => self::PERM_LOGGED, - 'getConfirmedActiveAmpeln' => self::PERM_LOGGED, - 'confirmAmpel' => self::PERM_LOGGED, + 'open' => self::PERM_LOGGED, + 'all' => self::PERM_LOGGED, + 'confirm' => self::PERM_LOGGED, 'alleAmpeln' => self::PERM_LOGGED, - ]); - $this->load->model('content/Ampel_model', 'AmpelModel'); $this->load->model('system/Sprache_model','SpracheModel'); - - //? put the uid and pid inside the controller for reusability $this->uid = getAuthUID(); $this->pid = getAuthPersonID(); @@ -50,22 +45,19 @@ class Ampeln extends FHCAPI_Controller // Public methods /** - * confirms ampel and inserts ampelID in public.tbl_ampel_benutzer_bestaetigt + * confirms ampel and inserts ampel_id in public.tbl_ampel_benutzer_bestaetigt * @access public * */ - public function confirmAmpel($ampel_id) + public function confirm($ampel_id) { - if(!isset($ampel_id)){ - $this->terminateWithError("missing parameter"); - } + $this->load->library('form_validation'); + $this->form_validation->set_data(['ampel_id'=> $ampel_id]); + $this->form_validation->set_rules('ampel_id', 'Ampel ID', 'required|integer'); + if($this->form_validation->run() == FALSE) $this->terminateWithValidationErrors($this->form_validation->error_array()); $insert_into_result = $this->AmpelModel->confirmAmpel($ampel_id,$this->uid); - if(isError($insert_into_result)){ - $this->terminateWithError(getError($insert_into_result)); - } - $insert_into_result = $this->getDataOrTerminateWithError($insert_into_result); $this->terminateWithSuccess($insert_into_result); @@ -76,9 +68,8 @@ class Ampeln extends FHCAPI_Controller * @access public * */ - public function getNonConfirmedActiveAmpeln() + public function open() { - $userAmpeln = array(); // fetch active ampeln @@ -98,33 +89,9 @@ class Ampeln extends FHCAPI_Controller // check if the user was assigned to the ampel $zugeteilt = $this->AmpelModel->isZugeteilt($this->uid, $ampel->benutzer_select); - if(isError($zugeteilt)){ - $this->addError(getError($zugeteilt)); - $zugeteilt = false; - }else{ - $zugeteilt = $this->getDataOrTerminateWithError($zugeteilt); - } + $zugeteilt = $this->getDataOrTerminateWithError($zugeteilt); if($zugeteilt) $userAmpeln[] = $this->translateAmpel($ampel); - - // old way to check if an ampel was assigned to the user - /* $userUID_array = $this->AmpelModel->execBenutzerSelect($ampel->benutzer_select); - if(isError($userUID_array)){ - $this->addError(getError($userUID_array)); - } - $userUID_array = $this->getDataOrTerminateWithError($userUID_array); - - - // check if user is assigned to the ampel - foreach($userUID_array as $user_obj){ - // property is called uid for students and mitarbeiter_uid for employees - $user_uid = property_exists($user_obj,"uid") ? $user_obj->uid : $user_obj->mitarbeiter_uid; - if($user_uid === $this->uid){ - $userAmpeln[] = $this->translateAmpel($ampel); - } - } */ - - } } @@ -132,11 +99,11 @@ class Ampeln extends FHCAPI_Controller } /** - * queries active ampeln by the user + * queries all ampeln of the user * @access public * */ - public function getAllActiveAmpeln() + public function all() { $userAmpeln = array(); @@ -151,15 +118,9 @@ class Ampeln extends FHCAPI_Controller // check if the ampel was assigned to the user $zugeteilt = $this->AmpelModel->isZugeteilt($this->uid, $ampel->benutzer_select); - if(isError($zugeteilt)){ - $this->addError(getError($zugeteilt)); - $zugeteilt = false; - }else{ - $zugeteilt = $this->getDataOrTerminateWithError($zugeteilt); - } + $zugeteilt = $this->getDataOrTerminateWithError($zugeteilt); - if($zugeteilt) $userAmpeln[] = $this->translateAmpel($ampel); - + if($zugeteilt) $userAmpeln[] = $this->translateAmpel($ampel); } $this->terminateWithSuccess($userAmpeln); @@ -175,8 +136,6 @@ class Ampeln extends FHCAPI_Controller //fetch all ampeln $alle_ampeln = $this->AmpelModel->alleAmpeln($this->uid); - if(isError($alle_ampeln)) $this->terminateWithError(getError($alle_ampeln)); - $alle_ampeln = $this->getDataOrTerminateWithError($alle_ampeln); $alle_ampeln = array_map(function($ampel){ @@ -206,12 +165,14 @@ class Ampeln extends FHCAPI_Controller $userLanguage = $this->SpracheModel->loadWhere(["sprache" => $userLanguage]); - if(isError($userLanguage)) $this->terminateWithError(getError($userLanguage)); $userLanguage = $this->getDataOrTerminateWithError($userLanguage)[0]->index - 1; // why does the index start at 1? // translate the ampel description and button text - if(isset($ampel->beschreibung) && count($ampel->beschreibung)>=($userLanguage+1)) $ampel->beschreibung = $ampel->beschreibung[$userLanguage]; - if(isset($ampel->buttontext) && count($ampel->buttontext)>=($userLanguage+1)) $ampel->buttontext = $ampel->buttontext[$userLanguage]; + if(isset($ampel->beschreibung) && count($ampel->beschreibung)>=($userLanguage+1)) + $ampel->beschreibung = $ampel->beschreibung[$userLanguage]; + + if(isset($ampel->buttontext) && count($ampel->buttontext)>=($userLanguage+1)) + $ampel->buttontext = $ampel->buttontext[$userLanguage]; return $ampel; diff --git a/application/helpers/hlp_return_object_helper.php b/application/helpers/hlp_return_object_helper.php index d9004d993..4db5eb9e3 100755 --- a/application/helpers/hlp_return_object_helper.php +++ b/application/helpers/hlp_return_object_helper.php @@ -25,6 +25,7 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); /** * Used to create a return object, should not be used directly + * @return stdClass */ function _createReturnObject($code, $error, $retval) { diff --git a/application/models/content/Ampel_model.php b/application/models/content/Ampel_model.php index 8f89ff3e9..7c3bf1900 100755 --- a/application/models/content/Ampel_model.php +++ b/application/models/content/Ampel_model.php @@ -16,7 +16,7 @@ class Ampel_model extends DB_Model * 1. not after the deadline date * 2. not before the vorlaufszeit * @param bool $email If true, then only ampeln are retrieved that are marked to be sent by mail. - * @return array Returns array of objects. + * @return stdClass Returns array of objects. */ public function active($email = false) { @@ -52,7 +52,7 @@ class Ampel_model extends DB_Model /** * Returns all Ampel-receiver of a specific Ampel. * @param string $benutzer_select SQL Statement which defines the Ampel-receiver. - * @return array Returns array of objects with property 'uid'. + * @return stdClass Returns array of objects with property 'uid'. */ public function execBenutzerSelect($benutzer_select) { @@ -102,19 +102,16 @@ class Ampel_model extends DB_Model * confirms Ampel by the user. * @param int $ampel_id Ampel-ID * @param string $uid UID - * @return bool insert into result + * @return stdClass insert into result */ public function confirmAmpel($ampel_id, $uid) { - if(isset($ampel_id) && isset($uid)){ - return $this->execQuery(' - INSERT INTO public.tbl_ampel_benutzer_bestaetigt (ampel_id, uid) - VALUES (?,?);', array($ampel_id, $uid)); - }else{ - - return error("parameter were missing to execute the insert into"); - } - + if(isset($ampel_id) && isset($uid)) + return error("parameter were missing to execute the insert into"); + + return $this->execQuery(' + INSERT INTO public.tbl_ampel_benutzer_bestaetigt (ampel_id, uid) + VALUES (?,?);', array($ampel_id, $uid)); } /** @@ -139,7 +136,6 @@ class Ampel_model extends DB_Model $zugeteilt = getData($zugeteilt); return success(current($zugeteilt)->zugeteilt); - } diff --git a/public/js/api/ampeln.js b/public/js/api/ampeln.js index 248903415..1c8ba81a2 100644 --- a/public/js/api/ampeln.js +++ b/public/js/api/ampeln.js @@ -1,33 +1,18 @@ export default { - getNonConfirmedActiveAmpeln: function () { + open: function () { return this.$fhcApi.get( - FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - `/api/frontend/v1/Ampeln/getNonConfirmedActiveAmpeln`,{}); + `/api/frontend/v1/Ampeln/open`,{}); }, - getAllActiveAmpeln: function () { + all: function () { return this.$fhcApi.get( - FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - `/api/frontend/v1/Ampeln/getAllActiveAmpeln`,{}); + `/api/frontend/v1/Ampeln/all`,{}); }, - - - confirmAmpel: function (ampel_id) { + confirm: function (ampel_id) { return this.$fhcApi.get( - FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - `/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`,{}); + `/api/frontend/v1/Ampeln/confirm/${ampel_id}`,{}); }, } \ No newline at end of file diff --git a/public/js/apps/Dashboard/Admin.js b/public/js/apps/Dashboard/Admin.js index ad4c2cf63..49d43657f 100755 --- a/public/js/apps/Dashboard/Admin.js +++ b/public/js/apps/Dashboard/Admin.js @@ -1,7 +1,6 @@ import {CoreNavigationCmpt} from '../../components/navigation/Navigation.js'; import DashboardAdmin from '../../components/Dashboard/Admin.js'; -import Phrasen from "../../plugin/Phrasen.js" -import FhcAlert from "../../plugin/FhcAlert.js" +import Phrasen from "../../plugin/Phrasen.js"; const app = Vue.createApp({ data: () => ({ @@ -13,5 +12,5 @@ const app = Vue.createApp({ } }); app.config.unwrapInjectedRef = true; -app.use(Phrasen).use(FhcAlert); +app.use(Phrasen); app.mount('#main'); diff --git a/public/js/apps/Dashboard/Fhc.js b/public/js/apps/Dashboard/Fhc.js index 824f03bd2..98f06f329 100755 --- a/public/js/apps/Dashboard/Fhc.js +++ b/public/js/apps/Dashboard/Fhc.js @@ -1,6 +1,5 @@ import FhcDashboard from '../../components/Dashboard/Dashboard.js'; import Phrasen from "../../plugin/Phrasen.js" -import FhcAlert from "../../plugin/FhcAlert.js" const app = Vue.createApp({ data: () => ({ @@ -11,5 +10,5 @@ const app = Vue.createApp({ } }); app.config.unwrapInjectedRef = true; -app.use(Phrasen).use(FhcAlert); +app.use(Phrasen); app.mount('#content'); diff --git a/public/js/components/DashboardWidget/Ampel.js b/public/js/components/DashboardWidget/Ampel.js index ca7442578..4cfa18d51 100755 --- a/public/js/components/DashboardWidget/Ampel.js +++ b/public/js/components/DashboardWidget/Ampel.js @@ -10,7 +10,6 @@ export default { source: '', allAmpeln:null, activeAmpeln:null, - isPhrasenLoaded: false, }), mixins: [ AbstractWidget @@ -52,12 +51,9 @@ export default { default: return data; } }, - - toggleFilter(value){ this.filter === value ? this.filter = '' : this.filter = value; }, - closeOffcanvasAmpeln() { for (let i = 0; i < this.ampelnComputed.length; i++) @@ -81,19 +77,17 @@ export default { // maybe we also want to reset the source (open/alle) of the displayed ampeln }, async fetchNonConfirmedActiveAmpeln(){ - - await this.$fhcApi.factory.ampeln.getNonConfirmedActiveAmpeln().then(res=>{ + await this.$fhcApi.factory.ampeln.open().then(res=>{ this.activeAmpeln = res.data.sort((a,b) => new Date(b.deadline) - new Date(a.deadline)); }); }, async fetchAllActiveAmpeln(){ - - await this.$fhcApi.factory.ampeln.getAllActiveAmpeln().then(res=>{ + await this.$fhcApi.factory.ampeln.all().then(res=>{ this.allAmpeln = res.data.sort((a,b) => new Date(b.deadline) - new Date(a.deadline)); }); }, async confirm(ampelId){ - this.$fhcApi.factory.ampeln.confirmAmpel(ampelId) + this.$fhcApi.factory.ampeln.confirm(ampelId) .then(res => res.data) .then(result => { this.$fhcAlert.alertSuccess(this.$p.t('ampeln','ampelBestaetigt')); @@ -114,13 +108,9 @@ export default { } }, created() { - this.$p.loadCategory(['ampel','ui']).then(() => { - this.isPhrasenLoaded = true; - }); this.$emit('setConfig', false); }, async mounted() { - await this.fetchNonConfirmedActiveAmpeln(); await this.fetchAllActiveAmpeln(); }, diff --git a/public/js/components/DashboardWidget/Stundenplan.js b/public/js/components/DashboardWidget/Stundenplan.js index 0b0840d73..b74095b32 100755 --- a/public/js/components/DashboardWidget/Stundenplan.js +++ b/public/js/components/DashboardWidget/Stundenplan.js @@ -36,7 +36,7 @@ export default { }, created() { this.$emit('setConfig', false); - /* axios + axios .get(this.apiurl + '/components/Cis/Stundenplan/Stunden').then(res => { res.data.retval.forEach(std => { this.stunden[std.stunde] = std; // TODO(chris): geht besser @@ -57,7 +57,7 @@ export default { }) .catch(err => { console.log(err);console.error('ERROR: ', err.response.data) }); }) - .catch(err => { console.error('ERROR: ', err.response.data) }); */ + .catch(err => { console.error('ERROR: ', err.response.data) }); }, template: `