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

fixes #3435

Closes #3435

Merge request studip/studip!2343
parent db3efb24
No related branches found
No related tags found
No related merge requests found
...@@ -205,6 +205,7 @@ class Consultation_AdminController extends ConsultationController ...@@ -205,6 +205,7 @@ class Consultation_AdminController extends ConsultationController
$block->calendar_events = Request::bool('calender-events', false); $block->calendar_events = Request::bool('calender-events', false);
$block->show_participants = Request::bool('show-participants', false); $block->show_participants = Request::bool('show-participants', false);
$block->require_reason = Request::option('require-reason'); $block->require_reason = Request::option('require-reason');
$block->mail_to_tutors = Request::bool('mail-to-tutors', false);
$block->confirmation_text = trim(Request::get('confirmation-text')) ?: null; $block->confirmation_text = trim(Request::get('confirmation-text')) ?: null;
$block->note = Request::get('note'); $block->note = Request::get('note');
$block->size = Request::int('size', 1); $block->size = Request::int('size', 1);
...@@ -395,6 +396,7 @@ class Consultation_AdminController extends ConsultationController ...@@ -395,6 +396,7 @@ class Consultation_AdminController extends ConsultationController
$this->block->calendar_events = Request::bool('calender-events', false); $this->block->calendar_events = Request::bool('calender-events', false);
$this->block->show_participants = Request::bool('show-participants', false); $this->block->show_participants = Request::bool('show-participants', false);
$this->block->require_reason = Request::option('require-reason'); $this->block->require_reason = Request::option('require-reason');
$this->block->mail_to_tutors = Request::bool('mail-to-tutors', false);
$this->block->confirmation_text = trim(Request::get('confirmation-text')); $this->block->confirmation_text = trim(Request::get('confirmation-text'));
$this->block->lock_time = Request::int('lock_time'); $this->block->lock_time = Request::int('lock_time');
......
...@@ -198,6 +198,13 @@ $intervals = [ ...@@ -198,6 +198,13 @@ $intervals = [
<?= _('Die freien Termine auch im Kalender markieren') ?> <?= _('Die freien Termine auch im Kalender markieren') ?>
</label> </label>
<? if ($range instanceof Course): ?>
<label>
<input type="checkbox" name="mail-to-tutors" value="1" checked>
<?= _('Tutor/innen beim Versand allgemeiner Nachrichten berücksichtigen?') ?>
</label>
<? endif; ?>
<label> <label>
<input type="checkbox" name="show-participants" value="1" <input type="checkbox" name="show-participants" value="1"
<? if (Request::bool('show-participants')) echo 'checked'; ?>> <? if (Request::bool('show-participants')) echo 'checked'; ?>>
......
...@@ -57,6 +57,14 @@ ...@@ -57,6 +57,14 @@
<?= _('Die freien Termine auch im Kalender markieren') ?> <?= _('Die freien Termine auch im Kalender markieren') ?>
</label> </label>
<? if ($block->range_type === 'course'): ?>
<label>
<input type="checkbox" name="mail-to-tutors" value="1"
<? if ($block->mail_to_tutors) echo 'checked'; ?>>
<?= _('Tutor/innen beim Versand allgemeiner Nachrichten berücksichtigen?') ?>
</label>
<? endif; ?>
<label> <label>
<input type="checkbox" name="show-participants" value="1" <input type="checkbox" name="show-participants" value="1"
<? if ($block->show_participants) echo 'checked'; ?>> <? if ($block->show_participants) echo 'checked'; ?>>
......
<?php
/**
* @author Jan-Hendrik Willms <tleilax+studip@gmail.com>
* @license GPL2 or any later version
* @see https://gitlab.studip.de/studip/studip/-/issues/3435
*/
final class AddTutorMailingOptionToConsultationBlocks extends Migration
{
public function description()
{
return 'Adds the flag "mail_to_tutors" to table "consultation_blocks"';
}
protected function up()
{
$query = "ALTER TABLE `consultation_blocks`
ADD COLUMN `mail_to_tutors` TINYINT(1) UNSIGNED NOT NULL DEFAULT 1 AFTER `require_reason`";
DBManager::get()->exec($query);
}
protected function down()
{
$query = "ALTER TABLE `consultation_blocks`
DROP COLUMN `mail_to_tutors`";
DBManager::get()->exec($query);
}
}
...@@ -5,30 +5,14 @@ ...@@ -5,30 +5,14 @@
*/ */
class ConsultationMailer 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. * Sends a consultation information message.
* *
* @param User|null $sender Sender * @param User|null $sender Sender
* @param User $user Recipient * @param User $user Recipient
* @param ConsultationSlot $slot Slot in question * @param ConsultationBooking $booking Booking in question
* @param string $subject Subject of the message * @param string $subject Subject of the message
* @param string $reason Reason for a booking or cancelation * @param string|null $reason Reason for a booking or cancelation
* @param User $sender Sender of the message
*/ */
public static function sendMessage(?User $sender, User $user, ConsultationBooking $booking, string $subject, ?string $reason = '') public static function sendMessage(?User $sender, User $user, ConsultationBooking $booking, string $subject, ?string $reason = '')
{ {
...@@ -63,11 +47,7 @@ class ConsultationMailer ...@@ -63,11 +47,7 @@ class ConsultationMailer
*/ */
public static function sendBookingMessageToResponsibilities(?User $sender, ConsultationBooking $booking) public static function sendBookingMessageToResponsibilities(?User $sender, ConsultationBooking $booking)
{ {
foreach ($booking->slot->block->responsible_persons as $user) { foreach (self::getResponsiblePersonsOfBlock($booking->slot->block) as $user) {
if ($user->id === $GLOBALS['user']->id) {
continue;
}
self::sendMessage( self::sendMessage(
$sender, $sender,
$user, $user,
...@@ -97,7 +77,7 @@ class ConsultationMailer ...@@ -97,7 +77,7 @@ 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 User $sender The sender of the message * @param User|null $sender The sender of the message
* @param ConsultationBooking $booking The booking * @param ConsultationBooking $booking The booking
* @param User $receiver The receiver of the message * @param User $receiver The receiver of the message
*/ */
...@@ -120,11 +100,7 @@ class ConsultationMailer ...@@ -120,11 +100,7 @@ class ConsultationMailer
*/ */
public static function sendCancelMessageToResponsibilities(?User $sender, ConsultationBooking $booking, string $reason = '') public static function sendCancelMessageToResponsibilities(?User $sender, ConsultationBooking $booking, string $reason = '')
{ {
foreach ($booking->slot->block->responsible_persons as $user) { foreach (self::getResponsiblePersonsOfBlock($booking->slot->block) as $user) {
if ($user->id === $GLOBALS['user']->id) {
continue;
}
self::sendMessage( self::sendMessage(
$sender, $sender,
$user, $user,
...@@ -150,4 +126,30 @@ class ConsultationMailer ...@@ -150,4 +126,30 @@ class ConsultationMailer
sprintf(_('Termin bei %s abgesagt'), $booking->slot->block->range_display), trim($reason) sprintf(_('Termin bei %s abgesagt'), $booking->slot->block->range_display), trim($reason)
); );
} }
/**
* @return Generator<User>
*/
private static function getResponsiblePersonsOfBlock(ConsultationBlock $block): Generator
{
foreach ($block->responsible_persons as $user) {
/** @var User $user */
// No mail to self
if ($user->id === User::findCurrent()->id) {
continue;
}
// No mails to tutors
if (
$block->range_type === 'course'
&& !$block->mail_to_tutors
&& !$GLOBALS['perm']->have_studip_perm('dozent', $block->range_id, $user->id)
) {
continue;
}
yield $user;
}
}
} }
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
* @property int $calendar_events database column * @property int $calendar_events database column
* @property int $show_participants database column * @property int $show_participants database column
* @property string $require_reason database column * @property string $require_reason database column
* @property bool $mail_to_tutors database column
* @property string|null $confirmation_text database column * @property string|null $confirmation_text database column
* @property string $note database column * @property string $note database column
* @property int $size database column * @property int $size database column
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment