ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  if( $this->parent_obj instanceof ilAssQuestionHintsGUI )
179  {
180  return;
181  }
182 
183  global $ilCtrl, $lng;
184 
185  $this->setFormAction( $ilCtrl->getFormAction($this->parent_obj) );
186 
187  $this->addCommandButton(
189  $lng->txt('tst_question_hints_back_to_question')
190  );
191  }
192 
201  private function initAdministrationColumns($rowCount)
202  {
203  global $lng;
204 
205  $this->addColumn( '', '', '30', true );
206 
207  $this->addColumn( $lng->txt('tst_question_hints_table_column_hint_order'), 'hint_index', '60');
208  $this->addColumn( $lng->txt('tst_question_hints_table_column_hint_text'), 'hint_text');
209  $this->addColumn( $lng->txt('tst_question_hints_table_column_hint_points'), 'hint_points', '250');
210 
211  $this->addColumn('', '', '100');
212 
213  $this->setDefaultOrderField("hint_index");
214  $this->setDefaultOrderDirection("asc");
215 
216  if( $rowCount < 1 )
217  {
218  $this->disable('header');
219  }
220  }
221 
229  private function initTestoutputColumns()
230  {
231  global $lng;
232 
233  $this->addColumn( $lng->txt('tst_question_hints_table_column_hint_index'), 'hint_index', '200');
234  $this->addColumn( $lng->txt('tst_question_hints_table_column_hint_text'), 'hint_text');
235  $this->addColumn( $lng->txt('tst_question_hints_table_column_hint_points'), 'hint_points', '200');
236 
237  $this->setDefaultOrderField("hint_index");
238  $this->setDefaultOrderDirection("asc");
239  }
240 
249  public function numericOrdering($field)
250  {
251  switch($field)
252  {
253  case 'hint_index':
254  case 'hint_points':
255 
256  return true;
257  }
258 
259  return false;
260  }
261 
270  public function fillRow($rowData)
271  {
272  global $ilCtrl, $lng;
273 
274  if( $this->tableMode == self::TBL_MODE_ADMINISTRATION )
275  {
276  $list = new ilAdvancedSelectionListGUI();
277  $list->setListTitle($lng->txt('actions'));
278  $list->setId("advsl_hint_{$rowData['hint_id']}_actions");
279 
280  if( $this->questionOBJ->isAdditionalContentEditingModePageObject() )
281  {
282  $editPointsHref = $ilCtrl->getLinkTargetByClass('ilAssQuestionHintGUI', ilAssQuestionHintGUI::CMD_SHOW_FORM);
283  $editPointsHref = ilUtil::appendUrlParameterString($editPointsHref, "hint_id={$rowData['hint_id']}", true);
284  $list->addItem($lng->txt('tst_question_hints_table_link_edit_hint_points'), '', $editPointsHref);
285 
286  $editPageHref = $ilCtrl->getLinkTargetByClass('ilasshintpagegui', 'edit');
287  $editPageHref = ilUtil::appendUrlParameterString($editPageHref, "hint_id={$rowData['hint_id']}", true);
288  $list->addItem($lng->txt('tst_question_hints_table_link_edit_hint_page'), '', $editPageHref);
289  }
290  else
291  {
292  $editHref = $ilCtrl->getLinkTargetByClass('ilAssQuestionHintGUI', ilAssQuestionHintGUI::CMD_SHOW_FORM);
293  $editHref = ilUtil::appendUrlParameterString($editHref, "hint_id={$rowData['hint_id']}", true);
294  $list->addItem($lng->txt('tst_question_hints_table_link_edit_hint'), '', $editHref);
295  }
296 
297  $deleteHref = $ilCtrl->getLinkTarget($this->parent_obj, ilAssQuestionHintsGUI::CMD_CONFIRM_DELETE);
298  $deleteHref = ilUtil::appendUrlParameterString($deleteHref, "hint_id={$rowData['hint_id']}", true);
299  $list->addItem($lng->txt('tst_question_hints_table_link_delete_hint'), '', $deleteHref);
300 
301  $this->tpl->setVariable('ACTIONS', $list->getHTML());
302 
303  $this->tpl->setVariable('HINT_ID', $rowData['hint_id']);
304 
305  $hintIndex = $rowData['hint_index'] * self::INDEX_TO_POSITION_FACTOR;
306 
307  }
308  else
309  {
310 
311  $showHref = $this->parent_obj->getHintPresentationLinkTarget($rowData['hint_id']);
312 
313  $this->tpl->setVariable('HINT_HREF', $showHref);
314 
315  $hintIndex = ilAssQuestionHint::getHintIndexLabel($lng, $rowData['hint_index']);
316  }
317 
318  $this->tpl->setVariable('HINT_INDEX', $hintIndex);
319  $this->tpl->setVariable('HINT_TEXT', $rowData['hint_text']);
320  $this->tpl->setVariable('HINT_POINTS', $rowData['hint_points']);
321  }
322 }
323 
const INDEX_TO_POSITION_FACTOR
the factor the ordering position value is multiplicated with (so the user gets non decimal gaps for r...
addCommandButton($a_cmd, $a_text, $a_onclick='', $a_id="", $a_class=null)
Add Command button.
numericOrdering($field)
returns the fact wether the passed field is to be ordered numerically or not
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
Abstract basic class which is to be extended by the concrete assessment question type classes...
__construct(assQuestion $questionOBJ, ilAssQuestionHintList $questionHintList, ilAssQuestionHintAbstractGUI $parentGUI, $parentCmd, $tableMode=self::TBL_MODE_TESTOUTPUT, ilAssQuestionHintsOrderingClipboard $hintOrderingClipboard=null)
Constructor.
setExternalSegmentation($a_val)
Set external segmentation.
initAdministrationColumns($rowCount)
inits the required columns for administration table mode
setNoEntriesText($a_text)
Set text for an empty table.
setId($a_val)
Set id.
global $ilCtrl
Definition: ilias.php:18
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
static getHintIndexLabel(ilLanguage $lng, $hintIndex)
static appendUrlParameterString($a_url, $a_par, $xml_style=false)
append URL parameter string ("par1=value1&par2=value2...") to given URL string
const TBL_MODE_TESTOUTPUT
the available table modes controlling the tables behaviour
Class ilTable2GUI.
initTestoutputColumns()
inits the required columns for testoutput table mode
Assessment hint page GUI class.
addMultiCommand($a_cmd, $a_text)
Add Command button.
setPrefix($a_prefix)
setRowTemplate($a_template, $a_template_dir="")
Set row template.
const CMD_SHOW_FORM
command constants
User interface class for advanced drop-down selection lists.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
disable($a_module_name)
diesables particular modules of table
global $lng
Definition: privfeed.php:17
initAdministrationCommands($rowCount)
inits the required command buttons / multi selection commands for administration table mode ...
getTitle()
Gets the title string of the assQuestion object.
setSelectAllCheckbox($a_select_all_checkbox)
Set the name of the checkbox that should be toggled with a select all button.
addColumn($a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
initTestoutputCommands()
inits the required command buttons / multi selection commands for testoutput table mode ...
fillRow($rowData)
renders a table row by filling wor data to table row template
getTableData()
returns an array with data of the hints in this list that is adopted to be used as table gui data ...