* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2 * @category Stud.IP * @package calender */ class Calendar_ContentboxController extends StudipController { /** * Widget controller to produce the formally known show_dates() * * @param String $range_id range id (or array of range ids) of the news to get displayed */ public function display_action($range_id, $timespan = 604800, $start = null) { $this->admin = false; $this->single = false; $this->userRange = false; $this->termine = []; // Fetch time if needed $this->start = $start ?: strtotime('today'); $this->timespan = $timespan; // To array fallback of $range_id if (!is_array($range_id)) { $this->single = true; $range_id = [$range_id]; } foreach ($range_id as $id) { switch (get_object_type($id, ['user', 'sem'])) { case 'user': $this->parseUser($id); $this->userRange = true; break; case 'sem': $this->parseSeminar($id); break; } } // Check permission to edit if ($this->single) { $this->admin = $range_id[0] === $GLOBALS['user']->id || ( get_object_type($range_id[0], ['sem']) === 'sem' && $GLOBALS['perm']->have_studip_perm('tutor', $range_id[0]) ); // Set range_id $this->range_id = $range_id[0]; } // Forge title if (!empty($this->termine)) { $this->title = sprintf( _('Termine für die Zeit vom %s bis zum %s'), strftime('%d. %B %Y', $this->start), strftime('%d. %B %Y', $this->start + $this->timespan) ); } else { $this->title = _('Termine'); } // Check out if we are on a profile if ($this->admin) { $this->isProfile = $this->single && $this->userRange; } } private function parseSeminar($id) { $course = Course::find($id); $dates = $course->getDatesWithExdates()->findBy('end_time', [$this->start, $this->start + $this->timespan], '><'); $this->termine = []; foreach ($dates as $courseDate) { // Build info $info = []; if (count($courseDate->dozenten) > 0) { $info[_('Durchführende Lehrende')] = implode(', ', $courseDate->dozenten->getFullname()); } if (count($courseDate->statusgruppen) > 0) { $info[_('Beteiligte Gruppen')] = implode(', ', $courseDate->statusgruppen->getValue('name')); } // Store for view $description = ''; if ($courseDate instanceof CourseExDate) { $description = $courseDate->content; } elseif ($courseDate->cycle instanceof SeminarCycleDate) { $description = $courseDate->cycle->description; } $this->termine[] = [ 'id' => $courseDate->id, 'chdate' => $courseDate->chdate, 'title' => $courseDate->getFullname() . (count($courseDate->topics) > 0 ? ', ' . implode(', ', $courseDate->topics->getValue('title')) : ''), 'description' => $description, 'topics' => $courseDate->topics->toArray('title description'), 'room' => $courseDate->getRoomName(), 'info' => $info ]; } } private function parseUser($id) { $restrictions = $GLOBALS['user']->id === $id ? [] : ['CLASS' => 'PUBLIC']; $events = SingleCalendar::getEventList( $id, $this->start, $this->start + $this->timespan, null, $restrictions ); $this->termine = []; // Prepare termine foreach ($events as $termin) { // Exclude events that begin after the given time range if ($termin->getStart() > $this->start + $this->timespan) { continue; } // Adjust title if (date('Ymd', $termin->getStart()) == date('Ymd')) { $title = _('Heute') . date(', H:i', $termin->getStart()); } else { $title = mb_substr(strftime('%a', $termin->getStart()), 0, 2); $title .= date('. d.m.Y, H:i', $termin->getStart()); } if ($termin->getStart() < $termin->getEnd()) { if (date('Ymd', $termin->getStart()) < date('Ymd', $termin->getEnd())) { $title .= ' - ' . mb_substr(strftime('%a', $termin->getEnd()), 0, 2); $title .= date('. d.m.Y, H:i', $termin->getEnd()); } else { $title .= ' - ' . date('H:i', $termin->getEnd()); } } if ($termin->getTitle()) { $tmp_titel = mila($termin->getTitle()); //Beschneiden des Titels $title .= ', ' . $tmp_titel; } // Store for view $this->termine[] = [ 'id' => $termin->id, 'type' => get_class($termin), 'range_id' => $termin->range_id, 'event_id' => $termin->event_id, 'chdate' => $termin->chdate, 'title' => $title, 'description' => $termin->getDescription(), 'room' => $termin->getLocation(), 'info' => [ _('Kategorie') => $termin->toStringCategories(), _('Priorität') => $termin->toStringPriority(), _('Sichtbarkeit') => $termin->toStringAccessibility(), _('Wiederholung') => $termin->toStringRecurrence()] ]; } } }