-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOSKA.php
More file actions
188 lines (155 loc) · 6.6 KB
/
OSKA.php
File metadata and controls
188 lines (155 loc) · 6.6 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
/**
* OSKA plugin class for Stud.IP
*
* @author Ron Lucke <lucke@elan-ev.de>
* @author Viktoria Wiebe <vwiebe@uni-osnabrueck.de>
*
* 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.
*/
class OSKA extends StudIPPlugin implements StandardPlugin, PortalPlugin
{
public function __construct()
{
global $perm;
parent::__construct();
// set up translation domain
bindtextdomain('OSKA', dirname(__FILE__) . '/locale');
StudipAutoloader::addClassLookups([
'OskaMatches' => __DIR__ . '/models/OskaMatches.php',
'OskaMentees' => __DIR__ . '/models/OskaMentees.php',
'OskaMentors' => __DIR__ . '/models/OskaMentors.php',
]);
}
/**
* Returns the plugin name
*/
public function getPluginName()
{
return 'OSKA';
}
/**
* Returns the tab navigation for the OSKA plugin in the given course.
*
* @param $course_id the given course ID
*/
public function getTabNavigation($course_id)
{
global $perm;
if ($perm->have_studip_perm('tutor', $course_id)) {
$navigation = new Navigation($this->getPluginName(), PluginEngine::getURL('OSKA/admin/index'));
$navigation->addSubNavigation('admin', new Navigation(_('Übersicht'), PluginEngine::getURL('OSKA/admin/index')));
$navigation->addSubNavigation('matches', new Navigation(_('Matches'), PluginEngine::getURL('OSKA/admin/matches')));
$navigation->addSubNavigation('mentees', new Navigation(_('Mentees'), PluginEngine::getURL('OSKA/admin/mentees')));
$navigation->addSubNavigation('mentors', new Navigation(_('Mentors'), PluginEngine::getURL('OSKA/admin/mentors')));
} else {
$navigation = new Navigation($this->getPluginName(), PluginEngine::getURL('OSKA/mentoring/index'));
$navigation->addSubNavigation('mentor_profile', new Navigation(_('Profil'), PluginEngine::getURL('OSKA/mentoring/index')));
$navigation->addSubNavigation('mentee_list', new Navigation(_('Mentee Liste'), PluginEngine::getURL('OSKA/mentoring/mentee_list')));
}
return ['oska' => $navigation];
}
/**
* Dispatches all actions.
*/
public function perform($unconsumed_path)
{
parent::perform($unconsumed_path);
}
/**
* Returns the portal widget template.
*/
function getPortalTemplate()
{
global $perm;
PageLayout::addStylesheet($this->getPluginURL() . '/css/oska.css');
PageLayout::addScript($this->getPluginURL() . '/js/oska.js');
$template_path = $this->getPluginPath() . '/templates';
$template_factory = new Flexi_TemplateFactory($template_path);
// if the mentee is already registered, show the searching template
// if the mentee is also matched, show their tutor
$mentee = OskaMentees::find($GLOBALS['user']->id);
if ($mentee) {
if ($mentee->hasTutor()) {
$template = $template_factory->open('widget_mentor');
$mentor = OskaMatches::getMentor($GLOBALS['user']->id)['mentor_id'];
$template->avatar = Avatar::getAvatar($mentor);
// mentor data
$user = User::find($mentor);
$template->mentor_name = $user->vorname . ' ' .$user->nachname;
$template->mentor_desc = OskaMentors::getMentorDescription($mentor);
// Fachbereiche / Institutes
$study_institutes = [];
if (count($user->institute_memberships) > 0
&& Visibility::verify('studying', $mentor)) {
$study_institutes = $user->institute_memberships->filter(function ($a) {
return $a->inst_perms === 'user';
});
}
$template->study_institutes = $study_institutes;
} else {
$template = $template_factory->open('widget_searching');
}
} else {
// Show widget only to first semester Bachelor students
$show_info = false;
$studycourses = new SimpleCollection(UserStudyCourse::findByUser($GLOBALS['user']->id));
// go through all subjects of the user and check if user is first semester and Bachelor student
foreach ($studycourses as $studycourse) {
if ($studycourse->semester > 1 || in_array($studycourse->abschluss_id, ['08','12', '14', '61', '62', '65', '91']) === false) {
$show_info = true;
}
}
// show info if user has no subject
if(sizeof($studycourses) == 0) {
$show_info = true;
}
// show info about OSKA if not first semester Bachelor student
if ($show_info) {
$template = $template_factory->open('widget_info');
} else {
// show OSKA widget otherwise
$show_form = Request::option('show_form');
if ($show_form) {
// show form if button was clicked
$template = $template_factory->open('widget_form');
$template->studycourses = $studycourses;
} else {
// show oska info for first semester students otherwise
$template = $template_factory->open('widget_index');
}
}
}
$template->title = _('OSKA – Mein*e Mentor*in am Studienanfang');
$template->oska_image_url = $this->getPluginURL() . '/images/OSKA.jpg';
$template->oska_footer_image_url = $this->getPluginURL() . '/images/OSKA_footer.png';
return $template;
}
/**
* Returns the course summary page template.
*
* @param $course_id the given course ID
*/
public function getInfoTemplate($course_id)
{
return NULL;
}
/**
* Returns the icon navigation object.
*
* @param $course_id the given course ID
* @param $last_visit point in time of the user's last visit
* @param $user_id the ID of the given user
*/
public function getIconNavigation($course_id, $last_visit, $user_id)
{
return NULL;
}
public function isActivatableForContext(Range $context)
{
return $GLOBALS['perm']->have_perm('root');
}
}