Skip to content
Snippets Groups Projects
Commit d24f4748 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

set sender for consultation mails, fixes #616

parent 910f14df
No related branches found
No related tags found
No related merge requests found
......@@ -23,13 +23,14 @@ class ConsultationMailer
/**
* Sends a consultation information message.
*
* @param User $user Recipient
* @param ConsultationSlot $slot Slot in question
* @param string $subject Subject of the message
* @param string $reason Reason for a booking or cancelation
* @param User $sender Sender of the message
* @param User|null $sender Sender
* @param User $user Recipient
* @param ConsultationSlot $slot Slot in question
* @param string $subject Subject of the message
* @param string $reason Reason for a booking or cancelation
* @param User $sender Sender of the message
*/
public static function sendMessage(User $user, ConsultationBooking $booking, $subject, $reason = '')
public static function sendMessage(?User $sender, User $user, ConsultationBooking $booking, string $subject, string $reason = '')
{
// Don't send message if user doesn't want it
if (!UserConfig::get($user->id)->CONSULTATION_SEND_MESSAGES) {
......@@ -44,7 +45,12 @@ class ConsultationMailer
'reason' => $reason ?: _('Kein Grund angegeben'),
]);
messaging::sendSystemMessage($user, $subject, $message);
if ($sender === null) {
messaging::sendSystemMessage($user, $subject, $message);
} else {
$messaging = new messaging();
$messaging->insert_message($message, $user->username, $sender->id, '', '', '', '', $subject);
}
restoreLanguage();
}
......@@ -52,9 +58,10 @@ class ConsultationMailer
/**
* Send a booking information message to the teacher of the booked slot.
*
* @param ConsultationBooking $booking The booking
* @param User|null $sender
* @param ConsultationBooking $booking The booking
*/
public static function sendBookingMessageToResponsibilities(ConsultationBooking $booking)
public static function sendBookingMessageToResponsibilities(?User $sender, ConsultationBooking $booking)
{
foreach ($booking->slot->block->responsible_persons as $user) {
if ($user->id === $GLOBALS['user']->id) {
......@@ -62,10 +69,10 @@ class ConsultationMailer
}
self::sendMessage(
$sender,
$user,
$booking,
sprintf(_('Termin von %s zugesagt'), $booking->user->getFullName()),
$booking->reason
sprintf(_('Termin von %s zugesagt'), $booking->user->getFullName()), $booking->reason
);
}
}
......@@ -73,15 +80,16 @@ class ConsultationMailer
/**
* Send a booking information message to the user of the booked slot.
*
* @param User|null $sender
* @param ConsultationBooking $booking The booking
*/
public static function sendBookingMessageToUser(ConsultationBooking $booking)
public static function sendBookingMessageToUser(?User $sender, ConsultationBooking $booking)
{
self::sendMessage(
$sender,
$booking->user,
$booking,
sprintf(_('Termin bei %s zugesagt'), $booking->slot->block->range_display),
$booking->reason
sprintf(_('Termin bei %s zugesagt'), $booking->slot->block->range_display), $booking->reason
);
}
......@@ -89,27 +97,28 @@ class ConsultationMailer
* Send an information message about a changed reason to a user of the
* booked slot.
*
* @param ConsultationBooking $booking The booking
* @param User $receiver The receiver of the message
* @param User $sender The sender of the message
* @param User $sender The sender of the message
* @param ConsultationBooking $booking The booking
* @param User $receiver The receiver of the message
*/
public static function sendReasonMessage(ConsultationBooking $booking, User $receiver)
public static function sendReasonMessage(?User $sender, ConsultationBooking $booking, User $receiver)
{
self::sendMessage(
$sender,
$receiver,
$booking,
sprintf(_('Grund des Termins bei %s bearbeitet'), $booking->slot->block->range_display),
$booking->reason
sprintf(_('Grund des Termins bei %s bearbeitet'), $booking->slot->block->range_display), $booking->reason
);
}
/**
* Send a cancelation message to the teacher of the booked slot.
*
* @param User|null $sender
* @param ConsultationBooking $booking The booking
* @param String $reason Reason of the cancelation
* @param String $reason Reason of the cancelation
*/
public static function sendCancelMessageToResponsibilities(ConsultationBooking $booking, $reason = '')
public static function sendCancelMessageToResponsibilities(?User $sender, ConsultationBooking $booking, string $reason = '')
{
foreach ($booking->slot->block->responsible_persons as $user) {
if ($user->id === $GLOBALS['user']->id) {
......@@ -117,10 +126,10 @@ class ConsultationMailer
}
self::sendMessage(
$sender,
$user,
$booking,
sprintf(_('Termin von %s abgesagt'), $booking->user->getFullName()),
trim($reason)
sprintf(_('Termin von %s abgesagt'), $booking->user->getFullName()), trim($reason)
);
}
}
......@@ -128,16 +137,17 @@ class ConsultationMailer
/**
* Send a cancelation message to the user of the booked slot.
*
* @param User|null $sender
* @param ConsultationBooking $booking The booking
* @param String $reason Reason of the cancelation
* @param String $reason Reason of the cancelation
*/
public static function sendCancelMessageToUser(ConsultationBooking $booking, $reason)
public static function sendCancelMessageToUser(?User $sender, ConsultationBooking $booking, string $reason)
{
self::sendMessage(
$sender,
$booking->user,
$booking,
sprintf(_('Termin bei %s abgesagt'), $booking->slot->block->range_display),
trim($reason)
sprintf(_('Termin bei %s abgesagt'), $booking->slot->block->range_display), trim($reason)
);
}
}
......@@ -59,20 +59,20 @@ class ConsultationBooking extends SimpleORMap implements PrivacyObject
};
$config['registered_callbacks']['after_create'][] = function (ConsultationBooking $booking) {
ConsultationMailer::sendBookingMessageToUser($booking);
ConsultationMailer::sendBookingMessageToResponsibilities($booking);
ConsultationMailer::sendBookingMessageToUser($GLOBALS['user']->getAuthenticatedUser(), $booking);
ConsultationMailer::sendBookingMessageToResponsibilities($GLOBALS['user']->getAuthenticatedUser(), $booking);
};
$config['registered_callbacks']['before_store'][] = function (ConsultationBooking $booking) {
if (!$booking->isNew() && $booking->isFieldDirty('reason')) {
if ($GLOBALS['user']->id !== $booking->user_id) {
ConsultationMailer::sendReasonMessage($booking,$booking->user);
ConsultationMailer::sendReasonMessage($GLOBALS['user']->getAuthenticatedUser(), $booking, $booking->user);
}
$responsible_persons = $booking->slot->block->responsible_persons;
foreach ($responsible_persons as $user) {
if ($GLOBALS['user']->id !== $user->id) {
ConsultationMailer::sendReasonMessage($booking, $user);
ConsultationMailer::sendReasonMessage($GLOBALS['user']->getAuthenticatedUser(), $booking, $user);
}
}
}
......@@ -97,10 +97,10 @@ class ConsultationBooking extends SimpleORMap implements PrivacyObject
public function cancel($reason = '')
{
if ($GLOBALS['user']->id !== $this->user_id) {
ConsultationMailer::sendCancelMessageToUser($this, $reason);
ConsultationMailer::sendCancelMessageToUser($GLOBALS['user']->getAuthenticatedUser(), $this, $reason);
}
ConsultationMailer::sendCancelMessageToResponsibilities($this, $reason);
ConsultationMailer::sendCancelMessageToResponsibilities($GLOBALS['user']->getAuthenticatedUser(), $this, $reason);
return $this->delete() ? 1 : 0;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment