diff options
| author | Moritz Strohm <strohm@data-quest.de> | 2024-01-29 15:16:24 +0000 |
|---|---|---|
| committer | Moritz Strohm <strohm@data-quest.de> | 2024-01-29 15:16:24 +0000 |
| commit | 7c1df847d94d3956bc763b94b73cebfe108dc9a1 (patch) | |
| tree | e18e003bff65c5bf0748c644d6cd3d235cb1feca /lib/models/CourseExDate.class.php | |
| parent | da0110d5e85279123e8dde392cb4c926397238bf (diff) | |
StEP 01354, closes #1354
Closes #1354
Merge request studip/studip!2116
Diffstat (limited to 'lib/models/CourseExDate.class.php')
| -rw-r--r-- | lib/models/CourseExDate.class.php | 174 |
1 files changed, 173 insertions, 1 deletions
diff --git a/lib/models/CourseExDate.class.php b/lib/models/CourseExDate.class.php index 993767a..ce50e31 100644 --- a/lib/models/CourseExDate.class.php +++ b/lib/models/CourseExDate.class.php @@ -33,7 +33,7 @@ * @property-read mixed $room_request additional field */ -class CourseExDate extends SimpleORMap implements PrivacyObject +class CourseExDate extends SimpleORMap implements PrivacyObject, Event { /** * Configures this model. @@ -247,4 +247,176 @@ class CourseExDate extends SimpleORMap implements PrivacyObject date('H:i', $this->end_time) ); } + + //Start of Event interface implementation. + + public static function getEvents(DateTime $begin, DateTime $end, string $range_id): array + { + return self::findBySQL( + "JOIN `seminar_user` + ON `seminar_user`.`seminar_id` = `ex_termine`.`range_id` + WHERE `seminar_user`.`user_id` = :user_id + AND `ex_termine`.`date` BETWEEN :begin AND :end + AND ( + IFNULL(`ex_termine`.`metadate_id`, '') = '' + OR `ex_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 + ] + ); + } + + //Event interface implementation: + + public function getObjectId() : string + { + return (string) $this->id; + } + + public function getPrimaryObjectID(): string + { + return $this->range_id; + } + + public function getObjectClass(): string + { + return static::class; + } + + public function getTitle(): string + { + return sprintf('%s (fällt aus)', $this->course->name ?? ''); + } + + public function getBegin(): DateTime + { + $begin = new DateTime(); + $begin->setTimestamp($this->date); + return $begin; + } + + public function getEnd(): DateTime + { + $end = new DateTime(); + $end->setTimestamp($this->end_time); + return $end; + } + + public function getDuration(): DateInterval + { + $begin = $this->getBegin(); + $end = $this->getEnd(); + return $end->diff($begin); + } + + public function getLocation(): string + { + return ''; + } + + public function getUniqueId(): string + { + return sprintf('Stud.IP-SEM-%1$s@%2$s', $this->id, $_SERVER['SERVER_NAME']); + } + + public function getDescription(): string + { + return trim($this->getValue('content')); + } + + public function getAdditionalDescriptions(): array + { + $descriptions = []; + if (count($this->dozenten) > 0) { + $descriptions[_('Durchführende Lehrende')] = implode(', ', $this->dozenten->getFullname()); + } + if (count($this->statusgruppen) > 0) { + $descriptions[_('Beteiligte Gruppen')] = implode(', ', $this->statusgruppen->getValue('name')); + } + return $descriptions; + } + + public function isAllDayEvent(): bool + { + //Course dates are never all day events. + return false; + } + + public function isWritable(string $user_id): bool + { + return $GLOBALS['perm']->have_studip_perm('dozent', $this->range_id, $user_id); + } + + public function getCreationDate(): DateTime + { + $mkdate = new DateTime(); + $mkdate->setTimestamp($this->mkdate); + return $mkdate; + } + + public function getModificationDate(): DateTime + { + $chdate = new DateTime(); + $chdate->setTimestamp($this->chdate); + return $chdate; + } + + public function getImportDate(): DateTime + { + return $this->getCreationDate(); + } + + public function getAuthor(): ?User + { + return $this->author; + } + + public function getEditor(): ?User + { + return null; + } + + public function toEventData(string $user_id): \Studip\Calendar\EventData + { + $begin = new DateTime(); + $begin->setTimestamp($this->date); + $end = new DateTime(); + $end->setTimestamp($this->end_time); + + $studip_view_urls = []; + if ($GLOBALS['perm']->have_studip_perm('user', $this->range_id, $user_id)) { + $studip_view_urls['show'] = URLHelper::getURL('dispatch.php/course/details', ['cid' => $this->range_id, 'link_to_course' => '1']); + } + + return new \Studip\Calendar\EventData( + $begin, + $end, + $this->getTitle(), + [], + '#000000', + '#aaaaaa', + $this->isWritable($user_id), + CourseExDate::class, + $this->id, + Course::class, + $this->range_id, + 'course', + $this->range_id, + $studip_view_urls, + [], + 'seminar', + 'rgba(0,0,0,0)' + ); + } + + //End of Event interface implementation. } |
