mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-24 10:22:18 +00:00
fixes a lot of bugs and adds the inseramum/insertvon/updateamum/updatevon fields to the cis_profil_update db table
This commit is contained in:
@@ -25,7 +25,8 @@ class Profil extends Auth_Controller
|
||||
'deleteProfilRequest' => ['student/anrechnung_beantragen:r', 'user:r'],
|
||||
'selectProfilRequest' => ['student/anrechnung_beantragen:r', 'user:r'],
|
||||
'insertFile' => ['student/anrechnung_beantragen:r', 'user:r'],
|
||||
|
||||
'getProfilRequestFiles' => ['student/anrechnung_beantragen:r', 'user:r'],
|
||||
|
||||
]);
|
||||
$this->load->model('ressource/mitarbeiter_model', 'MitarbeiterModel');
|
||||
$this->load->model('crm/Student_model', 'StudentModel');
|
||||
@@ -130,6 +131,10 @@ class Profil extends Auth_Controller
|
||||
}
|
||||
|
||||
|
||||
public function getProfilRequestFiles(){
|
||||
$id = json_decode($this->input->raw_input_stream);
|
||||
echo json_encode($this->ProfilChangeModel->getFilesFromChangeRequest($id));
|
||||
}
|
||||
|
||||
public function insertProfilRequest()
|
||||
{
|
||||
@@ -137,7 +142,7 @@ class Profil extends Auth_Controller
|
||||
$json = json_decode($this->input->raw_input_stream);
|
||||
$payload = $json->payload;
|
||||
|
||||
$identifier = property_exists($json->payload,"kontakt_id")? "kontakt_id" : "adresse_id";
|
||||
$identifier = property_exists($json->payload,"kontakt_id")? "kontakt_id" : (property_exists($json->payload,"adresse_id")? "adresse_id" : null);
|
||||
|
||||
$name = $this->PersonModel->getFullName($this->uid);
|
||||
if(isError($name)){
|
||||
@@ -145,7 +150,7 @@ class Profil extends Auth_Controller
|
||||
var_dump($name);
|
||||
return;
|
||||
}
|
||||
$data = ["topic"=>$json->topic,"uid" => $this->uid, "name"=>getData($name), "requested_change" => json_encode($payload), "change_timestamp" => "NOW()","status"=>"pending" ];
|
||||
$data = ["topic"=>$json->topic,"uid" => $this->uid, "name"=>getData($name), "requested_change" => json_encode($payload), "insertamum" => "NOW()", "insertvon"=>$this->uid,"status"=>"pending" ];
|
||||
|
||||
//? loops over all updateRequests from a user to validate if the new request is valid
|
||||
$res = $this->ProfilChangeModel->loadWhere(["uid"=>$this->uid]);
|
||||
@@ -165,22 +170,23 @@ class Profil extends Auth_Controller
|
||||
return;
|
||||
}
|
||||
|
||||
elseif(!isset($payload->add) && !isset($payload->delete) && $update_request->topic == $json->topic ){
|
||||
//? if it is not a delete or add request than the topic in combination with the uid of the user have to be unique
|
||||
elseif(!$identifier && $update_request->topic == $json->topic ){
|
||||
//? if it is not a delete or add request than the topic has to be unique
|
||||
echo json_encode(error("A request to change " . $json->topic . " is already open"));
|
||||
return;
|
||||
}
|
||||
}}
|
||||
|
||||
$insert_res = $this->ProfilChangeModel->insert($data);
|
||||
$insertID = $this->ProfilChangeModel->insert($data);
|
||||
|
||||
if(isError($insert_res)){
|
||||
if(isError($insertID)){
|
||||
//catch error
|
||||
}else{
|
||||
$editTimestamp = $this->ProfilChangeModel->getTimestamp($insert_res->retval);
|
||||
$insertID = hasData($insertID)? getData($insertID): null;
|
||||
$editTimestamp = $this->ProfilChangeModel->getTimestamp($insertID);
|
||||
|
||||
$insert_res->retval = date_create($editTimestamp)->format('d.m.Y');
|
||||
echo json_encode($insert_res);
|
||||
$date = success(date_create($editTimestamp)->format('d.m.Y'));
|
||||
echo json_encode($date);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,24 +195,16 @@ class Profil extends Auth_Controller
|
||||
|
||||
$json = json_decode($this->input->raw_input_stream);
|
||||
|
||||
|
||||
$data = ["topic"=>$json->topic,"uid" => $this->uid, "requested_change" => json_encode($json->payload), "change_timestamp" => "NOW()","status"=>"pending" ];
|
||||
|
||||
//? gets all the requested changes from a user
|
||||
|
||||
if(isSuccess($this->ProfilChangeModel->addSelect(["profil_update_id"])) ){
|
||||
$requestID = $this->ProfilChangeModel->loadWhere(["uid"=>$this->uid,"topic"=>$json->topic]);
|
||||
$requestID = hasData($requestID) ? getData($requestID)[0]->profil_update_id : null;
|
||||
};
|
||||
|
||||
$update_res =$this->ProfilChangeModel->update([$requestID],$data);
|
||||
if(isError($update_res)){
|
||||
$updateID =$this->ProfilChangeModel->update([$json->ID],["requested_change" => json_encode($json->payload), "updateamum" => "NOW()", "updatevon" => $this->uid]);
|
||||
if(isError($updateID)){
|
||||
//catch error
|
||||
}else{
|
||||
$editTimestamp = $this->ProfilChangeModel->getTimestamp($update_res->retval[0]);
|
||||
$updateID = hasData($updateID)? getData($updateID)[0]: null;
|
||||
$editTimestamp = $this->ProfilChangeModel->getTimestamp($updateID,true);
|
||||
|
||||
$update_res->retval = date_create($editTimestamp)->format('d.m.Y');
|
||||
echo json_encode($update_res);
|
||||
$date = success(date_create($editTimestamp)->format('d.m.Y'));
|
||||
echo json_encode($date);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,11 +17,30 @@ class Profil_change_model extends DB_Model
|
||||
/**
|
||||
* getTimestamp
|
||||
* returns insert or update timestamp of a certain profil update
|
||||
*
|
||||
* @param boolean $update: conditional whether to return insertamum or updateamum
|
||||
*/
|
||||
public function getTimestamp($uid){
|
||||
$this->addSelect(['change_timestamp']);
|
||||
$res = $this->load([$uid]);
|
||||
return hasData($res) ? getData($res)[0]->change_timestamp : null;
|
||||
public function getTimestamp($id, $update=false){
|
||||
$selectStatement = $update? 'updateamum' : 'insertamum';
|
||||
$this->addSelect([$selectStatement]);
|
||||
$res = $this->load([$id]);
|
||||
return hasData($res) ? getData($res)[0]->$selectStatement : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* getFilesFromChangeRequest
|
||||
*
|
||||
* returns all files associated to a profil update request in the following format:
|
||||
* {dms_id:123 , name:"test"}
|
||||
*
|
||||
* @param boolean $profil_update_id primary key of the profil update request
|
||||
* @return Array
|
||||
*/
|
||||
public function getFilesFromChangeRequest($profil_update_id){
|
||||
$this->addSelect(["requested_change"]);
|
||||
$res = $this->load([$profil_update_id]);
|
||||
$res = hasData($res) ? getData($res)[0] : null;
|
||||
return json_decode($res->requested_change)->files?:null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,7 +55,6 @@ class Profil_change_model extends DB_Model
|
||||
if(!is_null($uid)){
|
||||
$whereClause['uid']=$uid;
|
||||
}
|
||||
//?
|
||||
if(!is_null($id)){
|
||||
$whereClause['profil_update_id']=$id;
|
||||
}
|
||||
@@ -49,7 +67,7 @@ class Profil_change_model extends DB_Model
|
||||
|
||||
foreach($res->retval as $update){
|
||||
$update->requested_change = json_decode($update->requested_change);
|
||||
$update->change_timestamp = !is_null($update->change_timestamp)?date_create($update->change_timestamp)->format('d.m.Y'):null;
|
||||
$update->insertamum = !is_null($update->insertamum)?date_create($update->insertamum)->format('d.m.Y'):null;
|
||||
$update->status_timestamp = !is_null($update->status_timestamp)?date_create($update->status_timestamp)->format('d.m.Y'):null;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user