ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilAssQuestionFeedbackEditingGUI.php
Go to the documentation of this file.
1 <?php
2 
19 use ILIAS\Style\Content\Service as ContentStyle;
20 
33 {
37  public const CMD_SHOW = 'showFeedbackForm';
38  public const CMD_SAVE = 'saveFeedbackForm';
39  public const CMD_SHOW_SYNC = 'showSync';
40  private \ILIAS\TestQuestionPool\InternalRequestService $request;
41  private \ILIAS\TestQuestionPool\QuestionInfoService $questioninfo;
42 
49  protected $questionGUI = null;
50 
57  protected $questionOBJ = null;
58 
65  protected $feedbackOBJ = null;
66 
73  protected $ctrl = null;
74 
81  protected $access = null;
82 
89  protected $tpl = null;
90 
97  protected $tabs = null;
98 
105  protected $lng = null;
106 
107  protected ContentStyle $content_style;
108 
121  {
122  $this->questionGUI = $questionGUI;
123  $this->questionOBJ = $questionGUI->object;
124  $this->feedbackOBJ = $questionGUI->object->feedbackOBJ;
126  global $DIC;
127  $this->request = $DIC->testQuestionPool()->internal()->request();
128  $this->ctrl = $ctrl;
129  $this->access = $access;
130  $this->tpl = $tpl;
131  $this->tabs = $tabs;
132  $this->lng = $lng;
133  $this->questioninfo = $DIC->testQuestionPool()->questionInfo();
134  $this->content_style = $DIC->contentStyle();
135  }
136 
142  public function executeCommand(): void
143  {
144  global $DIC; /* @var \ILIAS\DI\Container $DIC */
145  $ilHelp = $DIC['ilHelp']; /* @var ilHelpGUI $ilHelp */
146  $ilHelp->setScreenIdComponent('qpl');
147 
148  $cmd = $this->ctrl->getCmd(self::CMD_SHOW);
149  $nextClass = $this->ctrl->getNextClass($this);
150 
151  $this->ctrl->setParameter($this, 'q_id', $this->request->getQuestionId());
152 
153  $this->setContentStyle();
154 
155  switch ($nextClass) {
156  case 'ilassspecfeedbackpagegui':
157  case 'ilassgenfeedbackpagegui':
158  $forwarder = new ilAssQuestionFeedbackPageObjectCommandForwarder($this->questionOBJ, $this->ctrl, $this->tabs, $this->lng);
159  $forwarder->forward();
160  break;
161 
162  default:
163  $this->tabs->setTabActive('feedback');
164  $cmd .= 'Cmd';
165  $this->$cmd();
166  break;
167  }
168  }
169 
173  protected function setContentStyle(): void
174  {
175  $this->content_style->gui()->addCss($this->tpl, $this->request->getRefId());
176  }
177 
183  private function showFeedbackFormCmd(): void
184  {
185  $form = $this->buildForm();
186 
187  $this->feedbackOBJ->initGenericFormProperties($form);
188  if ($this->questionOBJ->hasSpecificFeedback()) {
189  $this->feedbackOBJ->initSpecificFormProperties($form);
190  }
191 
192  $this->tpl->setContent($this->ctrl->getHTML($form));
193  }
194 
204  private function saveFeedbackFormCmd(): void
205  {
206  $form = $this->buildForm();
207 
208  $form->setValuesByPost();
209 
210  if ($form->checkInput()) {
211  $this->feedbackOBJ->saveGenericFormProperties($form);
212  if ($this->questionOBJ->hasSpecificFeedback()) {
213  $this->feedbackOBJ->saveSpecificFormProperties($form);
214  }
215  $this->questionOBJ->cleanupMediaObjectUsage();
216  $this->questionOBJ->updateTimestamp();
217 
218  if ($this->isSyncAfterSaveRequired()) {
219  $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
220  $this->ctrl->redirect($this, self::CMD_SHOW_SYNC);
221  }
222 
223  $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
224  $this->ctrl->redirect($this, self::CMD_SHOW);
225  }
226 
227  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
228  $this->tpl->setContent($this->ctrl->getHTML($form));
229  }
230 
231  private function createFeedbackPageCmd(): void
232  {
233  $mode = $this->request->raw('fb_mode');
234  $this->ctrl->redirectToUrl(
235  $this->feedbackOBJ->createFeedbackPages($mode)
236  );
237  }
238 
245  private function buildForm(): ilPropertyFormGUI
246  {
247  $form = new ilPropertyFormGUI();
248  $form->setFormAction($this->ctrl->getFormAction($this));
249  $form->setTitle($this->lng->txt('feedback_generic'));
250  $form->setTableWidth("100%");
251  $form->setId("feedback");
252 
253  $this->feedbackOBJ->completeGenericFormProperties($form);
254  if ($this->questionOBJ->hasSpecificFeedback()) {
255  $this->feedbackOBJ->completeSpecificFormProperties($form);
256  }
257 
258  if ($this->isFormSaveable()) {
259  $form->addCommandButton(self::CMD_SAVE, $this->lng->txt("save"));
260  }
261 
262  return $form;
263  }
264 
274  private function isFormSaveable(): bool
275  {
276  if ($this->questionOBJ->isAdditionalContentEditingModePageObject()
277  && !($this->feedbackOBJ->isSaveableInPageObjectEditingMode())) {
278  return false;
279  }
280 
281  $hasWriteAccess = $this->access->checkAccess("write", "", $this->request->getRefId());
282  $isSelfAssessmentEditingMode = $this->questionOBJ->getSelfAssessmentEditingMode();
283 
284  return $hasWriteAccess || $isSelfAssessmentEditingMode;
285  }
286 
294  private function isSyncAfterSaveRequired(): bool
295  {
296  global $DIC;
297  $ilUser = $DIC['ilUser'];
298 
299  if (!$this->request->isset("calling_test")) {
300  return false;
301  }
302 
303  if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
304  return false;
305  }
306 
307  if (!$this->questioninfo->questionExistsInPool((int) $this->questionOBJ->getOriginalId())) {
308  return false;
309  }
310 
311  if (!$this->questioninfo->questionExistsInPool((int) $this->questionOBJ->getOriginalId())) {
312  return false;
313  }
314 
315  if (!assQuestion::_isWriteable($this->questionOBJ->getOriginalId(), $ilUser->getId())) {
316  return false;
317  }
318 
319  return true;
320  }
321 
322  public function showSyncCmd(): void
323  {
324  $this->questionGUI->originalSyncForm('', 'true');
325  }
326 }
isFormSaveable()
returns the fact wether the feedback editing form has to be saveable or not.
showFeedbackFormCmd()
command for rendering the feedback editing form to the content area
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
buildForm()
builds the feedback editing form object
isSyncAfterSaveRequired()
returns the fact wether the presentation of the question sync2pool form is required after saving the ...
ILIAS TestQuestionPool QuestionInfoService $questioninfo
global $DIC
Definition: feed.php:28
__construct(VocabulariesInterface $vocabularies)
Basic GUI class for assessment questions.
saveFeedbackFormCmd()
command for processing the submitted feedback editing form.
ILIAS TestQuestionPool InternalRequestService $request
static _isWriteable(int $question_id, int $user_id)