ILIAS  release_7 Revision v7.30-3-g800a261c036
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 $DIC;
37 $ilCtrl = $DIC['ilCtrl'];
38 $ilTabs = $DIC['ilTabs'];
39 $lng = $DIC['lng'];
40 $tpl = $DIC['tpl'];
41
42 $cmd = $ilCtrl->getCmd(self::CMD_SHOW_FORM);
43 $nextClass = $ilCtrl->getNextClass($this);
44
45 switch ($nextClass) {
46 case 'ilasshintpagegui':
47
48 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintPageObjectCommandForwarder.php';
49 $forwarder = new ilAssQuestionHintPageObjectCommandForwarder($this->questionOBJ, $ilCtrl, $ilTabs, $lng);
51 $forwarder->forward();
52 break;
53
54 default:
55
56 $cmd .= 'Cmd';
57 $this->$cmd();
58 break;
59 }
60
61 return true;
62 }
63
71 private function showFormCmd(ilPropertyFormGUI $form = null)
72 {
73 global $DIC;
74 $ilCtrl = $DIC['ilCtrl'];
75 $tpl = $DIC['tpl'];
76 $ilToolbar = $DIC['ilToolbar'];
77 $lng = $DIC['lng'];
78 $ilCtrl = $DIC['ilCtrl'];
79
80 if ($form instanceof ilPropertyFormGUI) {
81 $form->setValuesByPost();
82 } elseif (isset($_GET['hint_id']) && (int) $_GET['hint_id']) {
83 $questionHint = new ilAssQuestionHint();
84
85 if (!$questionHint->load((int) $_GET['hint_id'])) {
86 ilUtil::sendFailure('invalid hint id given: ' . (int) $_GET['hint_id'], true);
87 $ilCtrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_SHOW_LIST);
88 }
89
90 $form = $this->buildForm($questionHint);
91 } else {
92 $form = $this->buildForm();
93 }
94
95 $tpl->setContent($form->getHTML());
96 }
97
105 private function saveFormCmd()
106 {
107 global $DIC;
108 $ilCtrl = $DIC['ilCtrl'];
109 $lng = $DIC['lng'];
110 $ilUser = $DIC['ilUser'];
111
112 $form = $this->buildForm();
113
114 if ($form->checkInput()) {
115 $questionHint = new ilAssQuestionHint();
116
117 if ((int) $form->getInput('hint_id')) {
118 $questionHint->load((int) $form->getInput('hint_id'));
119
120 $hintJustCreated = false;
121 } else {
122 $questionHint->setQuestionId($this->questionOBJ->getId());
123
124 $questionHint->setIndex(
125 ilAssQuestionHintList::getNextIndexByQuestionId($this->questionOBJ->getId())
126 );
127
128 $hintJustCreated = true;
129 }
130
131 $questionHint->setText($form->getInput('hint_text'));
132 $questionHint->setPoints($form->getInput('hint_points'));
133
134 $questionHint->save();
135
136 if ($this->questionOBJ->isAdditionalContentEditingModePageObject() && !ilAssHintPage::_exists(
137 'qht',
138 $form->getInput('hint_id')
139 )) {
140 $pageObject = new ilAssHintPage();
141 $pageObject->setParentId($this->questionOBJ->getId());
142 $pageObject->setId($questionHint->getId());
143 $pageObject->createFromXML();
144 }
145
146 ilUtil::sendSuccess($lng->txt('tst_question_hints_form_saved_msg'), true);
147
148 if (!$this->questionOBJ->isAdditionalContentEditingModePageObject()) {
149 $this->questionOBJ->updateTimestamp();
150 }
151
152 $originalexists = $this->questionOBJ->_questionExistsInPool($this->questionOBJ->original_id);
153 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
154 if ($_GET["calling_test"] && $originalexists && assQuestion::_isWriteable($this->questionOBJ->original_id, $ilUser->getId())) {
155 $ilCtrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_CONFIRM_SYNC);
156 }
157
158
159 if ($hintJustCreated && $this->questionOBJ->isAdditionalContentEditingModePageObject()) {
160 $ilCtrl->setParameterByClass('ilasshintpagegui', 'hint_id', $questionHint->getId());
161 $ilCtrl->redirectByClass('ilasshintpagegui', 'edit');
162 } else {
163 $ilCtrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_SHOW_LIST);
164 }
165 }
166
167 ilUtil::sendFailure($lng->txt('tst_question_hints_form_invalid_msg'));
168 $this->showFormCmd($form);
169 }
170
177 private function cancelFormCmd()
178 {
179 global $DIC;
180 $ilCtrl = $DIC['ilCtrl'];
181
182 $ilCtrl->redirectByClass('ilAssQuestionHintsGUI');
183 }
184
193 private function buildForm(ilAssQuestionHint $questionHint = null)
194 {
195 global $DIC;
196 $ilCtrl = $DIC['ilCtrl'];
197 $lng = $DIC['lng'];
198
199 require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
200 require_once 'Services/Form/classes/class.ilTextAreaInputGUI.php';
201 require_once 'Services/Form/classes/class.ilNumberInputGUI.php';
202 require_once 'Services/Form/classes/class.ilHiddenInputGUI.php';
203
204 $form = new ilPropertyFormGUI();
205 $form->setTableWidth('100%');
206
207 if (!$this->questionOBJ->isAdditionalContentEditingModePageObject()) {
208 // form input: hint text
209
210 $areaInp = new ilTextAreaInputGUI($lng->txt('tst_question_hints_form_label_hint_text'), 'hint_text');
211 $areaInp->setRequired(true);
212 $areaInp->setRows(10);
213 $areaInp->setCols(80);
214
215 if (!$this->questionOBJ->getPreventRteUsage()) {
216 $areaInp->setUseRte(true);
217 }
218
219 include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
220 $areaInp->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
221
222 $areaInp->setRTESupport($this->questionOBJ->getId(), 'qpl', 'assessment');
223
224 $areaInp->addPlugin("latex");
225 $areaInp->addButton("latex");
226 $areaInp->addButton("pastelatex");
227
228 $form->addItem($areaInp);
229 }
230
231 // form input: hint points
232
233 $numInp = new ilNumberInputGUI($lng->txt('tst_question_hints_form_label_hint_points'), 'hint_points');
234 $numInp->allowDecimals(true);
235 $numInp->setRequired(true);
236 $numInp->setSize(3);
237
238 $form->addItem($numInp);
239
240 if ($questionHint instanceof ilAssQuestionHint) {
241 // build form title for an existing hint
242
243 $form->setTitle(sprintf(
244 $lng->txt('tst_question_hints_form_header_edit'),
245 $questionHint->getIndex(),
246 $this->questionOBJ->getTitle()
247 ));
248
249 // hidden input: hint id
250
251 $hiddenInp = new ilHiddenInputGUI('hint_id');
252 $form->addItem($hiddenInp);
253
254 // init values
255
256 require_once 'Services/Utilities/classes/class.ilUtil.php';
257
258 if (!$this->questionOBJ->isAdditionalContentEditingModePageObject()) {
259 $areaInp->setValue($questionHint->getText());
260 }
261
262 $numInp->setValue($questionHint->getPoints());
263
264 $hiddenInp->setValue($questionHint->getId());
265 } else {
266 // build form title for a new hint
267 $form->setTitle(sprintf(
268 $lng->txt('tst_question_hints_form_header_create'),
269 $this->questionOBJ->getTitle()
270 ));
271 }
272
273 if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
274 if ($questionHint instanceof ilAssQuestionHint) {
275 $saveCmdLabel = $lng->txt('tst_question_hints_form_cmd_save_points');
276 } else {
277 $saveCmdLabel = $lng->txt('tst_question_hints_form_cmd_save_points_and_edit_page');
278 }
279 } else {
280 $saveCmdLabel = $lng->txt('tst_question_hints_form_cmd_save');
281 }
282
283 $form->setFormAction($ilCtrl->getFormAction($this));
284
285 $form->addCommandButton(self::CMD_SAVE_FORM, $saveCmdLabel);
286 $form->addCommandButton(self::CMD_CANCEL_FORM, $lng->txt('cancel'));
287
288 return $form;
289 }
290}
$_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.
Assessment hint page object.
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.
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
This class represents a property form user interface.
This class represents a text area property in a property form.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
global $DIC
Definition: goto.php:24
$ilUser
Definition: imgupload.php:18
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$lng