ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAssQuestionHintGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintAbstractGUI.php';
5 
18 {
22  const CMD_SHOW_FORM = 'showForm';
23  const CMD_SAVE_FORM = 'saveForm';
24  const CMD_CANCEL_FORM = 'cancelForm';
25  const CMD_CONFIRM_FORM = 'confirmForm';
26 
34  public function executeCommand()
35  {
36  global $ilCtrl, $ilTabs, $lng, $tpl;
37 
38  $cmd = $ilCtrl->getCmd(self::CMD_SHOW_FORM);
39  $nextClass = $ilCtrl->getNextClass($this);
40 
41  switch($nextClass)
42  {
43  case 'ilasshintpagegui':
44 
45  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintPageObjectCommandForwarder.php';
46  $forwarder = new ilAssQuestionHintPageObjectCommandForwarder($this->questionOBJ, $ilCtrl, $ilTabs, $lng);
48  $forwarder->forward();
49  break;
50 
51  default:
52 
53  $cmd .= 'Cmd';
54  $this->$cmd();
55  break;
56  }
57 
58  return true;
59  }
60 
68  private function showFormCmd(ilPropertyFormGUI $form = null)
69  {
70  global $ilCtrl, $tpl, $ilToolbar, $lng, $ilCtrl;
71 
72  if( $form instanceof ilPropertyFormGUI )
73  {
74  $form->setValuesByPost();
75  }
76  elseif( isset($_GET['hint_id']) && (int)$_GET['hint_id'] )
77  {
78  $questionHint = new ilAssQuestionHint();
79 
80  if( !$questionHint->load((int)$_GET['hint_id']) )
81  {
82  ilUtil::sendFailure('invalid hint id given: '.(int)$_GET['hint_id'], true);
83  $ilCtrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_SHOW_LIST);
84  }
85 
86  $form = $this->buildForm($questionHint);
87  }
88  else
89  {
90  $form = $this->buildForm();
91  }
92 
93  $tpl->setContent( $form->getHTML() );
94  }
95 
103  private function saveFormCmd()
104  {
105  global $ilCtrl, $lng, $ilUser;
106 
107  $form = $this->buildForm();
108 
109  if( $form->checkInput() )
110  {
111  $questionHint = new ilAssQuestionHint();
112 
113  if( (int)$form->getInput('hint_id') )
114  {
115  $questionHint->load( (int)$form->getInput('hint_id') );
116 
117  $hintJustCreated = false;
118  }
119  else
120  {
121  $questionHint->setQuestionId( $this->questionOBJ->getId() );
122 
123  $questionHint->setIndex(
124  ilAssQuestionHintList::getNextIndexByQuestionId($this->questionOBJ->getId())
125  );
126 
127  $hintJustCreated = true;
128  }
129 
130  $questionHint->setText( $form->getInput('hint_text') );
131  $questionHint->setPoints( $form->getInput('hint_points') );
132 
133  $questionHint->save();
134  ilUtil::sendSuccess($lng->txt('tst_question_hints_form_saved_msg'), true);
135 
136  $originalexists = $this->questionOBJ->_questionExistsInPool($this->questionOBJ->original_id);
137  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
138  if ($_GET["calling_test"] && $originalexists && assQuestion::_isWriteable($this->questionOBJ->original_id, $ilUser->getId()))
139  {
140  $ilCtrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_CONFIRM_SYNC);
141  }
142 
143 
144  if( $hintJustCreated && $this->questionOBJ->isAdditionalContentEditingModePageObject() )
145  {
146  $ilCtrl->setParameterByClass('ilasshintpagegui', 'hint_id', $questionHint->getId());
147  $ilCtrl->redirectByClass('ilasshintpagegui', 'edit');
148  }
149  else
150  {
151  $ilCtrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_SHOW_LIST);
152  }
153  }
154 
155  ilUtil::sendFailure($lng->txt('tst_question_hints_form_invalid_msg'));
156  $this->showFormCmd($form);
157  }
158 
165  private function cancelFormCmd()
166  {
167  global $ilCtrl;
168 
169  $ilCtrl->redirectByClass('ilAssQuestionHintsGUI');
170  }
171 
180  private function buildForm(ilAssQuestionHint $questionHint = null)
181  {
182  global $ilCtrl, $lng;
183 
184  require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
185  require_once 'Services/Form/classes/class.ilTextAreaInputGUI.php';
186  require_once 'Services/Form/classes/class.ilNumberInputGUI.php';
187  require_once 'Services/Form/classes/class.ilHiddenInputGUI.php';
188 
189  $form = new ilPropertyFormGUI();
190  $form->setTableWidth('100%');
191 
192  if( !$this->questionOBJ->isAdditionalContentEditingModePageObject() )
193  {
194  // form input: hint text
195 
196  $areaInp = new ilTextAreaInputGUI($lng->txt('tst_question_hints_form_label_hint_text'), 'hint_text');
197  $areaInp->setRequired(true);
198  $areaInp->setRows(10);
199  $areaInp->setCols(80);
200 
201  if( !$this->questionOBJ->getPreventRteUsage() ) $areaInp->setUseRte(true);
202 
203  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
204  $areaInp->setRteTags( ilObjAdvancedEditing::_getUsedHTMLTags("assessment") );
205 
206  $areaInp->setRTESupport($this->questionOBJ->getId(), 'qpl', 'assessment');
207 
208  $areaInp->addPlugin("latex");
209  $areaInp->addButton("latex");
210  $areaInp->addButton("pastelatex");
211 
212  $form->addItem($areaInp);
213  }
214 
215  // form input: hint points
216 
217  $numInp = new ilNumberInputGUI($lng->txt('tst_question_hints_form_label_hint_points'), 'hint_points');
218  $numInp->allowDecimals(true);
219  $numInp->setRequired(true);
220  $numInp->setSize(3);
221 
222  $form->addItem($numInp);
223 
224  if( $questionHint instanceof ilAssQuestionHint )
225  {
226  // build form title for an existing hint
227 
228  $form->setTitle(sprintf(
229  $lng->txt('tst_question_hints_form_header_edit'),
230  $questionHint->getIndex(),
231  $this->questionOBJ->getTitle()
232  ));
233 
234  // hidden input: hint id
235 
236  $hiddenInp = new ilHiddenInputGUI('hint_id');
237  $form->addItem($hiddenInp);
238 
239  // init values
240 
241  require_once 'Services/Utilities/classes/class.ilUtil.php';
242 
243  if( !$this->questionOBJ->isAdditionalContentEditingModePageObject() )
244  {
245  $areaInp->setValue( ilUtil::prepareTextareaOutput($questionHint->getText(), true) );
246  }
247 
248  $numInp->setValue($questionHint->getPoints());
249 
250  $hiddenInp->setValue($questionHint->getId());
251  }
252  else
253  {
254  // build form title for a new hint
255  $form->setTitle(sprintf(
256  $lng->txt('tst_question_hints_form_header_create'),
257  $this->questionOBJ->getTitle()
258  ));
259  }
260 
261  if( $this->questionOBJ->isAdditionalContentEditingModePageObject() )
262  {
263  if( $questionHint instanceof ilAssQuestionHint )
264  {
265  $saveCmdLabel = $lng->txt('tst_question_hints_form_cmd_save_points');
266  }
267  else
268  {
269  $saveCmdLabel = $lng->txt('tst_question_hints_form_cmd_save_points_and_edit_page');
270  }
271  }
272  else
273  {
274  $saveCmdLabel = $lng->txt('tst_question_hints_form_cmd_save');
275  }
276 
277  $form->setFormAction($ilCtrl->getFormAction($this));
278 
279  $form->addCommandButton(self::CMD_CANCEL_FORM, $lng->txt('cancel'));
280  $form->addCommandButton(self::CMD_SAVE_FORM, $saveCmdLabel);
281 
282  return $form;
283  }
284 
285 }