|
1
|
|
|
<?php |
|
2
|
|
|
/* For licensing terms, see /license.txt */ |
|
3
|
|
|
|
|
4
|
|
|
class MediaQuestion extends Question |
|
5
|
|
|
{ |
|
6
|
|
|
/** |
|
7
|
|
|
* Icon shown in the question-type menu. |
|
8
|
|
|
*/ |
|
9
|
|
|
public $typePicture = 'media.png'; |
|
10
|
|
|
public $explanationLangVar = 'MediaQuestion'; |
|
11
|
|
|
|
|
12
|
|
|
public function __construct() |
|
13
|
|
|
{ |
|
14
|
|
|
parent::__construct(); |
|
15
|
|
|
$this->type = MEDIA_QUESTION; |
|
16
|
|
|
// Mark as content so it’s not counted towards score |
|
17
|
|
|
$this->isContent = 1; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Form to create / edit a Media item. |
|
22
|
|
|
*/ |
|
23
|
|
|
public function createForm(&$form, $exercise) |
|
24
|
|
|
{ |
|
25
|
|
|
// Title for the media block |
|
26
|
|
|
$form->addText( |
|
27
|
|
|
'questionName', |
|
28
|
|
|
get_lang('Media Title'), |
|
29
|
|
|
false, |
|
30
|
|
|
['maxlength' => 255] |
|
31
|
|
|
); |
|
32
|
|
|
|
|
33
|
|
|
// WYSIWYG for the media content (could be text, embed code, etc.) |
|
34
|
|
|
$editorConfig = [ |
|
35
|
|
|
'ToolbarSet' => 'TestQuestionDescription', |
|
36
|
|
|
'Height' => '150' |
|
37
|
|
|
]; |
|
38
|
|
|
$form->addHtmlEditor( |
|
39
|
|
|
'questionDescription', |
|
40
|
|
|
get_lang('Media Content'), |
|
41
|
|
|
false, |
|
42
|
|
|
false, |
|
43
|
|
|
$editorConfig |
|
44
|
|
|
); |
|
45
|
|
|
|
|
46
|
|
|
global $text; |
|
47
|
|
|
$form->addButtonSave($text, 'submitQuestion'); |
|
48
|
|
|
|
|
49
|
|
|
// Populate defaults if editing |
|
50
|
|
|
$defaults = [ |
|
51
|
|
|
'questionName' => $this->question, |
|
52
|
|
|
'questionDescription' => $this->description |
|
53
|
|
|
]; |
|
54
|
|
|
$form->setDefaults($defaults); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* No answers to configure for media. |
|
59
|
|
|
*/ |
|
60
|
|
|
public function createAnswersForm($form) {} |
|
61
|
|
|
|
|
62
|
|
|
public function processAnswersCreation($form, $exercise) {} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* On save, treat like any other question: persist and attach to the exercise. |
|
66
|
|
|
*/ |
|
67
|
|
|
public function processCreation(FormValidator $form, Exercise $exercise) |
|
68
|
|
|
{ |
|
69
|
|
|
$this->updateTitle($form->getSubmitValue('questionName')); |
|
70
|
|
|
$this->updateDescription($form->getSubmitValue('questionDescription')); |
|
71
|
|
|
$this->save($exercise); |
|
72
|
|
|
$exercise->addToList($this->id); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|