-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.php
893 lines (802 loc) · 27.2 KB
/
lib.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
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
<?PHP // $Id: lib.php,v 1.1.1.1 2012-08-01 10:16:31 vf Exp $
/**
* @package mod-tracker
* @author Clifford Tham, Valery Fremaux > 1.8
* @date 02/12/2007
* @version Moodle 2.0
*
* Library of functions and constants for module tracker
*/
include_once('classes/trackercategorytype/trackerelement.class.php');
require_once($CFG->dirroot.'/mod/tracker/locallib.php');
/**
* List of features supported in tracker module
* @param string $feature FEATURE_xx constant for requested feature
* @return mixed True if module supports feature, false if not, null if doesn't know
*/
function tracker_supports($feature) {
switch($feature) {
case FEATURE_MOD_ARCHETYPE: return MOD_ARCHETYPE_OTHER;
case FEATURE_GROUPS: return false;
case FEATURE_GROUPINGS: return false;
case FEATURE_GROUPMEMBERSONLY: return false;
case FEATURE_MOD_INTRO: return true;
case FEATURE_COMPLETION_TRACKS_VIEWS: return false;
case FEATURE_GRADE_HAS_GRADE: return false;
case FEATURE_GRADE_OUTCOMES: return false;
case FEATURE_BACKUP_MOODLE2: return true;
case FEATURE_SHOW_DESCRIPTION: return true;
default: return null;
}
}
/**
* Given an object containing all the necessary data,
* (defined by the form in mod.html) this function
* will create a new instance and return the id number
* of the new instance.
* @param object $tracker
*/
function tracker_add_instance($tracker, $mform) {
global $DB;
$tracker->timemodified = time();
if (empty($tracker->allownotifications)) $tracker->allownotifications = 0;
if (empty($tracker->enablecomments)) $tracker->enablecomments = 0;
if (empty($tracker->format)) $tracker->format = FORMAT_MOODLE;
if (is_array(@$tracker->subtrackers)){
$tracker->subtrackers = implode(',', $tracker->subtrackers);
}
$tracker->id = $DB->insert_record('tracker', $tracker);
$context = context_module::instance($tracker->coursemodule);
// make some presets depending on tracker type
if ($tracker->supportmode != 'customized'){
tracker_setup_role_overrides($tracker, $context);
tracker_preset_states($tracker);
tracker_preset_params($tracker);
$DB->set_field('tracker', 'enabledstates', $tracker->enabledstates, array('id' => $tracker->id));
} else {
tracker_clear_role_overrides($context);
}
if (empty($tracker->ticketprefix)){
$tracker->ticketprefix = 'TRK'.$tracker->id.'_';
$DB->set_field('tracker', 'ticketprefix', $tracker->ticketprefix, array('id' => $tracker->id));
}
return $tracker->id;
}
/**
* Given an object containing all the necessary data,
* (defined by the form in mod.html) this function
* will update an existing instance with new data.
*/
function tracker_update_instance($tracker, $mform) {
global $DB;
$tracker->timemodified = time();
$tracker->id = $tracker->instance;
if (is_array(@$tracker->subtrackers)){
$tracker->subtrackers = implode(',', $tracker->subtrackers);
}
$context = context_module::instance($tracker->coursemodule);
if ($tracker->supportmode != 'customized'){
tracker_setup_role_overrides($tracker, $context);
tracker_preset_states($tracker);
tracker_preset_params($tracker);
$DB->set_field('tracker', 'enabledstates', $tracker->enabledstates, array('id' => $tracker->id));
} else {
tracker_clear_role_overrides($context);
}
if (empty($tracker->ticketprefix)){
$tracker->ticketprefix = 'TRK'.$tracker->id.'_';
$DB->set_field('tracker', 'ticketprefix', $tracker->ticketprefix, array('id' => $tracker->id));
}
return $DB->update_record('tracker', $tracker);
}
/**
* Given an ID of an instance of this module,
* this function will permanently delete the instance
* and any data that depends on it.
*/
function tracker_delete_instance($id) {
global $DB;
if (! $tracker = $DB->get_record('tracker', array('id' => "$id"))) {
return false;
}
if (!$cm = get_coursemodule_from_instance('tracker', $tracker->id)) {
return false;
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
$result = true;
/// Delete any dependent records here
$DB->delete_records('tracker_issue', array('trackerid' => "$tracker->id"));
$DB->delete_records('tracker_elementused', array('trackerid' => "$tracker->id"));
$DB->delete_records('tracker_query', array('trackerid' => "$tracker->id"));
$DB->delete_records('tracker_issuedependancy', array('trackerid' => "$tracker->id"));
$DB->delete_records('tracker_issueownership', array('trackerid' => "$tracker->id"));
$DB->delete_records('tracker_issueattribute', array('trackerid' => "$tracker->id"));
$DB->delete_records('tracker_issuecc', array('trackerid' => "$tracker->id"));
$DB->delete_records('tracker_issuecomment', array('trackerid' => "$tracker->id"));
// delete all files attached to this context
$fs = get_file_storage();
$fs->delete_area_files($context->id);
return $result;
}
/**
* Return a small object with summary information about what a
* user has done with a given particular instance of this module
* Used for user activity reports.
* $return->time = the time they did it
* $return->info = a short text description
*/
function tracker_user_outline($course, $user, $mod, $tracker) {
return NULL;
}
/**
* Print a detailed representation of what a user has done with
* a given particular instance of this module, for user activity reports.
*/
function tracker_user_complete($course, $user, $mod, $tracker) {
return NULL;
}
/**
* Given a course and a time, this module should find recent activity
* that has occurred in tracker activities and print it out.
* Return true if there was output, or false is there was none.
*/
function tracker_print_recent_activity($course, $isteacher, $timestart) {
global $DB, $CFG;
$sql = "
SELECT
ti.id,
ti.trackerid,
ti.summary,
ti.reportedby,
ti.datereported,
t.name,
t.ticketprefix
FROM
{tracker} t,
{tracker_issue} ti
WHERE
t.id = ti.trackerid AND
t.course = $course->id AND
ti.datereported > $timestart
";
$newstuff = $DB->get_records_sql($sql);
if ($newstuff){
foreach($newstuff as $anissue){
echo "<span style=\"font-size:0.8em\">";
echo get_string('modulename', 'tracker').': '.format_string($anissue->name).':<br/>';
echo "<a href=\"{$CFG->wwwroot}/mod/tracker/view.php?a={$anissue->trackerid}&view=view&page=viewanissue&issueid={$anissue->id}\">".shorten_text(format_string($anissue->summary), 20).'</a><br/>';
echo '   <span class="trackersmalldate">'.userdate($anissue->datereported).'</span><br/>';
echo "</span><br/>";
}
return true;
}
return false; // True if anything was printed, otherwise false
}
/**
* Print an overview of all trackers
* for the courses.
*
* @param mixed $courses The list of courses to print the overview for
* @param array $htmlarray The array of html to return
*/
function tracker_print_overview($courses, &$htmlarray) {
global $USER, $CFG, $DB;
if (empty($courses) || !is_array($courses) || count($courses) == 0) {
return array();
}
if (!$trackers = get_all_instances_in_courses('tracker', $courses)) {
return;
}
$strtracker = get_string('modulename', 'tracker');
foreach($trackers as $tracker){
$str = '<div class="tracker overview">';
$str .= '<div class="name">'.$strtracker. ': '.
'<a '.($tracker->visible ? '':' class="dimmed"').
'title="'.$strtracker.'" href="'.$CFG->wwwroot.
'/mod/tracker/view.php?id='.$tracker->coursemodule.'">'.
format_string($tracker->name).'</a></div>';
$context = context_module::instance($tracker->coursemodule);
if (has_capability('mod/tracker:develop', $context)) {
// count how many assigned
$sql = "
SELECT DISTINCT
i.id, i.id
FROM
{tracker_issue} i
LEFT JOIN
{tracker_issueownership} io
ON
io.issueid = i.id
WHERE
i.trackerid = ? AND
assignedto = ? AND
(status = ".POSTED." OR
status = ".OPEN." OR
status = ".RESOLVING.") AND
io.id IS NULL
";
$yours = $DB->get_records_sql($sql, array($tracker->id, $USER->id));
if ($yours) {
$link = new moodle_url('/mod/tracker/view.php', array('id' => $tracker->coursemodule, 'view' => 'view', 'screen' => 'mywork'));
$str .= '<div class="details"><a href="'.$link.'">'.get_string('issuestowatch', 'tracker', count($yours)).'</a></div>';
}
}
if (has_capability('mod/tracker:manage', $context)) {
// count how many unassigned
$unassigned = $DB->get_records('tracker_issue', array('trackerid' => $tracker->id, 'assignedto' => 0, 'status' => POSTED));
if ($unassigned) {
$link = new moodle_url('/mod/tracker/view.php', array('id' => $tracker->coursemodule, 'view' => 'view', 'screen' => 'mywork'));
$str .= '<div class="details"><a href="'.$link.'">'.get_string('issuestoassign', 'tracker', count($unassigned)).'</a></div>';
}
}
$str .= '</div>';
if (empty($htmlarray[$tracker->course]['tracker'])) {
$htmlarray[$tracker->course]['tracker'] = $str;
} else {
$htmlarray[$tracker->course]['tracker'] .= $str;
}
}
}
/**
* Function to be run periodically according to the moodle cron
* This function searches for things that need to be done, such
* as sending out mail, toggling flags etc ...
*/
function tracker_cron () {
global $CFG;
return true;
}
/**
* Must return an array of grades for a given instance of this module,
* indexed by user. It also returns a maximum allowed grade.
*
* $return->grades = array of grades;
* $return->maxgrade = maximum allowed grade;
*
* return $return;
*/
function tracker_grades($trackerid) {
return NULL;
}
/**
*
**/
function tracker_scale_used_anywhere($scaleid){
return false;
}
/**
* Must return an array of user records (all data) who are participants
* for a given instance of tracker. Must include every user involved
* in the instance, independent of his role (student, teacher, admin...)
* See other modules as example.
*/
function tracker_get_participants($trackerid) {
global $DB;
$resolvers = $DB->get_records('tracker_issueownership', array('trackerid' => $trackerid), '', 'id,id');
if(!$resolvers) $resolvers = array();
$developers = $DB->get_records('tracker_issuecc', array('trackerid' => $trackerid), '', 'id,id');
if(!$developers) $developers = array();
$reporters = $DB->get_records('tracker_issue', array('trackerid' => $trackerid), '', 'reportedby,reportedby');
if(!$reporters) $reporters = array();
$admins = $DB->get_records('tracker_issueownership', array('trackerid' => $trackerid), '', 'bywhomid,bywhomid');
if(!$admins) $admins = array();
$commenters = $DB->get_records('tracker_issuecomment', array('trackerid' => $trackerid), '', 'userid,userid');
if(!$commenters) $commenters = array();
$participants = array_merge(array_keys($resolvers), array_keys($developers), array_keys($reporters), array_keys($admins));
$participantlist = implode(',', array_unique($participants));
if (!empty($participantlist)){
return $DB->get_records_list('user', array('id' => $participantlist));
}
return array();
}
/*
* This function returns if a scale is being used by one tracker
* it it has support for grading and scales. Commented code should be
* modified if necessary. See forum, glossary or journal modules
* as reference.
*/
function tracker_scale_used ($trackerid, $scaleid) {
$return = false;
//$rec = get_record("tracker","id","$trackerid","scale","-$scaleid");
//
//if (!empty($rec) && !empty($scaleid)) {
// $return = true;
//}
return $return;
}
/**
*
*
*/
function tracker_install(){
global $DB;
$result = true;
if (!$DB->get_record('mnet_service', array('name' => 'tracker_cascade'))){
$service->name = 'tracker_cascade';
$service->description = get_string('transferservice', 'tracker');
$service->apiversion = 1;
$service->offer = 1;
if (!$serviceid = $DB->insert_record('mnet_service', $service)){
echo $OUTPUT->notification('Error installing tracker_cascade service.');
$result = false;
}
$rpc->function_name = 'tracker_rpc_get_instances';
$rpc->xmlrpc_path = 'mod/tracker/rpclib.php/tracker_rpc_get_instances';
$rpc->parent_type = 'mod';
$rpc->parent = 'tracker';
$rpc->enabled = 0;
$rpc->help = 'Get instances of available trackers for cascading.';
$rpc->profile = '';
if (!$rpcid = $DB->insert_record('mnet_rpc', $rpc)){
echo $OUTPUT->notification('Error installing tracker_cascade RPC calls.');
$result = false;
}
$rpcmap->serviceid = $serviceid;
$rpcmap->rpcid = $rpcid;
$DB->insert_record('mnet_service2rpc', $rpcmap);
$rpc->function_name = 'tracker_rpc_get_infos';
$rpc->xmlrpc_path = 'mod/tracker/rpclib.php/tracker_rpc_get_infos';
$rpc->parent_type = 'mod';
$rpc->parent = 'tracker';
$rpc->enabled = 0;
$rpc->help = 'Get information about one tracker.';
$rpc->profile = '';
if (!$rpcid = $DB->insert_record('mnet_rpc', $rpc)){
echo $OUTPUT->notification('Error installing tracker_cascade RPC calls.');
$result = false;
}
$rpcmap->rpcid = $rpcid;
$DB->insert_record('mnet_service2rpc', $rpcmap);
$rpc->function_name = 'tracker_rpc_post_issue';
$rpc->xmlrpc_path = 'mod/tracker/rpclib.php/tracker_rpc_post_issue';
$rpc->parent_type = 'mod';
$rpc->parent = 'tracker';
$rpc->enabled = 0;
$rpc->help = 'Cascades an issue.';
$rpc->profile = '';
if (!$rpcid = $DB->insert_record('mnet_rpc', $rpc)){
echo $OUTPUT->notification('Error installing tracker_cascade RPC calls.');
$result = false;
}
$rpcmap->rpcid = $rpcid;
$DB->insert_record('mnet_service2rpc', $rpcmap);
}
return $result;
}
/**
* a standard module API call for making some custom uninstall tasks
*
*/
function tracker_uninstall(){
global $DB;
$return = true;
// delete all tracker related mnet services and MNET bindings
$service = $DB->get_record('mnet_service', array('name' => 'tracker_cascade'));
if ($service){
$DB->delete_records('mnet_host2service', array('serviceid' => $service->id));
$DB->delete_records('mnet_service2rpc', array('serviceid' => $service->id));
$DB->delete_records('mnet_rpc', array('parent' => 'tracker'));
$DB->delete_records('mnet_service', array('name' => 'tracker_cascade'));
}
return $return;
}
function tracker_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
global $CFG, $DB;
if ($context->contextlevel != CONTEXT_MODULE) {
return false;
}
require_course_login($course, true, $cm);
$fileareas = array('issuedescription', 'issueresolution', 'issueattribute', 'issuecomment');
if (!in_array($filearea, $fileareas)) {
return false;
}
$itemid = (int)array_shift($args);
if (!$tracker = $DB->get_record('tracker', array('id' => $cm->instance))) {
return false;
}
$fs = get_file_storage();
$relativepath = implode('/', $args);
$fullpath = "/$context->id/mod_tracker/$filearea/$itemid/$relativepath";
if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
return false;
}
// finally send the file
send_stored_file($file, 0, 0, false); // download MUST be forced - security!
}
/**
* Adds some overrides that invert role to profile mapping. This is done by role archetype
* to help custom roles to adopt suitable behaviour.
*/
function tracker_setup_role_overrides(&$tracker, $context){
global $DB, $USER;
tracker_clear_role_overrides($context);
assert(!$DB->get_records('role_capabilities', array('contextid' => $context->id)));
$time = time();
if ($tracker->supportmode == 'taskspread'){
$overrides = array(
array(
'contextid' => $context->id,
'rolearchetype' => 'teacher',
'capability' => 'mod/tracker:report',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'editingteacher',
'capability' => 'mod/tracker:report',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'teacher',
'capability' => 'mod/tracker:viewallissues',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'editingteacher',
'capability' => 'mod/tracker:viewallissues',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'teacher',
'capability' => 'mod/tracker:seeissues',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'editingteacher',
'capability' => 'mod/tracker:seeissues',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'teacher',
'capability' => 'mod/tracker:comment',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'editingteacher',
'capability' => 'mod/tracker:comment',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'teacher',
'capability' => 'mod/tracker:managepriority',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'editingteacher',
'capability' => 'mod/tracker:managepriority',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'teacher',
'capability' => 'mod/tracker:develop',
'permission' => CAP_PREVENT,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'editingteacher',
'capability' => 'mod/tracker:develop',
'permission' => CAP_PREVENT,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'teacher',
'capability' => 'mod/tracker:resolve',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'editingteacher',
'capability' => 'mod/tracker:resolve',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'student',
'capability' => 'mod/tracker:develop',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'student',
'capability' => 'mod/tracker:report',
'permission' => CAP_PREVENT,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'student',
'capability' => 'mod/tracker:comment',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'student',
'capability' => 'mod/tracker:managepriority',
'permission' => CAP_PREVENT,
),
);
} elseif ($tracker->supportmode == 'bugtracker'){
$overrides = array(
array(
'contextid' => $context->id,
'rolearchetype' => 'teacher',
'capability' => 'mod/tracker:report',
'permission' => CAP_PREVENT,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'editingteacher',
'capability' => 'mod/tracker:report',
'permission' => CAP_PREVENT,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'teacher',
'capability' => 'mod/tracker:viewallissues',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'editingteacher',
'capability' => 'mod/tracker:viewallissues',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'teacher',
'capability' => 'mod/tracker:seeissues',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'editingteacher',
'capability' => 'mod/tracker:seeissues',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'teacher',
'capability' => 'mod/tracker:comment',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'editingteacher',
'capability' => 'mod/tracker:comment',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'teacher',
'capability' => 'mod/tracker:develop',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'editingteacher',
'capability' => 'mod/tracker:develop',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'teacher',
'capability' => 'mod/tracker:resolve',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'editingteacher',
'capability' => 'mod/tracker:resolve',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'student',
'capability' => 'mod/tracker:develop',
'permission' => CAP_PREVENT,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'student',
'capability' => 'mod/tracker:report',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'student',
'capability' => 'mod/tracker:comment',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'student',
'capability' => 'mod/tracker:seeissues',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'student',
'capability' => 'mod/tracker:viewallissues',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'student',
'capability' => 'mod/tracker:resolve',
'permission' => CAP_ALLOW,
),
);
} elseif($tracker->supportmode == 'ticketting') { // User individual support
$overrides = array(
array(
'contextid' => $context->id,
'rolearchetype' => 'teacher',
'capability' => 'mod/tracker:report',
'permission' => CAP_PREVENT,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'editingteacher',
'capability' => 'mod/tracker:report',
'permission' => CAP_PREVENT,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'teacher',
'capability' => 'mod/tracker:viewallissues',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'editingteacher',
'capability' => 'mod/tracker:viewallissues',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'teacher',
'capability' => 'mod/tracker:seeissues',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'editingteacher',
'capability' => 'mod/tracker:seeissues',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'teacher',
'capability' => 'mod/tracker:comment',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'editingteacher',
'capability' => 'mod/tracker:comment',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'teacher',
'capability' => 'mod/tracker:develop',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'editingteacher',
'capability' => 'mod/tracker:develop',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'teacher',
'capability' => 'mod/tracker:resolve',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'editingteacher',
'capability' => 'mod/tracker:resolve',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'student',
'capability' => 'mod/tracker:develop',
'permission' => CAP_PREVENT,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'student',
'capability' => 'mod/tracker:report',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'student',
'capability' => 'mod/tracker:comment',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'student',
'capability' => 'mod/tracker:viewallissues',
'permission' => CAP_PREVENT,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'student',
'capability' => 'mod/tracker:seeissues',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'student',
'capability' => 'mod/tracker:managepriority',
'permission' => CAP_ALLOW,
),
array(
'contextid' => $context->id,
'rolearchetype' => 'student',
'capability' => 'mod/tracker:resolve',
'permission' => CAP_ALLOW,
),
);
}
foreach ($overrides as $ov){
$overrideobj = (object) $ov;
$roles = $DB->get_records('role', array('archetype' => $overrideobj->rolearchetype));
foreach($roles as $r){
$overrideobj->roleid = $r->id;
$overrideobj->timemodified = $time;
$overrideobj->modifierid = $USER->id;
$DB->insert_record('role_capabilities', $overrideobj);
}
}
}
/**
* Remove all overrides on this context
*
*/
function tracker_clear_role_overrides($context){
global $DB;
$DB->delete_records('role_capabilities', array('contextid' => $context->id));
}
function tracker_preset_states(&$tracker){
if ($tracker->supportmode == 'taskspread'){
$tracker->enabledstates = ENABLED_OPEN | ENABLED_RESOLVED | ENABLED_WAITING | ENABLED_ABANDONNED;
} elseif ($tracker->supportmode == 'bugtracker'){
$tracker->enabledstates = ENABLED_ALL;
} elseif ($tracker->supportmode == 'ticketting'){
$tracker->enabledstates = ENABLED_OPEN | ENABLED_RESOLVING | ENABLED_RESOLVED | ENABLED_WAITING | ENABLED_ABANDONNED | ENABLED_VALIDATED;
} else {
if (is_array(@$tracker->stateprofile)){
$tracker->enabledstates = array_reduce($tracker->stateprofile, 'tracker_ror', 0);
}
}
}
function tracker_preset_params(&$tracker){
global $DB;
if ($tracker->supportmode == 'taskspread'){
$tracker->thanksmessage = get_string('message_taskspread', 'tracker');
$tracker->defaultassignee = 0;
} elseif ($tracker->supportmode == 'bugtracker'){
$tracker->thanksmessage = get_string('message_bugtracker', 'tracker');
} elseif ($tracker->supportmode == 'ticketting'){
if ($tracker->defaultassignee){
$defaultassignee = $DB->get_record('user', array('id' => $tracker->defaultassignee), 'id, firstname, lastname');
$tracker->thanksmessage = get_string('message_ticketting_preassigned', 'tracker', fullname($defaultassignee));
} else {
$tracker->thanksmessage = get_string('message_ticketting', 'tracker');
}
}
}