ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 {
43 case 'ilasshintpagegui':
44
45 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintPageObjectCommandForwarder.php';
46 $forwarder = new ilAssQuestionHintPageObjectCommandForwarder($this->questionOBJ, $ilCtrl, $ilTabs, $lng);
48 $forwarder->forward();
49 break;
50
51 default:
52
53 $cmd .= 'Cmd';
54 $this->$cmd();
55 break;
56 }
57
58 return true;
59 }
60
68 private function showFormCmd(ilPropertyFormGUI $form = null)
69 {
70 global $ilCtrl, $tpl, $ilToolbar, $lng, $ilCtrl;
71
72 if( $form instanceof ilPropertyFormGUI )
73 {
74 $form->setValuesByPost();
75 }
76 elseif( isset($_GET['hint_id']) && (int)$_GET['hint_id'] )
77 {
78 $questionHint = new ilAssQuestionHint();
79
80 if( !$questionHint->load((int)$_GET['hint_id']) )
81 {
82 ilUtil::sendFailure('invalid hint id given: '.(int)$_GET['hint_id'], true);
83 $ilCtrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_SHOW_LIST);
84 }
85
86 $form = $this->buildForm($questionHint);
87 }
88 else
89 {
90 $form = $this->buildForm();
91 }
92
93 $tpl->setContent( $form->getHTML() );
94 }
95
103 private function saveFormCmd()
104 {
105 global $ilCtrl, $lng, $ilUser;
106
107 $form = $this->buildForm();
108
109 if( $form->checkInput() )
110 {
111 $questionHint = new ilAssQuestionHint();
112
113 if( (int)$form->getInput('hint_id') )
114 {
115 $questionHint->load( (int)$form->getInput('hint_id') );
116
117 $hintJustCreated = false;
118 }
119 else
120 {
121 $questionHint->setQuestionId( $this->questionOBJ->getId() );
122
123 $questionHint->setIndex(
124 ilAssQuestionHintList::getNextIndexByQuestionId($this->questionOBJ->getId())
125 );
126
127 $hintJustCreated = true;
128 }
129
130 $questionHint->setText( $form->getInput('hint_text') );
131 $questionHint->setPoints( $form->getInput('hint_points') );
132
133 $questionHint->save();
134 ilUtil::sendSuccess($lng->txt('tst_question_hints_form_saved_msg'), true);
135
136 if(!$this->questionOBJ->isAdditionalContentEditingModePageObject())
137 {
138 $this->questionOBJ->updateTimestamp();
139 }
140
141 $originalexists = $this->questionOBJ->_questionExistsInPool($this->questionOBJ->original_id);
142 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
143 if ($_GET["calling_test"] && $originalexists && assQuestion::_isWriteable($this->questionOBJ->original_id, $ilUser->getId()))
144 {
145 $ilCtrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_CONFIRM_SYNC);
146 }
147
148
149 if( $hintJustCreated && $this->questionOBJ->isAdditionalContentEditingModePageObject() )
150 {
151 $ilCtrl->setParameterByClass('ilasshintpagegui', 'hint_id', $questionHint->getId());
152 $ilCtrl->redirectByClass('ilasshintpagegui', 'edit');
153 }
154 else
155 {
156 $ilCtrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_SHOW_LIST);
157 }
158 }
159
160 ilUtil::sendFailure($lng->txt('tst_question_hints_form_invalid_msg'));
161 $this->showFormCmd($form);
162 }
163
170 private function cancelFormCmd()
171 {
172 global $ilCtrl;
173
174 $ilCtrl->redirectByClass('ilAssQuestionHintsGUI');
175 }
176
185 private function buildForm(ilAssQuestionHint $questionHint = null)
186 {
187 global $ilCtrl, $lng;
188
189 require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
190 require_once 'Services/Form/classes/class.ilTextAreaInputGUI.php';
191 require_once 'Services/Form/classes/class.ilNumberInputGUI.php';
192 require_once 'Services/Form/classes/class.ilHiddenInputGUI.php';
193
194 $form = new ilPropertyFormGUI();
195 $form->setTableWidth('100%');
196
197 if( !$this->questionOBJ->isAdditionalContentEditingModePageObject() )
198 {
199 // form input: hint text
200
201 $areaInp = new ilTextAreaInputGUI($lng->txt('tst_question_hints_form_label_hint_text'), 'hint_text');
202 $areaInp->setRequired(true);
203 $areaInp->setRows(10);
204 $areaInp->setCols(80);
205
206 if( !$this->questionOBJ->getPreventRteUsage() ) $areaInp->setUseRte(true);
207
208 include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
209 $areaInp->setRteTags( ilObjAdvancedEditing::_getUsedHTMLTags("assessment") );
210
211 $areaInp->setRTESupport($this->questionOBJ->getId(), 'qpl', 'assessment');
212
213 $areaInp->addPlugin("latex");
214 $areaInp->addButton("latex");
215 $areaInp->addButton("pastelatex");
216
217 $form->addItem($areaInp);
218 }
219
220 // form input: hint points
221
222 $numInp = new ilNumberInputGUI($lng->txt('tst_question_hints_form_label_hint_points'), 'hint_points');
223 $numInp->allowDecimals(true);
224 $numInp->setRequired(true);
225 $numInp->setSize(3);
226
227 $form->addItem($numInp);
228
229 if( $questionHint instanceof ilAssQuestionHint )
230 {
231 // build form title for an existing hint
232
233 $form->setTitle(sprintf(
234 $lng->txt('tst_question_hints_form_header_edit'),
235 $questionHint->getIndex(),
236 $this->questionOBJ->getTitle()
237 ));
238
239 // hidden input: hint id
240
241 $hiddenInp = new ilHiddenInputGUI('hint_id');
242 $form->addItem($hiddenInp);
243
244 // init values
245
246 require_once 'Services/Utilities/classes/class.ilUtil.php';
247
248 if( !$this->questionOBJ->isAdditionalContentEditingModePageObject() )
249 {
250 $areaInp->setValue( ilUtil::prepareTextareaOutput($questionHint->getText(), true) );
251 }
252
253 $numInp->setValue($questionHint->getPoints());
254
255 $hiddenInp->setValue($questionHint->getId());
256 }
257 else
258 {
259 // build form title for a new hint
260 $form->setTitle(sprintf(
261 $lng->txt('tst_question_hints_form_header_create'),
262 $this->questionOBJ->getTitle()
263 ));
264 }
265
266 if( $this->questionOBJ->isAdditionalContentEditingModePageObject() )
267 {
268 if( $questionHint instanceof ilAssQuestionHint )
269 {
270 $saveCmdLabel = $lng->txt('tst_question_hints_form_cmd_save_points');
271 }
272 else
273 {
274 $saveCmdLabel = $lng->txt('tst_question_hints_form_cmd_save_points_and_edit_page');
275 }
276 }
277 else
278 {
279 $saveCmdLabel = $lng->txt('tst_question_hints_form_cmd_save');
280 }
281
282 $form->setFormAction($ilCtrl->getFormAction($this));
283
284 $form->addCommandButton(self::CMD_SAVE_FORM, $saveCmdLabel);
285 $form->addCommandButton(self::CMD_CANCEL_FORM, $lng->txt('cancel'));
286
287 return $form;
288 }
289
290}
global $tpl
Definition: ilias.php:8
$_GET["client_id"]
_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.
& _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 prepareTextareaOutput($txt_output, $prepare_for_latex_output=FALSE, $omitNl2BrWhenTextArea=false)
Prepares a string for a text area output where latex code may be in it If the text is HTML-free,...
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:40
$cmd
Definition: sahs_server.php:35
global $ilUser
Definition: imgupload.php:15