ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAssQuestionHintGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintAbstractGUI.php';
6 
16 {
20  const CMD_SHOW_FORM = 'showForm';
21  const CMD_SAVE_FORM = 'saveForm';
22  const CMD_CANCEL_FORM = 'cancelForm';
23  const CMD_CONFIRM_FORM = 'confirmForm';
24 
32  public function executeCommand()
33  {
34  global $ilCtrl;
35 
36  $cmd = $ilCtrl->getCmd(self::CMD_SHOW_FORM);
37  $nextClass = $ilCtrl->getNextClass($this);
38 
39  switch($nextClass)
40  {
41  default:
42 
43  $cmd .= 'Cmd';
44  return $this->$cmd();
45  break;
46  }
47  }
48 
56  private function showFormCmd(ilPropertyFormGUI $form = null)
57  {
58  global $ilCtrl, $tpl;
59 
60  if( $form instanceof ilPropertyFormGUI )
61  {
62  $form->setValuesByPost();
63  }
64  elseif( isset($_GET['hint_id']) && (int)$_GET['hint_id'] )
65  {
66  $questionHint = new ilAssQuestionHint();
67 
68  if( !$questionHint->load((int)$_GET['hint_id']) )
69  {
70  ilUtil::sendFailure('invalid hint id given: '.(int)$_GET['hint_id'], true);
71  $ilCtrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_SHOW_LIST);
72  }
73 
74  $form = $this->buildForm($questionHint);
75  }
76  else
77  {
78  $form = $this->buildForm();
79  }
80 
81  $tpl->setContent( $form->getHTML() );
82  }
83 
91  private function saveFormCmd()
92  {
93  global $ilCtrl, $lng, $ilUser;
94 
95  $form = $this->buildForm();
96 
97  if( $form->checkInput() )
98  {
99  $questionHint = new ilAssQuestionHint();
100 
101  if( (int)$form->getInput('hint_id') )
102  {
103  $questionHint->load( (int)$form->getInput('hint_id') );
104  }
105  else
106  {
107  $questionHint->setQuestionId( $this->questionOBJ->getId() );
108 
109  $questionHint->setIndex(
110  ilAssQuestionHintList::getNextIndexByQuestionId($this->questionOBJ->getId())
111  );
112  }
113 
114  $questionHint->setText( $form->getInput('hint_text') );
115  $questionHint->setPoints( $form->getInput('hint_points') );
116 
117  $questionHint->save();
118  ilUtil::sendSuccess($lng->txt('tst_question_hints_form_saved_msg'), true);
119 
120  $originalexists = $this->questionOBJ->_questionExistsInPool($this->questionOBJ->original_id);
121  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
122  if ($_GET["calling_test"] && $originalexists && assQuestion::_isWriteable($this->questionOBJ->original_id, $ilUser->getId()))
123  {
124  $ilCtrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_CONFIRM_SYNC);
125  }
126 
127  $ilCtrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_SHOW_LIST);
128  }
129 
130  ilUtil::sendFailure($lng->txt('tst_question_hints_form_invalid_msg'));
131  $this->showFormCmd($form);
132  }
133 
140  private function cancelFormCmd()
141  {
142  global $ilCtrl;
143 
144  $ilCtrl->redirectByClass('ilAssQuestionHintsGUI');
145  }
146 
155  private function buildForm(ilAssQuestionHint $questionHint = null)
156  {
157  global $ilCtrl, $lng;
158 
159  require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
160  require_once 'Services/Form/classes/class.ilTextAreaInputGUI.php';
161  require_once 'Services/Form/classes/class.ilNumberInputGUI.php';
162  require_once 'Services/Form/classes/class.ilHiddenInputGUI.php';
163 
164  $form = new ilPropertyFormGUI();
165  $form->setTableWidth('100%');
166 
167  // form input: hint text
168 
169  $areaInp = new ilTextAreaInputGUI($lng->txt('tst_question_hints_form_label_hint_text'), 'hint_text');
170  $areaInp->setRequired(true);
171  $areaInp->setRows(10);
172  $areaInp->setCols(80);
173 
174  if( !$this->questionGUI->getPreventRteUsage() ) $areaInp->setUseRte(true);
175 
176  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
177  $areaInp->setRteTags( ilObjAdvancedEditing::_getUsedHTMLTags("assessment") );
178 
179  $areaInp->setRTESupport($this->questionOBJ->getId(), 'qpl', 'assessment', null, false, '3.4.7');
180 
181  $areaInp->addPlugin("latex");
182  $areaInp->addButton("latex");
183  $areaInp->addButton("pastelatex");
184 
185  $form->addItem($areaInp);
186 
187  // form input: hint points
188 
189  $numInp = new ilNumberInputGUI($lng->txt('tst_question_hints_form_label_hint_points'), 'hint_points');
190  $numInp->allowDecimals(true);
191  $numInp->setRequired(true);
192  $numInp->setSize(3);
193 
194  $form->addItem($numInp);
195 
196  if( $questionHint instanceof ilAssQuestionHint )
197  {
198  // build form title for an existing hint
199 
200  $form->setTitle(sprintf(
201  $lng->txt('tst_question_hints_form_header_edit'),
202  $questionHint->getIndex(),
203  $this->questionOBJ->getTitle()
204  ));
205 
206  // hidden input: hint id
207 
208  $hiddenInp = new ilHiddenInputGUI('hint_id');
209  $form->addItem($hiddenInp);
210 
211  // init values
212 
213  require_once 'Services/Utilities/classes/class.ilUtil.php';
214 
215  $areaInp->setValue( ilUtil::prepareTextareaOutput($questionHint->getText(), true) );
216 
217  $numInp->setValue($questionHint->getPoints());
218 
219  $hiddenInp->setValue($questionHint->getId());
220  }
221  else
222  {
223  // build form title for a new hint
224  $form->setTitle(sprintf(
225  $lng->txt('tst_question_hints_form_header_create'),
226  $this->questionOBJ->getTitle()
227  ));
228  }
229 
230  $form->setFormAction($ilCtrl->getFormAction($this));
231 
232  $form->addCommandButton(self::CMD_CANCEL_FORM, $lng->txt('cancel'));
233  $form->addCommandButton(self::CMD_SAVE_FORM, $lng->txt('tst_question_hints_form_cmd_save'));
234 
235  return $form;
236  }
237 }