-
Notifications
You must be signed in to change notification settings - Fork 7
/
curriculumcoursepage.class.php
437 lines (381 loc) · 14.8 KB
/
curriculumcoursepage.class.php
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
<?php
/**
* ELIS(TM): Enterprise Learning Intelligence Suite
* Copyright (C) 2008-2013 Remote-Learner.net Inc (http://www.remote-learner.net)
*
* 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 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package local_elisprogram
* @author Remote-Learner.net Inc
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright (C) 2008-2013 Remote Learner.net Inc http://www.remote-learner.net
*
*/
defined('MOODLE_INTERNAL') or die();
require_once(elispm::lib('associationpage.class.php'));
require_once(elispm::lib('data/curriculumcourse.class.php'));
require_once(elispm::lib('data/curriculumstudent.class.php'));
require_once(elispm::lib('contexts.php'));
require_once(elispm::file('curriculumpage.class.php'));
require_once(elispm::file('coursepage.class.php'));
require_once(elispm::file('form/curriculumcourseform.class.php'));
/**
* Deepsight assignment page for program - course associations.
*/
class curriculumcoursepage extends deepsightpage {
/**
* @var string A unique name for the page.
*/
public $pagename = 'currcrs';
/**
* @var string The section of the page.
*/
public $section = 'curr';
/**
* @var string The page to get tabs from.
*/
public $tab_page = 'curriculumpage';
/**
* @var string The main data class.
*/
public $data_class = 'curriculumcourse';
/**
* @var string The page's parent.
*/
public $parent_page;
/**
* @var string The context level of the parent association.
*/
protected $contextlevel = 'program';
/**
* Construct the assigned datatable.
* @param string $uniqid A unique ID to assign to the datatable object.
* @return deepsight_datatable The datatable object.
*/
protected function construct_assigned_table($uniqid = null) {
global $DB;
$programid = $this->required_param('id', PARAM_INT);
$endpoint = qualified_me().'&action=deepsight_response&tabletype=assigned&id='.$programid;
$table = new deepsight_datatable_programcourse_assigned($DB, 'assigned', $endpoint, $uniqid);
$table->set_programid($programid);
return $table;
}
/**
* Construct the unassigned datatable.
* @param string $uniqid A unique ID to assign to the datatable object.
* @return deepsight_datatable The datatable object.
*/
protected function construct_unassigned_table($uniqid = null) {
global $DB;
$programid = $this->required_param('id', PARAM_INT);
$endpoint = qualified_me().'&action=deepsight_response&tabletype=unassigned&id='.$programid;
$table = new deepsight_datatable_programcourse_available($DB, 'unassigned', $endpoint, $uniqid);
$table->set_programid($programid);
return $table;
}
/**
* Assignment permission is handled at the action-object level.
* @return bool true
*/
public function can_do_action_programcourse_assign() {
return true;
}
/**
* Edit permission is handled at the action-object level.
* @return bool true
*/
public function can_do_action_programcourse_edit() {
return true;
}
/**
* Unassignment permission is handled at the action-object level.
* @return bool true
*/
public function can_do_action_programcourse_unassign() {
return true;
}
/**
* Whether the user has access to see the main page (assigned list)
* @return bool Whether the user has access.
*/
public function can_do_default() {
global $USER;
$id = $this->required_param('id', PARAM_INT);
$requiredperms = array('local/elisprogram:program_view', 'local/elisprogram:associate');
foreach ($requiredperms as $perm) {
$ctx = pm_context_set::for_user_with_capability('curriculum', $perm, $USER->id);
if ($ctx->context_allowed($id, 'curriculum') !== true) {
return false;
}
}
return true;
}
/**
* Determine whether the current user can assign tracks to the viewed userset.
* @return bool Whether the user can assign tracks to this userset.
*/
public function can_do_add() {
return $this->can_do_default();
}
/**
* Specifies whether the current user can edit prerequisites
* @return bool true if allowed, otherwise false
*/
public function can_do_prereqedit() {
return $this->can_do_default();
}
/**
* Specifies whether the current user can edit corequisites
* @return bool true if allowed, otherwise false
*/
public function can_do_coreqedit() {
return $this->can_do_default();
}
/**
* Display form to manage prerequisites.
*/
public function display_prereqedit() {
$curid = $this->required_param('id', PARAM_INT);
$curcrsid = $this->required_param('association_id', PARAM_INT);
$curcrs = new curriculumcourse($curcrsid);
$curcrs->seturl(null, array('s'=>$this->pagename, 'action'=>'prereqedit', 'id'=>$curid));
$prereqform = $curcrs->create_prerequisite_form();
if ($prereqform->is_cancelled()) {
$this->display_default();
return;
} else if ($prereqform->is_submitted() && $prereqform->is_validated()) {
$formdata = $prereqform->get_data();
$output = '';
$added = 0;
$deleted = 0;
// Process requested prerequisite deletions.
if (!empty($formdata->remove) && isset($formdata->sprereqs)) {
$sprereqs = $formdata->sprereqs;
} else {
$sprereqs = array();
}
foreach ($sprereqs as $sprereq) {
if ($curcrs->del_prerequisite($sprereq)) {
$deleted++;
}
}
// Process requested prerequisite additions.
if (!empty($formdata->add) && isset($formdata->prereqs)) {
$prereqs = $formdata->prereqs;
} else {
$prereqs = array();
}
// TODO: Ugly, this needs to be overhauled.
$cpage = new coursepage();
foreach ($prereqs as $prereq) {
if ($cpage->_has_capability('local/elisprogram:course_view', $prereq)
&& $curcrs->add_prerequisite($prereq, !empty($formdata->add_to_curriculum))) {
$added++;
}
}
if ($deleted > 0) {
$delstring = ($deleted > 1) ? 'deleted_prerequisites' : 'deleted_prerequisite';
$output .= get_string($delstring, 'local_elisprogram', $deleted);
}
if ($added > 0) {
$addstring = ($added > 1) ? 'added_prerequisites' : 'added_prerequisite';
$output .= (($deleted > 0) ? ' / ' : '').get_string($addstring, 'local_elisprogram', $added);
}
if ($deleted > 0 || $added > 0) {
$output .= "\n";
}
$curriculum = $curcrs->curriculum;
if ($curriculum->iscustom) {
$curassid = $this->_db->get_field(curriculumstudent::TABLE, 'id', array('curriculumid'=>$curriculum->id));
$stucur = new curriculumstudent($curassid);
redirect('index.php?s=stucur&section=curr&id='.$stucur->id.'&action=edit', $output, 3);
}
echo $output;
// Recreate the form, to reflect changes in the lists.
$prereqform = $curcrs->create_prerequisite_form();
}
$prereqform->display();
}
/**
* Display form to manage corequisites.
*/
public function display_coreqedit() {
$id = $this->required_param('id', PARAM_INT);
$curcrsid = $this->required_param('association_id', PARAM_INT);
$curcrs = new curriculumcourse($curcrsid);
$curcrs->seturl(null, array('s'=>$this->pagename, 'action'=>'coreqedit', 'id'=>$id));
$coreqform = $curcrs->create_corequisite_form();
if ($coreqform->is_cancelled()) {
$this->display_default();
return;
} else if ($coreqform->is_submitted() && $coreqform->is_validated()) {
$formdata = $coreqform->get_data();
$output = '';
$added = 0;
$deleted = 0;
// Process requested corequisite deletions.
$scoreqs = (isset($formdata->scoreqs)) ? $formdata->scoreqs : array();
foreach ($scoreqs as $scoreq) {
if ($curcrs->del_corequisite($scoreq)) {
$deleted++;
}
}
// Process requested corequisite additions.
$coreqs = (isset($formdata->coreqs)) ? $formdata->coreqs : array();
// TODO: Ugly, this needs to be overhauled.
$cpage = new coursepage();
foreach ($coreqs as $coreq) {
if ($cpage->_has_capability('local/elisprogram:course_view', $coreq)
&& $curcrs->add_corequisite($coreq, !empty($formdata->add_to_curriculum))) {
$added++;
}
}
if ($deleted > 0) {
$delstring = ($deleted > 1) ? 'deleted_corequisites' : 'deleted_corequisite';
$output .= get_string($delstring, 'local_elisprogram', $deleted);
}
if ($added > 0) {
$addstring = ($added > 1) ? 'added_corequisites' : 'added_corequisite';
$output .= (($deleted > 0) ? ' / ' : '').get_string($addstring, 'local_elisprogram', $added);
}
if ($deleted > 0 || $added > 0) {
$output .= "\n";
}
$curriculum = $curcrs->curriculum;
if ($curriculum->iscustom) {
$curassid = $this->_db->get_field(curriculumstudent::TABLE, 'id', array('curriculumid'=>$curriculum->id));
$stucur = new curriculumstudent($curassid);
redirect('index.php?s=stucur&section=curr&id='.$stucur->id.'&action=edit', $output, 3);
}
echo $output;
// Recreate the form, to reflect changes in the lists.
$coreqform = $curcrs->create_corequisite_form();
}
$coreqform->display();
}
}
/**
* Deepsight assignment page for course - program associations.
*/
class coursecurriculumpage extends deepsightpage {
/**
* @var string A unique name for the page.
*/
public $pagename = 'crscurr';
/**
* @var string The section of the page.
*/
public $section = 'curr';
/**
* @var string The page to get tabs from.
*/
public $tab_page = 'coursepage';
/**
* @var string The main data class.
*/
public $data_class = 'curriculumcourse';
/**
* @var string The page's parent.
*/
public $parent_page;
/**
* @var string The context level of the parent association.
*/
protected $contextlevel = 'course';
/**
* Construct the assigned datatable.
* @param string $uniqid A unique ID to assign to the datatable object.
* @return deepsight_datatable The datatable object.
*/
protected function construct_assigned_table($uniqid = null) {
global $DB;
$courseid = $this->required_param('id', PARAM_INT);
$endpoint = qualified_me().'&action=deepsight_response&tabletype=assigned&id='.$courseid;
$table = new deepsight_datatable_courseprogram_assigned($DB, 'assigned', $endpoint, $uniqid);
$table->set_courseid($courseid);
return $table;
}
/**
* Construct the unassigned datatable.
* @param string $uniqid A unique ID to assign to the datatable object.
* @return deepsight_datatable The datatable object.
*/
protected function construct_unassigned_table($uniqid = null) {
global $DB;
$courseid = $this->required_param('id', PARAM_INT);
$endpoint = qualified_me().'&action=deepsight_response&tabletype=unassigned&id='.$courseid;
$table = new deepsight_datatable_courseprogram_available($DB, 'unassigned', $endpoint, $uniqid);
$table->set_courseid($courseid);
return $table;
}
/**
* Assignment permission is handled at the action-object level.
* @return bool true
*/
public function can_do_action_courseprogram_assign() {
return true;
}
/**
* Edit permission is handled at the action-object level.
* @return bool true
*/
public function can_do_action_courseprogram_edit() {
return true;
}
/**
* Unassignment permission is handled at the action-object level.
* @return bool true
*/
public function can_do_action_courseprogram_unassign() {
return true;
}
/**
* Whether the user has access to see the main page (assigned list)
* @return bool Whether the user has access.
*/
public function can_do_default() {
global $USER;
$id = $this->required_param('id', PARAM_INT);
$requiredperms = array('local/elisprogram:course_view', 'local/elisprogram:associate');
foreach ($requiredperms as $perm) {
$ctx = pm_context_set::for_user_with_capability('course', $perm, $USER->id);
if ($ctx->context_allowed($id, 'course') !== true) {
return false;
}
}
return true;
}
/**
* Determine whether the current user can assign tracks to the viewed userset.
* @return bool Whether the user can assign tracks to this userset.
*/
public function can_do_add() {
return $this->can_do_default();
}
/**
* Display assigned table.
*/
public function display_default() {
global $OUTPUT;
if (false && has_capability('local/elisprogram:program_create', $this->_get_page_context())) {
echo '<div align="center">';
$options = array_merge(array('s' => 'cfc', 'id' => $id, 'cfccourseid' => $id));
$button = new single_button(new moodle_url('index.php', $options), get_string('makecurcourse', 'local_elisprogram'), 'get',
array('disabled'=>false, 'title'=>get_string('makecurcourse', 'local_elisprogram'), 'id'=>''));
echo $OUTPUT->render($button);
echo '</div>';
}
parent::display_default();
}
}