aboutsummaryrefslogtreecommitdiff
path: root/app/controllers/search/courses.php
blob: 536c361ae412fdef1f33cb94ce0dc5955f632122 (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
<?php
/**
 * 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   Rasmus Fuhse <fuhse@data-quest.de>
 * @license  http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
 * @category Stud.IP
 * @since    3.1
 */

class Search_CoursesController extends AuthenticatedController
{

    /**
     * @var string Holds the URL parameter with selected navigation option
     */
    private $nav_option = null;

    public function before_filter(&$action, &$args)
    {
        $this->allow_nobody = Config::get()->COURSE_SEARCH_IS_VISIBLE_NOBODY;

        parent::before_filter($action, $args);

        PageLayout::setHelpKeyword('Basis.VeranstaltungenAbonnieren');

        // activate navigation item
        $nav_options = Config::get()->COURSE_SEARCH_NAVIGATION_OPTIONS;
        URLHelper::bindLinkParam('option', $this->nav_option);
        if (!empty($nav_options[$this->nav_option])
                && Navigation::hasItem('/search/courses/' . $this->nav_option)) {
            Navigation::activateItem('/search/courses/' . $this->nav_option);
        } else {
            URLHelper::removeLinkParam('option');
            $level = Request::get('level', $_SESSION['sem_browse_data']['level'] ?? '');
            $default_option = SemBrowse::getSearchOptionNavigation('sidebar');
            if (!$level) {
                PageLayout::setTitle(_($default_option->getTitle()));
                $this->relocate($default_option->getURL());
            } elseif ($level == 'f' && $nav_options['courses']['visible']) {
                $course_option = SemBrowse::getSearchOptionNavigation('sidebar','courses');
                PageLayout::setTitle(_($course_option->getTitle()));
                Navigation::activateItem('/search/courses/semtree');
            } elseif (($level == 'vv') && $nav_options['semtree']['visible']) {
                $semtree_option = SemBrowse::getSearchOptionNavigation('sidebar','semtree');
                PageLayout::setTitle(_($semtree_option->getTitle()));
                Navigation::activateItem('/search/courses/semtree');
            } elseif ($level == 'ev' && $nav_options['rangetree']['visible']) {
                $rangetree_option = SemBrowse::getSearchOptionNavigation('sidebar','rangetree');
                PageLayout::setTitle(_($rangetree_option->getTitle()));
                Navigation::activateItem('/search/courses/rangetree');
            } else {
                throw new AccessDeniedException();
            }
        }
    }

    public function index_action()
    {
        SemBrowse::transferSessionData();
        $this->sem_browse_obj = new SemBrowse();

        if (!$GLOBALS['perm']->have_perm('root')) {
            $this->sem_browse_obj->target_url = 'dispatch.php/course/details/';
            $this->sem_browse_obj->target_id = 'sem_id';
        } else {
            $this->sem_browse_obj->target_url = 'seminar_main.php';
            $this->sem_browse_obj->target_id = 'auswahl';
        }

        $sidebar = Sidebar::get();

        // add search options to sidebar
        $level = Request::get('level', $_SESSION['sem_browse_data']['level'] ?? '');

        $widget = new OptionsWidget();
        $widget->setTitle(_('Suche'));
        //add a quicksearch input inside the widget
        $search_content = $this->sem_browse_obj->getQuickSearchForm();
        $search_element = new WidgetElement($search_content);
        $widget->addElement($search_element);
        $widget->addCheckbox(_('Erweiterte Suche anzeigen'),
        $_SESSION['sem_browse_data']['cmd'] == "xts",
        URLHelper::getURL('?level='.$level.'&cmd=xts&sset=0&option='),
        URLHelper::getURL('?level='.$level.'&cmd=qs&sset=0&option='));
        $sidebar->addWidget($widget);

        SemBrowse::setSemesterSelector($this->url_for('search/courses/index'));
        SemBrowse::setClassesSelector($this->url_for('search/courses/index'));


        if ($this->sem_browse_obj->show_result
                && count($_SESSION['sem_browse_data']['search_result'])) {
            $actions = new ActionsWidget();
            $actions->addLink(_('Download des Ergebnisses'),
                    URLHelper::getURL('dispatch.php/search/courses/export_results'),
                    Icon::create('file-office', 'clickable'));
            $sidebar->addWidget($actions);

            $grouping = new OptionsWidget();
            $grouping->setTitle(_('Suchergebnis gruppieren:'));
            foreach ($this->sem_browse_obj->group_by_fields as $i => $field) {
                $grouping->addRadioButton(
                    $field['name'],
                    URLHelper::getURL('?', ['group_by' => $i,
                        'keep_result_set' => 1]),
                    $_SESSION['sem_browse_data']['group_by'] == $i
                );
            }
            $sidebar->addWidget($grouping);
        }

        // show information about course class if class was changed
        $class = $GLOBALS['SEM_CLASS'][$_SESSION['sem_browse_data']['show_class']] ?? null;
        if (is_object($class) && $class->countSeminars() > 0) {
            if (trim($GLOBALS['SEM_CLASS'][$_SESSION['sem_browse_data']['show_class']]['description'])) {
                PageLayout::postInfo(sprintf(_('Gewählte Veranstaltungsklasse <i>%1s</i>: %2s'),
                        $GLOBALS['SEM_CLASS'][$_SESSION['sem_browse_data']['show_class']]['name'],
                        $GLOBALS['SEM_CLASS'][$_SESSION['sem_browse_data']['show_class']]['description']));
            } else {
                PageLayout::postInfo(sprintf(_('Gewählte Veranstaltungsklasse <i>%1s</i>.'),
                        $GLOBALS['SEM_CLASS'][$_SESSION['sem_browse_data']['show_class']]['name']));
            }
        } elseif ($_SESSION['sem_browse_data']['show_class'] != 'all') {
            PageLayout::postInfo(_('Im gewählten Semester ist in dieser Veranstaltungsklasse keine Veranstaltung verfügbar. Bitte wählen Sie eine andere Veranstaltungsklasse oder ein anderes Semester!'));
        }

        $this->controller = $this;
    }

    public function export_results_action()
    {
        $sem_browse_obj = new SemBrowse();
        $tmpfile = basename($sem_browse_obj->create_result_xls());
        if ($tmpfile) {
            $this->redirect(FileManager::getDownloadURLForTemporaryFile(
                    $tmpfile, _('ErgebnisVeranstaltungssuche.xls'), 4));
        } else {
            $this->render_nothing();
        }
    }

}