ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAssQuestionHintsTableGUI.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 'Services/Table/classes/class.ilTable2GUI.php';
5 require_once 'Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php';
6 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintRequestGUI.php';
7 
17 {
23 
27  const TBL_MODE_TESTOUTPUT = '1';
29 
36  private $questionOBJ = null;
37 
44  private $tableMode = null;
45 
52  private $hintOrderingClipboard = null;
53 
65  public function __construct(assQuestion $questionOBJ, ilAssQuestionHintList $questionHintList,
66  ilAssQuestionHintAbstractGUI $parentGUI, $parentCmd, $tableMode = self::TBL_MODE_TESTOUTPUT,
68  {
69  global $ilCtrl, $lng;
70 
71  $this->questionOBJ = $questionOBJ;
72  $this->tableMode = $tableMode;
73  $this->hintOrderingClipboard = $hintOrderingClipboard;
74 
75  $this->setPrefix('tsthints'.$tableMode);
76  $this->setId('tsthints'.$tableMode);
77 
78  parent::__construct($parentGUI, $parentCmd);
79 
80  $this->setTitle( sprintf($lng->txt('tst_question_hints_table_header'), $questionOBJ->getTitle()) );
81  $this->setNoEntriesText( $lng->txt('tst_question_hints_table_no_items') );
82 
83  // we don't take care about offset/limit values, so this avoids segmentation in general
84  // --> required for ordering via clipboard feature
85  $this->setExternalSegmentation(true);
86 
87  $tableData = $questionHintList->getTableData();
88 
89  if( $this->questionOBJ->isAdditionalContentEditingModePageObject() )
90  {
91  require_once 'Modules/TestQuestionPool/classes/class.ilAssHintPageGUI.php';
92 
93  foreach( $tableData as $key => $data )
94  {
95  $pageObjectGUI = new ilAssHintPageGUI($data['hint_id']);
96  $pageObjectGUI->setOutputMode("presentation");
97  $tableData[$key]['hint_text'] = $pageObjectGUI->presentation();
98  }
99  }
100 
101  $this->setData($tableData);
102 
103  if( $this->tableMode == self::TBL_MODE_ADMINISTRATION )
104  {
105  $this->setRowTemplate('tpl.tst_question_hints_administration_table_row.html', 'Modules/TestQuestionPool');
106 
107  $this->setSelectAllCheckbox('hint_ids[]');
108 
109  $rowCount = count($tableData);
110  $this->initAdministrationColumns($rowCount);
111  $this->initAdministrationCommands($rowCount);
112  }
113  else
114  {
115  $this->setRowTemplate('tpl.tst_question_hints_testoutput_table_row.html', 'Modules/TestQuestionPool');
116 
117  $this->initTestoutputColumns();
118  $this->initTestoutputCommands();
119  }
120  }
121 
131  private function initAdministrationCommands($rowCount)
132  {
133  global $ilCtrl, $lng;
134 
135  $this->setFormAction( $ilCtrl->getFormAction($this->parent_obj) );
136 
137  if( $this->hintOrderingClipboard->hasStored() )
138  {
139  $this->addMultiCommand(
141  $lng->txt('tst_questions_hints_table_multicmd_paste_hint_before')
142  );
143 
144  $this->addMultiCommand(
146  $lng->txt('tst_questions_hints_table_multicmd_paste_hint_after')
147  );
148  }
149  elseif( $rowCount > 0 )
150  {
151  $this->addMultiCommand(
153  $lng->txt('tst_questions_hints_table_multicmd_delete_hint')
154  );
155 
156  if( $rowCount > 1 ) $this->addMultiCommand(
158  $lng->txt('tst_questions_hints_table_multicmd_cut_hint')
159  );
160 
161  $this->addCommandButton(
163  $lng->txt('tst_questions_hints_table_cmd_save_order')
164  );
165  }
166  }
167 
176  private function initTestoutputCommands()
177  {
178  global $ilCtrl, $lng;
179 
180  $this->setFormAction( $ilCtrl->getFormAction($this->parent_obj) );
181 
182  $this->addCommandButton(
184  $lng->txt('tst_question_hints_back_to_question')
185  );
186  }
187 
196  private function initAdministrationColumns($rowCount)
197  {
198  global $lng;
199 
200  $this->addColumn( '', '', '30', true );
201 
202  $this->addColumn( $lng->txt('tst_question_hints_table_column_hint_order'), 'hint_index', '60');
203  $this->addColumn( $lng->txt('tst_question_hints_table_column_hint_text'), 'hint_text');
204  $this->addColumn( $lng->txt('tst_question_hints_table_column_hint_points'), 'hint_points', '250');
205 
206  $this->addColumn('', '', '100');
207 
208  $this->setDefaultOrderField("hint_index");
209  $this->setDefaultOrderDirection("asc");
210 
211  if( $rowCount < 1 )
212  {
213  $this->disable('header');
214  }
215  }
216 
224  private function initTestoutputColumns()
225  {
226  global $lng;
227 
228  $this->addColumn( $lng->txt('tst_question_hints_table_column_hint_index'), 'hint_index', '200');
229  $this->addColumn( $lng->txt('tst_question_hints_table_column_hint_text'), 'hint_text');
230  $this->addColumn( $lng->txt('tst_question_hints_table_column_hint_points'), 'hint_points', '200');
231 
232  $this->setDefaultOrderField("hint_index");
233  $this->setDefaultOrderDirection("asc");
234  }
235 
244  public function numericOrdering($field)
245  {
246  switch($field)
247  {
248  case 'hint_index':
249  case 'hint_points':
250 
251  return true;
252  }
253 
254  return false;
255  }
256 
265  public function fillRow($rowData)
266  {
267  global $ilCtrl, $lng;
268 
269  if( $this->tableMode == self::TBL_MODE_ADMINISTRATION )
270  {
271  $list = new ilAdvancedSelectionListGUI();
272  $list->setListTitle($lng->txt('actions'));
273  $list->setId("advsl_hint_{$rowData['hint_id']}_actions");
274 
275  if( $this->questionOBJ->isAdditionalContentEditingModePageObject() )
276  {
277  $editPointsHref = $ilCtrl->getLinkTargetByClass('ilAssQuestionHintGUI', ilAssQuestionHintGUI::CMD_SHOW_FORM);
278  $editPointsHref = ilUtil::appendUrlParameterString($editPointsHref, "hint_id={$rowData['hint_id']}", true);
279  $list->addItem($lng->txt('tst_question_hints_table_link_edit_hint_points'), '', $editPointsHref);
280 
281  $editPageHref = $ilCtrl->getLinkTargetByClass('ilasshintpagegui', 'edit');
282  $editPageHref = ilUtil::appendUrlParameterString($editPageHref, "hint_id={$rowData['hint_id']}", true);
283  $list->addItem($lng->txt('tst_question_hints_table_link_edit_hint_page'), '', $editPageHref);
284  }
285  else
286  {
287  $editHref = $ilCtrl->getLinkTargetByClass('ilAssQuestionHintGUI', ilAssQuestionHintGUI::CMD_SHOW_FORM);
288  $editHref = ilUtil::appendUrlParameterString($editHref, "hint_id={$rowData['hint_id']}", true);
289  $list->addItem($lng->txt('tst_question_hints_table_link_edit_hint'), '', $editHref);
290  }
291 
292  $deleteHref = $ilCtrl->getLinkTarget($this->parent_obj, ilAssQuestionHintsGUI::CMD_CONFIRM_DELETE);
293  $deleteHref = ilUtil::appendUrlParameterString($deleteHref, "hint_id={$rowData['hint_id']}", true);
294  $list->addItem($lng->txt('tst_question_hints_table_link_delete_hint'), '', $deleteHref);
295 
296  $this->tpl->setVariable('ACTIONS', $list->getHTML());
297 
298  $this->tpl->setVariable('HINT_ID', $rowData['hint_id']);
299 
300  $hintIndex = $rowData['hint_index'] * self::INDEX_TO_POSITION_FACTOR;
301 
302  }
303  else
304  {
305 
306  $showHref = $this->parent_obj->getHintPresentationLinkTarget($rowData['hint_id']);
307 
308  $this->tpl->setVariable('HINT_HREF', $showHref);
309 
310  $hintIndex = ilAssQuestionHint::getHintIndexLabel($lng, $rowData['hint_index']);
311  }
312 
313  $this->tpl->setVariable('HINT_INDEX', $hintIndex);
314  $this->tpl->setVariable('HINT_TEXT', $rowData['hint_text']);
315  $this->tpl->setVariable('HINT_POINTS', $rowData['hint_points']);
316  }
317 }
318