From 7e983292ea842aa4a69d9acca6733a1e5a8b71ff Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Tue, 23 Jul 2024 11:26:52 +0200 Subject: [PATCH] adds the endpoint that fetches all ampeln of a user that are not confirmed by the user yet and also removes some unnecessary comments from other enpoints --- .../controllers/api/frontend/v1/Ampeln.php | 84 +++++++++++++++++++ .../controllers/api/frontend/v1/Profil.php | 5 -- .../api/frontend/v1/ProfilUpdate.php | 5 -- public/js/api/ampeln.js | 10 +++ public/js/api/fhcapifactory.js | 2 + public/js/apps/Dashboard/Fhc.js | 2 + 6 files changed, 98 insertions(+), 10 deletions(-) create mode 100644 application/controllers/api/frontend/v1/Ampeln.php create mode 100644 public/js/api/ampeln.js diff --git a/application/controllers/api/frontend/v1/Ampeln.php b/application/controllers/api/frontend/v1/Ampeln.php new file mode 100644 index 000000000..e4029f841 --- /dev/null +++ b/application/controllers/api/frontend/v1/Ampeln.php @@ -0,0 +1,84 @@ +. + */ + +if (! defined('BASEPATH')) exit('No direct script access allowed'); + +class Ampeln extends FHCAPI_Controller +{ + + /** + * Object initialization + */ + public function __construct() + { + parent::__construct([ + 'getAmpeln' => self::PERM_LOGGED, + + ]); + + + $this->load->model('content/Ampel_model', 'AmpelModel'); + + + //? put the uid and pid inside the controller for reusability + $this->uid = getAuthUID(); + $this->pid = getAuthPersonID(); + + } + + //------------------------------------------------------------------------------------------------------------------ + // Public methods + + + /** + * function that queries all the ampeln that are addressed to the user uid + * @access public + * + */ + public function getAmpeln() + { + $userAmpeln = array(); + $ampel_result = $this->AmpelModel->active(); + + $ampel_result = $this->getDataOrTerminateWithError($ampel_result); + + $is_confirmed_array = array(); + foreach($ampel_result as $ampel){ + + $confirmedByUser = $this->AmpelModel->isConfirmed($ampel->ampel_id,$this->uid); + if(!$confirmedByUser){ + $userUID_array = $this->AmpelModel->execBenutzerSelect($ampel->benutzer_select); + $userUID_array = $this->getDataOrTerminateWithError($userUID_array); + foreach($userUID_array as $user_obj){ + + $user_uid = property_exists($user_obj,"uid") ? $user_obj->uid : $user_obj->mitarbeiter_uid; + if($user_uid === $this->uid){ + $userAmpeln[] = $ampel; + } + } + + } + + } + + $this->terminateWithSuccess($userAmpeln); + } + + +} + diff --git a/application/controllers/api/frontend/v1/Profil.php b/application/controllers/api/frontend/v1/Profil.php index ffb7449f8..63e86d1b2 100644 --- a/application/controllers/api/frontend/v1/Profil.php +++ b/application/controllers/api/frontend/v1/Profil.php @@ -18,11 +18,6 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); -/** - * This controller operates between (interface) the JS (GUI) and the SearchBarLib (back-end) - * Provides data to the ajax get calls about the searchbar component - * This controller works with JSON calls on the HTTP GET and the output is always JSON - */ class Profil extends FHCAPI_Controller { diff --git a/application/controllers/api/frontend/v1/ProfilUpdate.php b/application/controllers/api/frontend/v1/ProfilUpdate.php index 4b9dedb48..7a528b2de 100644 --- a/application/controllers/api/frontend/v1/ProfilUpdate.php +++ b/application/controllers/api/frontend/v1/ProfilUpdate.php @@ -18,11 +18,6 @@ if (! defined('BASEPATH')) exit('No direct script access allowed'); -/** - * This controller operates between (interface) the JS (GUI) and the SearchBarLib (back-end) - * Provides data to the ajax get calls about the searchbar component - * This controller works with JSON calls on the HTTP GET and the output is always JSON - */ class ProfilUpdate extends FHCAPI_Controller { diff --git a/public/js/api/ampeln.js b/public/js/api/ampeln.js new file mode 100644 index 000000000..8173d8511 --- /dev/null +++ b/public/js/api/ampeln.js @@ -0,0 +1,10 @@ +export default { + + getAmpeln: function () { + return this.$fhcApi.get( + FHC_JS_DATA_STORAGE_OBJECT.app_root + + FHC_JS_DATA_STORAGE_OBJECT.ci_router + + `/api/frontend/v1/Ampeln/getAmpeln`,{}); + }, + +} \ No newline at end of file diff --git a/public/js/api/fhcapifactory.js b/public/js/api/fhcapifactory.js index 73ce0dd7f..6df1d7467 100644 --- a/public/js/api/fhcapifactory.js +++ b/public/js/api/fhcapifactory.js @@ -22,6 +22,7 @@ import filter from "./filter.js"; import studstatus from "./studstatus.js"; import profil from "./profil.js"; import profilUpdate from "./profilUpdate.js"; +import ampeln from "./ampeln.js"; export default { search, @@ -31,4 +32,5 @@ export default { studstatus, profil, profilUpdate, + ampeln, }; diff --git a/public/js/apps/Dashboard/Fhc.js b/public/js/apps/Dashboard/Fhc.js index ebcbb4b78..98f06f329 100755 --- a/public/js/apps/Dashboard/Fhc.js +++ b/public/js/apps/Dashboard/Fhc.js @@ -1,4 +1,5 @@ import FhcDashboard from '../../components/Dashboard/Dashboard.js'; +import Phrasen from "../../plugin/Phrasen.js" const app = Vue.createApp({ data: () => ({ @@ -9,4 +10,5 @@ const app = Vue.createApp({ } }); app.config.unwrapInjectedRef = true; +app.use(Phrasen); app.mount('#content');