aboutsummaryrefslogtreecommitdiff
path: root/lib/calendar/CalendarWidgetView.php
blob: df980ff3953e529e720c799566d975ed670d08f5 (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
<?php
/**
 * Calendar widget view, links to details page of courses.
 *
 * @author  Jan-Hendrik Willms <tleilax+studip@gmail.com>
 * @license GPL2 or any later version
 * @since   Stud.IP 3.4
 *
 * @deprecated since Stud.IP 5.5
 */
class CalendarWidgetView extends CalendarWeekView
{
    /**
     * Creates a widget view from a week view.
     *
     * @param CalendarWeekView $view The CalendarWeekView object
     * @return CalendarWidgetView object with the data from the
     *         CalendarWeekView
     */
    public static function createFromWeekView(CalendarWeekView $view)
    {
        $new_view = new self($view->getColumns(), $view->getContext());
        $new_view->setReadOnly(true);
        return $new_view;
    }

    /**
     * Returns all columns of the calendar-view and removes everything that
     * is not needed and links the entry to the details page of the course.
     *
     * @return array of CalendarColumn
     */
    public function getColumns()
    {
        foreach ($this->entries as $column) {
            $column->setURL(false);
            foreach ($column->entries as $key => $entry) {
                if (isset($entry['cycle_id'])) {
                    list($course_id, $cycle_id) = explode('-', $entry['id']);

                    $url = URLHelper::getLink('dispatch.php/course/details/?sem_id=' . $course_id);
                    $column->entries[$key]['url'] = $url;
                } else {
                    unset($column->entries[$key]['url']);
                }

                unset($column->entries[$key]['onClick']);
                unset($column->entries[$key]['icons']);
            }
        }

        return $this->entries;
    }
}