ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilAssQuestionHintsTableGUI.php
Go to the documentation of this file.
1 <?php
2 
28 {
33  public const INDEX_TO_POSITION_FACTOR = 10;
34 
38  public const TBL_MODE_TESTOUTPUT = '1';
39  public const TBL_MODE_ADMINISTRATION = '2';
40 
47  private $questionOBJ = null;
48 
55  private $tableMode = null;
56 
57  private $hintOrderingClipboard = null;
58  private \ILIAS\DI\UIServices $ui;
59 
71  public function __construct(
73  ilAssQuestionHintList $questionHintList,
75  $parentCmd,
76  $tableMode = self::TBL_MODE_TESTOUTPUT,
78  ) {
79  global $DIC;
80  $lng = $DIC['lng'];
81  $this->ui = $DIC->ui();
82 
83  $this->questionOBJ = $questionOBJ;
84  $this->tableMode = $tableMode;
85  $this->hintOrderingClipboard = $hintOrderingClipboard;
86 
87  $this->setPrefix('tsthints' . $tableMode);
88  $this->setId('tsthints' . $tableMode);
89 
90  parent::__construct($parentGUI, $parentCmd);
91 
92  $this->setTitle(sprintf($lng->txt('tst_question_hints_table_header'), $questionOBJ->getTitleForHTMLOutput()));
93  $this->setNoEntriesText($lng->txt('tst_question_hints_table_no_items'));
94 
95  // we don't take care about offset/limit values, so this avoids segmentation in general
96  // --> required for ordering via clipboard feature
97  $this->setExternalSegmentation(true);
98 
99  $tableData = $questionHintList->getTableData();
100 
101  if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
102  foreach ($tableData as $key => $data) {
103  $this->questionOBJ->ensureHintPageObjectExists($data['hint_id']);
104  $pageObjectGUI = new ilAssHintPageGUI($data['hint_id']);
105  $pageObjectGUI->setOutputMode("presentation");
106  $tableData[$key]['hint_text'] = $pageObjectGUI->presentation();
107  }
108  }
109 
110  $this->setData($tableData);
111 
112  if ($this->tableMode == self::TBL_MODE_ADMINISTRATION) {
113  $this->setRowTemplate('tpl.tst_question_hints_administration_table_row.html', 'Modules/TestQuestionPool');
114 
115  $this->setSelectAllCheckbox('hint_ids[]');
116 
117  $rowCount = count($tableData);
118  $this->initAdministrationColumns($rowCount);
119  $this->initAdministrationCommands($rowCount);
120  } else {
121  $this->setRowTemplate('tpl.tst_question_hints_testoutput_table_row.html', 'Modules/TestQuestionPool');
122 
123  $this->initTestoutputColumns();
124  $this->initTestoutputCommands();
125  }
126  }
127 
137  private function initAdministrationCommands($rowCount): void
138  {
139  global $DIC;
140  $ilCtrl = $DIC['ilCtrl'];
141  $lng = $DIC['lng'];
142 
143  $this->setFormAction($ilCtrl->getFormAction($this->parent_obj));
144 
145  if ($this->hintOrderingClipboard->hasStored()) {
146  $this->addMultiCommand(
148  $lng->txt('tst_questions_hints_table_multicmd_paste_hint_before')
149  );
150 
151  $this->addMultiCommand(
153  $lng->txt('tst_questions_hints_table_multicmd_paste_hint_after')
154  );
155  } elseif ($rowCount > 0) {
156  $this->addMultiCommand(
158  $lng->txt('tst_questions_hints_table_multicmd_delete_hint')
159  );
160 
161  if ($rowCount > 1) {
162  $this->addMultiCommand(
164  $lng->txt('tst_questions_hints_table_multicmd_cut_hint')
165  );
166  }
167 
168  $this->addCommandButton(
170  $lng->txt('tst_questions_hints_table_cmd_save_order')
171  );
172  }
173  }
174 
183  private function initTestoutputCommands(): void
184  {
185  if ($this->parent_obj instanceof ilAssQuestionHintsGUI) {
186  return;
187  }
188 
189  global $DIC;
190  $ilCtrl = $DIC['ilCtrl'];
191  $lng = $DIC['lng'];
192 
193  $this->setFormAction($ilCtrl->getFormAction($this->parent_obj));
194 
195  $this->addCommandButton(
197  $lng->txt('tst_question_hints_back_to_question')
198  );
199  }
200 
209  private function initAdministrationColumns($rowCount): void
210  {
211  global $DIC;
212  $lng = $DIC['lng'];
213 
214  $this->addColumn('', '', '30', true);
215 
216  $this->addColumn($lng->txt('tst_question_hints_table_column_hint_order'), 'hint_index', '60');
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', '250');
219 
220  $this->addColumn('', '', '100');
221 
222  $this->setDefaultOrderField("hint_index");
223  $this->setDefaultOrderDirection("asc");
224 
225  if ($rowCount < 1) {
226  $this->disable('header');
227  }
228  }
229 
237  private function initTestoutputColumns(): void
238  {
239  global $DIC;
240  $lng = $DIC['lng'];
241 
242  $this->addColumn($lng->txt('tst_question_hints_table_column_hint_index'), 'hint_index', '200');
243  $this->addColumn($lng->txt('tst_question_hints_table_column_hint_text'), 'hint_text');
244  $this->addColumn($lng->txt('tst_question_hints_table_column_hint_points'), 'hint_points', '200');
245 
246  $this->setDefaultOrderField("hint_index");
247  $this->setDefaultOrderDirection("asc");
248  }
249 
257  public function numericOrdering(string $a_field): bool
258  {
259  switch ($a_field) {
260  case 'hint_index':
261  case 'hint_points':
262 
263  return true;
264  }
265 
266  return false;
267  }
268 
276  public function fillRow(array $a_set): void
277  {
278  global $DIC;
279  $ilCtrl = $DIC['ilCtrl'];
280  $lng = $DIC['lng'];
281 
282  if ($this->tableMode == self::TBL_MODE_ADMINISTRATION) {
283  $actions = [];
284 
285  if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
286  $actions[] = $this->ui->factory()->button()->shy(
287  $lng->txt('tst_question_hints_table_link_edit_hint_points'),
289  $ilCtrl->getLinkTargetByClass('ilAssQuestionHintGUI', ilAssQuestionHintGUI::CMD_SHOW_FORM),
290  "hint_id={$a_set['hint_id']}",
291  true
292  )
293  );
294 
295  $actions[] = $this->ui->factory()->button()->shy(
296  $lng->txt('tst_question_hints_table_link_edit_hint_page'),
298  $ilCtrl->getLinkTargetByClass('ilasshintpagegui', 'edit'),
299  "hint_id={$a_set['hint_id']}",
300  true
301  )
302  );
303  } else {
304  $actions[] = $this->ui->factory()->button()->shy(
305  $lng->txt('tst_question_hints_table_link_edit_hint'),
307  $ilCtrl->getLinkTargetByClass('ilAssQuestionHintGUI', ilAssQuestionHintGUI::CMD_SHOW_FORM),
308  "hint_id={$a_set['hint_id']}",
309  true
310  )
311  );
312  }
313 
314  $actions[] = $this->ui->factory()->button()->shy(
315  $lng->txt('tst_question_hints_table_link_delete_hint'),
317  $ilCtrl->getLinkTarget($this->parent_obj, ilAssQuestionHintsGUI::CMD_CONFIRM_DELETE),
318  "hint_id={$a_set['hint_id']}",
319  true
320  )
321  );
322 
323  $list = $this->ui->factory()->dropdown()->standard($actions)->withLabel($lng->txt('actions'));
324 
325  $this->tpl->setVariable('ACTIONS', $this->ui->renderer()->render($list));
326  $this->tpl->setVariable('HINT_ID', $a_set['hint_id']);
327  $hintIndex = $a_set['hint_index'] * self::INDEX_TO_POSITION_FACTOR;
328 
329  } else {
330  $showHref = $this->parent_obj->getHintPresentationLinkTarget($a_set['hint_id']);
331 
332  $this->tpl->setVariable('HINT_HREF', $showHref);
333 
334  $hintIndex = ilAssQuestionHint::getHintIndexLabel($lng, $a_set['hint_index']);
335  }
336 
337  $this->tpl->setVariable('HINT_INDEX', $hintIndex);
338  $txt = ilLegacyFormElementsUtil::prepareTextareaOutput($a_set['hint_text'], true);
339  $this->tpl->setVariable('HINT_TEXT', $txt);
340  $this->tpl->setVariable('HINT_POINTS', $a_set['hint_points']);
341  }
342 }
const INDEX_TO_POSITION_FACTOR
the factor the ordering position value is multiplicated with (so the user gets non decimal gaps for r...
setNoEntriesText(string $a_text)
setData(array $a_data)
static appendUrlParameterString(string $a_url, string $a_par, bool $xml_style=false)
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
setFormAction(string $a_form_action, bool $a_multipart=false)
Abstract basic class which is to be extended by the concrete assessment question type classes...
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
__construct(assQuestion $questionOBJ, ilAssQuestionHintList $questionHintList, ilAssQuestionHintAbstractGUI $parentGUI, $parentCmd, $tableMode=self::TBL_MODE_TESTOUTPUT, ilAssQuestionHintsOrderingClipboard $hintOrderingClipboard=null)
Constructor.
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
initAdministrationColumns($rowCount)
inits the required columns for administration table mode
ilLanguage $lng
setId(string $a_val)
global $DIC
Definition: feed.php:28
static getHintIndexLabel(ilLanguage $lng, $hintIndex)
__construct(VocabulariesInterface $vocabularies)
const TBL_MODE_TESTOUTPUT
the available table modes controlling the tables behaviour
setDefaultOrderField(string $a_defaultorderfield)
initTestoutputColumns()
inits the required columns for testoutput table mode
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
string $key
Consumer key/client ID value.
Definition: System.php:193
setDefaultOrderDirection(string $a_defaultorderdirection)
fillRow(array $a_set)
renders a table row by filling wor data to table row template public
$txt
Definition: error.php:14
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
const CMD_SHOW_FORM
command constants
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
initAdministrationCommands($rowCount)
inits the required command buttons / multi selection commands for administration table mode ...
disable(string $a_module_name)
numericOrdering(string $a_field)
returns the fact wether the passed field is to be ordered numerically or not public ...
static prepareTextareaOutput(string $txt_output, bool $prepare_for_latex_output=false, bool $omitNl2BrWhenTextArea=false)
Prepares a string for a text area output where latex code may be in it If the text is HTML-free...
addMultiCommand(string $a_cmd, string $a_text)
initTestoutputCommands()
inits the required command buttons / multi selection commands for testoutput table mode ...
getTableData()
returns an array with data of the hints in this list that is adopted to be used as table gui data ...
setExternalSegmentation(bool $a_val)
setPrefix(string $a_prefix)