diff --git a/application/controllers/Cis/ProfilUpdate.php b/application/controllers/Cis/ProfilUpdate.php index c6eade77f..0eeec40da 100755 --- a/application/controllers/Cis/ProfilUpdate.php +++ b/application/controllers/Cis/ProfilUpdate.php @@ -9,6 +9,11 @@ if (!defined('BASEPATH')) class ProfilUpdate extends Auth_Controller { + public static $STATUS_PENDING =NULL; + public static $STATUS_ACCEPTED =NULL; + public static $STATUS_REJECTED =NULL; + + public function __construct(){ parent::__construct([ 'index' => ['student/stammdaten:r','mitarbeiter/stammdaten:r'], @@ -38,7 +43,8 @@ class ProfilUpdate extends Auth_Controller $this->load->model('ressource/mitarbeiter_model', 'MitarbeiterModel'); $this->load->model('crm/Student_model', 'StudentModel'); $this->load->model('person/Benutzer_model', 'BenutzerModel'); - + $this->load->model('system/Sprache_model', 'SpracheModel'); + $this->load->model('person/Profil_update_status_model', 'ProfilUpdateStatusModel'); // Load language phrases $this->loadPhrases( @@ -57,9 +63,22 @@ class ProfilUpdate extends Auth_Controller //? put the uid and pid inside the controller for reusability $this->uid = getAuthUID(); $this->pid = getAuthPersonID(); + + // static constants + $this->ProfilUpdateStatusModel->addSelect(['status_kurzbz']); + $status_kurzbz = $this->ProfilUpdateStatusModel->load(); + if(hasData($status_kurzbz)){ + list($status_pending, $status_accepted, $status_rejected) = getData($status_kurzbz); + + self::$STATUS_PENDING = $status_pending->status_kurzbz; + self::$STATUS_ACCEPTED = $status_accepted->status_kurzbz; + self::$STATUS_REJECTED = $status_rejected->status_kurzbz; + } } + + public function index(){ $this->load->view('Cis/ProfilUpdate'); } @@ -324,7 +343,7 @@ class ProfilUpdate extends Auth_Controller $payload = $json->payload; $identifier = property_exists($json->payload,"kontakt_id")? "kontakt_id" : (property_exists($json->payload,"adresse_id")? "adresse_id" : null); - $data = ["topic"=>$json->topic,"uid" => $this->uid, "requested_change" => json_encode($payload), "insertamum" => "NOW()", "insertvon"=>$this->uid,"status"=>$this->p->t('profilUpdate', 'pending') ]; + $data = ["topic"=>$json->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($json->fileID)){ @@ -357,7 +376,7 @@ class ProfilUpdate extends Auth_Controller if($res){ $pending_changes = array_filter($res, function($element) { - return $element->status == 'Pending' || $element->status == 'Ausstehend'; + return $element->status == isset(self::$STATUS_PENDING)?:"Pending"; }); foreach($pending_changes as $update_request){ @@ -419,13 +438,30 @@ class ProfilUpdate extends Auth_Controller public function getProfilUpdateWithPermission($status=null){ + + + // early return if no status has been passed as argument + if(!isset($status)){ + echo json_encode($this->ProfilUpdateModel->getProfilUpdateWithPermission()); + return; + } + + // get the sprache of the user + $sprachenIndex = $this->SpracheModel->loadWhere(["sprache"=>getUserLanguage()]); + $sprachenIndex = hasData($sprachenIndex)? getData($sprachenIndex)[0]->index : null; + + if(isset($sprachenIndex) && isset($status)){ + // get the corresponding status kurz_bz primary key out of the translation + $status = $this->ProfilUpdateStatusModel->execReadOnlyQuery("select * from public.tbl_profil_update_status where ? = ANY(bezeichnung_mehrsprachig)",[$status]); + $status = hasData($status) ? getData($status)[0]->status_kurzbz : null; + $res = $this->ProfilUpdateModel->getProfilUpdateWithPermission(isset($status)?['status'=>$status]:null); - $res = $this->ProfilUpdateModel->getProfilUpdateWithPermission(isset($status)?['status'=>$status]:null); - - echo json_encode($res); + echo json_encode($res); + } } + private function getOE_from_student($student_uid){ diff --git a/application/models/person/Profil_update_model.php b/application/models/person/Profil_update_model.php index a49fc4c24..b7efcea22 100755 --- a/application/models/person/Profil_update_model.php +++ b/application/models/person/Profil_update_model.php @@ -88,7 +88,8 @@ class Profil_update_model extends DB_Model $studentBerechtigung = $this->permissionlib->isBerechtigt('student/stammdaten', 's'); $mitarbeiterBerechtigung = $this->permissionlib->isBerechtigt('mitarbeiter/stammdaten', 's'); $oe_berechtigung = $this->permissionlib->getOE_isEntitledFor('student/stammdaten'); - + + $lang = "select index from public.tbl_sprache where sprache =" . $this->escape(getUserLanguage()); $res = []; if ($studentBerechtigung) { @@ -98,8 +99,9 @@ class Profil_update_model extends DB_Model $parameters = []; $query = " SELECT - profil_update_id, tbl_profil_update.uid, (tbl_person.vorname || ' ' || tbl_person.nachname) AS name , topic, requested_change, tbl_profil_update.updateamum, tbl_profil_update.updatevon, tbl_profil_update.insertamum, tbl_profil_update.insertvon, status, status_timestamp, status_message, attachment_id - FROM public.tbl_profil_update + profil_update_id, tbl_profil_update.uid, (tbl_person.vorname || ' ' || tbl_person.nachname) AS name , topic, requested_change, tbl_profil_update.updateamum, tbl_profil_update.updatevon, tbl_profil_update.insertamum, tbl_profil_update.insertvon, status, public.tbl_profil_update_status.bezeichnung_mehrsprachig[(".$lang.")] as status_translated, status_timestamp, status_message, attachment_id + FROM public.tbl_profil_update + JOIN public.tbl_profil_update_status ON public.tbl_profil_update_status.status_kurzbz = public.tbl_profil_update.status JOIN public.tbl_student ON public.tbl_student.student_uid=public.tbl_profil_update.uid JOIN public.tbl_benutzer ON public.tbl_benutzer.uid = public.tbl_student.student_uid JOIN public.tbl_person ON public.tbl_benutzer.person_id=public.tbl_person.person_id @@ -123,7 +125,8 @@ class Profil_update_model extends DB_Model } } if ($mitarbeiterBerechtigung) { - $this->addSelect(["profil_update_id", "tbl_profil_update.uid", "(tbl_person.vorname || ' ' || tbl_person.nachname) AS name", "topic", "requested_change", "tbl_profil_update.updateamum", "tbl_profil_update.updatevon", "tbl_profil_update.insertamum", "tbl_profil_update.insertvon", "status", "status_timestamp", "status_message", "attachment_id"]); + $this->addSelect(["profil_update_id", "tbl_profil_update.uid", "(tbl_person.vorname || ' ' || tbl_person.nachname) AS name", "topic", "requested_change", "tbl_profil_update.updateamum", "tbl_profil_update.updatevon", "tbl_profil_update.insertamum", "tbl_profil_update.insertvon", "status", "public.tbl_profil_update_status.bezeichnung_mehrsprachig[(".$lang.")] AS status_translated", "status_timestamp", "status_message", "attachment_id"]); + $this->addJoin('tbl_profil_update_status', 'tbl_profil_update_status.status_kurzbz=tbl_profil_update.status'); $this->addJoin('tbl_mitarbeiter', 'tbl_mitarbeiter.mitarbeiter_uid=tbl_profil_update.uid'); $this->addJoin('tbl_benutzer', 'tbl_benutzer.uid=tbl_profil_update.uid'); $this->addJoin('tbl_person', 'tbl_benutzer.person_id=tbl_person.person_id'); diff --git a/application/models/person/Profil_update_status_model.php b/application/models/person/Profil_update_status_model.php new file mode 100644 index 000000000..e69f9a047 --- /dev/null +++ b/application/models/person/Profil_update_status_model.php @@ -0,0 +1,18 @@ +dbTable = 'public.tbl_profil_update_status'; + $this->pk = ['status_kurzbz']; + $this->hasSequence = false; + + + + } +} \ No newline at end of file diff --git a/application/models/person/Profil_update_topic_model.php b/application/models/person/Profil_update_topic_model.php new file mode 100644 index 000000000..0b7ad61e3 --- /dev/null +++ b/application/models/person/Profil_update_topic_model.php @@ -0,0 +1,16 @@ +dbTable = 'public.tbl_profil_update_topic'; + $this->pk = ['topic_kurzbz']; + $this->hasSequence = false; + + } +} \ No newline at end of file diff --git a/public/js/components/Cis/ProfilUpdate/ProfilUpdateView.js b/public/js/components/Cis/ProfilUpdate/ProfilUpdateView.js index 052520e42..f9b9ecb43 100644 --- a/public/js/components/Cis/ProfilUpdate/ProfilUpdateView.js +++ b/public/js/components/Cis/ProfilUpdate/ProfilUpdateView.js @@ -4,18 +4,25 @@ import AcceptDenyUpdate from "./AcceptDenyUpdate.js"; import Alert from "../../../components/Bootstrap/Alert.js"; import Loading from "../../../components/Loader.js"; +const STATUS = Object.freeze({ + PENDING: "Pending", + ACCEPTED: "Accepted", + REJECTED: "Rejected", +}) -const sortProfilUpdates = (ele1, ele2) => { +const sortProfilUpdates = (ele1, ele2, thisPointer)=> { + let result = 0; - if (ele1.status === this.$p.t('profilUpdate','pending')) { + if (ele1.status === STATUS.PENDING) { result = -1; - } else if (ele1.status === this.$p.t('profilUpdate','accepted')) { - result = ele2.status === this.$p.t('profilUpdate','rejected') ? -1 : 1; + } else if (ele1.status === STATUS.ACCEPTED) { + result = ele2.status === STATUS.REJECTED ? -1 : 1; } else { result = 1; } - //? if they have the same status the insert date is used for ordering + if (ele1.status === ele2.status) { + //? if they have the same status , insert_date gets compared for order result = new Date(ele2.insertamum.split(".").reverse().join("-")) - new Date(ele1.insertamum.split(".").reverse().join("-")); @@ -54,15 +61,15 @@ export default{ if (this.showAll) { return url + "getProfilUpdateWithPermission"; } else { - return url + "getProfilUpdateWithPermission/pending"; + return url + `getProfilUpdateWithPermission/${STATUS.PENDING}`; } }, - ajaxResponse: function (url, params, response) { + ajaxResponse: (url, params, response)=> { //url - the URL of the request //params - the parameters passed with the request //response - the JSON object returned in the body of the response. //? sorts the response data from the backend - if (response) response.sort(sortProfilUpdates); + if (response) response.sort((ele1,ele2)=>sortProfilUpdates(ele1,ele2,this)); return response; }, @@ -185,21 +192,17 @@ export default{ }, { title: "Status", - field: "status", + field: "status_translated", hozAlign: "center", headerFilter: true, formatter: (cell, para) => { - let iconClasses ="fa fa-lg" - if(cell.getValue() == this.$p.t('profilUpdate','pending')) { - iconClasses += " fa-circle-info text-info " + let iconClasses ="" + let status = cell.getRow().getData().status; + switch (status){ + case "Pending": iconClasses += "fa fa-lg fa-circle-info text-info "; break; + case "Accepted": iconClasses += "fa fa-lg fa-circle-check text-success "; break; + case "Rejected": iconClasses += "fa fa-lg fa-circle-xmark text-danger "; break; } - else if(cell.getValue() == this.$p.t('profilUpdate','accepted')) { - iconClasses += " fa-circle-check text-success " - } - else if(cell.getValue() == this.$p.t('profilUpdate','rejected')) { - iconClasses += " fa-circle-xmark text-danger " - } - return `