From 92afdf71cdf52488f946eb25314439952d5f3936 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Wed, 3 Jul 2024 15:53:01 +0200 Subject: [PATCH 01/17] changing fhcapi for the client side for the profil WIP --- .../controllers/api/frontend/v1/Profil.php | 616 ++++++++++++++++++ public/js/api/fhcapifactory.js | 4 +- public/js/api/profil.js | 76 +++ public/js/apps/Cis/Profil.js | 4 +- .../EditProfilComponents/EditAdresse.js | 3 + 5 files changed, 701 insertions(+), 2 deletions(-) create mode 100644 application/controllers/api/frontend/v1/Profil.php create mode 100755 public/js/api/profil.js diff --git a/application/controllers/api/frontend/v1/Profil.php b/application/controllers/api/frontend/v1/Profil.php new file mode 100644 index 000000000..88679c636 --- /dev/null +++ b/application/controllers/api/frontend/v1/Profil.php @@ -0,0 +1,616 @@ +. + */ + +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 +{ + + /** + * Object initialization + */ + public function __construct() + { + parent::__construct([ + 'getView' => self::PERM_LOGGED, + 'fotoSperre' => self::PERM_LOGGED, + ]); + + + $this->load->model('ressource/mitarbeiter_model', 'MitarbeiterModel'); + $this->load->model('crm/Student_model', 'StudentModel'); + $this->load->model('person/Benutzer_model', 'BenutzerModel'); + $this->load->model('person/Person_model', 'PersonModel'); + $this->load->model('person/Adresse_model', 'AdresseModel'); + $this->load->model('person/Benutzerfunktion_model', 'BenutzerfunktionModel'); + $this->load->model('person/Benutzergruppe_model', 'BenutzergruppeModel'); + $this->load->model('ressource/Betriebsmittelperson_model', 'BetriebsmittelpersonModel'); + $this->load->model('person/Kontakt_model', 'KontaktModel'); + $this->load->model('person/Profil_update_model', 'ProfilUpdateModel'); + $this->load->model('content/DmsVersion_model', 'DmsVersionModel'); + + + //? put the uid and pid inside the controller for reusability + $this->uid = getAuthUID(); + $this->pid = getAuthPersonID(); + + } + + //------------------------------------------------------------------------------------------------------------------ + // Public methods + + + /** + * function that returns the data used for the corresponding view + * the client side parses the @param $uid and calls this function to get the data to the correct view + * @access public + * @param boolean $uid the userID used to identify which information should be retrieved for which view + * @return stdClass all the data corresponding to a view of a user + */ + public function getView($uid) + { + $res = new stdClass(); + + // if parsing the URL did not found a UID then the UID of the logged in user is used + if ($uid == "Profil" || $uid == $this->uid) { + $isMitarbeiter = $this->MitarbeiterModel->isMitarbeiter($this->uid); + if (isError($isMitarbeiter)) { + show_error("error while checking if UID: " . $this->uid . " is a mitarbeiter"); + } + $isMitarbeiter = getData($isMitarbeiter); + if ($isMitarbeiter) { + $res->view = "MitarbeiterProfil"; + $res->data = $this->mitarbeiterProfil(); + $res->data->pid = $this->pid; + } else { + $res->view = "StudentProfil"; + $res->data = $this->studentProfil(); + $res->data->pid = $this->pid; + } + } + // UID is availabe when accessing Profil/View/:uid + else { + $this->PersonModel->addSelect(["person_id"]); + $pid = $this->PersonModel->getByUid($uid); + if (isError($pid)) { + show_error("error while trying to update table public.tbl_person while searching for a person with UID: " . $uid); + } + $pid = hasData($pid) ? getData($pid)[0] : null; + if (!$pid) { + show_error("Person with UID: " . $uid . " does not exist"); + } + $isMitarbeiter = $this->MitarbeiterModel->isMitarbeiter($uid); + if (isError($isMitarbeiter)) { + show_error("error while checking if UID: " . $uid . " is a mitarbeiter"); + } + $isMitarbeiter = getData($isMitarbeiter); + if ($isMitarbeiter) { + $res->view = "ViewMitarbeiterProfil"; + $res->data = $this->viewMitarbeiterProfil($uid); + + } else { + $res->view = "ViewStudentProfil"; + $res->data = $this->viewStudentProfil($uid); + } + } + $this->terminateWithSuccess($res); + } + + /** + * update column foto_sperre in public.tbl_person + * @access public + * @param boolean $value new value for the column + * @return boolean the new value added to the column in public.tbl_person + */ + public function fotoSperre($value) + { + if(!isset($value)){ + $this->terminateWithError("Missing parameter", self::ERROR_TYPE_GENERAL); + } + + $res = $this->PersonModel->update($this->pid, ["foto_sperre" => $value]); + if (isError($res)) { + show_error("error while trying to update table public.tbl_person"); + } + $this->PersonModel->addSelect("foto_sperre"); + $res = $this->PersonModel->load($this->pid); + if (isError($res)) { + show_error("error while trying to query table public.tbl_person"); + } + + $res = $this->getDataOrTerminateWithError($res); + + $this->terminateWithSuccess(current($res)); + } + + + // ----------------------------------------------------------------------------------------------------------------- + // Private methods + + /** + * function that returns the data used for viewing another mitarbeiter profile + * @access private + * @param integer $uid the userID to retrieve the mitarbeiter data + * @return stdClass restricted mitarbeiter data + */ + private function viewMitarbeiterProfil($uid) + { + $mailverteiler_res = $this->getMailverteiler($uid); + $benutzer_funktion_res = $this->getBenutzerFunktion($uid); + $benutzer_res = $this->getBenutzerAlias($uid); + $person_res = $this->getPersonInfo($uid); + $mitarbeiter_res = $this->getMitarbeiterInfo($uid); + $telefon_res = $this->getTelefonInfo($uid); + + $res = new stdClass(); + $res->username = $uid; + + //? Person Info + foreach ($person_res as $key => $val) { + $res->$key = $val; + } + + //? Mitarbeiter Info + foreach ($mitarbeiter_res as $key => $val) { + $res->$key = $val; + + } + + $intern_email = array(); + $intern_email["type"] = "intern"; + $intern_email["email"] = $uid . "@" . DOMAIN; + $extern_email = array(); + $extern_email["type"] = "alias"; + $extern_email["email"] = $benutzer_res->alias . "@" . DOMAIN; + $res->emails = array($intern_email, $extern_email); + + $res->funktionen = $benutzer_funktion_res; + $res->mailverteiler = $mailverteiler_res; + $res->standort_telefon = isset($telefon_res) ? $telefon_res->kontakt : null; + + return $res; + } + + /** + * function that returns the data used for viewing another student profile + * @access private + * @param integer $uid the userID to retrieve the student data + * @return stdClass restricted student data + */ + private function viewStudentProfil($uid) + { + $mailverteiler_res = $this->getMailverteiler($uid); + $person_res = $this->getPersonInfo($uid); + $student_res = $this->getStudentInfo($uid); + $matr_res = $this->getMatrikelNummer($uid); + + $res = new stdClass(); + $res->username = $uid; + + //? Person Information + foreach ($person_res as $key => $value) { + $res->$key = $value; + } + + //? Student Information + foreach ($student_res as $key => $value) { + $res->$key = $value; + } + + $intern_email = array(); + $intern_email["type"] = "intern"; + $intern_email["email"] = $uid . "@" . DOMAIN; + + $res->emails = [$intern_email]; + $res->matrikelnummer = $matr_res->matr_nr; + $res->mailverteiler = $mailverteiler_res; + + return $res; + } + + /** + * function that returns the data used for the mitarbeiter profile + * @access private + * @return stdClass mitarbeiter data + */ + private function mitarbeiterProfil() + { + + $zutrittskarte_ausgegebenam = $this->getZutrittskarteDatum($this->uid); + $adresse_res = $this->getAdressenInfo($this->pid); + $kontakte_res = $this->getKontaktInfo($this->pid); + $mailverteiler_res = $this->getMailverteiler($this->uid); + $person_res = $this->getPersonInfo($this->uid, true); + $benutzer_funktion_res = $this->getBenutzerFunktion($this->uid); + $betriebsmittelperson_res = $this->getBetriebsmittelInfo($this->pid); + $profilUpdates = $this->getProfilUpdates($this->uid); + $telefon_res = $this->getTelefonInfo($this->uid); + $mitarbeiter_res = $this->getMitarbeiterInfo($this->uid); + + $res = new stdClass(); + $res->username = $this->uid; + + //? Person Information + foreach ($person_res as $key => $value) { + $res->$key = $value; + } + + //? Mitarbeiter Information + foreach ($mitarbeiter_res as $key => $value) { + $res->$key = $value; + } + + $res->adressen = $adresse_res; + $res->zutrittsdatum = $zutrittskarte_ausgegebenam; + $res->kontakte = $kontakte_res; + $res->mittel = $betriebsmittelperson_res; + $res->mailverteiler = $mailverteiler_res; + + $intern_email = array(); + $intern_email["type"] = "intern"; + $intern_email["email"] = $this->uid . "@" . DOMAIN; + $extern_email = array(); + $extern_email["type"] = "alias"; + $extern_email["email"] = $mitarbeiter_res->alias . "@" . DOMAIN; + $res->emails = [$intern_email, $extern_email]; + + $res->funktionen = $benutzer_funktion_res; + $res->standort_telefon = $telefon_res; + $res->profilUpdates = $profilUpdates; + + return $res; + } + + /** + * function that returns the data used for the student profile + * @access private + * @return stdClass student data + */ + private function studentProfil() + { + $betriebsmittelperson_res = $this->getBetriebsmittelInfo($this->pid); + $kontakte_res = $this->getKontaktInfo($this->pid); + $zutrittskarte_ausgegebenam = $this->getZutrittskarteDatum($this->uid); + $adresse_res = $this->getAdressenInfo($this->pid); + $mailverteiler_res = $this->getMailverteiler($this->uid); + $person_res = $this->getPersonInfo($this->uid, true); + $zutrittsgruppe_res = $this->getZutrittsgruppen($this->uid); + $student_res = $this->getStudentInfo($this->uid); + $matr_res = $this->getMatrikelNummer($this->uid); + $profilUpdates = $this->getProfilUpdates($this->uid); + + $res = new stdClass(); + $res->username = $this->uid; + + //? Person Information + foreach ($person_res as $key => $value) { + $res->$key = $value; + } + + //? Student Information + foreach ($student_res as $key => $value) { + $res->$key = trim($value); + } + + $intern_email = array(); + $intern_email["type"] = "intern"; + $intern_email["email"] = $this->uid . "@" . DOMAIN; + + $res->emails = [$intern_email]; + $res->adressen = $adresse_res; + $res->zutrittsdatum = $zutrittskarte_ausgegebenam; + $res->kontakte = $kontakte_res; + $res->mittel = $betriebsmittelperson_res; + $res->matrikelnummer = $matr_res->matr_nr; + $res->zuttritsgruppen = $zutrittsgruppe_res; + $res->mailverteiler = $mailverteiler_res; + $res->profilUpdates = $profilUpdates; + + return $res; + } + + + /** + * gets all the mailverteiler using the tables: tbl_benutzer, tbl_benutzergruppe, tbl_gruppe + * @access private + * @param integer $uid the userID used to retrieve the mailverteiler + * @return array returns the mailvertailer corresponding to a userID + */ + private function getMailverteiler($uid) + { + $this->PersonModel->addSelect('gruppe_kurzbz, beschreibung'); + $this->PersonModel->addJoin('tbl_benutzer', 'person_id'); + $this->PersonModel->addJoin('tbl_benutzergruppe', 'uid'); + $this->PersonModel->addJoin('tbl_gruppe', 'gruppe_kurzbz'); + + $mailverteiler_res = $this->PersonModel->loadWhere(array('mailgrp' => true, 'uid' => $uid)); + if (isError($mailverteiler_res)) { + show_error("was not able to query the table public.tbl_benutzer:" . getData($mailverteiler_res)); + } + $mailverteiler_res = hasData($mailverteiler_res) ? getData($mailverteiler_res) : null; + $mailverteiler_res = array_map(function ($element) { + $element->mailto = "mailto:" . $element->gruppe_kurzbz . "@" . DOMAIN; + return $element; + }, $mailverteiler_res); + return $mailverteiler_res; + } + + /** + * gets all the Benutzerfunktionen of a corresponding user + * @access private + * @param integer $uid the userID used to retrieve the Benutzerfunktionen + * @return array returns the Benutzerfunktionen corresponding to a userID + */ + private function getBenutzerFunktion($uid) + { + $this->BenutzerfunktionModel->addSelect(["tbl_benutzerfunktion.bezeichnung as Bezeichnung", "tbl_organisationseinheit.bezeichnung as Organisationseinheit", "datum_von as Gültig_von", "datum_bis as Gültig_bis", "wochenstunden as Wochenstunden"]); + $this->BenutzerfunktionModel->addJoin("tbl_organisationseinheit", "oe_kurzbz"); + + $benutzer_funktion_res = $this->BenutzerfunktionModel->loadWhere(array('uid' => $uid)); + if (isError($benutzer_funktion_res)) { + show_error("was not able to query the table public.tbl_benutzerfunktion:" . getData($benutzer_funktion_res)); + } + $benutzer_funktion_res = hasData($benutzer_funktion_res) ? getData($benutzer_funktion_res) : null; + return $benutzer_funktion_res; + } + + /** + * gets all the Betriebsmittel of a corresponding user + * @access private + * @param integer $uid the userID used to retrieve the Betriebsmittel + * @return array returns the Betriebsmittel corresponding to a userID + */ + private function getBetriebsmittelInfo($pid) + { + $this->BetriebsmittelpersonModel->addSelect(["CONCAT(betriebsmitteltyp, ' ' ,beschreibung) as Betriebsmittel", "nummer as Nummer", "ausgegebenam as Ausgegeben_am"]); + + //? betriebsmittel are not needed in a view + $betriebsmittelperson_res = $this->BetriebsmittelpersonModel->getBetriebsmittel($pid); + if (isError($betriebsmittelperson_res)) { + show_error("was not able to query the table public.tbl_betriebsmittelperson:" . getData($betriebsmittelperson_res)); + } + $betriebsmittelperson_res = hasData($betriebsmittelperson_res) ? getData($betriebsmittelperson_res) : null; + return $betriebsmittelperson_res; + } + + /** + * gets the alias of a corresponding user + * @access private + * @param integer $uid the userID used to get the alias + * @return string the alias of the userID + */ + private function getBenutzerAlias($uid) + { + $this->BenutzerModel->addSelect(["alias"]); + $benutzer_res = $this->BenutzerModel->load([$uid]); + if (isError($benutzer_res)) { + show_error("was not able to query the table public.tbl_benutzer:" . getData($benutzer_res)); + } else { + $benutzer_res = hasData($benutzer_res) ? getData($benutzer_res)[0] : null; + } + + return $benutzer_res; + } + + /** + * gets the person information corresponding to a user + * @access private + * @param integer $uid the userID used to get the person information + * @param integer $geburtsInfo flag wether to add the columns gebort, gebdatum, foto_sperre or not + * @return array all the person informaion corresponding to a userID + */ + private function getPersonInfo($uid, $geburtsInfo = null) + { + $selectClause = ["foto", "anrede", "titelpost as postnomen", "titelpre as titel", "vorname", "nachname"]; + /** @param integer $geburtsInfo */ + if ($geburtsInfo) { + array_push($selectClause, "gebort"); + array_push($selectClause, "gebdatum"); + array_push($selectClause, "foto_sperre"); + } + $this->BenutzerModel->addSelect($selectClause); + $this->BenutzerModel->addJoin("tbl_person", "person_id"); + + $person_res = $this->BenutzerModel->load([$uid]); + if (isError($person_res)) { + show_error("was not able to query the table public.tbl_benutzer:" . getData($person_res)); + } else { + $person_res = hasData($person_res) ? getData($person_res)[0] : null; + } + + return $person_res; + } + + /** + * gets the mitarbeiter information corresponding to a user + * @access private + * @param integer $uid the userID used to get the mitarbeiter information + * @return array all the mitarbeiter informaion corresponding to a userID + */ + private function getMitarbeiterInfo($uid) + { + $this->MitarbeiterModel->addSelect(["kurzbz", "telefonklappe", "alias", "ort_kurzbz"]); + $this->MitarbeiterModel->addJoin("tbl_benutzer", "tbl_benutzer.uid = tbl_mitarbeiter.mitarbeiter_uid"); + $mitarbeiter_res = $this->MitarbeiterModel->load($uid); + if (isError($mitarbeiter_res)) { + show_error("was not able to query the table public.tbl_mitarbeiter:" . getData($mitarbeiter_res)); + } else { + $mitarbeiter_res = hasData($mitarbeiter_res) ? getData($mitarbeiter_res)[0] : null; + } + + return $mitarbeiter_res; + } + + /** + * gets the telefon information corresponding to a user + * @access private + * @param integer $uid the userID used to get the telefon information + * @return array all the telefon informaion corresponding to a userID + */ + private function getTelefonInfo($uid) + { + $this->MitarbeiterModel->addSelect(["kontakt"]); + $this->MitarbeiterModel->addJoin("tbl_kontakt", "tbl_mitarbeiter.standort_id = tbl_kontakt.standort_id"); + $this->MitarbeiterModel->addLimit(1); + $telefon_res = $this->MitarbeiterModel->loadWhere(["mitarbeiter_uid" => $uid, "kontakttyp" => "telefon"]); + if (isError($telefon_res)) { + show_error("was not able to query the table public.tbl_mitarbeiter:" . getData($telefon_res)); + } + $telefon_res = hasData($telefon_res) ? getData($telefon_res)[0] : null; + return $telefon_res; + } + + /** + * gets the student information corresponding to a user + * @access private + * @param integer $uid the userID used to get the student information + * @return array all the student informaion corresponding to a userID + */ + private function getStudentInfo($uid) + { + $this->StudentModel->addSelect(['tbl_studiengang.bezeichnung as studiengang', 'tbl_student.semester', 'tbl_student.verband', 'tbl_student.gruppe', 'tbl_student.matrikelnr as personenkennzeichen']); + $this->StudentModel->addJoin('tbl_studiengang', "tbl_studiengang.studiengang_kz=tbl_student.studiengang_kz"); + + $student_res = $this->StudentModel->load([$uid]); + if (isError($student_res)) { + show_error("was not able to query the table public.tbl_student:" . getData($student_res)); + } + $student_res = hasData($student_res) ? getData($student_res)[0] : null; + return $student_res; + } + + /** + * gets the profil updates corresponding to a user + * @access private + * @param integer $uid the userID used to get the profil updates + * @return array all the profil updates corresponding to a userID + */ + private function getProfilUpdates($uid) + { + $profilUpdates = $this->ProfilUpdateModel->getProfilUpdatesWhere(['uid' => $uid]); + if (isError($profilUpdates)) { + show_error("was not able to query the table public.tbl_profil_update:" . getData($profilUpdates)); + } + $profilUpdates = hasData($profilUpdates) ? getData($profilUpdates) : null; + return $profilUpdates; + } + + /** + * gets the Matrikelnummer corresponding to a user + * @access private + * @param integer $uid the userID used to get the Matrikelnummer + * @return integer the Matrikelnummer corresponding to a userID + */ + private function getMatrikelNummer($uid) + { + $this->BenutzerModel->addSelect(["matr_nr"]); + $this->BenutzerModel->addJoin("tbl_person", "person_id"); + + $matr_res = $this->BenutzerModel->load([$uid]); + if (isError($matr_res)) { + show_error("was not able to query the table public.tbl_benutzer:" . getData($matr_res)); + } + $matr_res = hasData($matr_res) ? getData($matr_res)[0] : []; + return $matr_res; + } + + /** + * gets the Zutrittsgruppen corresponding to a user + * @access private + * @param integer $uid the userID used to get the Zutrittsgruppen + * @return array all the Zutrittsgruppen corresponding to a userID + */ + private function getZutrittsgruppen($uid) + { + $this->BenutzergruppeModel->addSelect(['bezeichnung']); + $this->BenutzergruppeModel->addJoin('tbl_gruppe', 'gruppe_kurzbz'); + + $zutrittsgruppe_res = $this->BenutzergruppeModel->loadWhere(array("uid" => $uid, "zutrittssystem" => true)); + if (isError($zutrittsgruppe_res)) { + show_error("was not able to query the table public.tbl_benutzergruppe:" . getData($zutrittsgruppe_res)); + } + $zutrittsgruppe_res = hasData($zutrittsgruppe_res) ? getData($zutrittsgruppe_res) : null; + return $zutrittsgruppe_res; + } + + /** + * gets the address information corresponding to a user + * @access private + * @param integer $uid the userID used to get the address information + * @return array all the address information corresponding to a userID + */ + private function getAdressenInfo($pid) + { + $adresse_res = $this->AdresseModel->addSelect(["adresse_id", "strasse", "tbl_adressentyp.bezeichnung as typ", "plz", "ort", "zustelladresse", "gemeinde", "nation"]); + $adresse_res = $this->AdresseModel->addOrder("zustelladresse", "DESC"); + $adresse_res = $this->AdresseModel->addJoin("tbl_adressentyp", "typ=adressentyp_kurzbz"); + + $adresse_res = $this->AdresseModel->loadWhere(["person_id" => $pid]); + if (isError($adresse_res)) { + show_error("was not able to query the table public.tbl_adresse:" . getData($adresse_res)); + } + $adresse_res = hasData($adresse_res) ? getData($adresse_res) : null; + return $adresse_res; + } + + /** + * gets the kontakt information corresponding to a user + * @access private + * @param integer $uid the userID used to get the kontakt information + * @return array all the kontakt information corresponding to a userID + */ + private function getKontaktInfo($pid) + { + $this->KontaktModel->addSelect(['kontakttyp', 'kontakt_id', 'kontakt', 'tbl_kontakt.anmerkung', 'tbl_kontakt.zustellung']); + $this->KontaktModel->addJoin('public.tbl_standort', 'standort_id', 'LEFT'); + $this->KontaktModel->addJoin('public.tbl_firma', 'firma_id', 'LEFT'); + $this->KontaktModel->addOrder('kontakttyp, kontakt, tbl_kontakt.updateamum, tbl_kontakt.insertamum'); + + $kontakte_res = $this->KontaktModel->loadWhere(['person_id' => $pid]); + if (isError($kontakte_res)) { + show_error("was not able to query the table public.tbl_kontakt:" . getData($kontakte_res)); + } + $kontakte_res = hasData($kontakte_res) ? getData($kontakte_res) : null; + return $kontakte_res; + } + + /** + * gets the date of issue of the FH access card corresponding to a user + * @access private + * @param integer $uid the userID used to get the date of issue of the FH access card + * @return string the date of issue of the FH access card corresponding to a userID + */ + private function getZutrittskarteDatum($uid) + { + $zutrittskarte_ausgegebenam = $this->BetriebsmittelpersonModel->getBetriebsmittelByUid($uid, "Zutrittskarte"); + if (isError($zutrittskarte_ausgegebenam)) { + show_error("was not able to query the table wavi.tbl_bentriebsmittelperson:" . getData($zutrittskarte_ausgegebenam)); + } + $zutrittskarte_ausgegebenam = hasData($zutrittskarte_ausgegebenam) ? getData($zutrittskarte_ausgegebenam)[0]->ausgegebenam : null; + + //? formats date from 01-01-2000 to 01.01.2000 + $zutrittskarte_ausgegebenam = str_replace("-", ".", $zutrittskarte_ausgegebenam); + return $zutrittskarte_ausgegebenam; + } +} + diff --git a/public/js/api/fhcapifactory.js b/public/js/api/fhcapifactory.js index 41c89ef50..c993a86d6 100644 --- a/public/js/api/fhcapifactory.js +++ b/public/js/api/fhcapifactory.js @@ -20,11 +20,13 @@ import phrasen from "./phrasen.js"; import navigation from "./navigation.js"; import filter from "./filter.js"; import studstatus from "./studstatus.js"; +import profil from "./profil.js"; export default { search, phrasen, navigation, filter, - studstatus + studstatus, + profil, }; diff --git a/public/js/api/profil.js b/public/js/api/profil.js new file mode 100755 index 000000000..e2fba5f83 --- /dev/null +++ b/public/js/api/profil.js @@ -0,0 +1,76 @@ +export default { + + getView: function (uid) { + return this.$fhcApi.get( + FHC_JS_DATA_STORAGE_OBJECT.app_root + + FHC_JS_DATA_STORAGE_OBJECT.ci_router + + `/api/frontend/v1/Profil/getView/${uid}`,{} + ); + }, + + fotoSperre: function (value) { + return this.$fhcApi.get( + FHC_JS_DATA_STORAGE_OBJECT.app_root + + FHC_JS_DATA_STORAGE_OBJECT.ci_router + + `/api/frontend/v1/Profil/fotoSperre/${value}`, + {} + ); + + }, + + isStudent: function (uid) { + return this.$fhcApi.get( + FHC_JS_DATA_STORAGE_OBJECT.app_root + + FHC_JS_DATA_STORAGE_OBJECT.ci_router + + `/api/frontend/v1/Profil/isStudent`, + { + uid:uid, + } + ); + }, + + isMitarbeiter: function (uid) { + return this.$fhcApi.get( + FHC_JS_DATA_STORAGE_OBJECT.app_root + + FHC_JS_DATA_STORAGE_OBJECT.ci_router + + `/api/frontend/v1/Profil/isMitarbeiter`, + { + uid:uid, + } + ); + }, + + getZustellAdresse: function () { + return this.$fhcApi.get( + FHC_JS_DATA_STORAGE_OBJECT.app_root + + FHC_JS_DATA_STORAGE_OBJECT.ci_router + + `/api/frontend/v1/Profil/getZustellAdresse`,{} + ); + }, + + getZustellKontakt: function () { + return this.$fhcApi.get( + FHC_JS_DATA_STORAGE_OBJECT.app_root + + FHC_JS_DATA_STORAGE_OBJECT.ci_router + + `/api/frontend/v1/Profil/getZustellKontakt`,{} + ); + }, + + getGemeinden: function(nation,zip=null){ + return this.$fhcApi.get( + FHC_JS_DATA_STORAGE_OBJECT.app_root + + FHC_JS_DATA_STORAGE_OBJECT.ci_router + + "/api/frontend/v1/Profil/getGemeinden", + { nation: nation, + ...(zip? {zip:zip}:{}) } + ); + + }, + getAllNationen:function(){ + return this.$fhcApi.get( + FHC_JS_DATA_STORAGE_OBJECT.app_root + + FHC_JS_DATA_STORAGE_OBJECT.ci_router + + "/api/frontend/v1/Profil/getAllNationen",{} + ); + }, +} \ No newline at end of file diff --git a/public/js/apps/Cis/Profil.js b/public/js/apps/Cis/Profil.js index 9df5d42ae..3c3855147 100755 --- a/public/js/apps/Cis/Profil.js +++ b/public/js/apps/Cis/Profil.js @@ -5,6 +5,7 @@ import ViewMitarbeiterProfil from "../../components/Cis/Profil/MitarbeiterViewPr import fhcapifactory from "../api/fhcapifactory.js"; import Loading from "../../components/Loader.js"; import Phrasen from "../../plugin/Phrasen.js"; +import fhcapi from "../../plugin/FhcApi.js"; Vue.$fhcapi = fhcapifactory; Vue.$collapseFormatter = function (data) { @@ -373,7 +374,7 @@ const profilApp = Vue.createApp({ //? uid contains the last part of the uri let uid = location.pathname.split("/").pop(); - Vue.$fhcapi.UserData.getView(uid).then((res) => { + this.$fhcApi.factory.profil.getView(uid).then((res) => { if (!res.data) { this.notFoundUID = uid; } else { @@ -403,4 +404,5 @@ const profilApp = Vue.createApp({ profilApp .use(primevue.config.default, { zIndex: { overlay: 9999 } }) .use(Phrasen) + .use(fhcapi) .mount("#content"); diff --git a/public/js/components/Cis/Profil/ProfilModal/EditProfilComponents/EditAdresse.js b/public/js/components/Cis/Profil/ProfilModal/EditProfilComponents/EditAdresse.js index 47842a8c3..d1199686c 100755 --- a/public/js/components/Cis/Profil/ProfilModal/EditProfilComponents/EditAdresse.js +++ b/public/js/components/Cis/Profil/ProfilModal/EditProfilComponents/EditAdresse.js @@ -43,6 +43,7 @@ export default { this.data.plz > 999 && this.data.plz < 32000 ) { + Vue.$fhcapi.UserData.getGemeinden(this.data.nation, this.data.plz).then( (res) => { if (res.data.length) { @@ -91,6 +92,8 @@ export default { }, created() { + + Vue.$fhcapi.UserData.getAllNationen().then((res) => { this.nationenList = res.data; this.getGemeinde(); From 84029fc72963b29f31af68524251c2864c6ca147 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Mon, 8 Jul 2024 15:15:08 +0200 Subject: [PATCH 02/17] updates editAdressen in the Profil --- application/controllers/Cis/Profil.php | 28 +-- .../controllers/api/frontend/v1/Profil.php | 27 +++ application/models/codex/Gemeinde_model.php | 24 ++ public/js/api/profil.js | 7 +- public/js/apps/Cis/Profil.js | 6 +- .../Cis/Profil/MitarbeiterProfil.js | 1 + .../ProfilComponents/ProfilInformation.js | 8 +- .../EditProfilComponents/EditAdresse.js | 221 +++++++++--------- .../js/components/Cis/Profil/StudentProfil.js | 3 + 9 files changed, 194 insertions(+), 131 deletions(-) diff --git a/application/controllers/Cis/Profil.php b/application/controllers/Cis/Profil.php index dd2c1a311..1141808fe 100755 --- a/application/controllers/Cis/Profil.php +++ b/application/controllers/Cis/Profil.php @@ -244,23 +244,23 @@ class Profil extends Auth_Controller $this->GemeindeModel->addDistinct(); $this->GemeindeModel->addSelect(["name"]); if ($nation == "A") { - if (isset($zip) && $zip > 999 && $zip < 32000) { + if (isset($zip) && $zip > 999 && $zip < 32000) { - $gemeinde_res = $this->GemeindeModel->loadWhere(['plz' => $zip]); - if (isError($gemeinde_res)) { - show_error("error while trying to query bis.tbl_gemeinde"); + $gemeinde_res = $this->GemeindeModel->loadWhere(['plz' => $zip]); + if (isError($gemeinde_res)) { + show_error("error while trying to query bis.tbl_gemeinde"); + } + $gemeinde_res = hasData($gemeinde_res) ? getData($gemeinde_res) : null; + $gemeinde_res = array_map(function ($obj) { + return $obj->name; + }, $gemeinde_res); + echo json_encode($gemeinde_res); + + } else { + echo json_encode(error("ortschaftskennziffer code was not valid")); } - $gemeinde_res = hasData($gemeinde_res) ? getData($gemeinde_res) : null; - $gemeinde_res = array_map(function ($obj) { - return $obj->name; - }, $gemeinde_res); - echo json_encode($gemeinde_res); - - } else { - echo json_encode(error("ortschaftskennziffer code was not valid")); - } } else { - echo json_encode(error("Nation was not 'A' (Austria)")); + echo json_encode(error("Nation was not 'A' (Austria)")); } } diff --git a/application/controllers/api/frontend/v1/Profil.php b/application/controllers/api/frontend/v1/Profil.php index 88679c636..401c0b791 100644 --- a/application/controllers/api/frontend/v1/Profil.php +++ b/application/controllers/api/frontend/v1/Profil.php @@ -34,6 +34,8 @@ class Profil extends FHCAPI_Controller parent::__construct([ 'getView' => self::PERM_LOGGED, 'fotoSperre' => self::PERM_LOGGED, + 'getGemeinden' => self::PERM_LOGGED, + ]); @@ -143,6 +145,31 @@ class Profil extends FHCAPI_Controller $this->terminateWithSuccess(current($res)); } + public function getGemeinden($nation, $zip) + { + if(!isset($nation) || !isset($zip)){ + echo json_encode(error("Missing parameters")); + return; + } + + $this->load->model('codex/Gemeinde_model', "GemeindeModel"); + + + $gemeinde_res = $this->GemeindeModel->getGemeindeByPlz($zip); + + if (isError($gemeinde_res)) { + $this->terminateWithError(getError($gemeinde_res),self::ERROR_TYPE_GENERAL); + } + $gemeinde_res = $this->getDataOrTerminateWithError($gemeinde_res); + + /* $gemeinde_res = array_map(function ($obj) { + return $obj->ortschaftsname; + }, $gemeinde_res); */ + + $this->terminateWithSuccess($gemeinde_res); + + } + // ----------------------------------------------------------------------------------------------------------------- // Private methods diff --git a/application/models/codex/Gemeinde_model.php b/application/models/codex/Gemeinde_model.php index c782346a0..92f0e0ca4 100755 --- a/application/models/codex/Gemeinde_model.php +++ b/application/models/codex/Gemeinde_model.php @@ -19,4 +19,28 @@ class Gemeinde_model extends DB_Model return $this->loadWhere(array("plz" => $plz)); } + + public function getGemeindeByNation($nation, $zip){ + + + $this->addSelect(["name"]); + + if ($nation == "A") { + if (isset($zip) && $zip > 999 && $zip < 32000) { + + $gemeinde_res = $this->GemeindeModel->loadWhere(['plz' => $zip]); + if (isError($gemeinde_res)) { + show_error("error while trying to query bis.tbl_gemeinde"); + } + $gemeinde_res = hasData($gemeinde_res) ? getData($gemeinde_res) : null; + $gemeinde_res = array_map(function ($obj) { + return $obj->name; + }, $gemeinde_res); + echo json_encode($gemeinde_res); + + } else { + echo json_encode(error("ortschaftskennziffer code was not valid")); + } + } else {} + } } \ No newline at end of file diff --git a/public/js/api/profil.js b/public/js/api/profil.js index e2fba5f83..eefe7d880 100755 --- a/public/js/api/profil.js +++ b/public/js/api/profil.js @@ -56,13 +56,12 @@ export default { ); }, - getGemeinden: function(nation,zip=null){ + getGemeinden: function(nation,zip){ return this.$fhcApi.get( FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + - "/api/frontend/v1/Profil/getGemeinden", - { nation: nation, - ...(zip? {zip:zip}:{}) } + `/api/frontend/v1/Profil/getGemeinden/${nation}/${zip}`, + {} ); }, diff --git a/public/js/apps/Cis/Profil.js b/public/js/apps/Cis/Profil.js index 3c3855147..f2726a3db 100755 --- a/public/js/apps/Cis/Profil.js +++ b/public/js/apps/Cis/Profil.js @@ -318,16 +318,16 @@ const profilApp = Vue.createApp({ ?.filter((item) => { return !this.data.profilUpdates?.some((update) => { return ( - update.status === "pending" && + update.status === this.profilUpdateStates["Pending"] && update.requested_change?.adresse_id == item.adresse_id ); }); }) - .map((kontakt) => { + .map((adresse) => { return { listview: "Adresse", view: "EditAdresse", - data: kontakt, + data: adresse, }; }), }, diff --git a/public/js/components/Cis/Profil/MitarbeiterProfil.js b/public/js/components/Cis/Profil/MitarbeiterProfil.js index a899b0050..6653c8253 100755 --- a/public/js/components/Cis/Profil/MitarbeiterProfil.js +++ b/public/js/components/Cis/Profil/MitarbeiterProfil.js @@ -238,6 +238,7 @@ export default { created() { //? sorts the profil Updates: pending -> accepted -> rejected this.data.profilUpdates?.sort(this.sortProfilUpdates); + }, template: /*html*/ ` diff --git a/public/js/components/Cis/Profil/ProfilComponents/ProfilInformation.js b/public/js/components/Cis/Profil/ProfilComponents/ProfilInformation.js index a82f7bf3e..78e198170 100755 --- a/public/js/components/Cis/Profil/ProfilComponents/ProfilInformation.js +++ b/public/js/components/Cis/Profil/ProfilComponents/ProfilInformation.js @@ -20,11 +20,9 @@ export default { if (!this.data) { return; } - Vue.$fhcapi.UserData.sperre_foto_function(!this.FotoSperre).then( - (res) => { - this.FotoSperre = res.data.foto_sperre; - } - ); + this.$fhcApi.factory.profil.fotoSperre(!this.FotoSperre).then(res =>{ + this.FotoSperre = res.data.foto_sperre; + }) }, }, computed: { diff --git a/public/js/components/Cis/Profil/ProfilModal/EditProfilComponents/EditAdresse.js b/public/js/components/Cis/Profil/ProfilModal/EditProfilComponents/EditAdresse.js index d1199686c..e51bef24c 100755 --- a/public/js/components/Cis/Profil/ProfilModal/EditProfilComponents/EditAdresse.js +++ b/public/js/components/Cis/Profil/ProfilModal/EditProfilComponents/EditAdresse.js @@ -16,6 +16,7 @@ export default { data() { return { gemeinden: [], + ortschaftnamen: [], selectedNation: null, nationenList: [], originalValue: null, @@ -27,13 +28,25 @@ export default { "data.gemeinde": function (newValue, oldValue) { this.$emit("profilUpdate", this.isChanged ? this.data : null); }, + "data.ort": function (newValue, oldValue) { + this.$emit("profilUpdate", this.isChanged ? this.data : null); + }, }, methods: { - autocompleteSearch: function (event) { + test: function () { + console.log(this.gemeinden, "this are the gemeinden"); + console.log(this.ortschaftnamen, "this are the ortschaftsnamen"); + }, + + autocompleteSearchGemeinden: function (event) { this.gemeinden = this.gemeinden.map((gemeinde) => gemeinde); }, + autocompleteSearchOrtschaftsnamen: function (event) { + this.ortschaftnamen = this.ortschaftnamen.map((ortschaft) => ortschaft); + }, + getGemeinde: function () { //? only query the gemeinde is the nation is Austria and the PLZ is greater than 999 and less than 32000 if ( @@ -43,14 +56,27 @@ export default { this.data.plz > 999 && this.data.plz < 32000 ) { - - Vue.$fhcapi.UserData.getGemeinden(this.data.nation, this.data.plz).then( - (res) => { + this.$fhcApi.factory.profil + .getGemeinden(this.data.nation, this.data.plz) + .then((res) => { if (res.data.length) { - this.gemeinden = res.data; + console.log(res.data, "this is the data from the gemeinden"); + this.gemeinden = [ + ...new Set( + res.data.map((element) => { + return element.name; + }) + ), + ]; + this.ortschaftnamen = [ + ...new Set( + res.data.map((element) => { + return element.ortschaftsname; + }) + ), + ]; } - } - ); + }); } else { this.gemeinden = []; } @@ -87,13 +113,12 @@ export default { ) { return false; } + return this.originalValue !== JSON.stringify(this.data); }, }, created() { - - Vue.$fhcapi.UserData.getAllNationen().then((res) => { this.nationenList = res.data; this.getGemeinde(); @@ -104,103 +129,89 @@ export default { }, template: /*html*/ ` -
- - -
-
-
- {{$p.t('profilUpdate','zustelladresseWarning')}} -
-
-
- +
- -
- - -
- - -
- - - - - -
- - -
- -
-
{{$p.t('person','strasse')}}*
- - -
- - -
- -
- -
-
{{$p.t('profilUpdate','kontaktTyp')}}*
- - -
- - - - - -
- -
- -
-
{{$p.t('person','ort')}}*
- - -
-
-
-
-
{{$p.t('person','plz')}}*
- - - -
-
-
- -
-
{{$p.t('person','gemeinde')}}*
- -
-
-
-
-
{{$p.t('person','nation')}}*
- - -
-
- + +
+
+
+ {{$p.t('profilUpdate','zustelladresseWarning')}} +
+
+ + + +
+
+ + +
+
+ + +
+
+
{{$p.t('person','nation')}}*
+ +
+
+ + +
+
+
{{$p.t('person','plz')}}*
+ +
+
+ + +
+
+
{{$p.t('person','gemeinde')}}*
+ +
+
+ + +
+
+
{{$p.t('person','ort')}}*
+ +
+
+ + +
+
+
{{$p.t('person','strasse')}}*
+ +
+
+ + +
+
+
{{$p.t('profilUpdate','kontaktTyp')}}*
+ +
+
+ + + + + +
`, }; diff --git a/public/js/components/Cis/Profil/StudentProfil.js b/public/js/components/Cis/Profil/StudentProfil.js index 059742c69..ffb0d0fd3 100755 --- a/public/js/components/Cis/Profil/StudentProfil.js +++ b/public/js/components/Cis/Profil/StudentProfil.js @@ -85,6 +85,7 @@ export default { editData: Object, }, methods: { + betriebsmittelTableBuilt: function () { this.$refs.betriebsmittelTable.tabulator.setData(this.data.mittel); }, @@ -181,6 +182,7 @@ export default { created() { //? sorts the profil Updates: pending -> accepted -> rejected this.data.profilUpdates?.sort(this.sortProfilUpdates); + }, @@ -205,6 +207,7 @@ export default {
+ - `:'' + ` + : + `` }
`; @@ -302,7 +304,7 @@ export default { }, methods: { denyProfilUpdate: function (data) { - Vue.$fhcapi.ProfilUpdate.denyProfilRequest(data) + this.$fhcApi.factory.profilUpdate.denyProfilRequest(data) .then((res) => { // block when the request was successful }) @@ -314,7 +316,7 @@ export default { }); }, acceptProfilUpdate: function (data) { - Vue.$fhcapi.ProfilUpdate.acceptProfilRequest(data) + this.$fhcApi.factory.profilUpdate.acceptProfilRequest(data) .then((res) => { // block when the request was successful }) From a06f9b581fe0677f74768c892b6a353f0384f7b5 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Fri, 19 Jul 2024 13:11:58 +0200 Subject: [PATCH 10/17] adds selectProfilRequest to the new ProfilUpdate FhcAPIController --- .../api/frontend/v1/ProfilUpdate.php | 19 +++++++++++++++++++ public/js/api/profilUpdate.js | 13 +++++-------- .../Cis/Profil/MitarbeiterProfil.js | 14 ++++++-------- .../js/components/Cis/Profil/StudentProfil.js | 12 ++++++------ 4 files changed, 36 insertions(+), 22 deletions(-) diff --git a/application/controllers/api/frontend/v1/ProfilUpdate.php b/application/controllers/api/frontend/v1/ProfilUpdate.php index 706f2bf29..75e3bf9f0 100644 --- a/application/controllers/api/frontend/v1/ProfilUpdate.php +++ b/application/controllers/api/frontend/v1/ProfilUpdate.php @@ -43,6 +43,7 @@ class ProfilUpdate extends FHCAPI_Controller 'getProfilRequestFiles' => self::PERM_LOGGED, 'denyProfilRequest' => ['student/stammdaten:rw', 'mitarbeiter/stammdaten:rw'], 'acceptProfilRequest' => ['student/stammdaten:rw', 'mitarbeiter/stammdaten:rw'], + 'selectProfilRequest' => self::PERM_LOGGED, ]); @@ -115,6 +116,24 @@ class ProfilUpdate extends FHCAPI_Controller $this->terminateWithSuccess(self::$TOPICS); } + public function selectProfilRequest() + { + + $uid = $this->input->get('uid',true); + $id = $this->input->get('id',true); + $whereClause = ['uid' => $this->uid]; + + if (isset($uid)) + $whereClause['uid'] = $uid; + if (isset($id)) + $whereClause['id'] = $id; + + $res = $this->ProfilUpdateModel->getProfilUpdatesWhere($whereClause); + $res = $this->getDataOrTerminateWithError($res); + $this->terminateWithSuccess($res); + + } + public function getProfilRequestFiles($id) { if(!$id){ diff --git a/public/js/api/profilUpdate.js b/public/js/api/profilUpdate.js index 8d121fa65..ccef2f0b2 100644 --- a/public/js/api/profilUpdate.js +++ b/public/js/api/profilUpdate.js @@ -43,7 +43,7 @@ export default { }, //TODO post request - //? new reuquests + //? new requests insertFile: function (dms, replace = null) { const url = FHC_JS_DATA_STORAGE_OBJECT.app_root + @@ -61,19 +61,16 @@ export default { FHC_JS_DATA_STORAGE_OBJECT.ci_router + `/api/frontend/v1/ProfilUpdate/getProfilRequestFiles/${requestID}`,{}); }, - - search(searchsettings) { - const url = '/api/frontend/v1/searchbar/search'; - return this.$fhcApi.post(url, searchsettings); - }, - selectProfilRequest: function (uid = null, id = null) { return this.$fhcApi.get( FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + - `/Cis/ProfilUpdate/selectProfilRequest`,{ uid: uid, id: id }); + `/api/frontend/v1/ProfilUpdate/selectProfilRequest`, + {...(uid?{uid}:{}), + ...(id?{id}:{}) + }); }, //TODO post request diff --git a/public/js/components/Cis/Profil/MitarbeiterProfil.js b/public/js/components/Cis/Profil/MitarbeiterProfil.js index 6653c8253..94ae0078f 100755 --- a/public/js/components/Cis/Profil/MitarbeiterProfil.js +++ b/public/js/components/Cis/Profil/MitarbeiterProfil.js @@ -151,17 +151,17 @@ export default { hideEditProfilModal: function () { //? checks the editModal component property result, if the user made a successful request or not if (this.$refs.editModal.result) { - Vue.$fhcapi.ProfilUpdate.selectProfilRequest() + this.$fhcApi.factory.profilUpdate.selectProfilRequest() .then((request) => { - if (!request.error) { + if (!request.error && request) { this.data.profilUpdates = request.data; this.data.profilUpdates.sort(this.sortProfilUpdates); } else { - console.log("Error when fetching profile updates: " + res.data); + console.error("Error when fetching profile updates: " + res.data); } }) .catch((err) => { - console.log(err); + console.error(err); }); } else { // when modal was closed without submitting request @@ -184,8 +184,8 @@ export default { }, fetchProfilUpdates: function () { - Vue.$fhcapi.ProfilUpdate.selectProfilRequest().then((res) => { - if (!res.error) { + this.$fhcApi.factory.profilUpdate.selectProfilRequest().then((res) => { + if (!res.error && res) { this.data.profilUpdates = res.data?.length ? res.data.sort(this.sortProfilUpdates) : null; @@ -451,8 +451,6 @@ export default {
- - diff --git a/public/js/components/Cis/Profil/StudentProfil.js b/public/js/components/Cis/Profil/StudentProfil.js index ffb0d0fd3..5cf92fd9f 100755 --- a/public/js/components/Cis/Profil/StudentProfil.js +++ b/public/js/components/Cis/Profil/StudentProfil.js @@ -95,8 +95,8 @@ export default { ); }, fetchProfilUpdates: function () { - Vue.$fhcapi.ProfilUpdate.selectProfilRequest().then((res) => { - if (!res.error) { + this.$fhcApi.factory.profilUpdate.selectProfilRequest().then((res) => { + if (!res.error && res) { this.data.profilUpdates = res.data?.length ? res.data.sort(this.sortProfilUpdates) : null; @@ -107,17 +107,17 @@ export default { hideEditProfilModal: function () { //? checks the editModal component property result, if the user made a successful request or not if (this.$refs.editModal.result) { - Vue.$fhcapi.ProfilUpdate.selectProfilRequest() + this.$fhcApi.factory.profilUpdate.selectProfilRequest() .then((request) => { - if (!request.error) { + if (!request.error && res) { this.data.profilUpdates = request.data; this.data.profilUpdates.sort(this.sortProfilUpdates); } else { - console.log("Error when fetching profile updates: " + res.data); + console.error("Error when fetching profile updates: " + res.data); } }) .catch((err) => { - console.log(err); + console.error(err); }); } else { // when modal was closed without submitting request From 12626511e93da3cd60cc521a0a1501d76cc84b4e Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Fri, 19 Jul 2024 14:00:40 +0200 Subject: [PATCH 11/17] adds insertProfilRequest to the new ProfilUpdate FhcAPIController --- .../api/frontend/v1/ProfilUpdate.php | 146 +++++++++++++++++- public/js/api/profilUpdate.js | 16 +- .../js/components/Calendar/CalendarModal.js | 2 +- .../Cis/Profil/ProfilModal/EditProfil.js | 20 ++- 4 files changed, 166 insertions(+), 18 deletions(-) diff --git a/application/controllers/api/frontend/v1/ProfilUpdate.php b/application/controllers/api/frontend/v1/ProfilUpdate.php index 75e3bf9f0..27bc10349 100644 --- a/application/controllers/api/frontend/v1/ProfilUpdate.php +++ b/application/controllers/api/frontend/v1/ProfilUpdate.php @@ -44,7 +44,7 @@ class ProfilUpdate extends FHCAPI_Controller 'denyProfilRequest' => ['student/stammdaten:rw', 'mitarbeiter/stammdaten:rw'], 'acceptProfilRequest' => ['student/stammdaten:rw', 'mitarbeiter/stammdaten:rw'], 'selectProfilRequest' => self::PERM_LOGGED, - + 'insertProfilRequest' => self::PERM_LOGGED, ]); // Load language phrases @@ -134,6 +134,81 @@ class ProfilUpdate extends FHCAPI_Controller } + public function insertProfilRequest() + { + + $payload = $this->input->post('payload',true); + $topic = $this->input->post('topic',true); + $fileID = $this->input->post('fileID',true); + + if(!isset($payload) || !isset($topic)){ + $this->terminateWithError("required parameters are missing"); + } + + $identifier = array_key_exists("kontakt_id", $payload) ? "kontakt_id" : (array_key_exists("adresse_id", $payload) ? "adresse_id" : null); + + $data = ["topic" => $topic, "uid" => $this->uid, "requested_change" => json_encode($payload), "insertamum" => "NOW()", "insertvon" => $this->uid, "status" => self::$STATUS_PENDING ?: 'Pending']; + + //? insert fileID in the dataset if sent with post request + if (isset($fileID)) { + $data['attachment_id'] = $fileID; + } + + //? loops over all updateRequests from a user to validate if the new request is valid + $res = $this->ProfilUpdateModel->getProfilUpdatesWhere(["uid" => $this->uid]); + if (isError($res)) { + $this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_loading_error')); + } + $res = $this->getDataOrTerminateWithError($res); + + //? the user cannot delete a zustelladresse/kontakt + if (isset($payload->delete) && $payload->{$identifier == "kontakt_id" ? "zustellung" : "zustelladresse"}) { + $this->terminateWithError(error($this->p->t('profilUpdate', 'profilUpdate_deleteZustellung_error'))); + } + + //? if the user tries to delete a adresse, checks whether the adresse is a heimatadresse, if so an error is raised + if (isset($payload->delete) && $identifier == "adresse_id") { + $adr = $this->AdresseModel->load($payload->$identifier); + $adr = $this->getDataOrTerminateWithError($adr)[0]; + if ($adr->heimatadresse) { + $this->terminateWithError(error($this->p->t('profilUpdate', 'profilUpdate_deleteZustellung_error'))); + } + } + + if ($res) { + $pending_changes = array_filter($res, function ($element) { + return $element->status == (self::$STATUS_PENDING ?: "Pending"); + }); + + foreach ($pending_changes as $update_request) { + $existing_change = $update_request->requested_change; + + //? the user can add as many new kontakte/adressen as he likes + if (!isset($payload->add) && property_exists($existing_change, $identifier) && property_exists($payload, $identifier) && $existing_change->$identifier == $payload->$identifier) { + //? the kontakt_id / adresse_id of a change has to be unique + $this->terminateWithError(error($this->p->t('profilUpdate', 'profilUpdate_changeTwice_error'))); + } + + //? if it is not updating any kontakt/adresse, the topic has to be unique + elseif (!$identifier && $update_request->topic == $topic) { + $this->terminateWithError(error($this->p->t('profilUpdate', 'profilUpdate_changeTopicTwice_error', ['0' => $update_request->topic]))); + } + } + } + + $insertID = $this->ProfilUpdateModel->insert($data); + + if (isError($insertID)) { + $this->terminateWithError(error($insertID)); + } else { + + $insertID = hasData($insertID) ? getData($insertID) : null; + //? sends emails to the correspondents of the $uid + $this->sendEmail_onProfilUpdate_insertion($this->uid, $insertID, $topic); + $this->terminateWithSuccess(success($insertID)); + } + } + public function getProfilRequestFiles($id) { if(!$id){ @@ -277,6 +352,75 @@ class ProfilUpdate extends FHCAPI_Controller // Private methods + private function sendEmail_onProfilUpdate_insertion($uid, $profil_update_id, $topic) + { + + $this->load->helper('hlp_sancho_helper'); + $emails = []; + + $is_mitarbeiter = $this->MitarbeiterModel->isMitarbeiter($uid); + if (isError($is_mitarbeiter)) { + $this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_mitarbeiterCheck_error')); + } + $is_mitarbeiter = $this->getDataOrTerminateWithError($is_mitarbeiter); + + //! if the $uid is a mitarbeiter and student, only the hr is notified by email + if ($is_mitarbeiter) { + //? user is not a student therefore he is a mitarbeiter, send email to Personalverwaltung + //? use constant variable MAIL_GST to mail to the personalverwaltung + $this->MitarbeiterModel->addSelect([TRUE]); + $this->MitarbeiterModel->addJoin("public.tbl_benutzer", "public.tbl_benutzer.uid = public.tbl_mitarbeiter.mitarbeiter_uid"); + //? check if the the userID is a mitarbeiter and if the benutzer is active + $res = $this->MitarbeiterModel->loadWhere(["public.tbl_mitarbeiter.mitarbeiter_uid" => $uid, "public.tbl_benutzer.aktiv" => TRUE]); + if (isError($res)) { + $this->terminateWithError("was not able to query the mitarbeiter and benutzer by the uid: " . $uid); + } + if (hasData($res)) { + array_push($emails, MAIL_GST); + } else { + $this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_mitarbeiterCheck_error')); + } + } else { + //? if it is not a mitarbeiter, check whether it is a student and send email to studiengang + $is_student = $this->StudentModel->isStudent($uid); + if (isError($is_student)) { + $this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_studentCheck_error')); + } + $is_student = $this->getDataOrTerminateWithError($is_student); + if ($is_student) { + //? Send email to the Studiengangsassistentinnen + $this->StudentModel->addSelect(["public.tbl_studiengang.email"]); + $this->StudentModel->addJoin("public.tbl_benutzer", "public.tbl_benutzer.uid = public.tbl_student.student_uid"); + $this->StudentModel->addJoin("public.tbl_prestudent", "public.tbl_benutzer.person_id = public.tbl_prestudent.person_id"); + $this->StudentModel->addJoin("public.tbl_prestudentstatus", "public.tbl_prestudentstatus.prestudent_id = public.tbl_prestudent.prestudent_id"); + $this->StudentModel->addJoin("public.tbl_studiengang", "public.tbl_studiengang.studiengang_kz = public.tbl_prestudent.studiengang_kz"); + //* check if the benutzer itself is active + //* check if the student status is Student or Diplomand (active students) + $this->StudentModel->db->where_in("public.tbl_prestudentstatus.status_kurzbz", ['Student', 'Diplomand']); + $res = $this->StudentModel->loadWhere(["public.tbl_benutzer.aktiv" => TRUE, "public.tbl_student.student_uid" => $uid]); + if (isError($res)) { + $this->terminateWithError(getData($res)); + } else { + $res = $this->getDataOrTerminateWithError($res); + foreach ($res as $emailObj) { + array_push($emails, $emailObj->email); + } + } + } + } + $mail_res = []; + //? sending email + foreach ($emails as $email) { + array_push($mail_res, sendSanchoMail("profil_update", ['uid' => $uid, 'topic' => $topic, 'href' => APP_ROOT . 'Cis/ProfilUpdate/id/' . $profil_update_id], $email, ("Profil Änderung von " . $uid))); + } + foreach ($mail_res as $m_res) { + if (!$m_res) { + $this->addError($this->p->t('profilUpdate', 'profilUpdate_email_error')); + } + } + + } + private function sendEmail_onProfilUpdate_response($uid, $topic, $status) { $this->load->helper('hlp_sancho_helper'); diff --git a/public/js/api/profilUpdate.js b/public/js/api/profilUpdate.js index ccef2f0b2..ea4ca69c7 100644 --- a/public/js/api/profilUpdate.js +++ b/public/js/api/profilUpdate.js @@ -75,16 +75,16 @@ export default { //TODO post request insertProfilRequest: function (topic, payload, fileID = null) { - const url = + + return this.$fhcApi.post( FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + - `/Cis/ProfilUpdate/insertProfilRequest`; - - return axios.post(url, { - topic, - payload, - ...(fileID ? { fileID: fileID } : {}), - }); + "/api/frontend/v1/ProfilUpdate/insertProfilRequest", + { + topic, + payload, + ...(fileID ? { fileID } : {}), + }); }, //TODO post request diff --git a/public/js/components/Calendar/CalendarModal.js b/public/js/components/Calendar/CalendarModal.js index 5f6fd9d09..293ca49b8 100644 --- a/public/js/components/Calendar/CalendarModal.js +++ b/public/js/components/Calendar/CalendarModal.js @@ -95,7 +95,7 @@ export default { .catch((err) => { console.error(err); }) - : Vue.$fhcapi.ProfilUpdate.insertProfilRequest( + : this.$fhcApi.factory.profilUpdate.insertProfilRequest( this.topic, this.profilUpdate, this.fileID ? this.fileID[0] : null diff --git a/public/js/components/Cis/Profil/ProfilModal/EditProfil.js b/public/js/components/Cis/Profil/ProfilModal/EditProfil.js index 189dd8f5d..e3b2f08f3 100755 --- a/public/js/components/Cis/Profil/ProfilModal/EditProfil.js +++ b/public/js/components/Cis/Profil/ProfilModal/EditProfil.js @@ -55,6 +55,10 @@ export default { }, async submitProfilChange() { + + //todo delete this debugging line + console.log("this is a test") + //? check if data is valid before making a request if (this.topic && this.profilUpdate) { //? if profil update contains any attachment @@ -71,18 +75,18 @@ export default { this.loading = false; this.setLoading(false); - if (res.data.error == 0) { - this.result = true; - this.hide(); - Alert.popup( - "Ihre Anfrage wurde erfolgreich gesendet. Bitte warten Sie, während sich das Team um Ihre Anfrage kümmert." - ); - } else { + if (res.data.error) { this.result = false; this.hide(); Alert.popup( "Ein Fehler ist aufgetreten: " + JSON.stringify(res.data.retval) ); + } else { + this.result = true; + this.hide(); + Alert.popup( + "Ihre Anfrage wurde erfolgreich gesendet. Bitte warten Sie, während sich das Team um Ihre Anfrage kümmert." + ); } }; @@ -104,7 +108,7 @@ export default { .catch((err) => { console.error(err); }) - : Vue.$fhcapi.ProfilUpdate.insertProfilRequest( + : this.$fhcApi.factory.profilUpdate.insertProfilRequest( this.topic, this.profilUpdate, this.fileID ? this.fileID[0] : null From 8700abd0fae34c3592448af282029214ba9184e8 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Fri, 19 Jul 2024 14:50:00 +0200 Subject: [PATCH 12/17] adds updateProfilRequest to the new ProfilUpdate FhcAPIController --- .../api/frontend/v1/ProfilUpdate.php | 55 ++++++++++++++----- public/js/api/profilUpdate.js | 20 +++---- .../js/components/Calendar/CalendarModal.js | 2 +- .../Cis/Profil/ProfilModal/EditProfil.js | 2 +- system/phrasesupdate.php | 2 +- 5 files changed, 54 insertions(+), 27 deletions(-) diff --git a/application/controllers/api/frontend/v1/ProfilUpdate.php b/application/controllers/api/frontend/v1/ProfilUpdate.php index 27bc10349..c9b453c78 100644 --- a/application/controllers/api/frontend/v1/ProfilUpdate.php +++ b/application/controllers/api/frontend/v1/ProfilUpdate.php @@ -45,6 +45,8 @@ class ProfilUpdate extends FHCAPI_Controller 'acceptProfilRequest' => ['student/stammdaten:rw', 'mitarbeiter/stammdaten:rw'], 'selectProfilRequest' => self::PERM_LOGGED, 'insertProfilRequest' => self::PERM_LOGGED, + 'updateProfilRequest' => self::PERM_LOGGED, + ]); // Load language phrases @@ -163,7 +165,7 @@ class ProfilUpdate extends FHCAPI_Controller //? the user cannot delete a zustelladresse/kontakt if (isset($payload->delete) && $payload->{$identifier == "kontakt_id" ? "zustellung" : "zustelladresse"}) { - $this->terminateWithError(error($this->p->t('profilUpdate', 'profilUpdate_deleteZustellung_error'))); + $this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_deleteZustellung_error')); } //? if the user tries to delete a adresse, checks whether the adresse is a heimatadresse, if so an error is raised @@ -171,7 +173,7 @@ class ProfilUpdate extends FHCAPI_Controller $adr = $this->AdresseModel->load($payload->$identifier); $adr = $this->getDataOrTerminateWithError($adr)[0]; if ($adr->heimatadresse) { - $this->terminateWithError(error($this->p->t('profilUpdate', 'profilUpdate_deleteZustellung_error'))); + $this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_deleteZustellung_error')); } } @@ -186,12 +188,12 @@ class ProfilUpdate extends FHCAPI_Controller //? the user can add as many new kontakte/adressen as he likes if (!isset($payload->add) && property_exists($existing_change, $identifier) && property_exists($payload, $identifier) && $existing_change->$identifier == $payload->$identifier) { //? the kontakt_id / adresse_id of a change has to be unique - $this->terminateWithError(error($this->p->t('profilUpdate', 'profilUpdate_changeTwice_error'))); + $this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_changeTwice_error')); } //? if it is not updating any kontakt/adresse, the topic has to be unique elseif (!$identifier && $update_request->topic == $topic) { - $this->terminateWithError(error($this->p->t('profilUpdate', 'profilUpdate_changeTopicTwice_error', ['0' => $update_request->topic]))); + $this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_changeTopicTwice_error', ['0' => $update_request->topic])); } } } @@ -199,7 +201,7 @@ class ProfilUpdate extends FHCAPI_Controller $insertID = $this->ProfilUpdateModel->insert($data); if (isError($insertID)) { - $this->terminateWithError(error($insertID)); + $this->terminateWithError(getError($insertID)); } else { $insertID = hasData($insertID) ? getData($insertID) : null; @@ -209,6 +211,33 @@ class ProfilUpdate extends FHCAPI_Controller } } + public function updateProfilRequest() + { + $topic = $this->input->post('topic', true); + $payload = $this->input->post('payload', true); + $ID = $this->input->post('ID', true); + $fileID = $this->input->post('fileID', true);//optional + + if(!isset($topic) || !isset($payload) || !isset($ID)){ + $this->terminateWithError("required parameters are missing"); + } + + $updateData = ["requested_change" => json_encode($payload), "updateamum" => "NOW()", "updatevon" => $this->uid]; + if (isset($fileID)) { + $updateData['attachment_id'] = json_decode($fileID); + } + $updateID = $this->ProfilUpdateModel->update([$ID], $updateData); + //? insert fileID in the dataset if sent with post request + + if (isError($updateID)) { + $this->terminateWithError(getError($updateID)); + } + + $updateID = $this->getDataOrTerminateWithError($updateID)[0]; + + $this->terminateWithSuccess(success($updateID)); + } + public function getProfilRequestFiles($id) { if(!$id){ @@ -218,7 +247,7 @@ class ProfilUpdate extends FHCAPI_Controller $this->ProfilUpdateModel->addSelect(["attachment_id"]); $attachmentID = $this->ProfilUpdateModel->load([$id]); if (isError($attachmentID)) { - $this->terminateWithError(error($this->p->t('profilUpdate', 'profilUpdate_loading_error')),self::ERROR_TYPE_GENERAL); + $this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_loading_error'),self::ERROR_TYPE_GENERAL); } //? get the attachmentID $dms_id = $this->getDataOrTerminateWithError($attachmentID)[0]->attachment_id; @@ -227,7 +256,7 @@ class ProfilUpdate extends FHCAPI_Controller $this->DmsVersionModel->addSelect(["name", "dms_id"]); $attachment = $this->DmsVersionModel->load([$dms_id, 0]); if (isError($attachment)) { - $this->terminateWithError(error($this->p->t('profilUpdate', 'profilUpdate_dmsVersion_error')),self::ERROR_TYPE_GENERAL); + $this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_dmsVersion_error'),self::ERROR_TYPE_GENERAL); } $attachment = $this->getDataOrTerminateWithError($attachment); //? returns {name:..., dms_id:...} @@ -276,7 +305,7 @@ class ProfilUpdate extends FHCAPI_Controller //! check for required information if (!isset($id) || !isset($uid) || !isset($personID) || !isset($requested_change) || !isset($topic)) { - $this->terminateWithError(error($this->p->t('profilUpdate', 'profilUpdate_requiredInformation_error'))); + $this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_requiredInformation_error')); } $is_mitarbeiter = $this->MitarbeiterModel->isMitarbeiter($uid); @@ -299,7 +328,7 @@ class ProfilUpdate extends FHCAPI_Controller $requested_change['adresse_id'] = $insertID; $update_res = $this->updateRequestedChange($id, $requested_change); if (isError($update_res)) { - $this->terminateWithError(error($this->p->t('profilUpdate', 'profilUpdate_address_error', [$insertID]))); + $this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_address_error', [$insertID])); } } @@ -310,7 +339,7 @@ class ProfilUpdate extends FHCAPI_Controller $requested_change['kontakt_id'] = $insertID; $update_res = $this->updateRequestedChange($id, $requested_change); if (isError($update_res)) { - $this->terminateWithError(error($this->p->t('profilUpdate', 'profilUpdate_kontakt_error', [$insertID]))); + $this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_kontakt_error', [$insertID])); } } @@ -335,7 +364,7 @@ class ProfilUpdate extends FHCAPI_Controller } $result = $this->PersonModel->update($personID, [$topic => $requested_change["value"]]); - if (isError($result)) $this->terminateWithError(error($this->p->t('profilUpdate', 'profilUpdate_insert_error'))); + if (isError($result)) $this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_insert_error')); } $this->sendEmail_onProfilUpdate_response($uid, $topic, self::$STATUS_ACCEPTED); @@ -399,7 +428,7 @@ class ProfilUpdate extends FHCAPI_Controller $this->StudentModel->db->where_in("public.tbl_prestudentstatus.status_kurzbz", ['Student', 'Diplomand']); $res = $this->StudentModel->loadWhere(["public.tbl_benutzer.aktiv" => TRUE, "public.tbl_student.student_uid" => $uid]); if (isError($res)) { - $this->terminateWithError(getData($res)); + $this->terminateWithError(getError($res)); } else { $res = $this->getDataOrTerminateWithError($res); foreach ($res as $emailObj) { @@ -498,7 +527,7 @@ class ProfilUpdate extends FHCAPI_Controller elseif (array_key_exists('delete', $requested_change) && $requested_change['delete']) { $result = $this->AdresseModel->delete($adresse_id); if(isError($result)){ - $this->terminateWithError(error($result)); + $this->terminateWithError(getError($result)); } } //! UPDATE diff --git a/public/js/api/profilUpdate.js b/public/js/api/profilUpdate.js index ea4ca69c7..50ced7cdd 100644 --- a/public/js/api/profilUpdate.js +++ b/public/js/api/profilUpdate.js @@ -73,7 +73,6 @@ export default { }); }, - //TODO post request insertProfilRequest: function (topic, payload, fileID = null) { return this.$fhcApi.post( @@ -87,19 +86,18 @@ export default { }); }, - //TODO post request updateProfilRequest: function (topic, payload, ID, fileID = null) { - const url = + + return this.$fhcApi.post( FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + - `/Cis/ProfilUpdate/updateProfilRequest`; - - return axios.post(url, { - topic, - payload, - ID, - ...(fileID ? { fileID: fileID } : {}), - }); + `/api/frontend/v1/ProfilUpdate/updateProfilRequest`, + { + topic, + payload, + ID, + ...(fileID ? { fileID: fileID } : {}), + }); }, //TODO post request diff --git a/public/js/components/Calendar/CalendarModal.js b/public/js/components/Calendar/CalendarModal.js index 293ca49b8..a9a11f8f7 100644 --- a/public/js/components/Calendar/CalendarModal.js +++ b/public/js/components/Calendar/CalendarModal.js @@ -83,7 +83,7 @@ export default { this.setLoading(true); this.editData.updateID - ? Vue.$fhcapi.ProfilUpdate.updateProfilRequest( + ? this.$fhcApi.factory.profilUpdate.updateProfilRequest( this.topic, this.profilUpdate, this.editData.updateID, diff --git a/public/js/components/Cis/Profil/ProfilModal/EditProfil.js b/public/js/components/Cis/Profil/ProfilModal/EditProfil.js index e3b2f08f3..86b704c25 100755 --- a/public/js/components/Cis/Profil/ProfilModal/EditProfil.js +++ b/public/js/components/Cis/Profil/ProfilModal/EditProfil.js @@ -96,7 +96,7 @@ export default { this.setLoading(true); this.editData.updateID - ? Vue.$fhcapi.ProfilUpdate.updateProfilRequest( + ? this.$fhcApi.factory.profilUpdate.updateProfilRequest( this.topic, this.profilUpdate, this.editData.updateID, diff --git a/system/phrasesupdate.php b/system/phrasesupdate.php index 8c140ea63..8dc1d163f 100755 --- a/system/phrasesupdate.php +++ b/system/phrasesupdate.php @@ -25873,7 +25873,7 @@ array( 'phrases' => array( array( 'sprache' => 'German', - 'text' => '!Achtung: Eine deiner Adressen ist bereits als Zustelladresse gespeichert, sind sie sicher, dass sie die aktuelle Adresse stattdessen als Zustelladresse speichern wollen?', + 'text' => '!Achtung: Eine Ihrer Adressen ist bereits als Zustelladresse gespeichert, sind sie sicher, dass sie die aktuelle Adresse stattdessen als Zustelladresse speichern wollen?', 'description' => '', 'insertvon' => 'system' ), From 0cc62221757639ad30f4afe7d1777fa246a65fa8 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Fri, 19 Jul 2024 14:57:42 +0200 Subject: [PATCH 13/17] adds deleteProfilRequest to the new ProfilUpdate FhcAPIController --- .../controllers/api/frontend/v1/ProfilUpdate.php | 15 +++++++++++++-- public/js/api/profilUpdate.js | 11 ++++++----- .../Profil/ProfilComponents/FetchProfilUpdates.js | 5 +++-- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/application/controllers/api/frontend/v1/ProfilUpdate.php b/application/controllers/api/frontend/v1/ProfilUpdate.php index c9b453c78..44d70afb4 100644 --- a/application/controllers/api/frontend/v1/ProfilUpdate.php +++ b/application/controllers/api/frontend/v1/ProfilUpdate.php @@ -46,8 +46,8 @@ class ProfilUpdate extends FHCAPI_Controller 'selectProfilRequest' => self::PERM_LOGGED, 'insertProfilRequest' => self::PERM_LOGGED, 'updateProfilRequest' => self::PERM_LOGGED, - - ]); + 'deleteProfilRequest' => self::PERM_LOGGED, + ]); // Load language phrases $this->loadPhrases( @@ -238,6 +238,17 @@ class ProfilUpdate extends FHCAPI_Controller $this->terminateWithSuccess(success($updateID)); } + public function deleteProfilRequest() + { + + $requestID = $this->input->post('requestID', true); + $result = $this->ProfilUpdateModel->delete([$requestID]); + if (isError($result)) { + $this->terminateWithError(getError($result)); + } + $this->terminateWithSuccess($result); + } + public function getProfilRequestFiles($id) { if(!$id){ diff --git a/public/js/api/profilUpdate.js b/public/js/api/profilUpdate.js index 50ced7cdd..742e4a1b1 100644 --- a/public/js/api/profilUpdate.js +++ b/public/js/api/profilUpdate.js @@ -100,14 +100,15 @@ export default { }); }, - //TODO post request deleteProfilRequest: function (requestID) { - const url = + + return this.$fhcApi.post( FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + - `/Cis/ProfilUpdate/deleteProfilRequest`; - - return axios.post(url, requestID); + `/api/frontend/v1/ProfilUpdate/deleteProfilRequest`, + { + requestID, + }); }, }; \ No newline at end of file diff --git a/public/js/components/Cis/Profil/ProfilComponents/FetchProfilUpdates.js b/public/js/components/Cis/Profil/ProfilComponents/FetchProfilUpdates.js index 368b5e111..9caee9468 100755 --- a/public/js/components/Cis/Profil/ProfilComponents/FetchProfilUpdates.js +++ b/public/js/components/Cis/Profil/ProfilComponents/FetchProfilUpdates.js @@ -107,17 +107,18 @@ export default { }, deleteRequest: function (item) { - Vue.$fhcapi.ProfilUpdate.deleteProfilRequest(item.profil_update_id).then( + this.$fhcApi.factory.profilUpdate.deleteProfilRequest(item.profil_update_id).then( (res) => { if (res.data.error) { //? open alert - console.log(res.data); + console.error("error happened",res.data); } else { this.$emit("fetchUpdates"); } } ); }, + getView: function (topic, status) { if (!(status === this.profilUpdateStates["Pending"])) { return "Status"; From a0871657cafc401cc4f71b60b8da8dabde896ddd Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Mon, 22 Jul 2024 11:24:47 +0200 Subject: [PATCH 14/17] adds insertFile to the new ProfilUpdate FhcAPIController and starts a transaction when deleting the foreign key from the profil update and deleting the old file --- .../api/frontend/v1/ProfilUpdate.php | 115 ++++++++++++++++++ .../models/person/Profil_update_model.php | 15 +++ public/js/api/profilUpdate.js | 11 +- .../js/components/Calendar/CalendarModal.js | 4 +- .../Cis/Profil/ProfilModal/EditProfil.js | 4 +- 5 files changed, 139 insertions(+), 10 deletions(-) diff --git a/application/controllers/api/frontend/v1/ProfilUpdate.php b/application/controllers/api/frontend/v1/ProfilUpdate.php index 44d70afb4..4b9dedb48 100644 --- a/application/controllers/api/frontend/v1/ProfilUpdate.php +++ b/application/controllers/api/frontend/v1/ProfilUpdate.php @@ -47,6 +47,7 @@ class ProfilUpdate extends FHCAPI_Controller 'insertProfilRequest' => self::PERM_LOGGED, 'updateProfilRequest' => self::PERM_LOGGED, 'deleteProfilRequest' => self::PERM_LOGGED, + 'insertFile' => self::PERM_LOGGED, ]); // Load language phrases @@ -388,6 +389,68 @@ class ProfilUpdate extends FHCAPI_Controller } + public function insertFile($replace) + { + $replace = json_decode($replace); + + if (!count($_FILES)) { + $this->terminateWithError("No file available for upload"); + } + + //? if replace is set it contains the profil_update_id in which the attachment_id has to be replaced + if (isset($replace)) { + + $this->ProfilUpdateModel->addSelect(["attachment_id"]); + $profilUpdate = $this->ProfilUpdateModel->load([$replace]); + if (isError($profilUpdate)) { + $this->terminateWithError($this->p->t('profilUpdate', 'profilUpdate_loading_error')); + } + //? get the attachmentID + $dms_id = $this->getDataOrTerminateWithError($profilUpdate)[0]->attachment_id; + + //? delete old dms_file of Profil Update + $deleteOldFile_result = $this->deleteOldVersionFile($dms_id); + if(!$deleteOldFile_result){ + $this->terminateWithError("error while deleting the old file"); + } + } + + + $files = $_FILES['files']; + $file_count = count($files['name']); + + $res = []; + + for ($i = 0; $i < $file_count; $i++) { + $_FILES['files']['name'] = $files['name'][$i]; + $_FILES['files']['type'] = $files['type'][$i]; + $_FILES['files']['tmp_name'] = $files['tmp_name'][$i]; + $_FILES['files']['error'] = $files['error'][$i]; + $_FILES['files']['size'] = $files['size'][$i]; + + $dms = [ + "kategorie_kurzbz" => "profil_aenderung", + "version" => 0, + "name" => $_FILES['files']['name'], + "mimetype" => $_FILES['files']['type'], + "beschreibung" => $this->uid . " Profil Änderung", + "insertvon" => $this->uid, + "insertamum" => "NOW()", + ]; + + $tmp_res = $this->dmslib->upload($dms, 'files', array("jpg", "png", "pdf")); + + if(isError($tmp_res)){ + $this->addError(getError($tmp_res)); + } + + $tmp_res = $this->getDataOrTerminateWithError($tmp_res); + array_push($res, $tmp_res); + } + + $this->terminateWithSuccess($res); + } + //------------------------------------------------------------------------------------------------------------------ // Private methods @@ -584,6 +647,58 @@ class ProfilUpdate extends FHCAPI_Controller } } + private function deleteOldVersionFile($dms_id) + { + // starting the transaction + $this->db->trans_start(); + + + if (!isset($dms_id)) { + return; + } + + //? delete the file from the profilUpdate first + $profilUpdateFileDelete = $this->ProfilUpdateModel->removeFileFromProfilUpdate($dms_id); + if(isError($profilUpdateFileDelete)){ + $this->terminateWithError(getError($profilUpdateFileDelete)); + } + + //? delete all the different versions of the dms_file + $dmsVersions = $this->DmsVersionModel->loadWhere(["dms_id" => $dms_id]); + $dmsVersions = $this->getDataOrTerminateWithError($dmsVersions); + + + + $dms_versions = array_map(function ($item) { + return $item->version; + }, $dmsVersions); + + + $test_array = array(); + foreach ($dms_versions as $version) { + + $delete_result = $this->dmslib->removeVersion($dms_id, $version); + array_push($test_array, $delete_result); + + if(isError($delete_result)){ + $this->addError(getError($delete_result)); + } + } + + // transaction complete + $this->db->trans_complete(); + + if ($this->db->trans_status() === FALSE) + { + return false; + } + else + { + return true; + } + + } + } diff --git a/application/models/person/Profil_update_model.php b/application/models/person/Profil_update_model.php index 68394dd9a..ffb04b7e7 100755 --- a/application/models/person/Profil_update_model.php +++ b/application/models/person/Profil_update_model.php @@ -77,6 +77,21 @@ class Profil_update_model extends DB_Model } + //? remove File from the Profil Update + public function removeFileFromProfilUpdate($dms_id) + { + + if(!is_int($dms_id) || $dms_id < 0){ + return error("not valid dms_id"); + } + + return $this->execReadOnlyQuery(" + UPDATE public.tbl_profil_update + SET attachment_id = NULL + WHERE attachment_id = ?", [$dms_id]); + + } + /** * getProfilUpdateWithPermission diff --git a/public/js/api/profilUpdate.js b/public/js/api/profilUpdate.js index 742e4a1b1..acfe99813 100644 --- a/public/js/api/profilUpdate.js +++ b/public/js/api/profilUpdate.js @@ -45,14 +45,13 @@ export default { //TODO post request //? new requests insertFile: function (dms, replace = null) { - const url = + + return this.$fhcApi.post( FHC_JS_DATA_STORAGE_OBJECT.app_root + FHC_JS_DATA_STORAGE_OBJECT.ci_router + - `/Cis/ProfilUpdate/insertFile/${replace}`; - - return axios.post(url, dms, { - headers: { "Content-Type": "multipart/form-data" }, - }); + `/api/frontend/v1/ProfilUpdate/insertFile/${replace}`, + dms); + }, getProfilRequestFiles: function (requestID) { diff --git a/public/js/components/Calendar/CalendarModal.js b/public/js/components/Calendar/CalendarModal.js index a9a11f8f7..1d143986a 100644 --- a/public/js/components/Calendar/CalendarModal.js +++ b/public/js/components/Calendar/CalendarModal.js @@ -116,14 +116,14 @@ export default { const result = this.editData.updateID ? //? updating old attachment by replacing //* second parameter of api request insertFile checks if the file has to be replaced or not - await Vue.$fhcapi.ProfilUpdate.insertFile( + await this.$fhcApi.factory.profilUpdate.insertFile( formData, this.editData.updateID ).then((res) => { return res.data?.map((file) => file.dms_id); }) : //? fresh insert of new attachment - await Vue.$fhcapi.ProfilUpdate.insertFile(formData).then((res) => { + await this.$fhcApi.factory.profilUpdate.insertFile(formData).then((res) => { return res.data?.map((file) => file.dms_id); }); return result; diff --git a/public/js/components/Cis/Profil/ProfilModal/EditProfil.js b/public/js/components/Cis/Profil/ProfilModal/EditProfil.js index 86b704c25..1b54fe7f6 100755 --- a/public/js/components/Cis/Profil/ProfilModal/EditProfil.js +++ b/public/js/components/Cis/Profil/ProfilModal/EditProfil.js @@ -129,14 +129,14 @@ export default { const result = this.editData.updateID ? //? updating old attachment by replacing //* second parameter of api request insertFile checks if the file has to be replaced or not - await Vue.$fhcapi.ProfilUpdate.insertFile( + await this.$fhcApi.factory.profilUpdate.insertFile( formData, this.editData.updateID ).then((res) => { return res.data?.map((file) => file.dms_id); }) : //? fresh insert of new attachment - await Vue.$fhcapi.ProfilUpdate.insertFile(formData).then((res) => { + await this.$fhcApi.factory.profilUpdate.insertFile(formData).then((res) => { return res.data?.map((file) => file.dms_id); }); return result; From 82417a7f6f62b74e2d6f712fd47a99bc48e66405 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Mon, 22 Jul 2024 11:36:12 +0200 Subject: [PATCH 15/17] removes old api files and removes the use(fhcApi) because it is already imported in the Phrasen plugin --- public/js/api/profilUpdate.js | 14 --- public/js/apps/Cis/Profil.js | 5 +- public/js/apps/Cis/ProfilUpdateRequests.js | 2 - public/js/apps/api/profilUpdate.js | 120 --------------------- public/js/apps/api/userdata.js | 58 ---------- 5 files changed, 1 insertion(+), 198 deletions(-) delete mode 100755 public/js/apps/api/profilUpdate.js delete mode 100755 public/js/apps/api/userdata.js diff --git a/public/js/api/profilUpdate.js b/public/js/api/profilUpdate.js index acfe99813..fe15a295e 100644 --- a/public/js/api/profilUpdate.js +++ b/public/js/api/profilUpdate.js @@ -30,20 +30,6 @@ export default { "/api/frontend/v1/ProfilUpdate/denyProfilRequest",{profil_update_id,uid,topic,status_message}); }, - //TODO post request - replaceProfilUpdateAttachment: function (dms) { - const url = - FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - `/Cis/ProfilUpdate/replaceProfilUpdateAttachment`; - - return axios.post(url, dms, { - headers: { "Content-Type": "multipart/form-data" }, - }); - }, - - //TODO post request - //? new requests insertFile: function (dms, replace = null) { return this.$fhcApi.post( diff --git a/public/js/apps/Cis/Profil.js b/public/js/apps/Cis/Profil.js index 1fa2e404b..7a084744a 100755 --- a/public/js/apps/Cis/Profil.js +++ b/public/js/apps/Cis/Profil.js @@ -2,12 +2,10 @@ import StudentProfil from "../../components/Cis/Profil/StudentProfil.js"; import MitarbeiterProfil from "../../components/Cis/Profil/MitarbeiterProfil.js"; import ViewStudentProfil from "../../components/Cis/Profil/StudentViewProfil.js"; import ViewMitarbeiterProfil from "../../components/Cis/Profil/MitarbeiterViewProfil.js"; -import fhcapifactory from "../api/fhcapifactory.js"; import Loading from "../../components/Loader.js"; import Phrasen from "../../plugin/Phrasen.js"; -import fhcapi from "../../plugin/FhcApi.js"; -Vue.$fhcapi = fhcapifactory; + Vue.$collapseFormatter = function (data) { //data - an array of objects containing the column title and value for each cell var container = document.createElement("div"); @@ -405,5 +403,4 @@ const profilApp = Vue.createApp({ profilApp .use(primevue.config.default, { zIndex: { overlay: 9999 } }) .use(Phrasen) - .use(fhcapi) .mount("#content"); diff --git a/public/js/apps/Cis/ProfilUpdateRequests.js b/public/js/apps/Cis/ProfilUpdateRequests.js index 42e5bd576..b2c761b6e 100755 --- a/public/js/apps/Cis/ProfilUpdateRequests.js +++ b/public/js/apps/Cis/ProfilUpdateRequests.js @@ -1,7 +1,5 @@ -import fhcapifactory from "../api/fhcapifactory.js"; import ProfilUpdateView from "../../components/Cis/ProfilUpdate/ProfilUpdateView.js"; import Phrasen from "../../plugin/Phrasen.js"; -Vue.$fhcapi = fhcapifactory; const app = Vue.createApp({ components: { diff --git a/public/js/apps/api/profilUpdate.js b/public/js/apps/api/profilUpdate.js deleted file mode 100755 index 9a63dc4d6..000000000 --- a/public/js/apps/api/profilUpdate.js +++ /dev/null @@ -1,120 +0,0 @@ -export default { - //! API calls for profil update requests - - getStatus: function () { - const url = - FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - "/Cis/ProfilUpdate/getStatus"; - return axios.get(url); - }, - - getTopic: function () { - const url = - FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - "/Cis/ProfilUpdate/getTopic"; - return axios.get(url); - }, - - getProfilUpdateRequest: function () { - const url = - FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - "/Cis/ProfilUpdate/getAllRequests"; - return axios.get(url); - }, - - acceptProfilRequest: function (payload) { - const url = - FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - "/Cis/ProfilUpdate/acceptProfilRequest"; - return axios.post(url, payload); - }, - - denyProfilRequest: function (payload) { - const url = - FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - "/Cis/ProfilUpdate/denyProfilRequest"; - return axios.post(url, payload); - }, - - replaceProfilUpdateAttachment: function (dms) { - const url = - FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - `/Cis/ProfilUpdate/replaceProfilUpdateAttachment`; - - return axios.post(url, dms, { - headers: { "Content-Type": "multipart/form-data" }, - }); - }, - - //? new reuquests - insertFile: function (dms, replace = null) { - const url = - FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - `/Cis/ProfilUpdate/insertFile/${replace}`; - - return axios.post(url, dms, { - headers: { "Content-Type": "multipart/form-data" }, - }); - }, - - getProfilRequestFiles: function (requestID) { - const url = - FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - `/Cis/ProfilUpdate/getProfilRequestFiles`; - - return axios.post(url, requestID); - }, - - selectProfilRequest: function (uid = null, id = null) { - const url = - FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - `/Cis/ProfilUpdate/selectProfilRequest`; - - return axios.get(url, { uid: uid, id: id }); - }, - - insertProfilRequest: function (topic, payload, fileID = null) { - const url = - FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - `/Cis/ProfilUpdate/insertProfilRequest`; - - return axios.post(url, { - topic, - payload, - ...(fileID ? { fileID: fileID } : {}), - }); - }, - - updateProfilRequest: function (topic, payload, ID, fileID = null) { - const url = - FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - `/Cis/ProfilUpdate/updateProfilRequest`; - - return axios.post(url, { - topic, - payload, - ID, - ...(fileID ? { fileID: fileID } : {}), - }); - }, - - deleteProfilRequest: function (requestID) { - const url = - FHC_JS_DATA_STORAGE_OBJECT.app_root + - FHC_JS_DATA_STORAGE_OBJECT.ci_router + - `/Cis/ProfilUpdate/deleteProfilRequest`; - - return axios.post(url, requestID); - }, -}; diff --git a/public/js/apps/api/userdata.js b/public/js/apps/api/userdata.js deleted file mode 100755 index defea2cbb..000000000 --- a/public/js/apps/api/userdata.js +++ /dev/null @@ -1,58 +0,0 @@ -export default { - //! API Calls for Profil Views - - getGemeinden: function(nation,zip=null){ - const url = - FHC_JS_DATA_STORAGE_OBJECT.app_root + - `cis.php/Cis/Profil/getGemeinden`; - return axios.get(url,{params:{nation:nation,zip:zip}}); - }, - - getAllNationen:function(){ - const url = - FHC_JS_DATA_STORAGE_OBJECT.app_root + - `cis.php/Cis/Profil/getAllNationen`; - return axios.get(url); - }, - - getView: function (uid) { - const url = - FHC_JS_DATA_STORAGE_OBJECT.app_root + `cis.php/Cis/Profil/getView/${uid}`; - return axios.get(url); - }, - - sperre_foto_function: function (value) { - const url = - FHC_JS_DATA_STORAGE_OBJECT.app_root + - `cis.php/Cis/Profil/foto_sperre_function/${value}`; - return axios.get(url); - }, - - isStudent: function (uid) { - const url = - FHC_JS_DATA_STORAGE_OBJECT.app_root + - `cis.php/Cis/Profil/isStudent/${uid}`; - return axios.get(url); - }, - - isMitarbeiter: function (uid) { - const url = - FHC_JS_DATA_STORAGE_OBJECT.app_root + - `cis.php/Cis/Profil/isMitarbeiter/${uid}`; - return axios.get(url); - }, - - getZustellAdresse: function () { - const url = - FHC_JS_DATA_STORAGE_OBJECT.app_root + - `cis.php/Cis/Profil/getZustellAdresse`; - return axios.get(url); - }, - - getZustellKontakt: function () { - const url = - FHC_JS_DATA_STORAGE_OBJECT.app_root + - `cis.php/Cis/Profil/getZustellKontakt`; - return axios.get(url); - }, -}; From f2074198593764d8d71e6a2633d6708dd09f1c92 Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Tue, 23 Jul 2024 08:58:52 +0200 Subject: [PATCH 16/17] removes the import for userdata and profilUpdate from the old fhcapi which should be replaced by the new fhcapi --- application/views/Cis/Documents.php | 7 ++++--- public/js/apps/api/fhcapifactory.js | 4 ---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/application/views/Cis/Documents.php b/application/views/Cis/Documents.php index 191558d86..9ca3bc961 100755 --- a/application/views/Cis/Documents.php +++ b/application/views/Cis/Documents.php @@ -12,9 +12,10 @@ $this->load->view('templates/CISHTML-Header', $includesArray);

p->t('tools', 'dokumente'); ?>p->t('tools', 'bestaetigungenZeugnisse'); ?>

- +
-
+ +

p->t('tools', 'inskriptionsbestaetigung'); ?>p->t('tools', 'studienbuchblatt') : ''; ?>

@@ -199,7 +200,7 @@ $this->load->view('templates/CISHTML-Header', $includesArray);
-
+
diff --git a/public/js/apps/api/fhcapifactory.js b/public/js/apps/api/fhcapifactory.js index 9d4e3609a..35120779f 100755 --- a/public/js/apps/api/fhcapifactory.js +++ b/public/js/apps/api/fhcapifactory.js @@ -1,11 +1,7 @@ import Search from "./search.js"; import Cms from "./cms.js"; -import UserData from "./userdata.js"; -import ProfilUpdate from "./profilUpdate.js" export default { "Search": Search, - "UserData": UserData, - "ProfilUpdate": ProfilUpdate, "Cms": Cms, }; From 2083e95f8cf724ef7a57ee2099bd59813282818d Mon Sep 17 00:00:00 2001 From: SimonGschnell Date: Tue, 23 Jul 2024 09:14:38 +0200 Subject: [PATCH 17/17] adds vertical layout for the documents view when the viewport is less than lg --- application/views/Cis/Documents.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/application/views/Cis/Documents.php b/application/views/Cis/Documents.php index 9ca3bc961..74d7b1349 100755 --- a/application/views/Cis/Documents.php +++ b/application/views/Cis/Documents.php @@ -14,8 +14,8 @@ $this->load->view('templates/CISHTML-Header', $includesArray);
- -
+ +

p->t('tools', 'inskriptionsbestaetigung'); ?>p->t('tools', 'studienbuchblatt') : ''; ?>

@@ -200,12 +200,13 @@ $this->load->view('templates/CISHTML-Header', $includesArray);
-
+
+