aboutsummaryrefslogtreecommitdiff
path: root/app/controllers/studiengaenge/informationen.php
blob: 9889ab437520f903acaa5e81ad7ebbea77bf9760 (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
<?php
/**
 * @author      Peter Thienel <thienel@data-quest.de>
 * @author
 * @license     GPL2 or any later version
 * @since       4.6
 */

class Studiengaenge_InformationenController extends MVVController
{
    public function before_filter(&$action, &$args)
    {
        parent::before_filter($action, $args);

        if (!($GLOBALS['perm']->have_perm('root')
            || User::findCurrent()->hasRole('MVVAdmin'))) {
            throw new AccessDeniedException();
        }
        PageLayout::setTitle(_('Verwaltung der Studiengänge'));
        if (Navigation::hasItem('mvv/studiengaenge/informationen')) {
            Navigation::activateItem('mvv/studiengaenge/informationen');
        }
    }

    public function index_action()
    {
        $this->createSidebar();
        if ($GLOBALS['perm']->have_perm('root', $GLOBALS['user']->id)) {
            $this->studycourses = Fach::findBySQL('fach_id IN (SELECT DISTINCT(fach_id) FROM user_studiengang) ORDER BY name');
        } else {
            $inst_ids = SimpleCollection::createFromArray(Institute::findBySQL('Institut_id IN (SELECT institut_id FROM roles_user WHERE userid = :user_id)
                OR fakultaets_id IN (SELECT institut_id FROM roles_user WHERE userid = :user_id)',
                    [':user_id' => $GLOBALS['user']->user_id]))->pluck('institut_id');

            $this->studycourses = Fach::findBySQL('JOIN mvv_fach_inst as fach_inst ON (fach.fach_id = fach_inst.fach_id)
                WHERE fach_inst.institut_id IN (:inst_ids)
                GROUP BY fach.fach_id ORDER BY fach.name',
            [':inst_ids' => $inst_ids]);
        }
    }

    public function degree_action ()
    {
        $this->createSidebar('degrees');
        $this->degree = Degree::findBySQL('abschluss_id IN (SELECT DISTINCT(abschluss_id) FROM user_studiengang) ORDER BY name');
    }

    public function showdegree_action($studycourse_id, $nr = 0)
    {
        $this->studycourse = Fach::find($studycourse_id);
        $this->nr = $nr;
    }

    public function showstudycourse_action($degree_id, $nr = 0)
    {
        $this->nr = $nr;
        $this->degree = Abschluss::find($degree_id);
        $this->professions = $this->degree->professions;

        if ($GLOBALS['perm']->have_perm('root',$GLOBALS['user']->id)) {
            $this->studycourses = $this->degree->professions;
        } else {
            $inst_ids = SimpleCollection::createFromArray(Institute::findBySQL('Institut_id IN (SELECT institut_id FROM roles_user WHERE userid = :user_id)
                OR fakultaets_id IN (SELECT institut_id FROM roles_user WHERE userid = :user_id)',
                    [':user_id' => $GLOBALS['user']->user_id]))->pluck('institut_id');

            $this->studycourses = Fach::findBySQL('JOIN mvv_fach_inst as fach_inst ON (fach.fach_id = fach_inst.fach_id)
                WHERE fach_inst.institut_id IN (:inst_ids)
                GROUP BY fach.fach_id ORDER BY fach.name',
            [':inst_ids' => $inst_ids]);
        }
    }

    public function messagehelper_action()
    {
        $fach = Fach::find(Request::get('fach_id'));
        $degree = Degree::find(Request::get('abschluss_id'));

        if (!$degree && $fach) {
            $users = UserStudyCourse::findBySql('fach_id = :fach_id', [':fach_id' => $fach->id]);
        } else if ($degree && !$fach) {
            $users = UserStudyCourse::findBySql('abschluss_id = :abschluss_id', [':abschluss_id' => $degree->id]);
        } else {
            $users = UserStudyCourse::findBySql('fach_id = :fach_id AND abschluss_id = :abschluss_id',
                [':fach_id' => $fach->id, ':abschluss_id' => $degree->id]
            );
        }
        if (empty($users)) {
            PageLayout::postError(_('Keine Studierenden zu den gewählten Angaben gefunden'));
            $this->redirect($this->indexURL());
            return;
        }

        $_SESSION['sms_data']['p_rec'] = SimpleCollection::createFromArray(
            SimpleCollection::createFromArray($users)->pluck('user')
        )->pluck('username');

        $subject = sprintf(
            _('Information zum Studiengang: %s %s'),
            $fach ? $fach->name: '' , $degree ? $degree->name : ''
        );

        $this->redirect(URLHelper::getURL('dispatch.php/messages/write',
            ['default_subject' => $subject, 'emailrequest' => 1]
        ));
    }

    private function createSidebar($view = 'subject')
    {
        $widget = new ViewsWidget();
        $widget->addLink(
            _('Gruppieren nach Fächern'),
            $this->indexURL()
        )->setActive($view === 'subject');
        $widget->addLink(
            _('Gruppieren nach Abschlüssen'),
            $this->degreeURL()
        )->setActive($view === 'degrees');
        Sidebar::Get()->addWidget($widget);
    }
}