-
Notifications
You must be signed in to change notification settings - Fork 6
/
quiz.install
1357 lines (1296 loc) · 40.7 KB
/
quiz.install
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
/**
* @file
* Quiz install schema for installing the quiz module.
*/
/**
* Implements hook_install().
*/
function quiz_install() {
node_types_rebuild();
$types = node_type_get_types();
node_add_body_field($types['quiz']);
// Default the "Show Author and Date" for quiz nodes to OFF.
$temp_array = variable_get('theme_settings', array());
$temp_array['toggle_node_info_quiz'] = 0;
variable_set('theme_settings', $temp_array);
// Default the comment settings to disabled.
variable_set('comment_quiz', '0');
drupal_set_message(t('Quiz module has been enabled. To !create_a_quiz go to Create Content -> Quiz.', array('!create_a_quiz' => l(t('create a quiz'), 'node/add/quiz'))));
// Grant default permissions.
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('view own quiz results'));
user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, array('access quiz'));
// Set up default admin feedback review options.
quiz_update_7514();
// Set up default quiz result answer display.
quiz_update_7521();
// Install a default bundle.
db_insert('quiz_result_type')
->fields(array('label' => 'Quiz result', 'type' => 'quiz_result'))
->execute();
}
/**
* Implements hook_schema().
*/
function quiz_schema() {
$schema = array();
/*
* Connect all the quiz specific properties to the correct version of a quiz.
*/
// Create the quiz node properties table.
$schema['quiz_node_properties'] = array(
'description' => 'The base table for quiz nodes',
'fields' => array(
'qnp_id' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary identifier of a Quiz, or Quiz default settings object.',
),
'vid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The current {quiz}.vid version identifier.',
),
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'The primary identifier for the Quiz node.',
),
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'User ID of the Quiz default settings object.',
),
'number_of_random_questions' => array(
'type' => 'int',
'size' => 'small',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Number of random questions to pull from the pool.',
),
'max_score_for_random' => array(
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1,
'description' => 'Maximum score per random question.',
),
'pass_rate' => array(
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => FALSE,
'description' => 'Passing rate out of 100.',
),
'summary_pass' => array(
'type' => 'text',
'description' => 'Summary text for a passing grade.',
),
'summary_pass_format' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'Input format for the passing summary text.',
),
'summary_default' => array(
'type' => 'text',
'description' => 'Summary text for any grade.',
),
'summary_default_format' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'description' => 'Input format for the default summary text.',
),
'randomization' => array(
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'default' => 0,
'description' => 'Enumerated field indicating if this Quiz has random questions. 0=none, 1=random order, 2=random questions, 3=random taxonomy',
),
'backwards_navigation' => array(
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1,
'description' => 'Boolean indicating whether a quiz taker can navigate backwards.',
),
'keep_results' => array(
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 2,
'description' => 'Enumerated field indicating if this Quiz should prune old results. 0=only keep best, 1=only keep newest, 2=keep all',
),
'repeat_until_correct' => array(
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Boolean indicating whether a quiz taker must repeat the question until selecting the correct answer.',
),
'quiz_open' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Unix timestamp when the quiz will open.',
),
'quiz_close' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Unix timestamp when the quiz will close.',
),
'takes' => array(
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Limit the number of times this Quiz can be taken by a learner. 0 for unlimited.',
),
'show_attempt_stats' => array(
'type' => 'int',
'size' => 'tiny',
'unsigned' => FALSE,
'not null' => TRUE,
'default' => 1,
'description' => 'Boolean indicating whether or not to show the allowed attempts on the Quiz node.',
),
'time_limit' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Number of seconds for a user to complete an attempt.',
),
'quiz_always' => array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
'description' => 'Boolean indicating whether the quiz will ignore the quiz open and close dates.',
),
'time_left' => array(
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'default' => 0,
'description' => 'Deprecated field, no longer used.',
),
'max_score' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'The max score of this Quiz.',
),
'allow_skipping' => array(
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'default' => 0,
'description' => 'Boolean indicating whether the user can skip a question.',
),
'allow_resume' => array(
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'default' => 1,
'description' => 'Boolean indicating whether a user can resume a Quiz after logging out and in.',
),
'allow_jumping' => array(
'type' => 'int',
'size' => 'tiny',
'unsigned' => FALSE,
'not null' => TRUE,
'default' => 0,
'description' => 'Boolean indicating whether a user can skip to any question.',
),
'allow_change' => array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 1,
'description' => 'Boolean indicating whether a user can change the answer to an already answered question.',
),
'allow_change_blank' => array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
'description' => 'Boolean indicating whether a user can change the answer to a skipped question.',
),
'build_on_last' => array(
'type' => 'varchar',
'length' => '255',
'not null' => TRUE,
'default' => '',
'description' => 'Enumerated field indicating whether a user can build on the last attempt. "" for none, "correct" for correct answers only, "all" for all answers.',
),
'show_passed' => array(
'type' => 'int',
'size' => 'tiny',
'unsigned' => FALSE,
'not null' => TRUE,
'default' => 1,
'description' => 'Boolean indicating whether a message should display when the user has already passed this quiz.',
),
'mark_doubtful' => array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
'description' => 'Boolean indicating whether a user can mark a question as doubtful.',
),
'review_options' => array(
'type' => 'text',
'serialize' => TRUE,
'description' => 'Serialized field containing feedback times and options.',
),
'result_type' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'The result bundle to use.',
),
),
'primary key' => array('qnp_id'),
'indexes' => array('quiz_id' => array('vid', 'nid')),
);
/*
* Both a quiz and a quiz question are nodes with versions. A quiz is a parent
* node of a quiz question, making the quiz question the child.
*
* The quiz_node_relationship table stores this relationship in a way that
* allows a quiz question to be the child of multiple quizzes without losing
* version history.
*
* Future functionality will allow a quiz question to be a parent of another
* quiz question with the same data model. This will make adaptive quiz
* functionality possible without redesign.
*/
// Create the quiz node relationship table.
$schema['quiz_node_relationship'] = array(
'description' => 'Table storing what questions belong to what quizzes',
'fields' => array(
'qnr_id' => array(
'type' => 'serial',
'size' => 'normal',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The primary identifier of this relationship.',
),
'qnr_pid' => array(
'type' => 'int',
'size' => 'normal',
'unsigned' => TRUE,
'not null' => FALSE,
'default' => NULL,
'description' => 'The parent relationship of this relationship.',
),
'parent_nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The quiz that this question belongs to.',
),
'parent_vid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The quiz version that this question belongs to.',
),
'child_nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The question node ID.',
),
'child_vid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The question node version ID.',
),
'question_status' => array(
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1,
'description' => 'The status of the question in this quiz. 0=random, 1=always, 2=never',
),
'weight' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'The weight of this question in the Quiz.',
),
'max_score' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'The max score of the question in this Quiz.',
),
'auto_update_max_score' => array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
'description' => 'Boolean indicating whether updates to the question will update the max score of the question in the Quiz.',
),
),
'primary key' => array('qnr_id'),
'unique keys' => array(
'parent_child' => array('parent_nid', 'parent_vid', 'child_nid', 'child_vid'),
),
'indexes' => array(
'parent_id' => array('parent_vid'),
'child_id' => array('child_vid'),
'parent_nid' => array('parent_nid'),
'child_nid' => array('child_nid'),
),
);
/*
* Quiz specific options concerning availability and access to scores.
*/
// Create the quiz node results table.
$schema['quiz_node_results'] = array(
'description' => 'Table storing the total results for a quiz',
'fields' => array(
'result_id' => array(
'type' => 'serial',
'size' => 'normal',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The primary identifier for this result.',
),
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The quiz ID associated with this result.',
),
'vid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The quiz version ID associated with this result.',
),
'uid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The user associated with this result.',
),
'time_start' => array(
'type' => 'int',
'unsigned' => FALSE,
'description' => 'Unix timestamp when this result started.',
),
'time_end' => array(
'type' => 'int',
'unsigned' => FALSE,
'description' => 'Unix timestamp when this result ended. A NULL value indicates a quiz result not completed.',
),
'released' => array(
'type' => 'int',
'unsigned' => TRUE,
'default' => 0,
'description' => 'This field is not referenced.',
),
'score' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'The score of this result from 0 to 100.',
),
'is_invalid' => array(
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Boolean indicating if this result is marked for deletion.',
),
'is_evaluated' => array(
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Boolean indicating if this quiz requires manual grading and if it has been graded.',
),
'time_left' => array(
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'default' => 0,
'description' => 'Deprecated field, no longer used.',
),
'attempt' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 1,
'description' => 'The number of this attempt.',
),
'type' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
'description' => 'The result bundle.',
),
),
'primary key' => array('result_id'),
'indexes' => array(
'user_results' => array('uid', 'vid', 'nid'),
'vid' => array('vid'),
),
);
/*
* Information about a particular question in a result.
*/
$schema['quiz_node_results_answers'] = array(
'description' => 'Table storing information about each question response in an attempt.',
'fields' => array(
'result_answer_id' => array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The primary identifier for this result answer.',
),
'result_id' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The result ID associated with this answer.',
),
'question_nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The question ID of the answer.',
),
'question_vid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The question version ID of the answer.',
),
'tid' => array(
'type' => 'int',
'unsigned' => TRUE,
'description' => 'The taxonomy ID this question response was answered within, if this Quiz contained categorized random questions.',
),
'is_correct' => array(
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Boolean indicating whether this answer was correct.',
),
'is_skipped' => array(
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'description' => 'Boolean indicating whether this question was skipped.',
),
'points_awarded' => array(
'type' => 'int',
'size' => 'tiny',
'unsigned' => FALSE,
'not null' => TRUE,
'default' => 0,
'description' => 'Points awarded for this response.',
),
'answer_timestamp' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
'default' => NULL,
'description' => 'Unix timestamp when this question was answered.',
),
'number' => array(
'type' => 'int',
'size' => 'small',
'unsigned' => FALSE,
'not null' => TRUE,
'default' => 1,
'description' => 'The number of the question in the result.',
),
'display_number' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
'default' => NULL,
'description' => 'The display number of the question in the result.',
),
'is_doubtful' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
'description' => 'Boolean indicating whether the user marked this answer as doubtful.',
),
),
'primary key' => array('result_answer_id'),
'unique keys' => array(
'result_answer' => array('result_id', 'question_nid', 'question_vid'),
),
'indexes' => array(
'result_id' => array('result_id'),
),
);
/*
* Allows custom feedback based on the results of a user completing a quiz.
*/
// Create the quiz node result options table.
$schema['quiz_node_result_options'] = array(
'description' => 'Table storing result options for quizzes. Several result options may belong to a single quiz.',
'fields' => array(
'option_id' => array(
'type' => 'serial',
'size' => 'normal',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The primary identifier for the range.',
),
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Quiz ID associated with this range.',
),
'vid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Quiz version ID associated with this range.',
),
'option_name' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'description' => 'The name of this range.',
),
'option_summary' => array(
'type' => 'text',
'description' => 'The text to show when this range is met.',
),
'option_summary_format' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'description' => 'Text format of the range text.',
),
'option_start' => array(
'type' => 'int',
'unsigned' => TRUE,
'default' => 0,
'description' => 'Score range low value.',
),
'option_end' => array(
'type' => 'int',
'unsigned' => TRUE,
'default' => 0,
'description' => 'Score range high value.',
),
),
'primary key' => array('option_id'),
'indexes' => array(
'quiz_id' => array('vid', 'nid'),
),
);
$schema['quiz_terms'] = array(
'description' => 'Table storing what terms belongs to what quiz for categorized random quizzes',
'fields' => array(
'nid' => array(
'description' => 'The quiz ID of this quiz term.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'vid' => array(
'description' => 'The quiz version ID of this quiz term.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'weight' => array(
'description' => 'The terms weight decides the order of the terms',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'tid' => array(
'description' => 'Taxonomy term ID from which to pull questions.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'max_score' => array(
'description' => 'Max score for each question marked with this term.',
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
),
'number' => array(
'description' => 'Number of questions to be drawn from this term.',
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
),
),
'primary key' => array('vid', 'tid'),
'indexes' => array(
'version' => array('vid'),
),
);
$schema['quiz_result_type'] = array(
'description' => 'Stores information about all defined quiz result types.',
'fields' => array(
'id' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Unique result type ID.',
),
'type' => array(
'description' => 'The machine-readable name of this result type.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
),
'label' => array(
'description' => 'The human-readable name of this result type.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'status' => array(
'type' => 'int',
'not null' => TRUE,
// Set the default to ENTITY_CUSTOM without using the constant as it is
// not safe to use it at this point.
'default' => 0x01,
'size' => 'tiny',
'description' => 'The exportable status of the entity.',
),
'module' => array(
'description' => 'The name of the providing module if the entity has been defined in code.',
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
),
'primary key' => array('id'),
'unique keys' => array(
'type' => array('type'),
),
);
return $schema;
}
/**
* Implements hook_update_N().
*/
function quiz_update_7100(&$sandbox) {
// Should have been named quiz_update_7400.
db_add_field('quiz_node_properties', 'show_passed', array('type' => 'int', 'not null' => TRUE, 'default' => 1, 'size' => 'tiny'));
return t('Show passed field added to quiz config.');
}
/**
* Implements hook_update_N().
*/
function quiz_update_7101(&$sandbox) {
// Should have been named quiz_update_7401.
db_add_field('quiz_user_settings', 'show_passed', array('type' => 'int', 'not null' => TRUE, 'default' => 1, 'size' => 'tiny'));
return t('Done !');
}
/**
* Implements hook_update_N().
*/
function quiz_update_7402(&$sandbox) {
if (!db_field_exists('quiz_node_properties', 'summary_pass_format')) {
db_add_field('quiz_node_properties', 'summary_pass_format', array('type' => 'varchar', 'length' => 255));
db_add_field('quiz_node_properties', 'summary_default_format', array('type' => 'varchar', 'length' => 255));
db_add_field('quiz_node_result_options', 'option_summary_format', array('type' => 'varchar', 'length' => 255));
db_add_field('quiz_user_settings', 'summary_pass_format', array('type' => 'varchar', 'length' => 255));
db_add_field('quiz_user_settings', 'summary_default_format', array('type' => 'varchar', 'length' => 255));
}
return t("Added new format fields to the tables if they didn't already exist.");
}
/**
* Adds index on vid column to the quiz_node_results table and on child_vid to
* the quiz_node_relationship table.
*/
function quiz_update_7403() {
db_add_index('quiz_node_results', 'vid', array('vid'));
db_add_index('quiz_node_relationship', 'child_id', array('child_vid'));
}
/**
* Increase the maximum quiz size.
*/
function quiz_update_7404() {
db_change_field('quiz_node_properties', 'number_of_random_questions', 'number_of_random_questions', array(
'type' => 'int',
'size' => 'small',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
));
db_change_field('quiz_node_results_answers', 'number', 'number', array(
'type' => 'int',
'size' => 'small',
'unsigned' => FALSE,
'not null' => TRUE,
'default' => 1,
));
return t('Increased the maximum quiz size.');
}
/**
* Remove unsigned attribute from field time_start and time_end in
* quiz_node_results table.
*/
function quiz_update_7405() {
$spec = array(
'type' => 'int',
'unsigned' => FALSE,
'default' => 0,
);
db_change_field('quiz_node_results', 'time_start', 'time_start', $spec);
db_change_field('quiz_node_results', 'time_end', 'time_end', $spec);
return t('Removed unsigned attribute from field time_start and time_end in quiz_node_results table');
}
/**
* Adding columns mark answers as doubtful.
*/
function quiz_update_7406(&$sandbox) {
$spec = array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
);
db_add_field('quiz_node_results_answers', 'is_doubtful', $spec);
db_add_field('quiz_node_properties', 'mark_doubtful', $spec);
return t('Added new format fields to the tables');
}
/**
* Adding auto update max score.
*/
function quiz_update_7407(&$sandbox) {
$spec = array(
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
);
db_add_field('quiz_node_relationship', 'auto_update_max_score', $spec);
return t('Added new auto update max score field to the quiz_node_relationship table');
}
/**
* Adding userpoints tid column.
*/
function quiz_update_7409(&$sandbox) {
$table = 'quiz_node_properties';
$schema = drupal_get_schema_unprocessed('quiz', $table);
foreach (array('userpoints_tid') as $field) {
db_add_field($table, $field, $schema['fields'][$field]);
}
return t('Adding userpoints tid column to quiz_node_properties');
}
/**
* Implements hook_uninstall().
*/
function quiz_uninstall() {
db_delete('variable')
->condition('name', "quiz_%", 'like')
->execute();
}
/**
* Add new layout field to the quiz_node_results table.
*/
function quiz_update_7500() {
$spec = array(
'serialize' => TRUE,
'type' => 'text',
'description' => "Serialized layout data.",
'size' => 'medium',
);
db_add_field('quiz_node_results', 'layout', $spec);
return t('Added new layout field to the quiz_node_results table');
}
/**
* Add new result_answer_id field to the quiz_node_results_answers table.
*/
function quiz_update_7501() {
db_drop_primary_key('quiz_node_results_answers');
db_add_unique_key('quiz_node_results_answers', 'result_answer', array('result_id', 'question_nid', 'question_vid'));
$spec = array(
'description' => 'The result answer ID.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
);
db_add_field('quiz_node_results_answers', 'result_answer_id', $spec, array('primary key' => array('result_answer_id')));
return t('Added new result_answer_id field to the quiz_node_results_answers table.');
}
/**
* Add new qnr_id field to the quiz_node_relationship table.
*/
function quiz_update_7502() {
db_drop_primary_key('quiz_node_relationship');
db_add_unique_key('quiz_node_relationship', 'parent_child', array('parent_nid', 'parent_vid', 'child_nid', 'child_vid'));
$spec = array(
'type' => 'serial',
'size' => 'normal',
'unsigned' => TRUE,
'not null' => TRUE,
);
db_add_field('quiz_node_relationship', 'qnr_id', $spec, array('primary key' => array('qnr_id')));
return t('Added new qnr_id field to the quiz_node_relationship table.');
}
/**
* Add new qnr_pid field to the quiz_node_relationship table.
*/
function quiz_update_7503() {
$spec = array(
'type' => 'int',
'size' => 'normal',
'unsigned' => TRUE,
'not null' => FALSE,
'default' => NULL,
);
db_add_field('quiz_node_relationship', 'qnr_pid', $spec);
return t('Added new qnr_pid field to the quiz_node_relationship table.');
}
/**
* Allow time_start and time_end to be NULL. The time "0" is still a valid time.
* This lets us do better filtering in Views (where NULL).
*/
function quiz_update_7504() {
$spec = array(
'type' => 'int',
'unsigned' => FALSE,
);
db_change_field('quiz_node_results', 'time_start', 'time_start', $spec);
db_change_field('quiz_node_results', 'time_end', 'time_end', $spec);
db_query("UPDATE {quiz_node_results} SET time_end = NULL WHERE time_end = 0");
return t('Removed default attribute from field time_start and time_end in quiz_node_results table.');
}
/**
* Revamping quiz feedback options.
*/
function quiz_update_7505() {
db_add_field('quiz_node_properties', 'review_options', array(
'type' => 'text',
'serialize' => TRUE,
));
drupal_get_schema(NULL, TRUE);
$sql = "SELECT * FROM {quiz_node_properties}";
$result = db_query($sql);
while ($row = $result->fetch()) {
if ($row->feedback_time == 0) {
$row->review_options['end']['answer_feedback'] = 'answer_feedback';
if ($row->display_feedback) {
$row->review_options['end']['solution'] = 'solution';
}
}
if ($row->feedback_time == 1) {
$row->review_options['question']['answer_feedback'] = 'answer_feedback';
if ($row->display_feedback) {
$row->review_options['question']['solution'] = 'solution';
}
}
if ($row->feedback_time == 2) {
$row->review_options = array();
}
drupal_write_record('quiz_node_properties', $row, array('nid', 'vid'));
}
db_drop_field('quiz_node_properties', 'feedback_time');
db_drop_field('quiz_node_properties', 'display_feedback');
}
/**
* Add qnp_id and uid so we can have better quiz node defaults.
*/
function quiz_update_7506() {
db_drop_primary_key('quiz_node_properties');
db_add_field('quiz_node_properties', 'qnp_id', array(
'type' => 'serial',
'not null' => TRUE,
), array('primary key' => array('qnp_id')));
db_add_field('quiz_node_properties', 'uid', array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
));
// We could do this, but we should really migrate user settings from 4.x.
// Patches welcome.
// db_drop_table('quiz_user_settings');
}
/**
* Add allow_change to restrict users from changing answers.
*/
function quiz_update_7507() {
db_add_field('quiz_node_properties', 'allow_change', array(
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'default' => 1,
));