diff options
Diffstat (limited to 'lib/models/calendar')
| -rw-r--r-- | lib/models/calendar/CalendarCourseDate.class.php | 34 | ||||
| -rw-r--r-- | lib/models/calendar/CalendarCourseDate.php | 80 | ||||
| -rw-r--r-- | lib/models/calendar/CalendarCourseExDate.php (renamed from lib/models/calendar/CalendarCourseExDate.class.php) | 0 | ||||
| -rw-r--r-- | lib/models/calendar/CalendarDate.php (renamed from lib/models/calendar/CalendarDate.class.php) | 8 | ||||
| -rw-r--r-- | lib/models/calendar/CalendarDateAssignment.php (renamed from lib/models/calendar/CalendarDateAssignment.class.php) | 10 | ||||
| -rw-r--r-- | lib/models/calendar/CalendarDateException.php (renamed from lib/models/calendar/CalendarDateException.class.php) | 0 |
6 files changed, 89 insertions, 43 deletions
diff --git a/lib/models/calendar/CalendarCourseDate.class.php b/lib/models/calendar/CalendarCourseDate.class.php deleted file mode 100644 index 49179bd..0000000 --- a/lib/models/calendar/CalendarCourseDate.class.php +++ /dev/null @@ -1,34 +0,0 @@ -<?php - -/** - * CalendarCourseDate is a specialisation of CourseDate for - * course dates that are displayed in the personal calendar. - */ -class CalendarCourseDate extends CourseDate -{ - public static function getEvents(DateTime $begin, DateTime $end, string $range_id): array - { - return parent::findBySQL( - "JOIN `seminar_user` - ON `seminar_user`.`seminar_id` = `termine`.`range_id` - WHERE `seminar_user`.`user_id` = :user_id - AND `seminar_user`.`bind_calendar` = '1' - AND `termine`.`date` BETWEEN :begin AND :end - AND ( - IFNULL(`termine`.`metadate_id`, '') = '' - OR `termine`.`metadate_id` NOT IN ( - SELECT `metadate_id` - FROM `schedule_seminare` - WHERE `user_id` = :user_id - AND `visible` = 0 - ) - ) - ORDER BY date", - [ - 'begin' => $begin->getTimestamp(), - 'end' => $end->getTimestamp(), - 'user_id' => $range_id - ] - ); - } -} diff --git a/lib/models/calendar/CalendarCourseDate.php b/lib/models/calendar/CalendarCourseDate.php new file mode 100644 index 0000000..370dcd1 --- /dev/null +++ b/lib/models/calendar/CalendarCourseDate.php @@ -0,0 +1,80 @@ +<?php + +/** + * CalendarCourseDate is a specialisation of CourseDate for + * course dates that are displayed in the personal calendar. + */ +class CalendarCourseDate extends CourseDate +{ + public static function getEvents(DateTime $begin, DateTime $end, string $range_id): array + { + $events = []; + parent::findEachBySQL( + function ($e) use (&$events, $range_id) { + if (self::checkRelated($e, $range_id)) { + $events[] = $e; + } + }, + "JOIN `seminar_user` + ON `seminar_user`.`seminar_id` = `termine`.`range_id` + WHERE `seminar_user`.`user_id` = :user_id + AND `seminar_user`.`bind_calendar` = '1' + AND `termine`.`date` BETWEEN :begin AND :end + AND ( + IFNULL(`termine`.`metadate_id`, '') = '' + OR `termine`.`metadate_id` NOT IN ( + SELECT `metadate_id` + FROM `schedule_seminare` + WHERE `user_id` = :user_id + AND `visible` = 0 + ) + ) + ORDER BY date", + [ + 'begin' => $begin->getTimestamp(), + 'end' => $end->getTimestamp(), + 'user_id' => $range_id + ] + ); + return $events; + } + + /** + * Checks if given user is the responsible lecturer or is member of a + * related group. + * + * @global object $perm The global perm object. + * @param CalendarCourseDate $event The course event to check against. + * @param string $user_id The id of the user. + * @return boolean + */ + protected static function checkRelated(CalendarCourseDate $event, string $user_id): bool + { + $check_related = false; + $permission = $GLOBALS['perm']->get_studip_perm($event->range_id, $user_id); + switch ($permission) { + case 'dozent' : + $related_persons = $event->dozenten->pluck('user_id'); + if (count($related_persons) > 0) { + $check_related = in_array($user_id, $related_persons); + } else { + $check_related = true; + } + break; + case 'tutor' : + $check_related = true; + break; + default : + $group_ids = $event->statusgruppen->pluck('statusgruppe_id'); + if (count($group_ids) > 0) { + $member = StatusgruppeUser::findBySQL( + 'statusgruppe_id IN(?) AND user_id = ?', + [$group_ids, $user_id]); + $check_related = count($member) > 0; + } else { + $check_related = true; + } + } + return $check_related; + } +} diff --git a/lib/models/calendar/CalendarCourseExDate.class.php b/lib/models/calendar/CalendarCourseExDate.php index eb23aeb..eb23aeb 100644 --- a/lib/models/calendar/CalendarCourseExDate.class.php +++ b/lib/models/calendar/CalendarCourseExDate.php diff --git a/lib/models/calendar/CalendarDate.class.php b/lib/models/calendar/CalendarDate.php index e9269c6..0318dab 100644 --- a/lib/models/calendar/CalendarDate.class.php +++ b/lib/models/calendar/CalendarDate.php @@ -1,6 +1,6 @@ <?php /** - * CalendarDate.class.php - Model class for calendar dates. + * CalendarDate.php - Model class for calendar dates. * * CalendarDate represents a date in the personal calendar. * @@ -114,7 +114,7 @@ class CalendarDate extends SimpleORMap implements PrivacyObject public function cbSendDateModificationMail() { - $template_factory = new Flexi_TemplateFactory($GLOBALS['STUDIP_BASE_PATH'] . '/locale/'); + $template_factory = new Flexi\Factory($GLOBALS['STUDIP_BASE_PATH'] . '/locale/'); foreach ($this->calendars as $calendar) { if ($calendar->range_id === $this->editor_id) { @@ -402,8 +402,8 @@ class CalendarDate extends SimpleORMap implements PrivacyObject $sorm = self::findThru($storage->user_id, [ 'thru_table' => 'calendar_date_assignments', 'thru_key' => 'range_id', - 'thru_assoc_key' => 'event_id', - 'assoc_foreign_key' => 'event_id', + 'thru_assoc_key' => 'calendar_date_id', + 'assoc_foreign_key' => 'id', ]); if ($sorm) { $field_data = []; diff --git a/lib/models/calendar/CalendarDateAssignment.class.php b/lib/models/calendar/CalendarDateAssignment.php index fbd21a7..e0e2135 100644 --- a/lib/models/calendar/CalendarDateAssignment.class.php +++ b/lib/models/calendar/CalendarDateAssignment.php @@ -1,6 +1,6 @@ <?php /** - * CalendarDateAssignment.class.php - Model class for calendar date assignments. + * CalendarDateAssignment.php - Model class for calendar date assignments. * * CalendarDateAssignment represents the assignment of a calendar date * to a specific calendar. The calendar is represented by a range-ID @@ -79,7 +79,7 @@ class CalendarDateAssignment extends SimpleORMap implements Event return; } - $template_factory = new Flexi_TemplateFactory($GLOBALS['STUDIP_BASE_PATH'] . '/locale/'); + $template_factory = new Flexi\Factory($GLOBALS['STUDIP_BASE_PATH'] . '/locale/'); setTempLanguage($this->range_id); $lang_path = getUserLanguagePath($this->range_id); @@ -112,7 +112,7 @@ class CalendarDateAssignment extends SimpleORMap implements Event return; } - $template_factory = new Flexi_TemplateFactory($GLOBALS['STUDIP_BASE_PATH'] . '/locale/'); + $template_factory = new Flexi\Factory($GLOBALS['STUDIP_BASE_PATH'] . '/locale/'); setTempLanguage($this->range_id); $lang_path = getUserLanguagePath($this->range_id); @@ -160,7 +160,7 @@ class CalendarDateAssignment extends SimpleORMap implements Event return; } - $template_factory = new Flexi_TemplateFactory($GLOBALS['STUDIP_BASE_PATH'] . '/locale/'); + $template_factory = new Flexi\Factory($GLOBALS['STUDIP_BASE_PATH'] . '/locale/'); setTempLanguage($this->range_id); $lang_path = getUserLanguagePath($this->range_id); @@ -250,7 +250,7 @@ class CalendarDateAssignment extends SimpleORMap implements Event ]); - $sql_repetition = $sql . " AND `calendar_dates`.`begin` < :end AND `calendar_dates`.`repetition_type` IN ('DAYLY', 'WEEKLY', 'MONTHLY', 'YEARLY') + $sql_repetition = $sql . " AND `calendar_dates`.`begin` < :end AND `calendar_dates`.`repetition_type` IN ('DAILY', 'WEEKLY', 'MONTHLY', 'YEARLY') AND `calendar_dates`.`repetition_end` > :begin "; diff --git a/lib/models/calendar/CalendarDateException.class.php b/lib/models/calendar/CalendarDateException.php index b53a728..b53a728 100644 --- a/lib/models/calendar/CalendarDateException.class.php +++ b/lib/models/calendar/CalendarDateException.php |
