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