Skip to content
Snippets Groups Projects
Commit 308bd662 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms Committed by David Siegfried
Browse files

set sender for consultation mails, fixes #616

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