1
|
|
|
<?php |
2
|
|
|
/* For licensing terms, see /license.txt */ |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Class HotSpot |
6
|
|
|
* |
7
|
|
|
* This class allows to instantiate an object of type HotSpot (MULTIPLE CHOICE, UNIQUE ANSWER), |
8
|
|
|
* extending the class question |
9
|
|
|
* |
10
|
|
|
* @author Eric Marguin |
11
|
|
|
* @package chamilo.exercise |
12
|
|
|
**/ |
13
|
|
|
class HotSpot extends Question |
14
|
|
|
{ |
15
|
|
|
public static $typePicture = 'hotspot.png'; |
16
|
|
|
public static $explanationLangVar = 'HotSpot'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* HotSpot constructor. |
20
|
|
|
*/ |
21
|
|
|
public function __construct() |
22
|
|
|
{ |
23
|
|
|
parent::__construct(); |
24
|
|
|
$this -> type = HOT_SPOT; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function display() |
28
|
|
|
{ |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param FormValidator $form |
33
|
|
|
* @param int $fck_config |
34
|
|
|
*/ |
35
|
|
|
public function createForm (&$form, $fck_config=0) |
36
|
|
|
{ |
37
|
|
|
parent::createForm($form, $fck_config); |
38
|
|
|
|
39
|
|
|
if (!isset($_GET['editQuestion'])) { |
40
|
|
|
$form->addElement( |
41
|
|
|
'file', |
42
|
|
|
'imageUpload', |
43
|
|
|
array( |
44
|
|
|
'<img src="'.Display::return_icon('hotspot.png', null, null, ICON_SIZE_BIG, false, true).'" />', |
45
|
|
|
get_lang('UploadJpgPicture'), |
46
|
|
|
) |
47
|
|
|
); |
48
|
|
|
|
49
|
|
|
// setting the save button here and not in the question class.php |
50
|
|
|
// Saving a question |
51
|
|
|
$form->addButtonSave(get_lang('GoToQuestion'), 'submitQuestion'); |
52
|
|
|
//$form->addButtonSave(get_lang('GoToQuestion'), 'submitQuestion'); |
53
|
|
|
$form->addRule('imageUpload', get_lang('OnlyImagesAllowed'), 'filetype', array ('jpg', 'jpeg', 'png', 'gif')); |
54
|
|
|
$form->addRule('imageUpload', get_lang('NoImage'), 'uploadedfile'); |
55
|
|
|
} else { |
56
|
|
|
// setting the save button here and not in the question class.php |
57
|
|
|
// Editing a question |
58
|
|
|
$form->addButtonUpdate(get_lang('ModifyExercise'), 'submitQuestion'); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param FormValidator $form |
64
|
|
|
* @param null $objExercise |
65
|
|
|
* @return null|false |
66
|
|
|
*/ |
67
|
|
|
public function processCreation($form, $objExercise = null) |
68
|
|
|
{ |
69
|
|
|
$file_info = $form->getSubmitValue('imageUpload'); |
70
|
|
|
$_course = api_get_course_info(); |
71
|
|
|
parent::processCreation($form, $objExercise); |
72
|
|
|
|
73
|
|
|
if(!empty($file_info['tmp_name'])) { |
74
|
|
|
$this->uploadPicture($file_info['tmp_name'], $file_info['name']); |
75
|
|
|
$documentPath = api_get_path(SYS_COURSE_PATH).$_course['path'].'/document'; |
76
|
|
|
$picturePath = $documentPath.'/images'; |
77
|
|
|
|
78
|
|
|
// fixed width ang height |
79
|
|
|
if (file_exists($picturePath.'/'.$this->picture)) { |
80
|
|
|
$this->resizePicture('width', 800); |
81
|
|
|
$this->save(); |
82
|
|
|
} else { |
83
|
|
|
return false; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
function createAnswersForm($form) |
89
|
|
|
{ |
90
|
|
|
// nothing |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
function processAnswersCreation($form) |
94
|
|
|
{ |
95
|
|
|
// nothing |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Class HotSpotDelineation |
101
|
|
|
*/ |
102
|
|
|
class HotSpotDelineation extends HotSpot |
|
|
|
|
103
|
|
|
{ |
104
|
|
|
static $typePicture = 'hotspot-delineation.png'; |
105
|
|
|
static $explanationLangVar = 'HotspotDelineation'; |
106
|
|
|
|
107
|
|
|
function __construct() |
108
|
|
|
{ |
109
|
|
|
parent::__construct(); |
110
|
|
|
$this -> type = HOT_SPOT_DELINEATION; |
111
|
|
|
|
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
function createForm (&$form, $fck_config=0) |
115
|
|
|
{ |
116
|
|
|
parent::createForm ($form, $fck_config); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
function processCreation ($form, $objExercise = null) |
120
|
|
|
{ |
121
|
|
|
$file_info = $form -> getSubmitValue('imageUpload'); |
122
|
|
|
parent::processCreation ($form, $objExercise); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
function createAnswersForm ($form) |
126
|
|
|
{ |
127
|
|
|
parent::createAnswersForm ($form); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
function processAnswersCreation ($form) |
131
|
|
|
{ |
132
|
|
|
parent::processAnswersCreation ($form); |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
|
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.