ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilAssQuestionHintGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintAbstractGUI.php';
5
18{
22 const CMD_SHOW_FORM = 'showForm';
23 const CMD_SAVE_FORM = 'saveForm';
24 const CMD_CANCEL_FORM = 'cancelForm';
25 const CMD_CONFIRM_FORM = 'confirmForm';
26
34 public function executeCommand()
35 {
36 global $ilCtrl, $ilTabs, $lng, $tpl;
37
38 $cmd = $ilCtrl->getCmd(self::CMD_SHOW_FORM);
39 $nextClass = $ilCtrl->getNextClass($this);
40
41 switch ($nextClass) {
42 case 'ilasshintpagegui':
43
44 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintPageObjectCommandForwarder.php';
45 $forwarder = new ilAssQuestionHintPageObjectCommandForwarder($this->questionOBJ, $ilCtrl, $ilTabs, $lng);
47 $forwarder->forward();
48 break;
49
50 default:
51
52 $cmd .= 'Cmd';
53 $this->$cmd();
54 break;
55 }
56
57 return true;
58 }
59
67 private function showFormCmd(ilPropertyFormGUI $form = null)
68 {
69 global $ilCtrl, $tpl, $ilToolbar, $lng, $ilCtrl;
70
71 if ($form instanceof ilPropertyFormGUI) {
72 $form->setValuesByPost();
73 } elseif (isset($_GET['hint_id']) && (int) $_GET['hint_id']) {
74 $questionHint = new ilAssQuestionHint();
75
76 if (!$questionHint->load((int) $_GET['hint_id'])) {
77 ilUtil::sendFailure('invalid hint id given: ' . (int) $_GET['hint_id'], true);
78 $ilCtrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_SHOW_LIST);
79 }
80
81 $form = $this->buildForm($questionHint);
82 } else {
83 $form = $this->buildForm();
84 }
85
86 $tpl->setContent($form->getHTML());
87 }
88
96 private function saveFormCmd()
97 {
98 global $ilCtrl, $lng, $ilUser;
99
100 $form = $this->buildForm();
101
102 if ($form->checkInput()) {
103 $questionHint = new ilAssQuestionHint();
104
105 if ((int) $form->getInput('hint_id')) {
106 $questionHint->load((int) $form->getInput('hint_id'));
107
108 $hintJustCreated = false;
109 } else {
110 $questionHint->setQuestionId($this->questionOBJ->getId());
111
112 $questionHint->setIndex(
113 ilAssQuestionHintList::getNextIndexByQuestionId($this->questionOBJ->getId())
114 );
115
116 $hintJustCreated = true;
117 }
118
119 $questionHint->setText($form->getInput('hint_text'));
120 $questionHint->setPoints($form->getInput('hint_points'));
121
122 $questionHint->save();
123 ilUtil::sendSuccess($lng->txt('tst_question_hints_form_saved_msg'), true);
124
125 if (!$this->questionOBJ->isAdditionalContentEditingModePageObject()) {
126 $this->questionOBJ->updateTimestamp();
127 }
128
129 $originalexists = $this->questionOBJ->_questionExistsInPool($this->questionOBJ->original_id);
130 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
131 if ($_GET["calling_test"] && $originalexists && assQuestion::_isWriteable($this->questionOBJ->original_id, $ilUser->getId())) {
132 $ilCtrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_CONFIRM_SYNC);
133 }
134
135
136 if ($hintJustCreated && $this->questionOBJ->isAdditionalContentEditingModePageObject()) {
137 $ilCtrl->setParameterByClass('ilasshintpagegui', 'hint_id', $questionHint->getId());
138 $ilCtrl->redirectByClass('ilasshintpagegui', 'edit');
139 } else {
140 $ilCtrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_SHOW_LIST);
141 }
142 }
143
144 ilUtil::sendFailure($lng->txt('tst_question_hints_form_invalid_msg'));
145 $this->showFormCmd($form);
146 }
147
154 private function cancelFormCmd()
155 {
156 global $ilCtrl;
157
158 $ilCtrl->redirectByClass('ilAssQuestionHintsGUI');
159 }
160
169 private function buildForm(ilAssQuestionHint $questionHint = null)
170 {
171 global $ilCtrl, $lng;
172
173 require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
174 require_once 'Services/Form/classes/class.ilTextAreaInputGUI.php';
175 require_once 'Services/Form/classes/class.ilNumberInputGUI.php';
176 require_once 'Services/Form/classes/class.ilHiddenInputGUI.php';
177
178 $form = new ilPropertyFormGUI();
179 $form->setTableWidth('100%');
180
181 if (!$this->questionOBJ->isAdditionalContentEditingModePageObject()) {
182 // form input: hint text
183
184 $areaInp = new ilTextAreaInputGUI($lng->txt('tst_question_hints_form_label_hint_text'), 'hint_text');
185 $areaInp->setRequired(true);
186 $areaInp->setRows(10);
187 $areaInp->setCols(80);
188
189 if (!$this->questionOBJ->getPreventRteUsage()) {
190 $areaInp->setUseRte(true);
191 }
192
193 include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
194 $areaInp->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
195
196 $areaInp->setRTESupport($this->questionOBJ->getId(), 'qpl', 'assessment');
197
198 $areaInp->addPlugin("latex");
199 $areaInp->addButton("latex");
200 $areaInp->addButton("pastelatex");
201
202 $form->addItem($areaInp);
203 }
204
205 // form input: hint points
206
207 $numInp = new ilNumberInputGUI($lng->txt('tst_question_hints_form_label_hint_points'), 'hint_points');
208 $numInp->allowDecimals(true);
209 $numInp->setRequired(true);
210 $numInp->setSize(3);
211
212 $form->addItem($numInp);
213
214 if ($questionHint instanceof ilAssQuestionHint) {
215 // build form title for an existing hint
216
217 $form->setTitle(sprintf(
218 $lng->txt('tst_question_hints_form_header_edit'),
219 $questionHint->getIndex(),
220 $this->questionOBJ->getTitle()
221 ));
222
223 // hidden input: hint id
224
225 $hiddenInp = new ilHiddenInputGUI('hint_id');
226 $form->addItem($hiddenInp);
227
228 // init values
229
230 require_once 'Services/Utilities/classes/class.ilUtil.php';
231
232 if (!$this->questionOBJ->isAdditionalContentEditingModePageObject()) {
233 $areaInp->setValue($questionHint->getText());
234 }
235
236 $numInp->setValue($questionHint->getPoints());
237
238 $hiddenInp->setValue($questionHint->getId());
239 } else {
240 // build form title for a new hint
241 $form->setTitle(sprintf(
242 $lng->txt('tst_question_hints_form_header_create'),
243 $this->questionOBJ->getTitle()
244 ));
245 }
246
247 if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
248 if ($questionHint instanceof ilAssQuestionHint) {
249 $saveCmdLabel = $lng->txt('tst_question_hints_form_cmd_save_points');
250 } else {
251 $saveCmdLabel = $lng->txt('tst_question_hints_form_cmd_save_points_and_edit_page');
252 }
253 } else {
254 $saveCmdLabel = $lng->txt('tst_question_hints_form_cmd_save');
255 }
256
257 $form->setFormAction($ilCtrl->getFormAction($this));
258
259 $form->addCommandButton(self::CMD_SAVE_FORM, $saveCmdLabel);
260 $form->addCommandButton(self::CMD_CANCEL_FORM, $lng->txt('cancel'));
261
262 return $form;
263 }
264}
sprintf('%.4f', $callTime)
$tpl
Definition: ilias.php:10
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
static _isWriteable($question_id, $user_id)
Returns true if the question is writeable by a certain user.
const CMD_SHOW_FORM
command constants
buildForm(ilAssQuestionHint $questionHint=null)
builds the questions hints form
showFormCmd(ilPropertyFormGUI $form=null)
shows the form for managing a new/existing hint
saveFormCmd()
saves the form on successfull validation and redirects to showForm command
cancelFormCmd()
gateway command method to jump back to question hints overview
static getNextIndexByQuestionId($questionId)
determines the next index to be used for a new hint that is to be added to the list of existing hints...
const CMD_SHOW_LIST
command constants
This class represents a hidden form property in a property form.
This class represents a number property in a property form.
static _getUsedHTMLTags($a_module="")
Returns an array of all allowed HTML tags for text editing.
This class represents a property form user interface.
This class represents a text area property in a property form.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:17
if(isset($_POST['submit'])) $form
$ilUser
Definition: imgupload.php:18