blob: a22b89edf4e9f543a8338c78d04274ed4c0fbd93 (
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
|
<?php
# Lifter010: TODO
/*
* CourseNavigation.php - navigation for course / institute area
*
* 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 Elmar Ludwig
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
*/
class CourseNavigation extends Navigation
{
private $range;
/**
* Initialize a new Navigation instance.
*/
public function __construct(Range $range)
{
if (!($range instanceof Course) && !($range instanceof Institute)) {
throw new InvalidArgumentException('Invalid range type "' . get_class($range) . '" for course navigation');
}
$this->range = $range;
global $user;
// check if logged in
if (User::findCurrent()) {
$coursetext = _('Veranstaltungen');
$courseinfo = _('Meine Veranstaltungen & Einrichtungen');
$courselink = 'dispatch.php/my_courses';
} else {
$coursetext = _('Freie');
$courseinfo = _('Freie Veranstaltungen');
$courselink = 'dispatch.php/public_courses';
}
parent::__construct($coursetext, $courselink);
if (User::findCurrent()) {
$this->setImage(Icon::create('seminar', Icon::ROLE_NAVIGATION, ['title' => $courseinfo]));
}
}
/**
* Initialize the subnavigation of this item. This method
* is called once before the first item is added or removed.
*/
public function initSubNavigation()
{
parent::initSubNavigation();
$admin_plugin_ids = [];
$core_admin = PluginManager::getInstance()->getPlugin(CoreAdmin::class);
if ($core_admin) {
$admin_plugin_ids[] = $core_admin->getPluginId();
}
$core_studygroup_admin = PluginManager::getInstance()->getPlugin(CoreStudygroupAdmin::class);
if ($core_studygroup_admin) {
$admin_plugin_ids[] = $core_studygroup_admin->getPluginId();
}
$tools = $this->range->tools->getArrayCopy();
usort($tools, function ($a, $b) use ($admin_plugin_ids) {
if (in_array($a['plugin_id'], $admin_plugin_ids)) {
return -1;
}
if (in_array($b['plugin_id'], $admin_plugin_ids)) {
return 1;
}
return $a['position'] - $b['position'];
});
foreach ($tools as $tool) {
if (
!($this->range instanceof Institute)
&& !Seminar_Perm::get()->have_studip_perm($tool->getVisibilityPermission(), $this->range->id)
) {
continue;
}
$studip_module = $tool->getStudipModule();
if (!($studip_module instanceof StudipModule)) {
continue;
}
$tool_nav = $studip_module->getTabNavigation($this->range->id) ?: [];
foreach ($tool_nav as $nav_name => $navigation) {
if (!$nav_name || !$navigation instanceof Navigation) {
continue;
}
if ($tool->metadata['displayname']) {
$navigation->setTitle($tool->getDisplayname());
}
$this->addSubNavigation($nav_name, $navigation);
}
}
}
}
|