Skip to content
Snippets Groups Projects
Select Git revision
  • 420020047fabc213bd494bec473abd0cda4f5937
  • main default protected
  • step-3263
  • feature/plugins-cli
  • feature/vite
  • step-2484-peerreview
  • biest/issue-5051
  • tests/simplify-jsonapi-tests
  • fix/typo-in-1a70031
  • feature/broadcasting
  • database-seeders-and-factories
  • feature/peer-review-2
  • feature-feedback-jsonapi
  • feature/peerreview
  • feature/balloon-plus
  • feature/stock-images-unsplash
  • tic-2588
  • 5.0
  • 5.2
  • biest/unlock-blocks
  • biest-1514
21 results

ConsultationMailer.php

Blame
  • Forked from Stud.IP / Stud.IP
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ConsultationMailer.php 4.37 KiB
    <?php
    /**
     * @author  Jan-Hendrik Willms <tleilax+studip@gmail.com>
     * @license GPL2 or any later version
     */
    class ConsultationMailer
    {
        private static $messaging = null;
    
        /**
         * Returns a messaging object.
         *
         * @return messaging object
         */
        private static function getMessaging()
        {
            if (self::$messaging === null) {
                self::$messaging = new messaging();
            }
            return self::$messaging;
        }
    
        /**
         * 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
         */
        public static function sendMessage(User $user, ConsultationBooking $booking, $subject, $reason = '')
        {
            // Don't send message if user doesn't want it
            if (!UserConfig::get($user->id)->CONSULTATION_SEND_MESSAGES) {
                return;
            }
    
            setTempLanguage($user->id);
    
            $message = $GLOBALS['template_factory']->open('consultations/mail.php')->render([
                'user'   => $booking->user,
                'slot'   => $booking->slot,
                'reason' => $reason ?: _('Kein Grund angegeben'),
            ]);
    
            messaging::sendSystemMessage($user, $subject, $message);
    
            restoreLanguage();
        }
    
        /**
         * Send a booking information message to the teacher of the booked slot.
         *
         * @param  ConsultationBooking $booking The booking
         */
        public static function sendBookingMessageToResponsibilities(ConsultationBooking $booking)
        {
            foreach ($booking->slot->block->responsible_persons as $user) {
                if ($user->id === $GLOBALS['user']->id) {
                    continue;
                }
    
                self::sendMessage(
                    $user,
                    $booking,
                    sprintf(_('Termin von %s zugesagt'), $booking->user->getFullName()),
                    $booking->reason
                );
            }
        }
    
        /**
         * Send a booking information message to the user of the booked slot.
         *
         * @param  ConsultationBooking $booking The booking
         */
        public static function sendBookingMessageToUser(ConsultationBooking $booking)
        {
            self::sendMessage(
                $booking->user,
                $booking,
                sprintf(_('Termin bei %s zugesagt'), $booking->slot->block->range_display),
                $booking->reason
            );
        }
    
        /**
         * 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
         */
        public static function sendReasonMessage(ConsultationBooking $booking, User $receiver)
        {
            self::sendMessage(
                $receiver,
                $booking,
                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  ConsultationBooking $booking The booking
         * @param  String              $reason  Reason of the cancelation
         */
        public static function sendCancelMessageToResponsibilities(ConsultationBooking $booking, $reason = '')
        {
            foreach ($booking->slot->block->responsible_persons as $user) {
                if ($user->id === $GLOBALS['user']->id) {
                    continue;
                }
    
                self::sendMessage(
                    $user,
                    $booking,
                    sprintf(_('Termin von %s abgesagt'), $booking->user->getFullName()),
                    trim($reason)
                );
            }
        }
    
        /**
         * Send a cancelation message to the user of the booked slot.
         *
         * @param  ConsultationBooking $booking The booking
         * @param  String              $reason  Reason of the cancelation
         */
        public static function sendCancelMessageToUser(ConsultationBooking $booking, $reason)
        {
            self::sendMessage(
                $booking->user,
                $booking,
                sprintf(_('Termin bei %s abgesagt'), $booking->slot->block->range_display),
                trim($reason)
            );
        }
    }