forked from remotelearner/moodle-local_elisprogram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusersetpage.class.php
765 lines (659 loc) · 28.6 KB
/
usersetpage.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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
<?php
/**
* ELIS(TM): Enterprise Learning Intelligence Suite
* Copyright (C) 2008-2014 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-2014 Remote-Learner.net Inc (http://www.remote-learner.net)
*
*/
defined('MOODLE_INTERNAL') || die();
require_once(elispm::file('clustertrackpage.class.php'));
require_once(elispm::lib('deepsightpage.class.php'));
require_once(elispm::lib('managementpage.class.php'));
require_once(elispm::lib('data/clustercurriculum.class.php'));
require_once(elispm::lib('data/userset.class.php'));
require_once(elispm::lib('contexts.php'));
require_once(elispm::file('form/usersetform.class.php'));
require_once(elis::plugin_file('usetenrol_manual', 'usersetassignmentpage.class.php'));
/**
* Page to manage user subsets.
*/
class usersetsubusersetpage extends deepsightpage {
/**
* @var string A unique name for the page.
*/
public $pagename = 'clstsub';
/**
* @var string The section of the page.
*/
public $section = 'users';
/**
* @var string The page to get tabs from.
*/
public $tab_page = 'usersetpage';
/**
* @var string The main data class.
*/
public $data_class = 'userset';
/**
* @var string The page's parent.
*/
public $parent_page;
/**
* @var string The context level of the parent association.
*/
protected $contextlevel = 'userset';
/**
* 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;
$usersetid = $this->required_param('id', PARAM_INT);
$endpoint = qualified_me().'&action=deepsight_response&tabletype=assigned&id='.$usersetid;
$table = new deepsight_datatable_usersetsubuserset_assigned($DB, 'assigned', $endpoint, $uniqid);
$table->set_usersetid($usersetid);
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;
$usersetid = $this->required_param('id', PARAM_INT);
$endpoint = qualified_me().'&action=deepsight_response&tabletype=unassigned&id='.$usersetid;
$table = new deepsight_datatable_usersetsubuserset_available($DB, 'unassigned', $endpoint, $uniqid);
$table->set_usersetid($usersetid);
return $table;
}
/**
* Whether the user can view subsets.
* @return bool Whether the user has permission.
*/
public function can_do_default() {
$id = $this->required_param('id', PARAM_INT);
$requiredperms = array('local/elisprogram:userset_view');
return $this->has_perms_for_element($requiredperms, 'cluster', $id);
}
/**
* Whether the user can move existing usersets to a subset of the current userset.
* @return bool Whether user has permission.
*/
public function can_do_add() {
$id = $this->required_param('id', PARAM_INT);
$requiredperms = array('local/elisprogram:userset_edit');
return $this->has_perms_for_element($requiredperms, 'cluster', $id);
}
/**
* Delete permission is handled at the action-object level.
* @return bool true
*/
public function can_do_action_usersetsubuserset_delete() {
return true;
}
/**
* Permission for this action is handled at the action-object level.
* @return bool true
*/
public function can_do_action_usersetsubuserset_makesubset() {
return true;
}
/**
* Display user subsets
*/
public function display_default() {
$this->print_add_button();
parent::display_default();
}
/**
* Prints the single-button form used to request the add action for a record type.
*/
public function print_add_button() {
global $OUTPUT;
$id = required_param('id', PARAM_INT);
$targetpage = new usersetpage(array('action' => 'add', 'parent' => $id));
if (!$targetpage->can_do('add')) {
return;
}
$addbutton = $OUTPUT->single_button($targetpage->url, get_string("add_{$this->data_class}", 'local_elisprogram'), 'get');
echo html_writer::tag('div', $addbutton, array('style' => 'text-align: center'));
}
}
class usersetpage extends managementpage {
var $data_class = 'userset';
var $form_class = 'usersetform';
var $pagename = 'clst';
var $section = 'users';
var $view_columns = array('name');
static $contexts = array();
/**
* Return the context that the page is related to. Used by the constructor
* for calling $this->set_context().
* @return object The page context
*/
protected function _get_page_context() {
if (($id = $this->optional_param('id', 0, PARAM_INT))) {
return \local_elisprogram\context\userset::instance($id);
}
return parent::_get_page_context();
}
static function get_contexts($capability) {
if (!isset(self::$contexts[$capability])) {
global $USER;
self::$contexts[$capability] = get_contexts_by_capability_for_user('cluster', $capability, $USER->id);
}
return self::$contexts[$capability];
}
/**
* Check the cached capabilities for the current cluster.
*/
static function check_cached($capability, $id) {
if (isset(self::$contexts[$capability])) {
// we've already cached which contexts the user has
// capabilities in
$contexts = self::$contexts[$capability];
return $contexts->context_allowed($id, 'cluster');
}
return null;
}
/**
* Determines whether the current user is allowed to enrol users into the provided cluster
*
* @param int $clusterid The id of the cluster we are checking permissions on
*
* @return boolean Whether the user is allowed to enrol users into the cluster
*
*/
static function can_enrol_into_cluster($clusterid) {
global $USER;
//check the standard capability
$page = new usersetpage(array('id' => $clusterid, 'action' => 'view'));
if ($page->_has_capability('local/elisprogram:userset_enrol', $clusterid)) {
return true;
}
/* TBD: the folowing commented-out code was removed for ELIS-3846
$cluster = new userset($clusterid);
$cluster->load(); // ELIS-3848 Needed otherwise the 'parent' property is not set =(
if (!empty($cluster->parent)) {
//check to see if the current user has the secondary capability anywhere up the cluster tree
$contexts = pm_context_set::for_user_with_capability('cluster', 'local/elisprogram:userset_enrol_userset_user', $USER->id);
return $contexts->context_allowed($clusterid, 'cluster');
}
*/
//check to see if the current user has the secondary capability anywhere up the cluster tree
$contexts = pm_context_set::for_user_with_capability('cluster', 'local/elisprogram:userset_enrol_userset_user', $USER->id);
return $contexts->context_allowed($clusterid, 'cluster');
}
/**
* Check if the user has the given capability for the requested cluster
*/
function _has_capability($capability, $id = null) {
$id = $id ? $id : $this->required_param('id', PARAM_INT);
$cached = self::check_cached($capability, $id);
if ($cached !== null) {
return $cached;
}
$context = \local_elisprogram\context\userset::instance($id);
return has_capability($capability, $context);
}
/**
* Constructor
* @param array $params An array of parameters for the page.
*/
public function __construct(array $params=null) {
$this->tabs = array(
array(
'tab_id' => 'view',
'page' => 'usersetpage',
'params' => array('action' => 'view'),
'name' => get_string('detail', 'local_elisprogram'),
'showtab' => true
),
array(
'tab_id' => 'edit',
'page' => 'usersetpage',
'params' => array('action' => 'edit'),
'name' => get_string('edit', 'local_elisprogram'),
'showtab' => true,
'showbutton' => true,
'image' => 'edit'
),
array(
'tab_id' => 'usersetsubusersetpage',
'page' => 'usersetsubusersetpage',
'params' => array(),
'name' => get_string('usersubsets', 'local_elisprogram'),
'showtab' => true,
'showbutton' => true,
'image' => 'cluster'
),
array(
'tab_id' => 'clustertrackpage',
'page' => 'clustertrackpage',
'name' => get_string('tracks', 'local_elisprogram'),
'showtab' => true,
'showbutton' => true,
'image' => 'track'
),
array(
'tab_id' => 'clusteruserpage',
'page' => 'clusteruserpage',
'name' => get_string('users', 'local_elisprogram'),
'showtab' => true,
'showbutton' => true,
'image' => 'user'
),
array(
'tab_id' => 'clustercurriculumpage',
'page' => 'clustercurriculumpage',
'name' => get_string('curricula', 'local_elisprogram'),
'showtab' => true,
'showbutton' => true,
'image' => 'curriculum'
),
array(
'tab_id' => 'cluster_rolepage',
'page' => 'cluster_rolepage',
'name' => get_string('roles', 'role'),
'showtab' => true,
'showbutton' => false,
'image' => 'tag'
),
array(
'tab_id' => 'delete',
'page' => 'usersetpage',
'params' => array('action' => 'delete'),
'name' => get_string('delete_label', 'local_elisprogram'),
'showbutton' => true,
'image' => 'delete'
),
);
parent::__construct($params);
}
function can_do_view() {
$id = $this->required_param('id', PARAM_INT);
if ($this->_has_capability('local/elisprogram:userset_view')) {
return true;
}
/*
* Start of cluster hierarchy extension
*/
$viewable_clusters = userset::get_viewable_clusters();
$contextset = pm_context_set::for_user_with_capability('cluster', 'local/elisprogram:userset_view');
return in_array($id, $viewable_clusters)
|| userset::exists(array(new usersubset_filter('id', new field_filter('id', $id)),
$contextset->get_filter('id')))
|| userset::exists(array(new usersubset_filter('id', $contextset->get_filter('id')),
new field_filter('id', $id)));
/*
* End of cluster hierarchy extension
*/
}
function can_do_edit() {
return $this->_has_capability('local/elisprogram:userset_edit');
}
function can_do_subcluster() {
//obtain the contexts where editing is allowed for the subcluster
$subclusterid = $this->required_param('subclusterid', PARAM_INT);
$context = \local_elisprogram\context\userset::instance($subclusterid);
//make sure editing is allowed on both clusters
return $this->_has_capability('local/elisprogram:userset_edit') && has_capability('local/elisprogram:userset_edit', $context);
}
function can_do_delete() {
return $this->_has_capability('local/elisprogram:userset_delete');
}
function can_do_confirm() {
return $this->can_do_delete();
}
function can_do_add() {
$parent = ($this->optional_param('id', 0, PARAM_INT))
? $this->optional_param('id', 0, PARAM_INT)
: $this->optional_param('parent', 0, PARAM_INT);
if ($parent) {
$context = \local_elisprogram\context\userset::instance($parent);
} else {
$context = context_system::instance();
}
return has_capability('local/elisprogram:userset_create', $context);
}
/**
* Dummy can_do method for viewing a curriculum report (needed for the
* cluster tree parameter for reports)
*/
function can_do_viewreport() {
global $CFG, $DB;
$id = $this->required_param('id', PARAM_INT);
//needed for execution mode constants
require_once($CFG->dirroot . '/local/elisreports/php_report_base.php');
//check if we're scheduling or viewing
$execution_mode = $this->optional_param('execution_mode', php_report::EXECUTION_MODE_SCHEDULED, PARAM_INT);
//check the correct capability
$capability = ($execution_mode == php_report::EXECUTION_MODE_SCHEDULED) ? 'local/elisreports:schedule' : 'local/elisreports:view';
if ($this->_has_capability($capability)) {
return true;
}
/*
* Start of cluster hierarchy extension
*/
$viewable_clusters = userset::get_viewable_clusters($capability);
//if the user has no additional access through parent clusters, then they can't view this cluster
if (empty($viewable_clusters)) {
return false;
}
$parentpath = $DB->sql_concat('parent_context.path', "?");
$likeclause = $DB->sql_like('child_context.path', $parentpath);
list($in_clause, $params) = $DB->get_in_or_equal($viewable_clusters);
//determine if this cluster is the parent of some accessible child cluster
$sql = "SELECT parent_context.instanceid
FROM {context} parent_context
JOIN {context} child_context
ON child_context.instanceid {$in_clause}
AND {$likeclause}
AND parent_context.contextlevel = ".CONTEXT_ELIS_USERSET."
AND child_context.contextlevel = ".CONTEXT_ELIS_USERSET."
AND parent_context.instanceid = {$id}";
if (!isset($params) || !is_array($params)) {
$params = array('/%');
} else {
$params[] = '/%';
}
return $DB->record_exists_sql($sql, $params);
/*
* End of cluster hierarchy extension
*/
}
function can_do_default() {
$parent = $this->optional_param('id', 0, PARAM_INT);
if ($parent) {
return $this->can_do_view();
}
$contexts = self::get_contexts('local/elisprogram:userset_view');
return !$contexts->is_empty();
}
function build_navbar_view($who = null, $id_param = 'id', $extra_params = array()) {
// cluster name is already added by build_navbar_default, so don't
// print it again
return $this->build_navbar_default();
}
public function build_navbar_default($who = null, $addparent = true, $params = array()) {
global $CFG, $DB;
parent::build_navbar_default();
// add cluster hierarchy if cluster defined
$id = $this->optional_param('id', 0, PARAM_INT);
if ($id) {
$context = \local_elisprogram\context\userset::instance($id);
$ancestorids = substr(str_replace('/',',',$context->path),3);
$sql = "SELECT cluster.*
FROM {context} ctx
JOIN {" . userset::TABLE . "} cluster ON ctx.instanceid = cluster.id
WHERE ctx.id IN ($ancestorids) AND ctx.contextlevel = ".CONTEXT_ELIS_USERSET."
ORDER BY ctx.depth";
$ancestors = $DB->get_recordset_sql($sql);
foreach ($ancestors as $ancestor) {
$url = $this->get_new_page(array('action' => 'view',
'id' => $ancestor->id), true)->url;
$this->navbar->add($ancestor->name, $url);
}
}
}
public function get_page_title_default() {
if (($id = $this->optional_param('id', '', PARAM_INT))) {
return parent::get_page_title_view();
} else {
return parent::get_page_title_default();
}
}
public function get_navigation_view() {
return $this->get_navigation_default();
}
function display_default() {
global $OUTPUT;
// Get parameters
$sort = optional_param('sort', 'name', PARAM_ALPHA);
$dir = optional_param('dir', 'ASC', PARAM_ALPHA);
$page = optional_param('page', 0, PARAM_INT);
$perpage = optional_param('perpage', 30, PARAM_INT); // how many per page
$namesearch = trim(optional_param('search', '', PARAM_TEXT));
$alpha = optional_param('alpha', '', PARAM_ALPHA);
$parent = $this->optional_param('id', 0, PARAM_INT);
$classification = $this->optional_param('classification', NULL, PARAM_SAFEDIR);
$subsets = $this->optional_param('subsets', 0, PARAM_INT);
if ($parent) {
$this->print_tabs('subclusters', array('id' => $parent));
}
// Define columns
$columns = array(
'name' => array('header' => get_string('userset_name','local_elisprogram')),
'display' => array('header' => get_string('userset_description','local_elisprogram')),
);
// set sorting
if ($dir !== 'DESC') {
$dir = 'ASC';
}
if (isset($columns[$sort])) {
$columns[$sort]['sortable'] = $dir;
} else {
$sort = 'defaultsortcolumn';
$columns[$sort]['sortable'] = $dir;
}
$extrafilters = array('contexts' => self::get_contexts('local/elisprogram:userset_view'), 'classification' => $classification);
if (!$subsets || $parent) {
$extrafilters['parent'] = $parent;
} else {
$columns['parent'] = array('header' => get_string('userset_parent', 'local_elisprogram'));
}
$items = cluster_get_listing($sort, $dir, $page*$perpage, $perpage, $namesearch, $alpha, $extrafilters);
$numitems = cluster_count_records($namesearch, $alpha, $extrafilters);
self::get_contexts('local/elisprogram:userset_edit');
self::get_contexts('local/elisprogram:userset_delete');
$this->print_list_view($items, $numitems, $columns, null, true, true);
if ($this->optional_param('id', 0, PARAM_INT)) {
//get the non-parent clusters that are accessible based on the edit capability
$contexts = usersetpage::get_contexts('local/elisprogram:userset_edit');
$non_parent_clusters = cluster_get_possible_sub_clusters($this->optional_param('id', 0, PARAM_INT), $contexts);
//display the dropdown if there are one or more available clusters
if (count($non_parent_clusters) > 0) {
echo html_writer::start_tag('div', array('align' => 'center'));
echo get_string('cluster_subcluster_prompt','local_elisprogram') . ': ';
$url = $this->get_new_page(array('action'=>'subcluster','id'=>$this->optional_param('id', 0, PARAM_INT)))->url . '&subclusterid=';
echo $OUTPUT->single_select($url, 'subclusterid', $non_parent_clusters);
echo html_writer::end_tag('div');
}
}
}
/**
* Handler for the delete action. Deletes the record identified by the
* 'id' parameter, if the confirm parameter is set.
*
* Modified from the default handler to pass in whether or not subclusters
* should be deleted or promoted.
*/
public function do_delete() {
global $CFG;
if (!optional_param('confirm', 0, PARAM_INT)) {
return $this->display('delete');
}
$deletesubs = optional_param('deletesubs', 0, PARAM_INT);
require_sesskey();
$id = required_param('id', PARAM_INT);
//handling of cancel case
$view_params = array('id' => $id,
'action' => 'view');
$target_page = $this->get_new_page($view_params);
$form = new usersetdeleteform();
if ($form->is_cancelled()) {
//cancelled, so redirect back to view page
redirect($target_page->url, get_string('delete_cancelled', 'local_elisprogram'));
}
$obj = $this->get_new_data_object($id);
$obj->load(); // force load, so that the confirmation notice has something to display
$obj->deletesubs = $deletesubs;
$obj->delete();
$returnurl = optional_param('return_url', null, PARAM_URL);
if ($returnurl === null) {
$target_page = $this->get_new_page(array(), true);
$returnurl = $target_page->url;
} else {
$returnurl = $CFG->wwwroot.$returnurl;
}
redirect($returnurl, get_string('notice_'.get_class($obj).'_deleted', 'local_elisprogram', $obj->to_object()));
}
/**
* Handler for the confirm action. Assigns a child cluster to specified cluster.
*/
function do_subcluster() {
global $CFG;
$id = $this->required_param('id',PARAM_INT);
$target_page = $this->get_new_page(array('id'=>$id), true);
$sub_cluster_id = $this->required_param('subclusterid',PARAM_INT);
$cluster = new userset($sub_cluster_id);
$cluster->parent = $id;
$cluster->save();
redirect($target_page->url, get_string('cluster_assigned','local_elisprogram'));
}
/**
* Prints a deletion confirmation form.
* @param $obj record whose deletion is being confirmed
*/
function print_delete_form($obj) {
global $DB;
if (($count = userset::count(new field_filter('parent', $obj->id)))) {
// cluster has sub-clusters, so ask the user if they want to
// promote or delete the sub-clusters
$a = new stdClass;
$a->name = $obj->name;
$a->subclusters = $count;
$context = \local_elisprogram\context\userset::instance($obj->id);
$like = $DB->sql_like('path', '?');
$a->descendants = $DB->count_records_select('context',$DB->sql_like('path', '?'), array("{$context->path}/%")) - $a->subclusters;
print_string($a->descendants ? 'confirm_delete_with_usersubsets_and_descendants' : 'confirm_delete_with_usersubsets', 'local_elisprogram', $a);
$target = $this->get_new_page(array('action' => 'delete', 'confirm'=>'1'));
$form = new usersetdeleteform($target->url, array('obj' => $obj, 'a' => $a));
$form->display();
} else {
parent::print_delete_form($obj);
}
}
/**
* Prints the single-button form used to request the add action for a record type.
*/
function print_add_button() {
global $OUTPUT;
if (!$this->can_do('add')) {
return;
}
$options = array('action' => 'add');
$parent = $this->optional_param('id', 0, PARAM_INT);
if ($parent) {
$options['parent'] = $parent;
}
$target_page = $this->get_new_page($options, true);
$url = $target_page->url;
echo html_writer::tag('div', $OUTPUT->single_button($url, get_string("add_{$this->data_class}",'local_elisprogram'), 'get'), array('style' => 'text-align: center'));
}
/**
* Prints the text substring search interface.
* And optional subsets checkbox
*/
public function print_search() {
parent::print_search();
$parent = $this->optional_param('id', 0, PARAM_INT);
if (!$parent) {
$subsets = $this->optional_param('subsets', 0, PARAM_INT);
$url = $this->url;
$url->remove_params('subsets');
echo html_writer::checkbox('subsets', 1, $subsets, get_string('userset_subsets', 'local_elisprogram'), array(
'onclick' => 'window.location="'.$url.'&subsets="+(this.checked ? "1" : "0");',
'language' => 'javascript'));
}
}
function get_default_object_for_add() {
$parent = $this->optional_param('parent', 0, PARAM_INT);
if ($parent) {
$obj = new stdClass;
$obj->parent = $parent;
if ($parent) {
require_once(elis::plugin_file('elisprogram_usetclassify','usersetclassification.class.php'));
require_once(elis::plugin_file('elisprogram_usetclassify','lib.php'));
if ($classification = usersetclassification::get_for_cluster($parent)) {
$fieldname = 'field_'.USERSET_CLASSIFICATION_FIELD;
if ($classification->param_child_classification) {
$obj->$fieldname = $classification->param_child_classification;
} else {
$obj->$fieldname = $classification->shortname;
}
//default groups and groupings settings
if ($classification->param_autoenrol_groups) {
$obj->field_userset_group = $classification->param_autoenrol_groups;
}
if ($classification->param_autoenrol_groupings) {
$obj->field_userset_groupings = $classification->param_autoenrol_groupings;
}
}
}
return $obj;
} else {
return NULL;
}
}
/**
* Hook that gets called after a CM entity is added through this page
* (Note: this function should only use the id field from the supplied cm entity
* as the rest of the data is not guaranteed to be there)
*
* @param object $cm_entity The CM entity added
*/
function after_cm_entity_add($cm_entity) {
global $USER, $DB;
//make sure a valid role is set
if(!empty(elis::$config->local_elisprogram->default_cluster_role_id)
&& $DB->record_exists('role', array('id' => elis::$config->local_elisprogram->default_cluster_role_id))) {
//get the context instance for capability checking
$context_instance = \local_elisprogram\context\userset::instance($cm_entity->id);
//assign the appropriate role if the user does not have the edit capability
if (!has_capability('local/elisprogram:userset_edit', $context_instance)) {
role_assign(elis::$config->local_elisprogram->default_cluster_role_id, $USER->id, $context_instance->id);
}
}
}
/**
* Specifies a unique shortname for the entity represented by
* a page of this type, transforming the supplied value if necessary
*
* @param string $parent_path Path of all parent elements, or the empty string
* if none
* @param string $name Initial name provided for the element
*
* @return string|NULL A valid name to identify the item with, or NULL if
* not applicable
*/
static function get_entity_name($parent_path, $name) {
$parts = explode('_', $name);
//try to find the entity type and id, and combine them
if (count($parts) == 2) {
if ($parts[0] == 'userset') {
return $parts[0] . '-' . $parts[1];
}
}
return NULL;
}
}