ILIAS  release_7 Revision v7.30-3-g800a261c036
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(
67  ilAssQuestionHintList $questionHintList,
69  $parentCmd,
70  $tableMode = self::TBL_MODE_TESTOUTPUT,
72  ) {
73  global $DIC;
74  $ilCtrl = $DIC['ilCtrl'];
75  $lng = $DIC['lng'];
76 
77  $this->questionOBJ = $questionOBJ;
78  $this->tableMode = $tableMode;
79  $this->hintOrderingClipboard = $hintOrderingClipboard;
80 
81  $this->setPrefix('tsthints' . $tableMode);
82  $this->setId('tsthints' . $tableMode);
83 
84  parent::__construct($parentGUI, $parentCmd);
85 
86  $this->setTitle(sprintf($lng->txt('tst_question_hints_table_header'), $questionOBJ->getTitle()));
87  $this->setNoEntriesText($lng->txt('tst_question_hints_table_no_items'));
88 
89  // we don't take care about offset/limit values, so this avoids segmentation in general
90  // --> required for ordering via clipboard feature
91  $this->setExternalSegmentation(true);
92 
93  $tableData = $questionHintList->getTableData();
94 
95  if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
96  require_once 'Modules/TestQuestionPool/classes/class.ilAssHintPageGUI.php';
97 
98  foreach ($tableData as $key => $data) {
99  $this->ensurePageObjectExists('qht', $data['hint_id']);
100  $pageObjectGUI = new ilAssHintPageGUI($data['hint_id']);
101  $pageObjectGUI->setOutputMode("presentation");
102  $tableData[$key]['hint_text'] = $pageObjectGUI->presentation();
103  }
104  }
105 
106  $this->setData($tableData);
107 
108  if ($this->tableMode == self::TBL_MODE_ADMINISTRATION) {
109  $this->setRowTemplate('tpl.tst_question_hints_administration_table_row.html', 'Modules/TestQuestionPool');
110 
111  $this->setSelectAllCheckbox('hint_ids[]');
112 
113  $rowCount = count($tableData);
114  $this->initAdministrationColumns($rowCount);
115  $this->initAdministrationCommands($rowCount);
116  } else {
117  $this->setRowTemplate('tpl.tst_question_hints_testoutput_table_row.html', 'Modules/TestQuestionPool');
118 
119  $this->initTestoutputColumns();
120  $this->initTestoutputCommands();
121  }
122  }
123 
133  private function initAdministrationCommands($rowCount)
134  {
135  global $DIC;
136  $ilCtrl = $DIC['ilCtrl'];
137  $lng = $DIC['lng'];
138 
139  $this->setFormAction($ilCtrl->getFormAction($this->parent_obj));
140 
141  if ($this->hintOrderingClipboard->hasStored()) {
142  $this->addMultiCommand(
144  $lng->txt('tst_questions_hints_table_multicmd_paste_hint_before')
145  );
146 
147  $this->addMultiCommand(
149  $lng->txt('tst_questions_hints_table_multicmd_paste_hint_after')
150  );
151  } elseif ($rowCount > 0) {
152  $this->addMultiCommand(
154  $lng->txt('tst_questions_hints_table_multicmd_delete_hint')
155  );
156 
157  if ($rowCount > 1) {
158  $this->addMultiCommand(
160  $lng->txt('tst_questions_hints_table_multicmd_cut_hint')
161  );
162  }
163 
164  $this->addCommandButton(
166  $lng->txt('tst_questions_hints_table_cmd_save_order')
167  );
168  }
169  }
170 
179  private function initTestoutputCommands()
180  {
181  if ($this->parent_obj instanceof ilAssQuestionHintsGUI) {
182  return;
183  }
184 
185  global $DIC;
186  $ilCtrl = $DIC['ilCtrl'];
187  $lng = $DIC['lng'];
188 
189  $this->setFormAction($ilCtrl->getFormAction($this->parent_obj));
190 
191  $this->addCommandButton(
193  $lng->txt('tst_question_hints_back_to_question')
194  );
195  }
196 
205  private function initAdministrationColumns($rowCount)
206  {
207  global $DIC;
208  $lng = $DIC['lng'];
209 
210  $this->addColumn('', '', '30', true);
211 
212  $this->addColumn($lng->txt('tst_question_hints_table_column_hint_order'), 'hint_index', '60');
213  $this->addColumn($lng->txt('tst_question_hints_table_column_hint_text'), 'hint_text');
214  $this->addColumn($lng->txt('tst_question_hints_table_column_hint_points'), 'hint_points', '250');
215 
216  $this->addColumn('', '', '100');
217 
218  $this->setDefaultOrderField("hint_index");
219  $this->setDefaultOrderDirection("asc");
220 
221  if ($rowCount < 1) {
222  $this->disable('header');
223  }
224  }
225 
233  private function initTestoutputColumns()
234  {
235  global $DIC;
236  $lng = $DIC['lng'];
237 
238  $this->addColumn($lng->txt('tst_question_hints_table_column_hint_index'), 'hint_index', '200');
239  $this->addColumn($lng->txt('tst_question_hints_table_column_hint_text'), 'hint_text');
240  $this->addColumn($lng->txt('tst_question_hints_table_column_hint_points'), 'hint_points', '200');
241 
242  $this->setDefaultOrderField("hint_index");
243  $this->setDefaultOrderDirection("asc");
244  }
245 
254  public function numericOrdering($field)
255  {
256  switch ($field) {
257  case 'hint_index':
258  case 'hint_points':
259 
260  return true;
261  }
262 
263  return false;
264  }
265 
274  public function fillRow($rowData)
275  {
276  global $DIC;
277  $ilCtrl = $DIC['ilCtrl'];
278  $lng = $DIC['lng'];
279 
280  if ($this->tableMode == self::TBL_MODE_ADMINISTRATION) {
281  $list = new ilAdvancedSelectionListGUI();
282  $list->setListTitle($lng->txt('actions'));
283  $list->setId("advsl_hint_{$rowData['hint_id']}_actions");
284 
285  if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
286  $editPointsHref = $ilCtrl->getLinkTargetByClass('ilAssQuestionHintGUI', ilAssQuestionHintGUI::CMD_SHOW_FORM);
287  $editPointsHref = ilUtil::appendUrlParameterString($editPointsHref, "hint_id={$rowData['hint_id']}", true);
288  $list->addItem($lng->txt('tst_question_hints_table_link_edit_hint_points'), '', $editPointsHref);
289 
290  $editPageHref = $ilCtrl->getLinkTargetByClass('ilasshintpagegui', 'edit');
291  $editPageHref = ilUtil::appendUrlParameterString($editPageHref, "hint_id={$rowData['hint_id']}", true);
292  $list->addItem($lng->txt('tst_question_hints_table_link_edit_hint_page'), '', $editPageHref);
293  } else {
294  $editHref = $ilCtrl->getLinkTargetByClass('ilAssQuestionHintGUI', ilAssQuestionHintGUI::CMD_SHOW_FORM);
295  $editHref = ilUtil::appendUrlParameterString($editHref, "hint_id={$rowData['hint_id']}", true);
296  $list->addItem($lng->txt('tst_question_hints_table_link_edit_hint'), '', $editHref);
297  }
298 
299  $deleteHref = $ilCtrl->getLinkTarget($this->parent_obj, ilAssQuestionHintsGUI::CMD_CONFIRM_DELETE);
300  $deleteHref = ilUtil::appendUrlParameterString($deleteHref, "hint_id={$rowData['hint_id']}", true);
301  $list->addItem($lng->txt('tst_question_hints_table_link_delete_hint'), '', $deleteHref);
302 
303  $this->tpl->setVariable('ACTIONS', $list->getHTML());
304 
305  $this->tpl->setVariable('HINT_ID', $rowData['hint_id']);
306 
307  $hintIndex = $rowData['hint_index'] * self::INDEX_TO_POSITION_FACTOR;
308  } else {
309  $showHref = $this->parent_obj->getHintPresentationLinkTarget($rowData['hint_id']);
310 
311  $this->tpl->setVariable('HINT_HREF', $showHref);
312 
313  $hintIndex = ilAssQuestionHint::getHintIndexLabel($lng, $rowData['hint_index']);
314  }
315 
316  $this->tpl->setVariable('HINT_INDEX', $hintIndex);
317  $txt = ilUtil::prepareTextareaOutput($rowData['hint_text'], true);
318  $this->tpl->setVariable('HINT_TEXT', $txt);
319  $this->tpl->setVariable('HINT_POINTS', $rowData['hint_points']);
320  }
321 
322  protected function ensurePageObjectExists($pageObjectType, $pageObjectId) : void
323  {
324  if (!ilAssHintPage::_exists($pageObjectType, $pageObjectId)) {
325  $pageObject = new ilAssHintPage();
326  $pageObject->setParentId($this->questionOBJ->getId());
327  $pageObject->setId($pageObjectId);
328  $pageObject->createFromXML();
329  }
330  }
331 }
const INDEX_TO_POSITION_FACTOR
the factor the ordering position value is multiplicated with (so the user gets non decimal gaps for r...
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
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.
static prepareTextareaOutput($txt_output, $prepare_for_latex_output=false, $omitNl2BrWhenTextArea=false)
Prepares a string for a text area output where latex code may be in it If the text is HTML-free...
setExternalSegmentation($a_val)
Set external segmentation.
initAdministrationColumns($rowCount)
inits the required columns for administration table mode
ensurePageObjectExists($pageObjectType, $pageObjectId)
setNoEntriesText($a_text)
Set text for an empty table.
setId($a_val)
Set id.
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
Assessment hint page object.
const TBL_MODE_TESTOUTPUT
the available table modes controlling the tables behaviour
setSelectAllCheckbox($a_select_all_checkbox, $a_select_all_on_top=false)
Set the name of the checkbox that should be toggled with a select all button.
initTestoutputColumns()
inits the required columns for testoutput table mode
Assessment hint page GUI class.
global $DIC
Definition: goto.php:24
addMultiCommand($a_cmd, $a_text)
Add Command button.
setPrefix($a_prefix)
$txt
Definition: error.php:13
setRowTemplate($a_template, $a_template_dir="")
Set row template.
const CMD_SHOW_FORM
command constants
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
disable($a_module_name)
diesables particular modules of table
__construct(Container $dic, ilPlugin $plugin)
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.
initAdministrationCommands($rowCount)
inits the required command buttons / multi selection commands for administration table mode ...
getTitle()
Gets the title string of the assQuestion object.
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 ...