ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilAssQuestionHintGUI.php
Go to the documentation of this file.
1 <?php
2 
19 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintAbstractGUI.php';
20 
33 {
37  public const CMD_SHOW_FORM = 'showForm';
38  public const CMD_SAVE_FORM = 'saveForm';
39  public const CMD_CANCEL_FORM = 'cancelForm';
40  public const CMD_CONFIRM_FORM = 'confirmForm';
41  private \ilGlobalTemplateInterface $main_tpl;
43  {
44  parent::__construct($questionGUI);
45  global $DIC;
46  $this->main_tpl = $DIC->ui()->mainTemplate();
47  }
48 
56  public function executeCommand()
57  {
58  global $DIC;
59  $ilCtrl = $DIC['ilCtrl'];
60  $ilTabs = $DIC['ilTabs'];
61  $lng = $DIC['lng'];
62  $tpl = $DIC['tpl'];
63 
64  $cmd = $ilCtrl->getCmd(self::CMD_SHOW_FORM);
65  $nextClass = $ilCtrl->getNextClass($this);
66 
67  switch ($nextClass) {
68  case 'ilasshintpagegui':
69  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintPageObjectCommandForwarder.php';
70  $forwarder = new ilAssQuestionHintPageObjectCommandForwarder($this->questionOBJ, $ilCtrl, $ilTabs, $lng);
72  $forwarder->forward();
73  break;
74 
75  default:
76  $this->tabs->setTabActive('tst_question_hints_tab');
77  $cmd .= 'Cmd';
78  $this->$cmd();
79  break;
80  }
81 
82  return true;
83  }
84 
92  private function showFormCmd(ilPropertyFormGUI $form = null): void
93  {
94  global $DIC;
95  $ilCtrl = $DIC['ilCtrl'];
96  $tpl = $DIC['tpl'];
97  $ilToolbar = $DIC['ilToolbar'];
98  $lng = $DIC['lng'];
99  $ilCtrl = $DIC['ilCtrl'];
100 
101  if ($form instanceof ilPropertyFormGUI) {
102  $form->setValuesByPost();
103  } elseif ($this->request->isset('hint_id') && (int) $this->request->raw('hint_id')) {
104  $questionHint = new ilAssQuestionHint();
105 
106  if (!$questionHint->load((int) $this->request->raw('hint_id'))) {
107  $this->main_tpl->setOnScreenMessage('failure', 'invalid hint id given: ' . (int) $this->request->raw('hint_id'), true);
108  $ilCtrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_SHOW_LIST);
109  }
110 
111  $form = $this->buildForm($questionHint);
112  } else {
113  $form = $this->buildForm();
114  }
115 
116  $tpl->setContent($form->getHTML());
117  }
118 
126  private function saveFormCmd(): void
127  {
128  global $DIC;
129  $ilCtrl = $DIC['ilCtrl'];
130  $lng = $DIC['lng'];
131  $ilUser = $DIC['ilUser'];
132 
133  $questionHint = new ilAssQuestionHint();
134  if ($this->request->isset('hint_id')) {
135  $questionHint->load((int) $this->request->int('hint_id'));
136 
137  $hintJustCreated = false;
138  $form = $this->buildForm($questionHint);
139  } else {
140  $questionHint->setQuestionId($this->questionOBJ->getId());
141 
142  $questionHint->setIndex(
143  ilAssQuestionHintList::getNextIndexByQuestionId($this->questionOBJ->getId())
144  );
145 
146  $hintJustCreated = true;
147  $form = $this->buildForm();
148  }
149 
150  if ($form->checkInput()) {
151  $questionHint->setText($form->getInput('hint_text'));
152  $questionHint->setPoints($form->getInput('hint_points'));
153 
154  $questionHint->save();
155  $this->main_tpl->setOnScreenMessage('success', $lng->txt('tst_question_hints_form_saved_msg'), true);
156 
157  if (!$this->questionOBJ->isAdditionalContentEditingModePageObject()) {
158  $this->questionOBJ->updateTimestamp();
159  }
160 
161  $originalexists = $this->questionOBJ->_questionExistsInPool((int) $this->questionOBJ->getOriginalId());
162  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
163  if ($this->request->raw('calling_test') && $originalexists && assQuestion::_isWriteable($this->questionOBJ->getOriginalId(), $ilUser->getId())) {
164  $ilCtrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_CONFIRM_SYNC);
165  }
166 
167 
168  if ($hintJustCreated && $this->questionOBJ->isAdditionalContentEditingModePageObject()) {
169  $ilCtrl->setParameterByClass('ilasshintpagegui', 'hint_id', $questionHint->getId());
170  $ilCtrl->redirectByClass('ilasshintpagegui', 'edit');
171  } else {
172  $ilCtrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_SHOW_LIST);
173  }
174  }
175 
176  $this->main_tpl->setOnScreenMessage('failure', $lng->txt('tst_question_hints_form_invalid_msg'));
177  $this->showFormCmd($form);
178  }
179 
186  private function cancelFormCmd(): void
187  {
188  global $DIC;
189  $ilCtrl = $DIC['ilCtrl'];
190 
191  $ilCtrl->redirectByClass('ilAssQuestionHintsGUI');
192  }
193 
202  private function buildForm(ilAssQuestionHint $questionHint = null): ilPropertyFormGUI
203  {
204  global $DIC;
205  $ilCtrl = $DIC['ilCtrl'];
206  $lng = $DIC['lng'];
207 
208  require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
209  require_once 'Services/Form/classes/class.ilTextAreaInputGUI.php';
210  require_once 'Services/Form/classes/class.ilNumberInputGUI.php';
211  require_once 'Services/Form/classes/class.ilHiddenInputGUI.php';
212 
213  $form = new ilPropertyFormGUI();
214  $form->setTableWidth('100%');
215 
216  if (!$this->questionOBJ->isAdditionalContentEditingModePageObject()) {
217  // form input: hint text
218 
219  $areaInp = new ilTextAreaInputGUI($lng->txt('tst_question_hints_form_label_hint_text'), 'hint_text');
220  $areaInp->setRequired(true);
221  $areaInp->setRows(10);
222  $areaInp->setCols(80);
223 
224  if (!$this->questionOBJ->getPreventRteUsage()) {
225  $areaInp->setUseRte(true);
226  }
227 
228  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
229  $areaInp->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
230 
231  $areaInp->setRTESupport($this->questionOBJ->getId(), 'qpl', 'assessment');
232 
233  $areaInp->addPlugin("latex");
234  $areaInp->addButton("latex");
235  $areaInp->addButton("pastelatex");
236 
237  $form->addItem($areaInp);
238  }
239 
240  // form input: hint points
241 
242  $numInp = new ilNumberInputGUI($lng->txt('tst_question_hints_form_label_hint_points'), 'hint_points');
243  $numInp->allowDecimals(true);
244  $numInp->setRequired(true);
245  $numInp->setSize(3);
246 
247  $form->addItem($numInp);
248 
249  if ($questionHint instanceof ilAssQuestionHint) {
250  // build form title for an existing hint
251 
252  $form->setTitle(sprintf(
253  $lng->txt('tst_question_hints_form_header_edit'),
254  $questionHint->getIndex(),
255  $this->questionOBJ->getTitleForHTMLOutput()
256  ));
257 
258  // hidden input: hint id
259 
260  $hiddenInp = new ilHiddenInputGUI('hint_id');
261  $form->addItem($hiddenInp);
262 
263  // init values
264 
265  require_once 'Services/Utilities/classes/class.ilUtil.php';
266 
267  if (!$this->questionOBJ->isAdditionalContentEditingModePageObject()) {
268  $areaInp->setValue($questionHint->getText());
269  }
270 
271  $numInp->setValue($questionHint->getPoints());
272 
273  $hiddenInp->setValue($questionHint->getId());
274  } else {
275  // build form title for a new hint
276  $form->setTitle(sprintf(
277  $lng->txt('tst_question_hints_form_header_create'),
278  $this->questionOBJ->getTitleForHTMLOutput()
279  ));
280  }
281 
282  if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
283  if ($questionHint instanceof ilAssQuestionHint) {
284  $saveCmdLabel = $lng->txt('tst_question_hints_form_cmd_save_points');
285  } else {
286  $saveCmdLabel = $lng->txt('tst_question_hints_form_cmd_save_points_and_edit_page');
287  }
288  } else {
289  $saveCmdLabel = $lng->txt('tst_question_hints_form_cmd_save');
290  }
291 
292  $form->setFormAction($ilCtrl->getFormAction($this));
293 
294  $form->addCommandButton(self::CMD_SAVE_FORM, $saveCmdLabel);
295  $form->addCommandButton(self::CMD_CANCEL_FORM, $lng->txt('cancel'));
296 
297  return $form;
298  }
299 }
cancelFormCmd()
gateway command method to jump back to question hints overview
$lng
saveFormCmd()
saves the form on successfull validation and redirects to showForm command
const CMD_SHOW_LIST
command constants
__construct(assQuestionGUI $questionGUI)
global $DIC
Definition: feed.php:28
allowDecimals(bool $a_value)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
This class represents a number property in a property form.
buildForm(ilAssQuestionHint $questionHint=null)
builds the questions hints form
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setRequired(bool $a_required)
const CMD_SHOW_FORM
command constants
__construct(Container $dic, ilPlugin $plugin)
This class represents a text area property in a property form.
$ilUser
Definition: imgupload.php:34
static _isWriteable(int $question_id, int $user_id)
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
ilGlobalTemplateInterface $main_tpl
static _getUsedHTMLTags(string $a_module="")
Returns an array of all allowed HTML tags for text editing.
showFormCmd(ilPropertyFormGUI $form=null)
shows the form for managing a new/existing hint