stores the status of profilUpdate with their language in the database and adapts the logic to it

This commit is contained in:
SimonGschnell
2024-04-09 15:02:17 +02:00
parent 78031bf1ad
commit 5b2365a1e2
7 changed files with 214 additions and 59 deletions
+42 -6
View File
@@ -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){
@@ -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');
@@ -0,0 +1,18 @@
<?php
class Profil_update_status_model extends DB_Model
{
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
$this->dbTable = 'public.tbl_profil_update_status';
$this->pk = ['status_kurzbz'];
$this->hasSequence = false;
}
}
@@ -0,0 +1,16 @@
<?php
class Profil_update_topic_model extends DB_Model
{
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
$this->dbTable = 'public.tbl_profil_update_topic';
$this->pk = ['topic_kurzbz'];
$this->hasSequence = false;
}
}