From 7ec7134a463e823ec6de8d8a2a5e18d8810ca25d Mon Sep 17 00:00:00 2001
From: Moritz Strohm <strohm@data-quest.de>
Date: Fri, 13 May 2022 07:29:13 +0000
Subject: [PATCH] TIC #841

Merge request studip/studip!489
---
 lib/cronjobs/check_admission.class.php | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/lib/cronjobs/check_admission.class.php b/lib/cronjobs/check_admission.class.php
index 36cfed6ab18..600598b48f4 100644
--- a/lib/cronjobs/check_admission.class.php
+++ b/lib/cronjobs/check_admission.class.php
@@ -34,6 +34,12 @@ class CheckAdmissionJob extends CronJob
                 'status'      => 'optional',
                 'description' => _('Sollen interne Nachrichten an alle betroffenen Nutzer gesendet werden)'),
             ],
+            'send_applications_to_owner' => [
+                'type'        => 'boolean',
+                'default'     => false,
+                'status'      => 'optional',
+                'description' => _('Die Liste mit Anmeldungen an die Person senden, der das Anmeldeset gehört.')
+            ]
         ];
     }
 
@@ -99,6 +105,24 @@ class CheckAdmissionJob extends CronJob
                         $applicants_file = $GLOBALS['TMP_PATH'] . '/seat_distribution_logs/applicants_' . $set_id . '.csv';
                         if (array_to_csv($data, $applicants_file, $captions)) {
                             echo 'applicants written to ' . $applicants_file . chr(10);
+                            if ($parameters['send_applications_to_owner']) {
+                                //Send a mail to the owner of the course set:
+                                $owner = User::find($courseset->getUserId());
+                                if ($owner) {
+                                    setTempLanguage($owner->id);
+                                    $mail = new StudipMail();
+                                    $mail->addRecipient($owner->email)
+                                        ->setSubject(
+                                            sprintf(_('Das Stud.IP Anmeldeset %s wird gelost'), $courseset->getName()))
+                                        ->setBodyText(sprintf(
+                                            _('Ihr Anmeldeset %s wird jetzt gelost. Im Anhang finden Sie die Liste der Anmeldungen.'),
+                                            $courseset->getName()
+                                        ))
+                                        ->addFileAttachment($applicants_file)
+                                        ->send();
+                                    restoreLanguage();
+                                }
+                            }
                         }
                     }
                     $courseset->distributeSeats();
-- 
GitLab