forked from gbateson/moodle-mod_hotpot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
locallib.php
2305 lines (2033 loc) · 73.9 KB
/
locallib.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
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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.
//
// Moodle 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Library of internal classes and functions for module hotpot
*
* All the hotpot specific functions, needed to implement the module
* logic, should go to here. Instead of having bunch of function named
* hotpot_something() taking the hotpot instance as the first
* parameter, we use a class hotpot that provides all methods.
*
* @package mod-hotpot
* @copyright 2010 Gordon Bateson <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once(dirname(__FILE__).'/lib.php'); // we extend this library here
require_once($CFG->libdir . '/gradelib.php'); // we use some rounding and comparing routines here
/**
* Full-featured hotpot API
*
* This wraps the hotpot database record with a set of methods that are called
* from the module itself. The class should be initialized right after you get
* $hotpot, $cm and $course records at the begining of the script.
*/
class hotpot {
/**#@+
* internal codes to indicate what text is to be used
* for the name and introduction of a HotPot instance
*
* @var integer
*/
const TEXTSOURCE_FILE = 0; // was TEXTSOURCE_QUIZ
const TEXTSOURCE_FILENAME = 1;
const TEXTSOURCE_FILEPATH = 2;
const TEXTSOURCE_SPECIFIC = 3;
/**#@-*/
/**#@+
* database codes to indicate what navigation aids are used
* when the quiz apears in the browser
*
* @var integer
*/
const NAVIGATION_NONE = 0; // was 6
const NAVIGATION_MOODLE = 1; // was NAVIGATION_BAR
const NAVIGATION_FRAME = 2;
const NAVIGATION_EMBED = 3; // was NAVIGATION_IFRAME
const NAVIGATION_ORIGINAL = 4;
const NAVIGATION_TOPBAR = 5; // was NAVIGATION_GIVEUP but that was replaced by stopbutton
/**#@-*/
/**#@+
* database codes to indicate the grading method for a HotPot instance
*
* @var integer
*/
const GRADEMETHOD_HIGHEST = 1;
const GRADEMETHOD_AVERAGE = 2;
const GRADEMETHOD_FIRST = 3;
const GRADEMETHOD_LAST = 4;
/**#@-*/
/**#@+
* database codes to indicate the source/config location for a HotPot instance
*
* @var integer
*/
const LOCATION_COURSEFILES = 0;
const LOCATION_SITEFILES = 1;
const LOCATION_WWW = 2;
/**#@-*/
/**#@+
* bit-masks used to extract bits from the hotpot "title" setting
*
* @var integer
*/
const TITLE_SOURCE = 0x03; // 1st - 2nd bits
const TITLE_UNITNAME = 0x04; // 3rd bit
const TITLE_SORTORDER = 0x08; // 4th bit
/**#@-*/
/**#@+
* database codes for the following time fields
* - timelimit : the maximum length of one attempt
* - delay3 : the delay after end of quiz before control returns to Moodle
*
* @var integer
*/
const TIME_SPECIFIC = 0;
const TIME_TEMPLATE = -1;
const TIME_AFTEROK = -2;
const TIME_DISABLE = -3;
/**#@-*/
/**#@+
* internal codes to indicate whether a HotPot can resume or restart
*
* @var integer
*/
const CONTINUE_RESUMEQUIZ = 1;
const CONTINUE_RESTARTQUIZ = 2;
const CONTINUE_RESTARTUNIT = 3;
const CONTINUE_ABANDONUNIT = 4;
/**#@-*/
/**#@+
* internal codes to refer to the HTTP return code
*
* @var integer
*/
const HTTP_NO_RESPONSE = 0; // was false
const HTTP_204_RESPONSE = 1; // was true
/**#@-*/
/**#@+
* database code to indicate current state of HotPot attempt
*
* @var integer
*/
const STATUS_INPROGRESS = 1;
const STATUS_TIMEDOUT = 2;
const STATUS_ABANDONED = 3;
const STATUS_COMPLETED = 4;
const STATUS_PAUSED = 5;
/**#@-*/
/**#@+
* database code to indicate the kind of feedback link, if any
*
* @var integer
*/
const FEEDBACK_NONE = 0;
const FEEDBACK_WEBPAGE = 1;
const FEEDBACK_FORMMAIL = 2;
const FEEDBACK_MOODLEFORUM = 3;
const FEEDBACK_MOODLEMESSAGING = 4;
/**#@-*/
/**#@+
* database code to indicate the kind of STOP button
*
* @var integer
*/
const STOPBUTTON_NONE = 0;
const STOPBUTTON_LANGPACK = 1;
const STOPBUTTON_SPECIFIC = 2;
/**#@-*/
/**#@+
* database code to indicate the kind of previous/next activity
*
* @var integer
*/
const ACTIVITY_NONE = 0;
const ACTIVITY_COURSE_ANY = -1;
const ACTIVITY_SECTION_ANY = -2;
const ACTIVITY_COURSE_HOTPOT = -3;
const ACTIVITY_SECTION_HOTPOT = -4;
/**#@-*/
/**#@+
* database code to indicate options on the entry page
*
* @var integer
*/
const ENTRYOPTIONS_TITLE = 0x01;
const ENTRYOPTIONS_GRADING = 0x02;
const ENTRYOPTIONS_DATES = 0x04;
const ENTRYOPTIONS_ATTEMPTS = 0x08;
/**#@-*/
/**#@+
* database code to indicate options on the exit page
*
* @var integer
*/
const EXITOPTIONS_TITLE = 0x01;
const EXITOPTIONS_ENCOURAGEMENT = 0x02;
const EXITOPTIONS_ATTEMPTSCORE = 0x04;
const EXITOPTIONS_HOTPOTGRADE = 0x08;
const EXITOPTIONS_RETRY = 0x10;
const EXITOPTIONS_INDEX = 0x20;
const EXITOPTIONS_COURSE = 0x40;
const EXITOPTIONS_GRADES = 0x80;
/**#@-*/
/**#@+
* database code to indicate which CSS styles should be overridden
*
* @var integer
*/
const BODYSTYLES_BACKGROUND = 0x01;
const BODYSTYLES_COLOR = 0x02;
const BODYSTYLES_FONT = 0x04;
const BODYSTYLES_MARGIN = 0x08;
/**#@-*/
/**#@+
* three sets of 6 bits define the times at which a quiz may be reviewed
* e.g. 0x3f = 0011 1111 (i.e. right most 6 bits)
*
* @var integer
*/
const REVIEW_DURINGATTEMPT = 0x0003f; // 1st set of 6 bits : during attempt
const REVIEW_AFTERATTEMPT = 0x00fc0; // 2nd set of 6 bits : after attempt (but before quiz closes)
const REVIEW_AFTERCLOSE = 0x3f000; // 3rd set of 6 bits : after the quiz closes
/**#@-*/
/**#@+
* within each group of 6 bits we determine what should be shown
* e.g. 0x1041 = 00-0001 0000-01 00-0001 (i.e. 3 sets of 6 bits)
*
* @var integer
*/
const REVIEW_RESPONSES = 0x1041; // 1*0x1041 : 1st bit of each 6-bit set : Show student responses
const REVIEW_ANSWERS = 0x2082; // 2*0x1041 : 2nd bit of each 6-bit set : Show correct answers
const REVIEW_SCORES = 0x4104; // 3*0x1041 : 3rd bit of each 6-bit set : Show scores
const REVIEW_FEEDBACK = 0x8208; // 4*0x1041 : 4th bit of each 6-bit set : Show feedback
/**#@-*/
/** @var stdclass course module record */
public $cm;
/** @var stdclass course record */
public $course;
/** @var stdclass context object */
public $context;
/** @var int hotpot instance identifier */
public $id;
/** @var string hotpot activity name */
public $name;
/** @var string url or path of the source file for this HotPot instance */
public $sourcefile;
/** @var string the type of the source file for this HotPot instance */
public $sourcetype;
/** @var int the file itemid of the sourcefile for this HotPot instance */
public $sourcelocation;
/** @var string url or path of the config file for this HotPot instance */
public $configfile;
/** @var int the location of the configfile for this HotPot instance */
public $configlocation;
/** @var xxx */
public $entrycm;
/** @var xxx */
public $entrygrade;
/** @var xxx */
public $entrypage;
/** @var xxx */
public $entrytext;
/** @var xxx */
public $entryformat;
/** @var xxx */
public $entryoptions;
/** @var xxx */
public $exitpage;
/** @var xxx */
public $exittext;
/** @var xxx */
public $exitformat;
/** @var xxx */
public $exitoptions;
/** @var xxx */
public $exitcm;
/** @var xxx */
public $exitgrade;
/** @var string the output format to be used when generating browser content */
public $outputformat;
/** @var int navigation aids to be used when this HotPot instance appears in the browser */
public $navigation;
/** @var int defines what will be displayed as the title in the browser */
public $title;
/** @var int indicates what kind of of stop button, if any, will be displayed */
public $stopbutton;
/** @var string the string to be displayed on the stop button */
public $stoptext;
/** @var boolean flag to indicate copy-paste should be allowed or not */
public $allowpaste;
/** @var boolean flag to indicate quiz content should be run processed by Moodle filters */
public $usefilters;
/** @var boolean flag to indicate quiz content should be linked to Moodle glossaries */
public $useglossary;
/** @var string name, if any, of mediaplayer filter to be used to replace media players */
public $usemediafilter;
/** @var int what kind of popup, if any, should be shown for student feedback */
public $studentfeedback;
/** @var string url, if any, to which student feedback will be sent */
public $studentfeedbackurl;
/** @var int time after which this HotPot becomes available */
public $timeopen;
/** @var int time after which this HotPot is no longer available */
public $timeclose;
/** @var int the time limit for a single attempt at this HotPot */
public $timelimit;
/** @var int minimum time delay, in seconds, between first and second attempt */
public $delay1;
/** @var int minimum time delay, in seconds, between attempts after the second attempt */
public $delay2;
/** @var int delay, in seconds, between finishing a quiz and returning control to Moodle */
public $delay3;
/** @var string optional password required to access this HotPot instance */
public $password;
/** @var string optional IP mask to limit access this HotPot instance */
public $subnet;
/** @var xxx */
public $reviewoptions;
/** @var int 0-100 to show maximum number of attempts allowed at this HotPot instance */
public $attemptlimit;
/** @var int code denoting the grading method for this HotPot instance */
public $grademethod;
/** @var int 0-100 to show maximum grade for this HotPot instance */
public $gradeweighting;
/** @var boolean if true, every click of "hint", "clue" or "check" will be stored in the Moodle database */
public $clickreporting;
/** @var boolean if true, the raw xml returned form the attempt will be stored in the Moodle database */
public $discarddetails;
/** @var int timestamp of when the module was modified */
public $timemodified;
/** @var int timestamp of when the module was created */
public $timecreated;
/**#@+ @var int completion settings */
public $completionmingrade;
public $completionpass;
public $completioncompleted;
/**#@-*/
/** @var int timestamp of when this object was created */
public $time;
/** @var object representing the source file */
public $source;
/** @var object representing the config file */
public $config;
/** @var object representing a record from the hotpot_attempt table */
public $attempt;
/** @var array cache of all attempts by current user at this HotPot activity */
public $attempts;
/** @var object representing the grade_grade this HotPot activity */
public $gradeitem;
/** @var boolean cache for hotpot:attempt capability */
public $canattempt;
/** @var boolean cache for hotpot:deleteallattempts capability */
public $candeleteallattempts;
/** @var boolean cache for hotpot:deletemyattempts capability */
public $candeletemyattempts;
/** @var boolean cache for hotpot:manage capability */
public $canmanage;
/** @var boolean cache for hotpot:preview capability */
public $canpreview;
/** @var boolean cache for hotpot:reviewallattempts capability */
public $canreviewallattempts;
/** @var boolean cache for hotpot:reviewmyattempts capability */
public $canreviewmyattempts;
/** @var boolean cache for hotpot:view capability */
public $canview;
/** @var boolean cache of swithc to show if user can start this hotpot */
public $canstart;
/**
* Initializes the hotpot API instance using the data from DB
*
* Makes deep copy of all passed records properties. Replaces integer $course attribute
* with a full database record (course should not be stored in instances table anyway).
*
* The method is "protected" to prevent it being called directly. To create a new
* instance of this class please use the self::create() method (see below).
*
* @param stdclass $dbrecord HotPot instance data from the {hotpot} table
* @param stdclass $cm Course module record as returned by {@link get_coursemodule_from_id()}
* @param stdclass $course Course record from {course} table
* @param stdclass $context The context of the hotpot instance
* @param stdclass $attempt attempt data from the {hotpot_attempts} table
*/
private function __construct($dbrecord, $cm, $course, $context=null, $attempt=null) {
foreach ($dbrecord as $field => $value) {
if (property_exists('hotpot', $field)) {
$this->$field = $value;
}
}
$this->cm = $cm;
$this->course = $course;
if (is_null($context)) {
$this->context = hotpot_get_context(CONTEXT_MODULE, $this->cm->id);
} else {
$this->context = $context;
}
if (is_null($attempt)) {
// do nothing
} else {
$this->attempt = $attempt;
}
$this->time = time();
}
////////////////////////////////////////////////////////////////////////////////
// Static methods //
////////////////////////////////////////////////////////////////////////////////
/**
* Creates a new HotPot object
*
* @param stdclass $dbrecord a row from the hotpot table
* @param stdclass $cm a row from the course_modules table
* @param stdclass $course a row from the course table
* @return hotpot the new hotpot object
*/
static public function create($dbrecord, $cm, $course, $context=null, $attempt=null) {
return new hotpot($dbrecord, $cm, $course, $context, $attempt);
}
/**
* set_user_editing
*/
static public function set_user_editing() {
global $USER;
$editmode = optional_param('editmode', null, PARAM_BOOL);
if (! is_null($editmode)) {
$USER->editing = $editmode;
}
}
/**
* Returns the localized list of navigation settings for a HotPot instance
*
* @return array
*/
static public function available_navigations_list() {
return array (
self::NAVIGATION_MOODLE => get_string('navigation_moodle', 'mod_hotpot'),
self::NAVIGATION_TOPBAR => get_string('navigation_topbar', 'mod_hotpot'),
self::NAVIGATION_FRAME => get_string('navigation_frame', 'mod_hotpot'),
self::NAVIGATION_EMBED => get_string('navigation_embed', 'mod_hotpot'),
self::NAVIGATION_ORIGINAL => get_string('navigation_original', 'mod_hotpot'),
self::NAVIGATION_NONE => get_string('navigation_none', 'mod_hotpot')
);
}
/**
* Returns the localized list of feedback settings for a HotPot instance
*
* @return array
*/
static public function available_feedbacks_list() {
global $CFG;
$list = array (
self::FEEDBACK_NONE => get_string('none'),
self::FEEDBACK_WEBPAGE => get_string('feedbackwebpage', 'mod_hotpot'),
self::FEEDBACK_FORMMAIL => get_string('feedbackformmail', 'mod_hotpot'),
self::FEEDBACK_MOODLEFORUM => get_string('feedbackmoodleforum', 'mod_hotpot')
);
if ($CFG->messaging) {
$list[self::FEEDBACK_MOODLEMESSAGING] = get_string('feedbackmoodlemessaging', 'mod_hotpot');
}
return $list;
}
/**
* Returns the list of media players for the HotPot module
*
* @return array
*/
static public function available_mediafilters_list() {
$plugins = get_list_of_plugins('mod/hotpot/mediafilter'); // sorted
if (in_array('moodle', $plugins)) {
// make 'moodle' the first element in the plugins array
unset($plugins[array_search('moodle', $plugins)]);
array_unshift($plugins, 'moodle');
}
// define element type for list of mediafilters (select, radio, checkbox)
$options = array('' => get_string('none'));
foreach ($plugins as $plugin) {
$options[$plugin] = get_string('mediafilter_'.$plugin, 'mod_hotpot');
}
return $options;
}
/**
* Returns the localized list of output format setings for a given HotPot sourcetype
*
* @return array
*/
static public function available_outputformats_list($sourcetype) {
$outputformats = array(
'0' => get_string('outputformat_best', 'mod_hotpot')
);
if ($sourcetype) {
$classes = self::get_classes('hotpotattempt', 'renderer.php', 'mod_', '_renderer');
foreach ($classes as $class) {
// use call_user_func() to prevent syntax error in PHP 5.2.x
$sourcetypes = call_user_func(array($class, 'sourcetypes'));
if (in_array($sourcetype, $sourcetypes)) {
// strip prefix, "mod_hotpot_attempt_", and suffix, "_renderer"
$outputformat = substr($class, 19, -9);
$outputformats[$outputformat] = get_string('outputformat_'.$outputformat, 'mod_hotpot');
}
}
uksort($outputformats, array('hotpot', 'uksort_outputformats'));
// remove "best" if there is only one compatible output format
// if (count($outputformats)==2) {
// unset($outputformats[0]);
// }
}
return $outputformats;
}
/**
* uksort_outputformats
*
* @param string $a
* @param string $b
* @return integer
*/
static public function uksort_outputformats($a, $b) {
if ($a == '0') {
return -1;
}
if ($b == '0') {
return 1;
}
$a = explode('_', $a);
$b = explode('_', $b);
$a_count = count($a);
$b_count = count($b);
// special rules for comparing two "hp" classes
$hp = ($a[0] == 'hp' && $b[0] == 'hp');
$i = 0;
while ($i < $a_count && $i < $b_count) {
// For HP files, the source format ($i=1) and output version ($i=4)
// are sorted in DESCENDING order.
if ($hp && ($i == 1 || $i == 4)) {
$asc = false;
} else {
$asc = true;
}
if ($a[$i] < $b[$i]) {
return ($asc ? -1 : 1);
}
if ($a[$i] > $b[$i]) {
return ($asc ? 1 : -1);
}
$i++;
}
// For Jmatch/JMix, the drag-and-drop formats (v6/v7 plus) come first
if ($hp && ($a[2] == 'jmatch' || $a[2] == 'jmix') && ($a[4] == 'v6' || $a[4] == 'v7')) {
if ($a_count == 6 && $a[5] == 'plus') {
return -1;
}
if ($b_count == 6 && $b[5] == 'plus') {
return 1;
}
}
// Otherwise, shorter formats come first.
if ($a_count < $b_count) {
return -1;
}
if ($a_count > $b_count) {
return 1;
}
return 0;
}
/**
* Returns the localized list of attempt limit settings for a HotPot instance
*
* @return array
*/
static public function available_attemptlimits_list() {
$options = array(
0 => get_string('attemptsunlimited', 'mod_hotpot'),
);
for ($i=1; $i<=10; $i++) {
$options[$i] = "$i";
}
return $options;
}
/**
* Returns the localized list of grade method settings for a HotPot instance
*
* @return array
*/
static public function available_grademethods_list() {
return array (
self::GRADEMETHOD_HIGHEST => get_string('highestscore', 'mod_hotpot'),
self::GRADEMETHOD_AVERAGE => get_string('averagescore', 'mod_hotpot'),
self::GRADEMETHOD_FIRST => get_string('firstattempt', 'mod_hotpot'),
self::GRADEMETHOD_LAST => get_string('lastattempt', 'mod_hotpot'),
);
}
/**
* Returns the localized list of status settings for a HotPot attempt
*
* @return array
*/
static public function available_statuses_list() {
return array (
self::STATUS_INPROGRESS => get_string('inprogress', 'mod_hotpot'),
self::STATUS_TIMEDOUT => get_string('timedout', 'mod_hotpot'),
self::STATUS_ABANDONED => get_string('abandoned', 'mod_hotpot'),
self::STATUS_COMPLETED => get_string('completed', 'mod_hotpot')
);
}
/**
* Returns the localized list of grade method settings for a HotPot instance
*
* @return array
*/
static public function available_namesources_list() {
return array (
self::TEXTSOURCE_FILE => get_string('textsourcefile', 'mod_hotpot'),
self::TEXTSOURCE_FILENAME => get_string('textsourcefilename', 'mod_hotpot'),
self::TEXTSOURCE_FILEPATH => get_string('textsourcefilepath', 'mod_hotpot'),
self::TEXTSOURCE_SPECIFIC => get_string('textsourcespecific', 'mod_hotpot')
);
}
/**
* Returns the localized list of grade method settings for a HotPot instance
*
* @return array
*/
static public function available_titles_list() {
return array (
self::TEXTSOURCE_SPECIFIC => get_string('hotpotname', 'mod_hotpot'),
self::TEXTSOURCE_FILE => get_string('textsourcefile', 'mod_hotpot'),
self::TEXTSOURCE_FILENAME => get_string('textsourcefilename', 'mod_hotpot'),
self::TEXTSOURCE_FILEPATH => get_string('textsourcefilepath', 'mod_hotpot')
);
}
/**
* Returns the localized list of maximum grade settings for a HotPot instance
*
* @return array
*/
static public function available_gradeweightings_list() {
$options = array();
for ($i=100; $i>=1; $i--) {
$options[$i] = $i;
}
$options[0] = get_string('nograde');
return $options;
}
/**
* Detects the type of the source file
*
* @param stored_file $sourcefile the file that has just been uploaded and stored
* @return string the type of the source file (e.g. hp_6_jcloze_xml)
*/
static public function get_sourcetype($sourcefile) {
// include all the hotpot_source classes
$classes = self::get_classes('hotpotsource');
// loop through the classes checking to see if this file is recognized
// use call_user_func() to prevent syntax error in PHP 5.2.x
foreach ($classes as $class) {
if (call_user_func(array($class, 'is_quizfile'), $sourcefile)) {
return call_user_func(array($class, 'get_type'), $class);
}
}
// file is not a recognized quiz type :-(
return '';
}
/**
* Returns a js module object for the HotPot module
*
* @param array $requires
* e.g. array('base', 'dom', 'event-delegate', 'event-key')
* @return array $strings
* e.g. array(
* array('timesup', 'quiz'),
* array('functiondisabledbysecuremode', 'quiz'),
* array('flagged', 'question')
* )
*/
static public function get_js_module(array $requires = null, array $strings = null) {
return array(
'name' => 'mod_hotpot',
'fullpath' => '/mod/hotpot/module.js',
'requires' => $requires,
'strings' => $strings,
);
}
/**
* get_version_info
*
* @param xxx $info
* @return xxx
*/
static public function get_version_info($info) {
global $CFG;
static $plugin = null;
if (is_null($plugin)) {
$plugin = new stdClass();
require($CFG->dirroot.'/mod/hotpot/version.php');
}
if (isset($plugin->$info)) {
return $plugin->$info;
} else {
return "no $info found";
}
}
/**
* load_mediafilter_filter
*
* @param xxx $classname
*/
static public function load_mediafilter_filter($classname) {
global $CFG;
$path = $CFG->dirroot.'/mod/hotpot/mediafilter/'.$classname.'/class.php';
// check the filter exists
if (! file_exists($path)) {
debugging('hotpot mediafilter class is not accessible: '.$classname, DEBUG_DEVELOPER);
return false;
}
return require_once($path);
}
/**
* sourcefile_options
*
* @param xxx $context
* @return xxx
*/
static public function sourcefile_options() {
return array('subdirs' => 1, 'maxbytes' => 0, 'maxfiles' => -1);
}
/**
* text_editors_options
*
* @param xxx $context
* @return xxx
*/
static public function text_editors_options($context) {
return array('subdirs' => 1, 'maxbytes' => 0, 'maxfiles' => EDITOR_UNLIMITED_FILES,
'changeformat' => 1, 'context' => $context, 'noclean' => 1, 'trusttext' => 0);
}
/**
* text_page_types
*
* @return xxx
*/
static public function text_page_types() {
return array('entry', 'exit');
}
/**
* text_page_options
*
* @param xxx $type
* @return xxx
*/
static public function text_page_options($type) {
if ($type=='entry') {
return array(
'title' => self::ENTRYOPTIONS_TITLE,
'grading' => self::ENTRYOPTIONS_GRADING,
'dates' => self::ENTRYOPTIONS_DATES,
'attempts' => self::ENTRYOPTIONS_ATTEMPTS
);
}
if ($type=='exit') {
return array(
'title' => self::ENTRYOPTIONS_TITLE,
'encouragement' => self::EXITOPTIONS_ENCOURAGEMENT,
'attemptscore' => self::EXITOPTIONS_ATTEMPTSCORE,
'hotpotgrade' => self::EXITOPTIONS_HOTPOTGRADE,
'retry' => self::EXITOPTIONS_RETRY,
'index' => self::EXITOPTIONS_INDEX,
'course' => self::EXITOPTIONS_COURSE,
'grades' => self::EXITOPTIONS_GRADES
);
}
return array();
}
/**
* reviewoptions_timesitems
*
* @return xxx
*/
static public function reviewoptions_times_items() {
return array(
array( // times
'duringattempt' => self::REVIEW_DURINGATTEMPT,
'afterattempt' => self::REVIEW_AFTERATTEMPT,
'afterclose' => self::REVIEW_AFTERCLOSE
),
array( // items
'responses' => self::REVIEW_RESPONSES,
'answers' => self::REVIEW_ANSWERS,
'scores' => self::REVIEW_SCORES,
'feedback' => self::REVIEW_FEEDBACK
)
);
}
/**
* user_preferences_fields
*
* @return array of user_preferences used by the HotPot module
*/
static public function user_preferences_fieldnames() {
return array(
// fields used only when adding a new HotPot
'namesource','entrytextsource','exittextsource','quizchain',
// source/config files
'sourcefile','sourcelocation','configfile','configlocation',
// entry/exit pages
'entrypage','entryformat','entryoptions',
'exitpage','exitformat','exitoptions',
'entrycm','entrygrade','exitcm','exitgrade',
// display
'outputformat','navigation','title','stopbutton','stoptext','allowpaste',
'usefilters','useglossary','usemediafilter','studentfeedback','studentfeedbackurl',
// access restrictions
'timeopen','timeclose','timelimit','delay1','delay2','delay3',
'password','subnet','reviewoptions','attemptlimit',
// grading and reporting
'grademethod','gradeweighting','clickreporting','discarddetails'
);
}
/**
* string_ids
*
* @param xxx $field_value
* @return xxx
*/
static public function string_ids($field_value, $max_field_length=255) {
$ids = array();
$strings = explode(',', $field_value);
foreach($strings as $str) {
if ($id = self::string_id($str)) {
$ids[] = $id;
}
}
$ids = implode(',', $ids);
// we have to make sure that the list of $ids is no longer
// than the maximum allowable length for this field
if (strlen($ids) > $max_field_length) {
// truncate $ids just before last comma in allowable field length
// Note: largest possible id is something like 9223372036854775808
// so we must leave space for that in the $ids string
$ids = substr($ids, 0, $max_field_length - 20);
$ids = substr($ids, 0, strrpos($ids, ','));
// create single $str(ing) containing all $strings not included in $ids
$str = implode(',', array_slice($strings, substr_count($ids, ',') + 1));
// append the id of the string containing all the strings not yet in $ids
if ($id = self::string_id($str)) {
$ids .= ','.$id;
}
}
// return comma separated list of string $ids
return $ids;
}
/**
* string_id
*
* @param xxx $str
* @return xxx
*/
static public function string_id($str) {
global $DB;
if (! isset($str) || ! is_string($str) || trim($str)=='') {
// invalid input string
return false;
}
// create md5 key
$md5key = md5($str);
if ($id = $DB->get_field('hotpot_strings', 'id', array('md5key'=>$md5key))) {
// string already exists
return $id;
}
// create a new string record
$record = (object)array('string'=>$str, 'md5key'=>$md5key);
if (! $id = $DB->insert_record('hotpot_strings', $record)) {
print_error('error_insertrecord', 'hotpot', '', 'hotpot_strings');
}