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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
|
<?php
/**
* lvgselector.php - LvgselectorController
*
* 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 Peter Thienel <thienel@data-quest.de>
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
* @since 3.5
*/
require 'config/mvv_config.php';
class Course_LvgselectorController extends AuthenticatedController
{
// see Trails_Controller#before_filter
public function before_filter(&$action, &$args)
{
parent::before_filter($action, $args);
$this->course = Course::findCurrent();
if (!$this->course) {
throw new Trails_Exception(404, _('Es wurde keine Veranstaltung ausgewählt!'));
}
$this->course_id = $this->course->id;
if (!$GLOBALS['perm']->have_studip_perm('tutor', $this->course_id)) {
throw new AccessDeniedException();
}
$this->selection = new StudipLvgruppeSelection($this->course_id);
$this->semester_id = $this->course->start_semester->id;
$widget = new HelpbarWidget();
$widget->addElement(new WidgetElement(_('Auf dieser Seite kann die Veranstaltung ausgewählten Lehrveranstaltungsgruppen zugeordnet werden.')));
Helpbar::get()->addWidget($widget);
}
/**
* This method shows the lvgruppen selection form for a given course ID.
*
* @return void
*/
public function index_action()
{
$this->url_params = [];
if (Request::get('from')) {
$this->url_params['from'] = Request::get('from');
}
if (!Request::isXHR()) {
Navigation::activateItem('/course/admin/lvgruppen');
}
PageLayout::setTitle(sprintf('%s - %s',
$this->course->getFullname(),
_('Lehrveranstaltungsgruppen')));
// is locked?
// Set global state in MVV_ACCESS_ASSIGN_LVGRUPPEN
$this->locked = $this->is_locked($this->course_id);
// DOES the course's class permit "lvgruppen"?
$this->lvgruppen_not_allowed = !$this->course->getSemClass()->offsetGet('module');
if ($this->lvgruppen_not_allowed) {
$this->render_text(MessageBox::info(_('Für diesen Veranstaltungstyp ist die Zuordnung zu Lehrveranstaltungsgruppen nicht vorgesehen.')));
return;
}
$this->open_lvg_nodes = [];
if (Request::submitted('open_nodes')) {
$already_open_nodes = (array)json_decode(Request::get('open_nodes'));
foreach ($already_open_nodes as $open_lvgnode) {
$this->open_lvg_nodes[] = $open_lvgnode;
}
}
if (!$this->locked && !$this->lvgruppen_not_allowed) {
if (Request::get('open_node')) {
$node_to_open = Request::get('open_node');
if (!in_array($node_to_open, $this->open_lvg_nodes)) {
$this->open_lvg_nodes[] = $node_to_open;
} else {
$k = array_search($node_to_open, $this->open_lvg_nodes);
unset($this->open_lvg_nodes[$k]);
}
}
if (Request::submitted('lvgruppe_selection')) {
$lvgruppe_selection = Request::getArray('lvgruppe_selection');
if(isset($lvgruppe_selection['details'])) {
foreach (array_keys($lvgruppe_selection['details']) as $lvgid) {
$detail = $this->getLVGroupDetails($lvgid);
$this->selection_details[$detail['id']] = $detail['html_string'];
}
}
if (isset($lvgruppe_selection['remove'])) {
foreach (array_keys($lvgruppe_selection['remove']) as $lvgid) {
$this->selection->remove($lvgid);
}
$this->store_selection($this->course_id, $this->selection);
}
}
if ($assign = array_keys(Request::getArray('assign'))) {
$this->selection->add($assign[0]);
}
if (Request::submitted('save')) {
$this->save_action();
}
$lvgtree = new StudipLvgruppeSelection();
$this->tree = $lvgtree->getRootItem()->getChildren();
}
$this->ajax_url = $this->url_for('course/lvgselector/ajax');
$this->no_js_url = '';
$this->url = $this->action_url('index');
}
/**
* Wrapper for ajax calls to step classes. Three things must be given
* via Request:
* - step number
* - method to call in target step
* - parameters for the target method (will be passed in given order)
*/
public function ajax_action()
{
$stepNumber = Request::int('step');
$method = Request::get('method');
$parameters = Request::getArray('parameter');
$wizard_step = new LVGroupsWizardStep();
$result = call_user_func_array([$wizard_step, $method], $parameters);
if (is_array($result) || is_object($result)) {
$this->render_json($result);
} else {
$this->render_text($result);
}
}
/**
* Returns lvgroup details of a given lvgroup ID.
*
* @param string either the MD5ish ID of a lvgroup
*
* @return array lvgroup id, html string with lvgroup details
*/
public function getLVGroupDetails($id)
{
$mvvid = explode('-', $id);
$this->area = Lvgruppe::find($mvvid[0]);
$data = [
'id' => $this->area->id,
'html_string' => $this->render_template_as_string('course/lvgselector/entry_trails')
];
if (Request::isXhr()) {
return json_encode($data);
} else {
return $data;
}
}
/**
* Saves the changes to the LvGruppen-Selection a given course ID.
*
* @param string either the MD5ish ID of a course or something falsy to
* indicate a course that is currently being created
*
*/
public function save_action()
{
if ($this->is_locked($this->course_id)) {
throw new AccessDeniedException();
}
$selected = Request::getArray('lvgruppe_selection');
$selection = new StudipLvgruppeSelection();
if (!empty($selected['areas'])) {
foreach ($selected['areas'] as $area_id) {
$lvgroup = Lvgruppe::find($area_id);
$selection->add($lvgroup);
$open_nodes[] = $area_id;
}
}
$this->store_selection($this->course_id, $selection);
if (Request::get('from')) {
$url = URLHelper::getURL('dispatch.php/'.Request::get('from'));
} else {
$url = $this->action_url('index');
}
$this->redirect($url);
}
/**
* This method is sent using AJAX to remove a lvgruppe from a course.
*
* @param
* string the MD5ish ID of the course
* @return void
*/
public function remove_action()
{
if ($this->is_locked($this->course_id)) {
throw new AccessDeniedException();
}
$id = isset($_POST['id']) ? $_POST['id'] : NULL;
if ($id === NULL) {
$this->set_status(400);
$this->render_nothing();
return;
}
$selection = new StudipLvgruppeSelection($this->course_id);
// MVV: no problem here to delete LvGruppe
if ($selection->size() == 1) {
$this->set_status(409);
$this->render_nothing();
return;
}
$selection->remove($id);
$this->store_selection($this->course_id, $selection);
$this->render_nothing();
}
/**
* Returns the lock state of a given course ID.
*
* @param string either the MD5ish ID of a course or something falsy to
* indicate a course that is currently being created
*
* @return bool
*/
public function is_locked($course_id)
{
global $perm;
// Has user access to this function? Access state is configured in global config.
$access_right = Config::get()->MVV_ACCESS_ASSIGN_LVGRUPPEN;
if ($perm->have_perm('root')) {
return false;
} else if (LockRules::Check($course_id, 'mvv_lvgruppe')) {
return true;
} else {
if ($access_right == 'fakadmin') {
if ($perm->have_perm('admin')) {
$db = DBManager::get();
$st = $db->prepare("SELECT Seminar_id FROM user_inst a
LEFT JOIN Institute b ON(a.Institut_id=b.Institut_id AND b.Institut_id=b.fakultaets_id)
LEFT JOIN Institute c ON (b.Institut_id=c.fakultaets_id)
LEFT JOIN seminare d ON (d.Institut_id=c.Institut_id)
WHERE a.user_id = ? AND a.inst_perms='admin' AND d.Seminar_id = ? LIMIT 1");
$st->execute([$GLOBALS['user']->id, $course_id]);
if ($st->fetchColumn()) {
return false;
}
}
return true;
}
}
return !$perm->have_studip_perm($access_right, $course_id);
}
/**
* Stores a LvGruppen-Selection object for a given course ID.
*
* @param string either the MD5ish ID of a course or something falsy to
* indicate a course that is currently being created
* @param StudipStudyAreaSelection a LvGruppen-Selection object
*/
public function store_selection($course_id, $selection)
{
if ($this->is_locked($course_id)) {
throw new AccessDeniedException();
}
$lv_group_ids = $selection->getLvgruppenIDs();
// check whether at least one lv-group or study area is required
$study_areas_combined_enabled = CourseWizardStepRegistry::findOneBySQL("
`classname` = 'StudyAreasLVGroupsCombinedWizardStep'
AND `enabled` = 1");
if ($study_areas_combined_enabled && !count($lv_group_ids)) {
$sem_class = $this->course->getSemClass();
if ($sem_class['bereiche'] && !count($this->course->study_areas)) {
PageLayout::postMessage(MessageBox::error(_('Die Veranstaltung muss mindestens einem Studienbereich oder einer LV-Gruppe zugeordnet sein.')));
return;
}
}
// write the new lvgruppen to the db
Lvgruppe::setLvgruppen($course_id, $lv_group_ids);
PageLayout::postMessage(MessageBox::success(_('Die Zuordnung der LV-Gruppen wurde übernommen.')));
}
}
|