ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAssQuestionHintsTableGUI.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 'Services/Table/classes/class.ilTable2GUI.php';
6 require_once 'Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php';
7 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintRequestGUI.php';
8 
18 {
24 
28  const TBL_MODE_TESTOUTPUT = '1';
30 
37  private $questionOBJ = null;
38 
45  private $tableMode = null;
46 
53  private $hintOrderingClipboard = null;
54 
66  public function __construct(assQuestion $questionOBJ, ilAssQuestionHintList $questionHintList,
67  ilAssQuestionHintAbstractGUI $parentGUI, $parentCmd, $tableMode = self::TBL_MODE_TESTOUTPUT,
69  {
70  global $ilCtrl, $lng;
71 
72  $this->questionOBJ = $questionOBJ;
73  $this->tableMode = $tableMode;
74  $this->hintOrderingClipboard = $hintOrderingClipboard;
75 
76  $this->setPrefix('tsthints'.$tableMode);
77  $this->setId('tsthints'.$tableMode);
78 
79  parent::__construct($parentGUI, $parentCmd);
80 
81  $this->setTitle( sprintf($lng->txt('tst_question_hints_table_header'), $questionOBJ->getTitle()) );
82  $this->setNoEntriesText( $lng->txt('tst_question_hints_table_no_items') );
83 
84  // we don't take care about offset/limit values, so this avoids segmentation in general
85  // --> required for ordering via clipboard feature
86  $this->setExternalSegmentation(true);
87 
88  $tableData = $questionHintList->getTableData();
89  $this->setData($tableData);
90 
91  if( $this->tableMode == self::TBL_MODE_ADMINISTRATION )
92  {
93  $this->setRowTemplate('tpl.tst_question_hints_administration_table_row.html', 'Modules/TestQuestionPool');
94 
95  $this->setSelectAllCheckbox('hint_ids[]');
96 
97  $rowCount = count($tableData);
98  $this->initAdministrationColumns($rowCount);
99  $this->initAdministrationCommands($rowCount);
100  }
101  else
102  {
103  $this->setRowTemplate('tpl.tst_question_hints_testoutput_table_row.html', 'Modules/TestQuestionPool');
104 
105  $this->initTestoutputColumns();
106  $this->initTestoutputCommands();
107  }
108  }
109 
119  private function initAdministrationCommands($rowCount)
120  {
121  global $ilCtrl, $lng;
122 
123  $this->setFormAction( $ilCtrl->getFormAction($this->parent_obj) );
124 
125  if( $this->hintOrderingClipboard->hasStored() )
126  {
127  $this->addMultiCommand(
129  $lng->txt('tst_questions_hints_table_multicmd_paste_hint_before')
130  );
131 
132  $this->addMultiCommand(
134  $lng->txt('tst_questions_hints_table_multicmd_paste_hint_after')
135  );
136  }
137  elseif( $rowCount > 0 )
138  {
139  $this->addMultiCommand(
141  $lng->txt('tst_questions_hints_table_multicmd_delete_hint')
142  );
143 
144  if( $rowCount > 1 ) $this->addMultiCommand(
146  $lng->txt('tst_questions_hints_table_multicmd_cut_hint')
147  );
148 
149  $this->addCommandButton(
151  $lng->txt('tst_questions_hints_table_cmd_save_order')
152  );
153  }
154  }
155 
164  private function initTestoutputCommands()
165  {
166  global $ilCtrl, $lng;
167 
168  $this->setFormAction( $ilCtrl->getFormAction($this->parent_obj) );
169 
170  $this->addCommandButton(
172  $lng->txt('tst_question_hints_back_to_question')
173  );
174  }
175 
184  private function initAdministrationColumns($rowCount)
185  {
186  global $lng;
187 
188  $this->addColumn( '', '', '30', true );
189 
190  $this->addColumn( $lng->txt('tst_question_hints_table_column_hint_order'), 'hint_index', '60');
191  $this->addColumn( $lng->txt('tst_question_hints_table_column_hint_text'), 'hint_text');
192  $this->addColumn( $lng->txt('tst_question_hints_table_column_hint_points'), 'hint_points', '250');
193 
194  $this->addColumn('', '', '100');
195 
196  $this->setDefaultOrderField("hint_index");
197  $this->setDefaultOrderDirection("asc");
198 
199  if( $rowCount < 1 )
200  {
201  $this->disable('header');
202  }
203  }
204 
212  private function initTestoutputColumns()
213  {
214  global $lng;
215 
216  $this->addColumn( $lng->txt('tst_question_hints_table_column_hint_index'), 'hint_index', '200');
217  $this->addColumn( $lng->txt('tst_question_hints_table_column_hint_text'), 'hint_text');
218  $this->addColumn( $lng->txt('tst_question_hints_table_column_hint_points'), 'hint_points', '200');
219 
220  $this->setDefaultOrderField("hint_index");
221  $this->setDefaultOrderDirection("asc");
222  }
223 
232  public function numericOrdering($field)
233  {
234  switch($field)
235  {
236  case 'hint_index':
237  case 'hint_points':
238 
239  return true;
240  }
241 
242  return false;
243  }
244 
253  public function fillRow($rowData)
254  {
255  global $ilCtrl, $lng;
256 
257  if( $this->tableMode == self::TBL_MODE_ADMINISTRATION )
258  {
259  $editHref = $ilCtrl->getLinkTargetByClass('ilAssQuestionHintGUI', ilAssQuestionHintGUI::CMD_SHOW_FORM);
260  $editHref = ilUtil::appendUrlParameterString($editHref, "hint_id={$rowData['hint_id']}", true);
261 
262  $deleteHref = $ilCtrl->getLinkTarget($this->parent_obj, ilAssQuestionHintsGUI::CMD_CONFIRM_DELETE);
263  $deleteHref = ilUtil::appendUrlParameterString($deleteHref, "hint_id={$rowData['hint_id']}", true);
264 
265  $list = new ilAdvancedSelectionListGUI();
266  $list->setListTitle($lng->txt('actions'));
267  $list->setId("advsl_hint_{$rowData['hint_id']}_actions");
268 
269  $list->addItem($lng->txt('tst_question_hints_table_link_edit_hint'), '', $editHref);
270  $list->addItem($lng->txt('tst_question_hints_table_link_delete_hint'), '', $deleteHref);
271 
272  $this->tpl->setVariable('ACTIONS', $list->getHTML());
273 
274  $this->tpl->setVariable('HINT_ID', $rowData['hint_id']);
275 
276  $hintIndex = $rowData['hint_index'] * self::INDEX_TO_POSITION_FACTOR;
277 
278  }
279  else
280  {
281  $showHref = $ilCtrl->getLinkTarget($this->parent_obj, ilAssQuestionHintRequestGUI::CMD_SHOW_HINT);
282  $showHref = ilUtil::appendUrlParameterString($showHref, "hintId={$rowData['hint_id']}", true);
283 
284  $this->tpl->setVariable('HINT_HREF', $showHref);
285 
286  $hintIndex = sprintf($lng->txt('tst_question_hints_index_column_label'), $rowData['hint_index']);
287  }
288 
289  $this->tpl->setVariable('HINT_INDEX', $hintIndex);
290  $this->tpl->setVariable('HINT_TEXT', $rowData['hint_text']);
291  $this->tpl->setVariable('HINT_POINTS', $rowData['hint_points']);
292  }
293 }
294