ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilAssQuestionFeedbackEditingGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 use ILIAS\Style\Content\Service as ContentStyle;
23 
32 {
33  public const CMD_SHOW = 'showFeedbackForm';
34  public const CMD_SAVE = 'saveFeedbackForm';
35  public const CMD_SHOW_SYNC = 'confirmSync';
36  public const CMD_SYNC = 'sync';
37 
40 
41  public function __construct(
42  protected readonly assQuestionGUI $question_gui,
43  protected readonly ilCtrl $ctrl,
44  protected readonly ilAccessHandler $access,
45  protected readonly ilGlobalTemplateInterface $tpl,
46  protected readonly ilTabsGUI $tabs,
47  protected readonly ilLanguage $lng,
48  protected readonly ilHelpGUI $help,
49  private readonly RequestDataCollector $request,
50  private readonly ContentStyle $content_style,
51  private readonly bool $in_pool_context = false
52  ) {
53  $this->question_obj = $question_gui->getObject();
54  $this->feedback_obj = $question_gui->getObject()->feedbackOBJ;
55  }
56 
57  public function executeCommand(): void
58  {
59  $this->help->setScreenIdComponent('qpl');
60 
61  $cmd = $this->ctrl->getCmd(self::CMD_SHOW);
62  $nextClass = $this->ctrl->getNextClass($this);
63 
64  $this->ctrl->setParameter($this, 'q_id', $this->question_gui->getObject()->getId());
65 
66  $this->setContentStyle();
67 
68  switch ($nextClass) {
69  case 'ilassspecfeedbackpagegui':
70  case 'ilassgenfeedbackpagegui':
71  $forwarder = new ilAssQuestionFeedbackPageObjectCommandForwarder($this->question_obj, $this->ctrl, $this->tabs, $this->lng);
72  $forwarder->forward();
73  break;
74 
75  default:
76  $this->tabs->setTabActive('feedback');
77  $cmd .= 'Cmd';
78  $this->$cmd();
79  break;
80  }
81  }
82 
83  protected function setContentStyle(): void
84  {
85  $this->content_style->gui()->addCss($this->tpl, $this->request->getRefId());
86  }
87 
88  private function showFeedbackFormCmd(string $additional_content = ''): void
89  {
90  $form = $this->buildForm();
91 
92  $this->feedback_obj->initGenericFormProperties($form);
93  if ($this->question_obj->hasSpecificFeedback()) {
94  $this->feedback_obj->initSpecificFormProperties($form);
95  }
96 
97  $this->tpl->setContent($form->getHTML() . $additional_content);
98  }
99 
100  private function saveFeedbackFormCmd(): void
101  {
102  $form = $this->buildForm();
103  $form->setValuesByPost();
104 
105  if ($form->checkInput()) {
106  $this->feedback_obj->saveGenericFormProperties($form);
107  if ($this->question_obj->hasSpecificFeedback()) {
108  $this->feedback_obj->saveSpecificFormProperties($form);
109  }
110  $this->question_obj->cleanupMediaObjectUsage();
111  $this->question_obj->updateTimestamp();
112 
113  if ($this->isSyncAfterSaveRequired()) {
114  $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
115  $this->ctrl->redirect($this, self::CMD_SHOW_SYNC);
116  }
117 
118  $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
119  $this->ctrl->redirect($this, self::CMD_SHOW);
120  }
121 
122  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('form_input_not_valid'));
123  $this->tpl->setContent($this->ctrl->getHTML($form));
124  }
125 
126  private function createFeedbackPageCmd(): void
127  {
128  $mode = $this->request->raw('fb_mode');
129  $this->ctrl->redirectToUrl(
130  $this->feedback_obj->createFeedbackPages($mode)
131  );
132  }
133 
134  private function buildForm(): ilPropertyFormGUI
135  {
136  $form = new ilPropertyFormGUI();
137  $form->setFormAction($this->ctrl->getFormAction($this));
138  $form->setTitle($this->lng->txt('feedback_generic'));
139  $form->setTableWidth("100%");
140  $form->setId("feedback");
141 
142  $this->feedback_obj->completeGenericFormProperties($form);
143  if ($this->question_obj->hasSpecificFeedback()) {
144  $this->feedback_obj->completeSpecificFormProperties($form);
145  }
146 
147  if ($this->isFormSaveable()) {
148  $form->addCommandButton(self::CMD_SAVE, $this->lng->txt("save"));
149  }
150 
151  return $form;
152  }
153 
154  private function isFormSaveable(): bool
155  {
156  if ($this->question_obj->isAdditionalContentEditingModePageObject()
157  && !($this->feedback_obj->isSaveableInPageObjectEditingMode())) {
158  return false;
159  }
160  return true;
161  }
162 
163  private function isSyncAfterSaveRequired(): bool
164  {
165  if ($this->in_pool_context) {
166  return false;
167  }
168 
169  if ($this->question_obj->isAdditionalContentEditingModePageObject()) {
170  return false;
171  }
172 
173  if (!$this->question_gui->needsSyncQuery()) {
174  return false;
175  }
176 
177  return true;
178  }
179 
180  public function confirmSyncCmd(): void
181  {
182  $modal = $this->question_gui->getQuestionSyncModal(self::CMD_SYNC, self::class);
183  $this->showFeedbackFormCmd($modal);
184  }
185 
186  public function syncCmd(): void
187  {
188  $this->question_obj->syncWithOriginal();
189  $this->showFeedbackFormCmd();
190  }
191 }
__construct(protected readonly assQuestionGUI $question_gui, protected readonly ilCtrl $ctrl, protected readonly ilAccessHandler $access, protected readonly ilGlobalTemplateInterface $tpl, protected readonly ilTabsGUI $tabs, protected readonly ilLanguage $lng, protected readonly ilHelpGUI $help, private readonly RequestDataCollector $request, private readonly ContentStyle $content_style, private readonly bool $in_pool_context=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Help GUI class.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $lng
Definition: privfeed.php:31