aboutsummaryrefslogtreecommitdiff
path: root/lib/raumzeit/raumzeit_functions.inc.php
blob: a65f3bb0dd744032242c6f4c704eab2b4be659b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
# Lifter002: TODO
# Lifter007: TODO
# Lifter003: TODO
# Lifter010: TODO
/*
raumzeit_functions.inc.php
Helper functions for the "RaumZeit"-pages
Copyright (C) 2005-2007 Till Glöggler <tgloeggl@uos.de>

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

function getAllSortedSingleDates(&$sem) {
    $turnus = $sem->getFormattedTurnusDates();

    $termine = [];
    foreach ($sem->metadate->cycles as $metadate_id => $val) {
        $termine = array_merge($termine, $sem->getSingleDatesForCycle($metadate_id));
    }

    $termine = array_merge($termine, $sem->getSingleDates(true, false, true));
    uasort ($termine, function ($a, $b) {
        if ($a->getStartTime() === $b->getStartTime()) {
            return strnatcasecmp($a->getRoom(), $b->getRoom());
        }
        return $a->getStartTime() - $b->getStartTime();
    });

    return $termine;
}

/**
 * @param string $comment
 * @param array $dates SingleDate
 */
function raumzeit_send_cancel_message($comment, $dates)
{
    if (!is_array($dates)) {
        $dates = [$dates];
    }
    $course = Course::find($dates[0]->range_id);
    if ($course) {
        $subject = sprintf(_("[%s] Terminausfall"), $course->name);
        $recipients = $course->members->pluck('username');
        $lecturers = $course->members->findBy('status', 'dozent')->pluck('nachname');
        $message = sprintf(_("In der Veranstaltung %s fällt der/die folgende(n) Termine aus:"),
                 $course->name . ' ('. join(',', $lecturers) .') ' . $course->start_semester->name);
        $message .= "\n\n- ";
        $message .= join("\n- " , array_map(function($a) {return (string)$a; }, $dates));
        if ($comment) {
            $message .= "\n\n" . $comment;
        }
        $msg = new messaging();
        return $msg->insert_message($message, $recipients, '____%system%____', '', '', '', '', $subject, true);
    }

}