ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
4 require_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  ilUtil::sendSuccess($lng->txt('tst_question_hints_form_saved_msg'), true);
136 
137  if (!$this->questionOBJ->isAdditionalContentEditingModePageObject()) {
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  $ilCtrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_CONFIRM_SYNC);
145  }
146 
147 
148  if ($hintJustCreated && $this->questionOBJ->isAdditionalContentEditingModePageObject()) {
149  $ilCtrl->setParameterByClass('ilasshintpagegui', 'hint_id', $questionHint->getId());
150  $ilCtrl->redirectByClass('ilasshintpagegui', 'edit');
151  } else {
152  $ilCtrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_SHOW_LIST);
153  }
154  }
155 
156  ilUtil::sendFailure($lng->txt('tst_question_hints_form_invalid_msg'));
157  $this->showFormCmd($form);
158  }
159 
166  private function cancelFormCmd()
167  {
168  global $DIC;
169  $ilCtrl = $DIC['ilCtrl'];
170 
171  $ilCtrl->redirectByClass('ilAssQuestionHintsGUI');
172  }
173 
182  private function buildForm(ilAssQuestionHint $questionHint = null)
183  {
184  global $DIC;
185  $ilCtrl = $DIC['ilCtrl'];
186  $lng = $DIC['lng'];
187 
188  require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
189  require_once 'Services/Form/classes/class.ilTextAreaInputGUI.php';
190  require_once 'Services/Form/classes/class.ilNumberInputGUI.php';
191  require_once 'Services/Form/classes/class.ilHiddenInputGUI.php';
192 
193  $form = new ilPropertyFormGUI();
194  $form->setTableWidth('100%');
195 
196  if (!$this->questionOBJ->isAdditionalContentEditingModePageObject()) {
197  // form input: hint text
198 
199  $areaInp = new ilTextAreaInputGUI($lng->txt('tst_question_hints_form_label_hint_text'), 'hint_text');
200  $areaInp->setRequired(true);
201  $areaInp->setRows(10);
202  $areaInp->setCols(80);
203 
204  if (!$this->questionOBJ->getPreventRteUsage()) {
205  $areaInp->setUseRte(true);
206  }
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  // build form title for an existing hint
231 
232  $form->setTitle(sprintf(
233  $lng->txt('tst_question_hints_form_header_edit'),
234  $questionHint->getIndex(),
235  $this->questionOBJ->getTitle()
236  ));
237 
238  // hidden input: hint id
239 
240  $hiddenInp = new ilHiddenInputGUI('hint_id');
241  $form->addItem($hiddenInp);
242 
243  // init values
244 
245  require_once 'Services/Utilities/classes/class.ilUtil.php';
246 
247  if (!$this->questionOBJ->isAdditionalContentEditingModePageObject()) {
248  $areaInp->setValue($questionHint->getText());
249  }
250 
251  $numInp->setValue($questionHint->getPoints());
252 
253  $hiddenInp->setValue($questionHint->getId());
254  } else {
255  // build form title for a new hint
256  $form->setTitle(sprintf(
257  $lng->txt('tst_question_hints_form_header_create'),
258  $this->questionOBJ->getTitle()
259  ));
260  }
261 
262  if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
263  if ($questionHint instanceof ilAssQuestionHint) {
264  $saveCmdLabel = $lng->txt('tst_question_hints_form_cmd_save_points');
265  } else {
266  $saveCmdLabel = $lng->txt('tst_question_hints_form_cmd_save_points_and_edit_page');
267  }
268  } else {
269  $saveCmdLabel = $lng->txt('tst_question_hints_form_cmd_save');
270  }
271 
272  $form->setFormAction($ilCtrl->getFormAction($this));
273 
274  $form->addCommandButton(self::CMD_SAVE_FORM, $saveCmdLabel);
275  $form->addCommandButton(self::CMD_CANCEL_FORM, $lng->txt('cancel'));
276 
277  return $form;
278  }
279 }
This class represents a property form user interface.
global $DIC
Definition: saml.php:7
cancelFormCmd()
gateway command method to jump back to question hints overview
$_GET["client_id"]
$tpl
Definition: ilias.php:10
static _getUsedHTMLTags($a_module="")
Returns an array of all allowed HTML tags for text editing.
saveFormCmd()
saves the form on successfull validation and redirects to showForm command
const CMD_SHOW_LIST
command constants
global $ilCtrl
Definition: ilias.php:18
allowDecimals($a_value)
Toggle Decimals.
This class represents a hidden form property in a property form.
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...
if(isset($_POST['submit'])) $form
$lng
This class represents a number property in a property form.
buildForm(ilAssQuestionHint $questionHint=null)
builds the questions hints form
$ilUser
Definition: imgupload.php:18
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
const CMD_SHOW_FORM
command constants
This class represents a text area property in a property form.
setRequired($a_required)
Set Required.
showFormCmd(ilPropertyFormGUI $form=null)
shows the form for managing a new/existing hint
static _isWriteable($question_id, $user_id)
Returns true if the question is writeable by a certain user.