ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAssQuestionFeedbackEditingGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
16 {
20  const CMD_SHOW = 'show';
21  const CMD_SAVE = 'save';
22  const CMD_SHOW_SYNC = 'showSync';
23 
30  protected $questionGUI = null;
31 
38  protected $questionOBJ = null;
39 
46  protected $feedbackOBJ = null;
47 
54  protected $ctrl = null;
55 
62  protected $access = null;
63 
70  protected $tpl = null;
71 
78  protected $tabs = null;
79 
86  protected $lng = null;
87 
100  {
101  $this->questionGUI = $questionGUI;
102  $this->questionOBJ = $questionGUI->object;
103  $this->feedbackOBJ = $questionGUI->object->feedbackOBJ;
104 
105  $this->ctrl = $ctrl;
106  $this->access = $access;
107  $this->tpl = $tpl;
108  $this->tabs = $tabs;
109  $this->lng = $lng;
110  }
111 
117  public function executeCommand()
118  {
119  $cmd = $this->ctrl->getCmd(self::CMD_SHOW);
120  $nextClass = $this->ctrl->getNextClass($this);
121 
122  $this->ctrl->setParameter($this, 'q_id', (int)$_GET['q_id']);
123 
124  switch($nextClass)
125  {
126  case 'ilassspecfeedbackpagegui':
127  case 'ilassgenfeedbackpagegui':
128  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionFeedbackPageObjectCommandForwarder.php';
129  $forwarder = new ilAssQuestionFeedbackPageObjectCommandForwarder($this->questionOBJ, $this->ctrl, $this->tabs, $this->lng);
130  $forwarder->forward();
131  break;
132 
133  default:
134 
135  $cmd .= 'Cmd';
136  $this->$cmd();
137  break;
138  }
139  }
140 
146  private function showCmd()
147  {
148  $form = $this->buildForm();
149 
150  $this->feedbackOBJ->initGenericFormProperties($form);
151  $this->feedbackOBJ->initSpecificFormProperties($form);
152 
153  $this->tpl->setContent( $this->ctrl->getHTML($form) );
154  }
155 
165  private function saveCmd()
166  {
167  $form = $this->buildForm();
168 
169  $form->setValuesByPost();
170 
171  if( $form->checkInput() )
172  {
173  $this->feedbackOBJ->saveGenericFormProperties($form);
174  $this->feedbackOBJ->saveSpecificFormProperties($form);
175 
176  $this->questionOBJ->cleanupMediaObjectUsage();
177 
178  if( $this->isSyncAfterSaveRequired() )
179  {
180  ilUtil::sendSuccess($this->lng->txt('saved_successfully'), true);
181  $this->ctrl->redirect($this, self::CMD_SHOW_SYNC);
182  }
183 
184  ilUtil::sendSuccess($this->lng->txt('saved_successfully'), true);
185  $this->ctrl->redirect($this, self::CMD_SHOW);
186  }
187 
188  ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
189  $this->tpl->setContent( $this->ctrl->getHTML($form) );
190  }
191 
198  private function buildForm()
199  {
200  require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
201 
202  $form = new ilPropertyFormGUI();
203  $form->setFormAction($this->ctrl->getFormAction($this));
204  $form->setTitle($this->lng->txt('feedback_generic'));
205  $form->setTableWidth("100%");
206  $form->setId("feedback");
207 
208  $this->feedbackOBJ->completeGenericFormProperties($form);
209  $this->feedbackOBJ->completeSpecificFormProperties($form);
210 
211  if( $this->isFormSaveable() )
212  {
213  $form->addCommandButton(self::CMD_SAVE, $this->lng->txt("save"));
214  }
215 
216  return $form;
217  }
218 
228  private function isFormSaveable()
229  {
230  $isAdditionalContentEditingModePageObject = $this->questionOBJ->isAdditionalContentEditingModePageObject();
231  $isSaveableInPageObjectEditingMode = $this->feedbackOBJ->isSaveableInPageObjectEditingMode();
232 
233  if( $isAdditionalContentEditingModePageObject && !$isSaveableInPageObjectEditingMode )
234  {
235  return false;
236  }
237 
238  $hasWriteAccess = $this->access->checkAccess("write", "", $_GET['ref_id']);
239  $isSelfAssessmentEditingMode = $this->questionOBJ->getSelfAssessmentEditingMode();
240 
241  return $hasWriteAccess || $isSelfAssessmentEditingMode;
242  }
243 
251  private function isSyncAfterSaveRequired()
252  {
253  global $ilUser;
254 
255  if( !$_GET["calling_test"] )
256  {
257  return false;
258  }
259 
260  if( $this->questionOBJ->isAdditionalContentEditingModePageObject() )
261  {
262  return false;
263  }
264 
265  if( !$this->questionOBJ->_questionExistsInPool($this->questionOBJ->original_id) )
266  {
267  return false;
268  }
269 
270  if( !assQuestion::_isWriteable($this->questionOBJ->original_id, $ilUser->getId()) )
271  {
272  return false;
273  }
274 
275  return true;
276  }
277 
278  public function showSyncCmd()
279  {
280  $this->questionGUI->originalSyncForm('','true');
281  }
282 }