mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-01 20:29:29 +00:00
Merge branch 'feature-5698/Clean_ViewMessage_MessageToken_model'
This commit is contained in:
@@ -37,12 +37,13 @@ class Redirect extends FHC_Controller
|
||||
public function redirectByToken($token)
|
||||
{
|
||||
$msg = $this->MessageTokenModel->getMessageByToken($token);
|
||||
if ($msg->error)
|
||||
if (isError($msg))
|
||||
{
|
||||
show_error(getError($msg));
|
||||
}
|
||||
|
||||
$oe_kurzbz = $msg->retval[0]->oe_kurzbz;
|
||||
$oe_kurzbz = null;
|
||||
if (hasData($msg)) $oe_kurzbz = getData($msg)[0]->oe_kurzbz;
|
||||
|
||||
if ($oe_kurzbz != null && $oe_kurzbz != '')
|
||||
{
|
||||
@@ -51,7 +52,7 @@ class Redirect extends FHC_Controller
|
||||
$getOERoot = $this->MessageTokenModel->getOERoot($oe_kurzbz);
|
||||
if (isSuccess($getOERoot)) // If no errors occurred
|
||||
{
|
||||
$organisationRoot = $getOERoot->retval;
|
||||
$organisationRoot = getData($getOERoot);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -43,8 +43,7 @@ class ViewMessage extends FHC_Controller
|
||||
public function toHTML($token)
|
||||
{
|
||||
$msg = $this->MessageTokenModel->getMessageByToken($token);
|
||||
|
||||
if ($msg->error)
|
||||
if (isError($msg))
|
||||
{
|
||||
show_error(getError($msg));
|
||||
}
|
||||
@@ -52,10 +51,9 @@ class ViewMessage extends FHC_Controller
|
||||
if (is_array(getData($msg)) && count(getData($msg)) > 0)
|
||||
{
|
||||
$setReadMessageStatusByToken = $this->MessageTokenModel->setReadMessageStatusByToken($token);
|
||||
|
||||
if (isError($setReadMessageStatusByToken))
|
||||
{
|
||||
show_error($msg);
|
||||
show_error(getError($setReadMessageStatusByToken));
|
||||
}
|
||||
|
||||
$sender_id = getData($msg)[0]->sender_id;
|
||||
@@ -64,9 +62,9 @@ class ViewMessage extends FHC_Controller
|
||||
|
||||
// To decide how to change the redirection
|
||||
$isEmployee = $this->MessageTokenModel->isEmployee($receiver_id);
|
||||
if (!is_bool($isEmployee) && isError($isEmployee))
|
||||
if (isError($isEmployee))
|
||||
{
|
||||
show_error($isEmployee);
|
||||
show_error(getError($isEmployee));
|
||||
}
|
||||
|
||||
if($this->config->item('redirect_view_message_url') != '')
|
||||
@@ -78,7 +76,7 @@ class ViewMessage extends FHC_Controller
|
||||
'sender_id' => $sender_id,
|
||||
'sender' => getData($sender)[0],
|
||||
'message' => getData($msg)[0],
|
||||
'isEmployee' => $isEmployee,
|
||||
'isEmployee' => hasData($isEmployee),
|
||||
'href' => $href
|
||||
);
|
||||
|
||||
|
||||
@@ -37,17 +37,7 @@ class MessageToken_model extends DB_Model
|
||||
WHERE r.token = ?
|
||||
LIMIT 1';
|
||||
|
||||
$result = $this->db->query($sql, array(MSG_STATUS_DELETED, $token));
|
||||
|
||||
// If no errors occurred
|
||||
if ($result)
|
||||
{
|
||||
return success($result->result());
|
||||
}
|
||||
else
|
||||
{
|
||||
return error($this->db->error());
|
||||
}
|
||||
return $this->execQuery($sql, array(MSG_STATUS_DELETED, $token));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,25 +64,24 @@ class MessageToken_model extends DB_Model
|
||||
WHERE r.token = ?
|
||||
LIMIT 1';
|
||||
|
||||
$msgs = $this->db->query($sql, array(MSG_STATUS_ARCHIVED, $token));
|
||||
$msgsResult = $this->execQuery($sql, array(MSG_STATUS_ARCHIVED, $token));
|
||||
|
||||
// If no errors occurred
|
||||
if ($msgs)
|
||||
if (isSuccess($msgsResult))
|
||||
{
|
||||
$msgs_result = $msgs->result();
|
||||
// If at least a record is present
|
||||
if (count($msgs_result) > 0)
|
||||
if (hasData($msgsResult))
|
||||
{
|
||||
$msg = $msgs_result[0];
|
||||
$msg = getData($msgsResult)[0];
|
||||
$msgStatusResult = error();
|
||||
|
||||
$msgStatusResult = false; // pessimistic expectation
|
||||
$this->load->model('system/MsgStatus_model', 'MsgStatusModel');
|
||||
|
||||
// If the status of the message is unread
|
||||
if ($msg->status == MSG_STATUS_UNREAD)
|
||||
{
|
||||
// Insert the read status
|
||||
$msgStatusResult = $this->db->insert(
|
||||
'public.tbl_msg_status',
|
||||
$msgStatusResult = $this->MsgStatusModel->insert(
|
||||
array(
|
||||
'message_id' => $msg->message_id,
|
||||
'person_id' => $msg->receiver_id,
|
||||
@@ -108,31 +97,23 @@ class MessageToken_model extends DB_Model
|
||||
// If the status of the message is read
|
||||
else if ($msg->status == MSG_STATUS_READ)
|
||||
{
|
||||
// Update updateamum to current date
|
||||
$this->db->set('updateamum', 'NOW()');
|
||||
|
||||
$this->db->where('message_id', $msg->message_id);
|
||||
$this->db->where('person_id', $msg->receiver_id);
|
||||
$this->db->where('status', MSG_STATUS_READ);
|
||||
|
||||
$msgStatusResult = $this->db->update('public.tbl_msg_status');
|
||||
$msgStatusResult = $this->MsgStatusModel->update(
|
||||
array(
|
||||
'message_id' => $msg->message_id,
|
||||
'person_id' => $msg->receiver_id,
|
||||
'status' => MSG_STATUS_READ
|
||||
),
|
||||
array('updateamum' => 'NOW()')
|
||||
);
|
||||
}
|
||||
|
||||
// If some of the previous DB manipulation (update or insert) has failed
|
||||
if (!$msgStatusResult)
|
||||
{
|
||||
return error($this->db->error());
|
||||
}
|
||||
return $msgStatusResult;
|
||||
}
|
||||
|
||||
return success($msgs_result);
|
||||
}
|
||||
else
|
||||
{
|
||||
return error($this->db->error());
|
||||
return $msgsResult;
|
||||
}
|
||||
|
||||
return success($result->result());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,17 +133,7 @@ class MessageToken_model extends DB_Model
|
||||
LEFT JOIN public.tbl_mitarbeiter m ON(b.uid = m.mitarbeiter_uid)
|
||||
WHERE p.person_id = ?';
|
||||
|
||||
$result = $this->db->query($sql, array($person_id));
|
||||
|
||||
// If no errors occurred
|
||||
if ($result)
|
||||
{
|
||||
return success($result->result());
|
||||
}
|
||||
else
|
||||
{
|
||||
return error($this->db->error());
|
||||
}
|
||||
return $this->execQuery($sql, array($person_id));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -180,17 +151,7 @@ class MessageToken_model extends DB_Model
|
||||
FROM public.tbl_person
|
||||
WHERE person_id %s ?';
|
||||
|
||||
$result = $this->db->query(sprintf($sql, is_array($person_id) ? 'IN' : '='), array($person_id));
|
||||
|
||||
// If no errors occurred
|
||||
if ($result)
|
||||
{
|
||||
return success($result->result());
|
||||
}
|
||||
else
|
||||
{
|
||||
return error($this->db->error());
|
||||
}
|
||||
return $this->execQuery(sprintf($sql, is_array($person_id) ? 'IN' : '='), array($person_id));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -200,35 +161,12 @@ class MessageToken_model extends DB_Model
|
||||
{
|
||||
$sql = 'SELECT m.mitarbeiter_uid
|
||||
FROM public.tbl_person p
|
||||
LEFT JOIN public.tbl_benutzer b USING(person_id)
|
||||
LEFT JOIN public.tbl_mitarbeiter m ON(b.uid = m.mitarbeiter_uid)
|
||||
JOIN public.tbl_benutzer b USING(person_id)
|
||||
JOIN public.tbl_mitarbeiter m ON(b.uid = m.mitarbeiter_uid)
|
||||
WHERE p.person_id = ?
|
||||
AND b.aktiv = TRUE';
|
||||
|
||||
$result = $this->db->query($sql, array($person_id));
|
||||
|
||||
// If no errors occurred
|
||||
if ($result)
|
||||
{
|
||||
// If data are present
|
||||
if (is_array($result->result()) && count($result->result()) > 0)
|
||||
{
|
||||
$personresults = $result->result();
|
||||
$person = $personresults[0];
|
||||
|
||||
// If it is an employee
|
||||
if ($person->mitarbeiter_uid != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return error($this->db->error());
|
||||
}
|
||||
return $this->execQuery($sql, array($person_id));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -254,28 +192,6 @@ class MessageToken_model extends DB_Model
|
||||
LIMIT 1
|
||||
';
|
||||
|
||||
$result = $this->db->query($sql, array($oe_kurzbz));
|
||||
if ($result) // If no errors occurred
|
||||
{
|
||||
$result_arr = $result->result();
|
||||
// If data are present
|
||||
if (is_array($result_arr)
|
||||
&& count($result_arr) > 0
|
||||
&& is_object($result_arr[0])
|
||||
&& isset($result_arr[0]->oe_kurzbz))
|
||||
{
|
||||
return success($result_arr[0]->oe_kurzbz);
|
||||
}
|
||||
else
|
||||
{
|
||||
return error();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return error($this->db->error());
|
||||
}
|
||||
|
||||
return $result;
|
||||
return $this->execQuery($sql, array($oe_kurzbz));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user