aboutsummaryrefslogtreecommitdiff
path: root/app/controllers/settings/calendar.php
blob: e2775d0f417006c0820e00595d5d25d139d04247 (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
<?php
/**
 * Settings_CalendarController - Administration of all user calendar related
 * settings
 *
 * 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      Jan-Hendrik Willms <tleilax+studip@gmail.com>
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
 * @category    Stud.IP
 * @since       2.4
 */

require_once 'settings.php';

class Settings_CalendarController extends Settings_SettingsController
{
    /**
     * Set up this controller
     *
     * @param String $action Name of the action to be invoked
     * @param Array  $args   Arguments to be passed to the action method
     * @throws AccessDeniedException if the calendar is not globally enabled
     */
    public function before_filter(&$action, &$args)
    {
        if (!Config::get()->CALENDAR_ENABLE) {
            throw new AccessDeniedException(_('Der Kalender ist nicht aktiviert.'));
        }

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

        PageLayout::setHelpKeyword('Basis.MyStudIPTerminkalender');
        PageLayout::setTitle(_('Einstellungen des Kalenders anpassen'));
        Navigation::activateItem('/profile/settings/calendar_new');
    }

    /**
     * Display a user's calendar settings
     */
    public function index_action()
    {
        $calendar_user_control_data = (array) UserConfig::get($GLOBALS['user']->id)->getValue('CALENDAR_SETTINGS');
        foreach ($calendar_user_control_data as $key => $value) {
            $this->$key = $value;
        }
    }

    /**
     * Stores a user's calendar settings
     */
    public function store_action()
    {
        $this->check_ticket();

        $start = Request::option('cal_start');
        $end   = Request::option('cal_end');
        if ($start >= $end) {
            PageLayout::postError(_('Die Startuhrzeit muss vor der Enduhrzeit liegen.'));
            $calendar_user_control_data = (array) UserConfig::get($GLOBALS['user']->id)->getValue('CALENDAR_SETTINGS');
            foreach ($calendar_user_control_data as $key => $value) {
                $this->$key = $value;
            }
            $this->start = $start;
            $this->end   = $end;
            return;
        }

        $this->config->store('CALENDAR_SETTINGS', [
            'view'            => Request::option('cal_view'),
            'start'           => $start,
            'end'             => $end,
            'step_day'        => Request::option('cal_step_day'),
            'step_week'       => Request::option('cal_step_week'),
            'type_week'       => Request::option('cal_type_week'),
            'holidays'        => Request::option('cal_holidays'),
            'sem_data'        => Request::option('cal_sem_data'),
            'delete'          => Request::option('cal_delete'),
            'step_week_group' => Request::option('cal_step_week_group'),
            'step_day_group'  => Request::option('cal_step_day_group')
        ]);

        PageLayout::postSuccess(_('Die Einstellungen wurden gespeichert'));
        if (Request::isDialog()) {
            $this->response->add_header('X-Dialog-Close', '1');
            $this->render_nothing();
        } else {
            $this->redirect('settings/calendar');
        }
    }
}