aboutsummaryrefslogtreecommitdiff
path: root/lib/raumzeit/SingleDate.class.php
blob: 6faeb4b97741235df766766aa3440a2a7fdcc70b (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
<?php
# Lifter002: TODO
# Lifter007: TODO
# Lifter003: TODO
# Lifter010: TODO
/**
 * SingelDate.class.php - Ein (Ex-)Termin
 *
 * Diese Klasse stellt einen einzelnen Eintrag in der Tabelle termine, bzw. ex_termine dar.
 *
 * 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.
 *
 * @author      Till Glöggler <tgloeggl@uos.de>
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
 * @category    Stud.IP
 */
require_once 'lib/dates.inc.php';

class SingleDate
{
    var $termin_id       = '';
    var $date_typ        = 1;
    var $metadate_id     = '';
    var $date            = 0;
    var $end_time        = 0;
    var $mkdate          = 0;
    var $chdate          = 0;
    var $orig_ex         = false;
    var $ex_termin       = false;
    var $range_id        = '';
    var $author_id       = '';
    var $resource_id     = '';
    var $raum            = '';
    var $request_id      = NULL;
    var $requestData     = NULL;
    var $update          = false;
    var $issues          = NULL;
    var $messages        = NULL;
    var $content         = '';
    var $room_request    = NULL;
    var $related_persons = [];
    var $related_groups  = [];

    /**
     * Return the SingleDate instance of the given id
     *
     * @param string      the id of the instance
     * @return SingleDate the SingleDate instance
     */
    function getInstance($singledate_id)
    {
        static $singledate_object_pool;

        if ($singledate_id) {
            if (is_object($singledate_object_pool[$singledate_id]) && $singledate_object_pool[$singledate_id]->getTerminId() == $singledate_id) {
                return $singledate_object_pool[$singledate_id];
            } else {
                $singledate_object_pool[$singledate_id] = new SingleDate($singledate_id);

                return $singledate_object_pool[$singledate_id];
            }
        } else {
            return new SingleDate();
        }

    }

    function __construct($data = '')
    {
        global $user, $id;
        if ($data instanceOf CourseDate || $data instanceof CourseExDate) {
            $single_date_data = $data->toArray();
            $single_date_data['ex_termin'] = $data instanceOf CourseDate ? 0 : 1;
            $single_date_data['resource_id'] = $data->room_booking->resource_id ?: '';
            if ($data instanceOf CourseDate) {
                $single_date_data['related_persons'] = $data->dozenten->pluck('user_id');
                $single_date_data['related_groups'] = $data->statusgruppen->pluck('statusgruppe_id');
            }
            $this->fillValuesFromArray($single_date_data);
        } else {
            if (is_array($data)) {
                if ($data['termin_id']) $termin_id = $data['termin_id'];
                if ($data['seminar_id']) $id = $data['seminar_id'];
            } else {
                $termin_id = $data;
            }
            if ($termin_id != '') {
                $this->termin_id = $termin_id;
                $this->update = true;
                $this->restore();
            } else {
                $this->termin_id = md5(uniqid('SingleDate', 1));
                $this->author_id = $user->id;
                $this->range_id = $id;
                $this->mkdate = time();
                $this->chdate = time();
                $this->update = false;
            }
        }
    }


    function getStartTime()
    {
        return $this->date;
    }

    function setTime($start, $end)
    {
        if (($start == 0) || ($end == 0)) return false;

        if (($this->date != $start) || ($this->end_time != $end)) {
            // validate the passed variables: they have to be ints and $start
            // has to be smaller than $end
            if ($this->validate($start, $end)) {
                $before = $this->toString();

                // if the time-span has been shortened, keep the room-booking,
                // otherwise remove it.
                if ($this->resource_id) {
                    if ($start >= $this->date && $end <= $this->end_time) {
                        //Shrink the booking.
                        if ($assign_id = SingleDateDB::getAssignID($this->termin_id)) {
                            $assign_object = new ResourceBooking($assign_id);
                            $assign_object->resource_id = $this->resource_id;
                            $assign_object->begin = $start;
                            $assign_object->end = $end;
                            $assign_object->repeat_end = $end;
                            $assign_object->store();
                        }
                    } else {
                        $this->killAssign();
                    }
                }

                $this->date = $start;
                $this->end_time = $end;

                $after = $this->toString();
                // logging
                if ($before) {
                    StudipLog::log("SINGLEDATE_CHANGE_TIME", $this->range_id, $before, $before . ' -> ' . $after);
                } else {
                    StudipLog::log("SEM_ADD_SINGLEDATE", $this->range_id, $after);
                }

                return true;
            }

            return false;
        }

        return false;
    }

    function getEndTime()
    {
        return $this->end_time;
    }

    function setComment($comment)
    {
        $this->content = $comment;
    }

    function getComment()
    {
        if (!$this->isExTermin()) return '';

        return $this->content;
    }

    function getMetaDateID()
    {
        return $this->metadate_id;
    }

    function setMetaDateID($id)
    {
        if ($id != '') {
            $this->metadate_id = $id;

            return true;
        } else {
            $this->metadate_id = 0;

            return false;
        }
    }

    function getRangeID()
    {
        return $this->range_id;
    }

    function setDateType($typ)
    {
        $this->date_typ = $typ;

        return true;
    }

    function getDateType()
    {
        return $this->date_typ;
    }

    function getTypeName()
    {
        global $TERMIN_TYP;

        return $TERMIN_TYP[$this->date_typ]['name'];
    }

    function getAuthorID()
    {
        return $this->author_id;
    }

    function getChDate()
    {
        return $this->chdate;
    }

    function getMkDate()
    {
        return $this->mkdate;
    }

    function setSeminarID($seminar_id)
    {
        $this->range_id = $seminar_id;
    }

    function getSeminarID()
    {
        return $this->range_id;
    }

    function getSingleDateID()
    {
        return $this->termin_id;
    }

    function getResourceID()
    {
        return $this->resource_id;
    }

    function getTerminID()
    {
        return $this->termin_id;
    }

    function getFreeRoomText()
    {
        return $this->raum;
    }

    function setFreeRoomText($freeRoomText)
    {
        $this->raum = $freeRoomText;
    }

    function getCycleID()
    {
        return $this->metadate_id;
    }

    function killIssue()
    {
        // We delete the issue, cause there is no chance anybody can get to it without the expert view
        if (!Config::get()->RESOURCES_ENABLE_EXPERT_SCHEDULE_VIEW) {
            if ($issue_ids = $this->getIssueIDs()) {
                foreach ($issue_ids as $issue_id) {
                    // delete this issue
                    unset($this->issues[$issue_id]);
                    $issue = new Issue(['issue_id' => $issue_id]);
                    $issue->delete();
                }
            }
        }
    }

    function delete($keepIssues = false)
    {
        $cache = StudipCacheFactory::getCache();
        $cache->expire('course/undecorated_data/' . $this->range_id);

        $this->chdate = time();
        $this->killAssign();
        if (!$keepIssues) {
            $this->killIssue();
        }

        return SingleDateDB::deleteSingleDate($this->termin_id, $this->ex_termin);
    }

    function store()
    {

        $cache = StudipCacheFactory::getCache();
        $cache->expire('course/undecorated_data/' . $this->range_id);

        $this->chdate = time();
        if ($this->ex_termin) {
            $this->killAssign();
        }

        // date_typ = 0 defaults to TERMIN_TYP[1] because there never exists one with zero
        if (!$this->date_typ) $this->date_typ = 1;

        if ($this->orig_ex != $this->ex_termin) {
            SingleDateDB::deleteSingleDate($this->termin_id, $this->orig_ex);
        }

        return SingleDateDB::storeSingleDate($this);
    }

    function restore()
    {
        if (!($data = SingleDateDB::restoreSingleDate($this->termin_id))) {
            return false;
        }
        $this->fillValuesFromArray($data);

        return true;
    }

    function setExTermin($ex)
    {
        if ($ex != $this->ex_termin) {
            $this->update = false;
            $this->ex_termin = $ex;

            return true;
        }

        return false;
    }

    function isExTermin()
    {
        return $this->ex_termin;
    }

    function isPresence()
    {
        return $GLOBALS['TERMIN_TYP'][$this->date_typ]['sitzung'] ? true : false;
    }

    function isUpdate()
    {
        return $this->update;
    }

    function isHoliday()
    {
        foreach (SemesterHoliday::getAll() as $val) {
            if (($val['beginn'] <= $this->date) && ($val['ende'] >= $this->end_time)) {
                $name = $val['name'];
            }
        }

        if (!$name) {
            $holy_type = holiday($this->date);
            $name = $holy_type['name'];
        }

        if ($name) {
            return $name;
        } else {
            return false;
        }
    }

    function fillValuesFromArray($daten)
    {
        $this->metadate_id = $daten['metadate_id'];
        $this->termin_id = $daten['termin_id'];
        if ($daten['date_typ'] != 0) {
            $this->date_typ = $daten['date_typ'];
        } else {
            // if no date_typ is specified it defaults to 1
            $this->date_typ = 1;
        }
        $this->date = $daten['date'];
        $this->end_time = $daten['end_time'];
        $this->mkdate = $daten['mkdate'];
        $this->chdate = $daten ['chdate'];
        $this->ex_termin = $daten['ex_termin'];
        $this->orig_ex = $daten['ex_termin'];
        $this->range_id = $daten['range_id'];
        $this->author_id = $daten['autor_id'];
        $this->resource_id = $daten['resource_id'];
        $this->raum = $daten['raum'];
        $this->content = $daten['content'];
        $this->update = true;
        $this->related_persons = is_array($daten['related_persons']) ? $daten['related_persons'] : [];
        $this->related_groups = is_array($daten['related_groups']) ? $daten['related_groups'] : [];

        return true;
    }

    function toString()
    {
        $end_hours = strtotime(strftime('%H:%M', $this->end_time));
        $start_hours = strtotime(strftime('%H:%M', $this->date));
        if (!$this->date) {
            return null;
        } elseif ((($end_hours - $start_hours) / 60 / 60) > 23) {
            return sprintf('%s , %s (%s)',strftime('%a', $this->date),
                strftime('%d.%m.%Y', $this->date),
                _('ganztägig'));
        } else {
            return sprintf('%s., %s - %s',strftime('%a', $this->date),
                strftime('%d.%m.%Y %H:%M', $this->date),
                strftime('%H:%M', $this->end_time));
        }
    }

    function bookRoom($room_id, $preparation_time = 0)
    {
        if ($this->ex_termin || !$room_id) {
            return false;
        }

        // create a resource-object of the passed room
        $room = Room::find($room_id);

        // there is no room with the passed id
        if (!$room) {
            return false;
        }

        // check permissions (is current user allowed to book the passed room?)
        if (!$room->userHasBookingRights(User::findCurrent())) {
            return false;
        }

        // clear the freetext-field, if we book a room
        $this->setFreeRoomText('');
        $this->store();

        //If there is already a room assigned, "change" the booking.
        //Otherwise create a new one.
        if ($this->resource_id != '') {
            $this->changeAssign($room, $preparation_time);
        } else {
            $this->insertAssign($room, $preparation_time);
        }

        return $room;
    }

    private function insertAssign(Room $room, $preparation_time = 0)
    {
        $begin = new DateTime();
        $begin->setTimestamp($this->date);
        $end = new DateTime();
        $end->setTimestamp($this->end_time);

        //If the following code is executed a new room booking can be created:
        try {
            $booking = $room->createBooking(
                User::findCurrent(),
                $this->termin_id,
                [
                    [
                        'begin' => $begin,
                        'end' => $end
                    ]
                ],
                null,
                0,
                null,
                $preparation_time * 60
            );
            if ($booking instanceof ResourceBooking) {
                $booking->deleteOverlappingReservations();
                $room_link_string = sprintf(
                    '<a href="%1$s" data-dialog="1">%2$s</a>',
                    $room->getActionLink(),
                    htmlReady($room->name)
                );

                $this->assign_id = $booking->id;
                SingleDateDB::storeSingleDate($this);
                $msg = sprintf(
                    _('Für den Termin %1$s wurde der Raum %2$s gebucht.'),
                    $this->toString(),
                    $room_link_string
                );
                $this->messages['success'][] = $msg;
            }
        } catch (ResourceBookingRangeException $e) {
            $this->messages['error'][] = _('Fehler beim Verknüpfen der Raumbelegung mit dem Einzeltermin!');
            return false;
        } catch (ResourceBookingOverlapException $e) {
            $error_message = sprintf(
                _('Für den Termin %1$s konnte der Raum %2$s nicht gebucht werden, da es Überschneidungen mit folgenden Terminen gibt:'),
                $this->toString(),
                htmlReady($room->name)
                ) . '<br>';
            $overlapping_bookings = array_merge(
                $room->getResourceBookings($begin, $end),
                $room->getResourceLocks($begin, $end)
            );
            foreach ($overlapping_bookings as $overlapping_booking) {
                $error_message .= $overlapping_booking->getOverlapMessage();
            }
            $this->messages['error'][] = $error_message;
            return false;
        } catch (ResourcePermissionException $e) {
            $this->messages['error'][] = $e->getMessage();
            return false;
        } catch (ResourceBookingException $e) {
            $this->messages['error'][] = $e->getMessage();
            return false;
        }

        return true;
    }


    private function changeAssign(Room $room, $preparation_time = 0)
    {
        $max_preparation_time = (Config::get()->RESOURCES_MAX_PREPARATION_TIME);
        if ($preparation_time > $max_preparation_time) {
            $this->messages['error'][] = sprintf(
                _('Die eingegebene Rüstzeit überschreitet das erlaubte Maximum von %d Minuten!'),
                $max_preparation_time
            );
            return false;
        }
        if ($assign_id = SingleDateDB::getAssignID($this->termin_id)) {
            $changeAssign = new ResourceBooking($assign_id);
            $changeAssign->resource_id = $room->id;
            $changeAssign->range_id = $this->termin_id;
            $changeAssign->begin = $this->date;
            $changeAssign->end = $this->end_time;
            $changeAssign->repeat_end = $this->end_time;
            $changeAssign->repeat_quantity = 0;
            $changeAssign->repetition_interval = '';
            if ($preparation_time > 0) {
                $changeAssign->preparation_time = $preparation_time * 60;
            }

            $room_link_string = sprintf(
                '<a href="%1$s" data-dialog="1">%2$s</a>',
                $room->getActionLink(),
                htmlReady($room->name)
            );

            $overlaps = $changeAssign->getOverlappingBookings();
            if (is_array($overlaps) && (sizeof($overlaps) > 0)) {
                $msg = sprintf(
                    _('Für den Termin %1$s konnte der Raum %2$s nicht gebucht werden, da es Überschneidungen mit folgenden Terminen gibt:'),
                    $this->toString(),
                    $room_link_string
                    ) . '<br>';
                foreach ($overlaps as $overlap) {
                    $msg .= $this->getOverlapMessage($overlap);
                }
                $this->messages['error'][] = $msg;

                return false;
            }

            $this->resource_id = $room->id;
            try {
                $changeAssign->store();
            } catch (ResourceBookingOverlapException $e) {
                $room = $changeAssign->resource->getDerivedClassInstance();
                if($room instanceof Room) {
                    $room_text = $link = sprintf(
                        '<a href="%1$s" data-dialog="1">%2$s</a>',
                        $room->getActionLink(),
                        htmlReady($room->name)
                    );
                } else {
                    $room_text = $changeAssign->resource->name;
                }
                $this->messages['error'][] = sprintf(
                    _('%1$s: Die Buchung vom %2$s bis %3$s konnte wegen Überlappungen nicht gespeichert werden: %4$s'),
                    $room_text,
                    date('d.m.Y H:i', $changeAssign->begin),
                    date('H:i', $changeAssign->end),
                    htmlReady($e->getMessage())
                );
            }

            $msg = sprintf(
                _('Für den Termin %1$s wurde der Raum %2$s gebucht.'),
                $this->toString(),
                $room_link_string
            );
            $this->messages['success'][] = $msg;

            return true;
        }

        return false;
    }

    function killAssign()
    {
        $this->resource_id = '';
        if ($assign_id = SingleDateDB::getAssignID($this->termin_id)) {
            $assign_object = new ResourceBooking($assign_id);
            $assign_object->delete();
        }
    }


    /**
     * Returns the room name for this SingleDate object.
     *
     * @returns string The room name.
     */
    public function getRoom()
    {
        if (!$this->resource_id) {
            return null;
        } else {
            $room = Room::find($this->resource_id);

            return $room->name;
        }
    }


    function readIssueIDs()
    {
        if (!$this->issues) {
            if ($data = SingleDateDB::getIssueIDs($this->termin_id)) {
                foreach ($data as $val) {
                    $this->issues[$val['issue_id']] = $val['issue_id'];
                }
            }
        }

        return true;
    }

    function getIssueIDs()
    {
        $this->readIssueIDs();

        return $this->issues;
    }

    function addIssueID($issue_id)
    {
        $this->readIssueIDs();
        $this->issues[$issue_id] = $issue_id;

        return true;
    }

    function deleteIssueID($issue_id)
    {
        $this->readIssueIDs();
        unset($this->issues[$issue_id]);
        SingleDateDB::deleteIssueID($issue_id, $this->termin_id);

        return true;
    }

    function getMessages()
    {
        $temp = $this->messages;
        $this->messages = NULL;

        return $temp;
    }

    // checks, if the single-date has plausible values
    function validate($start = 0, $end = 0)
    {
        if ($start == 0) {
            $start = $this->date;
        }
        if ($end == 0) {
            $end = $this->end_time;
        }

        if ($start < 100000) return false;
        if ($end < 100000) return false;
        if ($start > $end) {
            $this->messages['error'][] = _("Die Endzeitpunkt darf nicht vor dem Anfangszeitpunkt liegen!");

            return false;
        }

        return true;
    }


    /**
     * returns a html representation of the date
     *
     * @param  array  optional variables which are passed to the template
     * @return  string  the html-representation of the date
     *
     * @author Till Glöggler <tgloeggl@uos.de>
     */
    function getDatesHTML($params = [])
    {
        $template = $GLOBALS['template_factory']->open('dates/date_html.php');
        $template->set_attributes($params);

        return $this->getDatesTemplate($template);
    }

    /**
     * returns a representation without html of the date
     *
     * @param  array  optional variables which are passed to the template
     * @return  string  the representation of the date without html
     *
     * @author Till Glöggler <tgloeggl@uos.de>
     */
    function getDatesExport($params = [])
    {
        $template = $GLOBALS['template_factory']->open('dates/date_export.php');
        $params['link'] = false;
        $template->set_attributes($params);

        return $this->getDatesTemplate($template);
    }

    /**
     * returns a xml-representation of the date
     *
     * @param  array  optional variables which are passed to the template
     * @return  string  the xml-representation of the date
     *
     * @author Till Glöggler <tgloeggl@uos.de>
     */
    function getDatesXML($params = [])
    {
        $template = $GLOBALS['template_factory']->open('dates/date_xml.php');
        $template->set_attributes($params);

        return $this->getDatesTemplate($template);
    }

    /**
     * returns a representation of the date with a specifiable template
     *
     * @param  mixed  this can be a template-object or a string pointing to a template in path_to_studip/templates
     * @return  string  the template output of the date
     *
     * @author Till Glöggler <tgloeggl@uos.de>
     */
    function getDatesTemplate($template)
    {
        if (!$template instanceof Flexi_Template && is_string($template)) {
            $template = $GLOBALS['template_factory']->open($template);
        }

        $template->set_attribute('date', $this);

        return $template->render();
    }

    /**
     * adds a given user_id as a related person to the date
     * @param string $user_id user_id from auth_user_md5 of the person to be added
     */
    public function addRelatedPerson($user_id)
    {
        $this->related_persons[] = $user_id;
        $this->related_persons = array_unique($this->related_persons);
    }

    /**
     * unsets a given user_id from the array of related persons
     * @param string $user_id user_id from auth_user_md5 of the person to be added
     */
    public function deleteRelatedPerson($user_id)
    {
        if (!$this->related_persons) {
            $sem = Seminar::getInstance($this->getSeminarID());
            $this->related_persons = array_keys($sem->getMembers('dozent'));
        }
        foreach ($this->related_persons as $key => $related_person) {
            if ($related_person === $user_id) {
                unset($this->related_persons[$key]);
            }
        }
    }

    /**
     * gets all user_ids of related persons of this date
     * @return array of user_ids
     */
    public function getRelatedPersons()
    {
        if (count($this->related_persons)) {
            return $this->related_persons;
        } else {
            $sem = Seminar::getInstance($this->getSeminarID());

            return array_keys($sem->getMembers('dozent'));
        }
    }

    /**
     * clears all related persons (in the interface this means that all dozents are
     * marked as related to the date)
     */
    public function clearRelatedPersons()
    {
        $this->related_persons = [];
    }

    /**
     * adds a given statusgruppe_id as a related group to the date
     * @param string $statusgruppe_id statusgruppe_id from statusgruppen of the group to be added
     */
    public function addRelatedGroup($statusgruppe_id)
    {
        $this->related_groups[] = $statusgruppe_id;
        $this->related_groups = array_unique($this->related_groups);
    }

    /**
     * unsets a given statusgruppe_id from the array of related statusgruppen
     * @param string $statusgruppe_id statusgruppe_id from statusgruppen of the group to be removed
     */
    public function deleteRelatedGroup($statusgruppe_id)
    {
        if (!$this->related_groups) {
            $groups = Statusgruppen::findBySeminar_id($this->getSeminarID());
            $this->related_groups = array_map(function ($g) {
                return $g->getId();
            }, $groups);
        }
        foreach ($this->related_groups as $key => $related_group) {
            if ($related_group === $statusgruppe_id) {
                unset($this->related_groups[$key]);
            }
        }
    }

    /**
     * gets all statusgruppe_ids of related groups of this date
     * @return array of statusgruppe_ids
     */
    public function getRelatedGroups()
    {
        if (count($this->related_groups)) {
            return $this->related_groups;
        } else {
            $groups = Statusgruppen::findBySeminar_id($this->getSeminarID());

            return array_map(function ($g) {
                return $g->getId();
            }, $groups);
        }
    }

    /**
     * clears all related groups
     */
    public function clearRelatedGroups()
    {
        $this->related_groups = [];
        $this->messages['success'][] = _('Die beteiligten Gruppen wurden zurückgesetzt!');
    }
}