- Remove global constant OU_SENDER_TEST_REMINDER from application/config/constants.php

- Page for the Infocenter details messages block should use CL/Message_model logic
- Page to read personal messages wrongly displays the sender
- Page to read message with token wrongly displays the sender
- All the pages should display the sender using the following logic:
 	- If the sender id is set and it is not the system sender and the organization unit is not set then display the sender name + surname
 	- If the sender id is set and it is not the system sender and the organization unit is set then display the sender name + surname
 	- If the sender id is set and it is the system sender and the organization unit is set then display the organization unit
 	- If the sender id is set and it is the system sender and the organization unit is not set then display "System sender"
 	- The organization unit should firstly retrieved from the degree programs, if not available then from the organization units, if not available then display "System sender"
- Centralized this logic in the CL/Message_model as much as possible
This commit is contained in:
Paolo
2023-04-19 13:51:53 +02:00
parent 932f5efb5c
commit a0b368683e
8 changed files with 398 additions and 318 deletions
+57 -36
View File
@@ -1,6 +1,6 @@
<?php
/**
* Copyright (C) 2022 fhcomplete.org
* Copyright (C) 2023 fhcomplete.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -225,12 +225,23 @@ class Messages_model extends CI_Model
$jsonRecord->message_id = $receivedMessage->message_id;
$jsonRecord->subject = $receivedMessage->subject;
$jsonRecord->body = $receivedMessage->body;
$jsonRecord->from = $receivedMessage->vorname.' '.$receivedMessage->nachname;
$sentDate = new DateTime($receivedMessage->sent);
$jsonRecord->sent = $sentDate->format('d/m/Y H:i:s');
$jsonRecord->status = $receivedMessage->status;
$jsonRecord->statusPersonId = $receivedMessage->statuspersonid;
$jsonRecord->status = $receivedMessage->lastStatus;
$jsonRecord->statusPersonId = $receivedMessage->senderPersonId;
$jsonRecord->token = $receivedMessage->token;
$jsonRecord->from = self::SYSTEM_SENDER_NAME; // default fallback
// If the sender id is the system sender then use the organisation unit
if ($receivedMessage->senderPersonId == $this->config->item(MessageLib::CFG_SYSTEM_PERSON_ID))
{
// If the oe exists
if (!isEmptyString($receivedMessage->oe)) $jsonRecord->from = $receivedMessage->oe;
}
else // otherwise use the name and surname of the person sender
{
$jsonRecord->from = $receivedMessage->senderName.' '.$receivedMessage->senderSurname;
}
$jsonArray[] = $jsonRecord;
}
@@ -264,17 +275,20 @@ class Messages_model extends CI_Model
$jsonRecord->body = $sentMessage->body;
$sentDate = new DateTime($sentMessage->sent);
$jsonRecord->sent = $sentDate->format('d/m/Y H:i:s');
$jsonRecord->status = $sentMessage->status;
$jsonRecord->statusPersonId = $sentMessage->statuspersonid;
$jsonRecord->status = $sentMessage->lastStatus;
$jsonRecord->statusPersonId = $sentMessage->senderPersonId;
$jsonRecord->token = $sentMessage->token;
$jsonRecord->to = self::SYSTEM_SENDER_NAME; // default fallback
if ($sentMessage->person_id == $this->config->item(MessageLib::CFG_SYSTEM_PERSON_ID))
// If the recipient id is the system sender then use the organisation unit
if ($sentMessage->recipientPersonId == $this->config->item(MessageLib::CFG_SYSTEM_PERSON_ID))
{
$jsonRecord->to = $sentMessage->oe;
// If the oe exists
if (!isEmptyString($sentMessage->oe)) $jsonRecord->to = $sentMessage->oe;
}
else
else // otherwise use the name and surname of the person recipient
{
$jsonRecord->to = $sentMessage->vorname.' '.$sentMessage->nachname;
$jsonRecord->to = $sentMessage->recipientName.' '.$sentMessage->recipientSurname;
}
$jsonArray[] = $jsonRecord;
@@ -308,38 +322,33 @@ class Messages_model extends CI_Model
$sender = self::SYSTEM_SENDER_NAME; // default fallback
// If the sender is a person
if (isEmptyString($message->oe_kurzbz))
if ($message->sender_id != $this->config->item(MessageLib::CFG_SYSTEM_PERSON_ID))
{
// And if this person is not the system sender
if ($message->sender_id != $this->config->item(MessageLib::CFG_SYSTEM_PERSON_ID))
{
// Retrieves message sender information
$senderResult = $this->MessageTokenModel->getSenderData($message->sender_id);
if (isError($senderResult)) show_error(getError($senderResult));
if (!hasData($senderResult)) show_error('No sender information found');
// Retrieves message sender information
$senderResult = $this->MessageTokenModel->getSenderData($message->sender_id);
if (isError($senderResult)) show_error(getError($senderResult));
if (!hasData($senderResult)) show_error('No sender information found');
$sender = getData($senderResult)[0]->vorname.' '.getData($senderResult)[0]->nachname;
}
$sender = getData($senderResult)[0]->vorname.' '.getData($senderResult)[0]->nachname;
}
//case ReihungstestReminderJob
elseif($message->oe_kurzbz == OU_SENDER_TEST_REMINDER)
{
$ouResult = $this->OrganisationseinheitModel->loadWhere(array('oe_kurzbz' => $message->oe_kurzbz));
if (isError($ouResult)) show_error(getError($ouResult));
if (!hasData($ouResult)) show_error('No organization unit information found');
$sender = getData($ouResult)[0]->bezeichnung;
}
else // otherwise if the sender is an organization unit (degree program)
{
// Looks into the degree programs
$ouResult = $this->StudiengangModel->loadWhere(array('oe_kurzbz' => $message->oe_kurzbz));
if (isError($ouResult)) show_error(getError($ouResult));
if (!hasData($ouResult)) show_error('No organization unit information found');
$sender = getData($ouResult)[0]->bezeichnung;
if (isError($ouResult)) show_error(getError($ouResult));
// If not found here
if (!hasData($ouResult))
{
// Then looks into the organisation units
$ouResult = $this->OrganisationseinheitModel->loadWhere(array('oe_kurzbz' => $message->oe_kurzbz));
if (isError($ouResult)) show_error(getError($ouResult));
}
// If found then set it, otherwise the fallback is used
if (hasData($ouResult)) $sender = getData($ouResult)[0]->bezeichnung;
}
// If the sender is not the system sender and configurations to reply exist
@@ -752,6 +761,17 @@ class Messages_model extends CI_Model
}
}
/**
* Returns all the received and sent messages for the given person
*/
public function getReceivedAndSentMessages($person_id)
{
return $this->RecipientModel->getReceivedAndSentMessages(
$person_id,
$this->config->item(MessageLib::CFG_OU_RECEIVERS)
);
}
//------------------------------------------------------------------------------------------------------------------
// Private methods
@@ -984,7 +1004,7 @@ class Messages_model extends CI_Model
* @param object $otherMsgVarsDataObj Can be success object or simple object.
* @return object Returns success object.
*/
public function _addMsgVarsDataOfLoggedInUser($otherMsgVarsDataObj, $uid = null)
private function _addMsgVarsDataOfLoggedInUser($otherMsgVarsDataObj, $uid = null)
{
// First check if param type is object
if (!is_object($otherMsgVarsDataObj)) show_error('Must pass an object to merge with data of logged in user');
@@ -1006,3 +1026,4 @@ class Messages_model extends CI_Model
return success(array((object)(array_merge((array)$otherMsgVarsDataObj, (array)$msgVarsDataLoggedInUser))));
}
}
@@ -77,69 +77,6 @@ class Message_model extends DB_Model
return $this->execQuery($sql, $parametersArray);
}
/**
* Gets massages with a person being sender OR receiver.
* @param $person_id
* @param null $status message status. by default, latest status is returned
* @return array|null
*/
public function getMessagesOfPerson($person_id, $status = null)
{
$sql = 'SELECT m.message_id,
m.person_id,
m.subject,
m.body,
m.priority,
m.insertamum,
m.relationmessage_id,
m.oe_kurzbz,
oe.bezeichnung AS oebezeichnung,
se.person_id AS sepersonid,
se.anrede AS seanrede,
se.titelpost AS setitelpost,
se.titelpre AS setitelpre,
se.nachname AS senachname,
se.vorname AS sevorname,
se.vornamen AS sevornamen,
re.person_id AS repersonid,
re.anrede AS reanrede,
re.titelpost AS retitelpost,
re.titelpre AS retitelpre,
re.nachname AS renachname,
re.vorname AS revorname,
re.vornamen AS revornamen,
s.status,
s.statusinfo,
s.insertamum AS statusamum
FROM public.tbl_msg_message m
JOIN public.tbl_msg_recipient r ON m.message_id = r.message_id
JOIN public.tbl_person se ON (m.person_id = se.person_id)
JOIN public.tbl_person re ON (r.person_id = re.person_id)
JOIN public.tbl_organisationseinheit oe ON (m.oe_kurzbz = oe.oe_kurzbz)
LEFT JOIN (
SELECT message_id, person_id, status, statusinfo, insertamum
FROM public.tbl_msg_status
%s
ORDER BY insertamum DESC
) s ON (m.message_id = s.message_id AND re.person_id = s.person_id)
WHERE se.person_id = ?
OR re.person_id = ?
';
if (is_numeric($status))
{
$sql = sprintf($sql, 'WHERE status = '.$status);
}
else
{
$sql = sprintf($sql, '');
}
$parametersArray = array($person_id, $person_id);
return $this->execQuery($sql, $parametersArray);
}
/**
* getMessageVars
*/
+175 -95
View File
@@ -267,69 +267,14 @@ class Recipient_model extends DB_Model
*/
public function getReceivedMessages($person_id, $functions)
{
$sql = '-- Messages sent directly to the person
SELECT mr.message_id,
mm.relationmessage_id,
mm.subject,
mm.body,
mm.insertamum AS sent,
p.vorname,
p.nachname,
MAX(ms.status) AS status,
ms.person_id AS statusPersonId,
mr.token
FROM public.tbl_msg_recipient mr
JOIN public.tbl_msg_message mm ON (mm.message_id = mr.message_id)
JOIN public.tbl_msg_status ms ON (ms.message_id = mr.message_id AND ms.person_id = mr.person_id)
JOIN public.tbl_person p ON (p.person_id = mm.person_id)
WHERE mr.person_id = ?
GROUP BY mr.message_id,
mm.relationmessage_id,
mm.subject,
mm.body,
mm.insertamum,
p.vorname,
p.nachname,
ms.person_id,
mr.token
UNION
-- Messages sent to a person that belongs to the recipient organisation unit
SELECT mrou.message_id,
mm.relationmessage_id,
mm.subject,
mm.body,
mm.insertamum AS sent,
pr.vorname,
pr.nachname,
MAX(ms.status) AS status,
ms.person_id AS statusPersonId,
mrou.token
FROM public.tbl_person p
JOIN public.tbl_benutzer b ON (b.person_id = p.person_id)
JOIN (
SELECT uid, oe_kurzbz
FROM public.tbl_benutzerfunktion
WHERE (datum_von IS NULL OR datum_von <= NOW())
AND (datum_bis IS NULL OR datum_bis >= NOW())
AND funktion_kurzbz IN ?
) bf ON (bf.uid = b.uid)
JOIN public.tbl_msg_recipient mrou ON (mrou.oe_kurzbz = bf.oe_kurzbz)
JOIN public.tbl_msg_message mm ON (mm.message_id = mrou.message_id)
JOIN public.tbl_msg_status ms ON (ms.message_id = mrou.message_id AND ms.person_id = mrou.person_id)
JOIN public.tbl_person pr ON (pr.person_id = mm.person_id)
WHERE p.person_id = ?
GROUP BY mrou.message_id,
mm.relationmessage_id,
mm.subject,
mm.body,
mm.insertamum,
pr.vorname,
pr.nachname,
ms.person_id,
mrou.token
ORDER BY sent DESC';
return $this->execQuery($sql, array($person_id, $functions, $person_id));
return $this->execQuery(
$this->_getReceivedMessagesQuery().' ORDER BY sent DESC',
array(
$person_id,
$functions,
$person_id
)
);
}
/**
@@ -337,38 +282,7 @@ class Recipient_model extends DB_Model
*/
public function getSentMessages($person_id)
{
$sql = 'SELECT mm.message_id,
mm.relationmessage_id,
mm.subject,
mm.body,
mm.insertamum AS sent,
p.person_id,
p.vorname,
p.nachname,
MAX(ms.status) AS status,
ms.person_id AS statusPersonId,
oe.bezeichnung AS oe,
mr.token
FROM public.tbl_msg_message mm
JOIN public.tbl_msg_recipient mr ON (mr.message_id = mm.message_id)
JOIN public.tbl_msg_status ms ON (ms.message_id = mm.message_id AND ms.person_id = mr.person_id)
JOIN public.tbl_person p ON (p.person_id = mr.person_id)
LEFT JOIN public.tbl_organisationseinheit oe ON (oe.oe_kurzbz = mr.oe_kurzbz)
WHERE mm.person_id = ?
GROUP BY mm.message_id,
mm.relationmessage_id,
mm.subject,
mm.body,
mm.insertamum,
p.person_id,
p.vorname,
p.nachname,
ms.person_id,
oe.bezeichnung,
mr.token
ORDER BY sent DESC';
return $this->execQuery($sql, array($person_id));
return $this->execQuery($this->_getSentMessagesQuery().' ORDER BY sent DESC', array($person_id));
}
/**
@@ -393,4 +307,170 @@ class Recipient_model extends DB_Model
return $this->execQuery($sql, array($messageIds));
}
/**
*
*/
public function getReceivedAndSentMessages($person_id, $functions)
{
return $this->execQuery(
$this->_getReceivedMessagesQuery().
' UNION '.
$this->_getSentMessagesQuery().
' ORDER BY sent DESC',
array(
$person_id,
$functions,
$person_id,
$person_id
)
);
}
// -------------------------------------------------------------------------------------------------------------------------
// Private methods
/**
* Returns the query used to get the sent messages for a given person
*/
private function _getSentMessagesQuery()
{
return 'SELECT mm.message_id,
mm.relationmessage_id,
mm.subject,
mm.body,
mm.insertamum AS sent,
pr.person_id AS "recipientPersonId",
pr.vorname AS "recipientName",
pr.nachname AS "recipientSurname",
ps.person_id AS "senderPersonId",
ps.vorname AS "senderName",
ps.nachname AS "senderSurname",
(SELECT MAX(status) FROM public.tbl_msg_status WHERE message_id = mm.message_id AND person_id = mr.person_id) AS "lastStatus",
(SELECT MAX(insertamum) FROM public.tbl_msg_status WHERE message_id = mm.message_id AND person_id = mr.person_id) AS "lastStatusDate",
oe.oe_kurzbz AS "oeId",
COALESCE(sg.bezeichnung, oe.bezeichnung) AS oe,
mr.token
FROM public.tbl_msg_message mm
JOIN public.tbl_msg_recipient mr ON (mr.message_id = mm.message_id)
JOIN public.tbl_person pr ON (pr.person_id = mr.person_id)
JOIN public.tbl_person ps ON (ps.person_id = mm.person_id)
LEFT JOIN public.tbl_organisationseinheit oe ON (oe.oe_kurzbz = mr.oe_kurzbz)
LEFT JOIN public.tbl_studiengang sg ON (sg.oe_kurzbz = mr.oe_kurzbz)
WHERE mm.person_id = ?
GROUP BY mm.message_id,
mm.relationmessage_id,
mm.subject,
mm.body,
mm.insertamum,
pr.person_id,
pr.vorname,
pr.nachname,
ps.person_id,
ps.vorname,
ps.nachname,
"lastStatus",
"lastStatusDate",
oe.oe_kurzbz,
oe,
mr.token';
}
/**
* Returns the query used to get the received messages for a given person
*/
private function _getReceivedMessagesQuery()
{
return '-- Messages sent directly to the person
SELECT mr.message_id,
mm.relationmessage_id,
mm.subject,
mm.body,
mm.insertamum AS sent,
pr.person_id AS "recipientPersonId",
pr.vorname AS "recipientName",
pr.nachname AS "recipientSurname",
ps.person_id AS "senderPersonId",
ps.vorname AS "senderName",
ps.nachname AS "senderSurname",
(SELECT MAX(status) FROM public.tbl_msg_status WHERE message_id = mm.message_id AND person_id = mr.person_id) AS "lastStatus",
(SELECT MAX(insertamum) FROM public.tbl_msg_status WHERE message_id = mm.message_id AND person_id = mr.person_id) AS "lastStatusDate",
oe.oe_kurzbz AS "oeId",
COALESCE(sg.bezeichnung, oe.bezeichnung) AS oe,
mr.token
FROM public.tbl_msg_recipient mr
JOIN public.tbl_msg_message mm ON (mm.message_id = mr.message_id)
JOIN public.tbl_person ps ON (ps.person_id = mm.person_id)
JOIN public.tbl_person pr ON (pr.person_id = mr.person_id)
LEFT JOIN public.tbl_organisationseinheit oe ON (oe.oe_kurzbz = mm.oe_kurzbz)
LEFT JOIN public.tbl_studiengang sg ON (sg.oe_kurzbz = mm.oe_kurzbz)
WHERE mr.person_id = ?
GROUP BY mr.message_id,
mm.relationmessage_id,
mm.subject,
mm.body,
mm.insertamum,
pr.person_id,
pr.vorname,
pr.nachname,
ps.person_id,
ps.vorname,
ps.nachname,
"lastStatus",
"lastStatusDate",
oe.oe_kurzbz,
oe,
mr.token
UNION
-- Messages sent to a person that belongs to the recipient organisation unit
SELECT mrou.message_id,
mm.relationmessage_id,
mm.subject,
mm.body,
mm.insertamum AS sent,
pr.person_id AS "recipientPersonId",
pr.vorname AS "recipientName",
pr.nachname AS "recipientSurname",
ps.person_id AS "senderPersonId",
ps.vorname AS "senderName",
ps.nachname AS "senderSurname",
(SELECT MAX(status) FROM public.tbl_msg_status WHERE message_id = mrou.message_id AND person_id = mrou.person_id) AS "lastStatus",
(SELECT MAX(insertamum) FROM public.tbl_msg_status WHERE message_id = mrou.message_id AND person_id = mrou.person_id) AS "lastStatusDate",
oe.oe_kurzbz AS "oeId",
COALESCE(sg.bezeichnung, oe.bezeichnung) AS oe,
mrou.token
FROM public.tbl_person p
JOIN public.tbl_benutzer b ON (b.person_id = p.person_id)
JOIN (
SELECT uid, oe_kurzbz
FROM public.tbl_benutzerfunktion
WHERE (datum_von IS NULL OR datum_von <= NOW())
AND (datum_bis IS NULL OR datum_bis >= NOW())
AND funktion_kurzbz IN ?
) bf ON (bf.uid = b.uid)
JOIN public.tbl_msg_recipient mrou ON (mrou.oe_kurzbz = bf.oe_kurzbz)
JOIN public.tbl_msg_message mm ON (mm.message_id = mrou.message_id)
JOIN public.tbl_person ps ON (ps.person_id = mm.person_id)
JOIN public.tbl_person pr ON (pr.person_id = mrou.person_id)
LEFT JOIN public.tbl_organisationseinheit oe ON (oe.oe_kurzbz = mrou.oe_kurzbz)
LEFT JOIN public.tbl_studiengang sg ON (sg.oe_kurzbz = mrou.oe_kurzbz)
WHERE p.person_id = ?
GROUP BY mrou.message_id,
mm.relationmessage_id,
mm.subject,
mm.body,
mm.insertamum,
pr.person_id,
pr.vorname,
pr.nachname,
ps.person_id,
ps.vorname,
ps.nachname,
"lastStatus",
"lastStatusDate",
oe.oe_kurzbz,
oe,
mrou.token';
}
}