ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilTestRandomQuestionSetSourcePoolDefinitionListTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
33 {
35  public const IDENTIFIER = 'tstRndPools';
36  private bool $definitionEditModeEnabled = false;
37  private bool $questionAmountColumnEnabled = false;
38  private bool $showMappedTaxonomyFilter = false;
40 
41  public function __construct(
43  string $parent_cmd,
44  private ilAccess $access,
45  private UIFactory $ui_factory,
46  private UIRenderer $ui_renderer,
47  private array $defined_order,
48  private array $question_amount
49  ) {
50  parent::__construct($parent_obj, $parent_cmd);
51  }
52 
54  {
55  $this->taxonomyLabelTranslater = $translater;
56  }
57 
58  public function setDefinitionEditModeEnabled($definitionEditModeEnabled): void
59  {
60  $this->definitionEditModeEnabled = $definitionEditModeEnabled;
61  }
62 
63  public function isDefinitionEditModeEnabled(): bool
64  {
66  }
67 
68  public function setQuestionAmountColumnEnabled(bool $questionAmountColumnEnabled): void
69  {
70  $this->questionAmountColumnEnabled = $questionAmountColumnEnabled;
71  }
72 
73  public function isQuestionAmountColumnEnabled(): bool
74  {
76  }
77 
78  public function setShowMappedTaxonomyFilter(bool $showMappedTaxonomyFilter): void
79  {
80  $this->showMappedTaxonomyFilter = $showMappedTaxonomyFilter;
81  }
82 
83  public function fillRow(array $a_set): void
84  {
85  if ($this->isDefinitionEditModeEnabled()) {
86  $this->tpl->setCurrentBlock('col_selection_checkbox');
87  $this->tpl->setVariable('SELECTION_CHECKBOX_HTML', $this->getSelectionCheckboxHTML($a_set['def_id']));
88  $this->tpl->parseCurrentBlock();
89 
90  $this->tpl->setCurrentBlock('col_actions');
91  $this->tpl->setVariable('ACTIONS_HTML', $this->getActionsHTML($a_set['def_id']));
92  $this->tpl->parseCurrentBlock();
93 
94  $this->tpl->setCurrentBlock('col_order_checkbox');
95  $this->tpl->setVariable('ORDER_INPUT_HTML', $this->getDefinitionOrderInputHTML(
96  $a_set['def_id'],
97  $this->getOrderNumberForSequencePosition($a_set['sequence_position'])
98  ));
99  $this->tpl->parseCurrentBlock();
100  }
101  // fau: taxFilter/typeFilter - show sequence position to identify the filter in the database
102  else {
103  $this->tpl->setCurrentBlock('col_order_checkbox');
104  $this->tpl->setVariable('ORDER_INPUT_HTML', $a_set['sequence_position']);
105  $this->tpl->parseCurrentBlock();
106  }
107  // fau.
108 
109  if ($this->isQuestionAmountColumnEnabled()) {
110  if ($this->isDefinitionEditModeEnabled()) {
111  $questionAmountHTML = $this->getQuestionAmountInputHTML(
112  $a_set['def_id'],
113  $a_set['question_amount']
114  );
115  } else {
116  $questionAmountHTML = $a_set['question_amount'];
117  }
118 
119  $this->tpl->setCurrentBlock('col_question_amount');
120  $this->tpl->setVariable('QUESTION_AMOUNT_INPUT_HTML', $questionAmountHTML);
121  $this->tpl->parseCurrentBlock();
122  }
123 
124  $this->tpl->setVariable(
125  'SOURCE_POOL_LABEL',
126  $this->buildPossiblyLinkedQuestonPoolTitle(
127  $this->ctrl,
128  $this->access,
129  $this->lng,
130  $this->ui_factory,
131  $this->ui_renderer,
132  $a_set['ref_id'],
133  $a_set['source_pool_label'],
134  true
135  )
136  );
137  // fau: taxFilter/typeFilter - set taxonomy/type filter label in a single coulumn each
138 
139  $this->tpl->setVariable('TAXONOMY_FILTER', $this->taxonomyLabelTranslater->getTaxonomyFilterLabel($a_set['taxonomy_filter'], '<br />'));
140  $this->tpl->setVariable('LIFECYCLE_FILTER', $this->taxonomyLabelTranslater->getLifecycleFilterLabel($a_set['lifecycle_filter']));
141  $this->tpl->setVariable('TYPE_FILTER', $this->taxonomyLabelTranslater->getTypeFilterLabel($a_set['type_filter']));
142  // fau.
143  }
144 
145  private function getSelectionCheckboxHTML($sourcePoolDefinitionId): string
146  {
147  return '<input type="checkbox" value="' . $sourcePoolDefinitionId . '" name="src_pool_def_ids[]" />';
148  }
149 
150  private function getDefinitionOrderInputHTML($srcPoolDefId, $defOrderNumber): string
151  {
152  return '<input type="text" size="2" value="' . $defOrderNumber . '" name="def_order[' . $srcPoolDefId . ']" />';
153  }
154 
155  private function getQuestionAmountInputHTML($srcPoolDefId, $questionAmount): string
156  {
157  return '<input type="text" size="4" value="' . $questionAmount . '" name="quest_amount[' . $srcPoolDefId . ']" />';
158  }
159 
160  private function getActionsHTML($sourcePoolDefinitionId): string
161  {
162  $actions = [];
163  $actions[] = $this->ui_factory->link()->standard($this->lng->txt('edit'), $this->getEditHref($sourcePoolDefinitionId));
164  $actions[] = $this->ui_factory->link()->standard($this->lng->txt('delete'), $this->getDeleteHref($sourcePoolDefinitionId));
165  $dropdown = $this->ui_factory->dropdown()->standard($actions);
166  return $this->ui_renderer->render($dropdown);
167  }
168 
169  private function getEditHref($sourcePoolDefinitionId): string
170  {
171  $href = $this->ctrl->getLinkTarget(
172  $this->parent_obj,
174  );
175 
176  $href = ilUtil::appendUrlParameterString($href, "src_pool_def_id=" . $sourcePoolDefinitionId, true);
177 
178  return $href;
179  }
180 
181  private function getDeleteHref($sourcePoolDefinitionId): string
182  {
183  $href = $this->ctrl->getLinkTarget(
184  $this->parent_obj,
186  );
187 
188  $href = ilUtil::appendUrlParameterString($href, "src_pool_def_id=" . $sourcePoolDefinitionId, true);
189 
190  return $href;
191  }
192 
193  private function getOrderNumberForSequencePosition($sequencePosition)
194  {
195  return ($sequencePosition * 10);
196  }
197 
198  private function getTaxonomyTreeLabel($taxonomyTreeId)
199  {
200  if (!$taxonomyTreeId) {
201  return '';
202  }
203 
204  return $this->taxonomyLabelTranslater->getTaxonomyTreeLabel($taxonomyTreeId);
205  }
206 
207  private function getTaxonomyNodeLabel($taxonomyNodeId)
208  {
209  if (!$taxonomyNodeId) {
210  return '';
211  }
212 
213  return $this->taxonomyLabelTranslater->getTaxonomyNodeLabel($taxonomyNodeId);
214  }
215 
216  public function build(): void
217  {
218  $this->setTableIdentifiers();
219 
220  $this->setTitle($this->lng->txt('tst_src_quest_pool_def_list_table'));
221 
222  $this->setRowTemplate("tpl.il_tst_rnd_quest_set_src_pool_def_row.html", "Modules/Test");
223 
224  $this->enable('header');
225  $this->disable('sort');
226 
227  $this->enable('select_all');
228  $this->setSelectAllCheckbox('src_pool_def_ids[]');
229 
230  $this->setExternalSegmentation(true);
231  $this->setLimit(PHP_INT_MAX);
232 
233  $this->setFormAction($this->ctrl->getFormAction($this->parent_obj));
234 
235  $this->addCommands();
236  $this->addColumns();
237  }
238 
239  private function setTableIdentifiers(): void
240  {
241  $this->setId(self::IDENTIFIER);
242  $this->setPrefix(self::IDENTIFIER);
243  $this->setFormName(self::IDENTIFIER);
244  }
245 
246  private function addCommands(): void
247  {
248  if ($this->isDefinitionEditModeEnabled()) {
251  }
252  }
253 
254  private function addColumns(): void
255  {
256  if ($this->isDefinitionEditModeEnabled()) {
257  $this->addColumn('', 'select', '1%', true);
258  $this->addColumn('', 'order', '1%', true);
259  } else {
260  $this->addColumn($this->lng->txt("position"));
261  }
262 
263  $this->addColumn($this->lng->txt("tst_source_question_pool"), 'source_question_pool', '');
264  $this->addColumn($this->lng->txt("tst_filter_taxonomy") . ' / ' . $this->lng->txt("tst_filter_tax_node"), 'tst_filter_taxonomy', '');
265  #$this->addColumn($this->lng->txt("tst_filter_taxonomy"),'tst_filter_taxonomy', '');
266  #$this->addColumn($this->lng->txt("tst_filter_tax_node"),'tst_filter_tax_node', '');
267  $this->addColumn($this->lng->txt("qst_lifecycle"), 'tst_filter_lifecycle', '');
268  $this->addColumn($this->lng->txt("tst_filter_question_type"), 'tst_filter_question_type', '');
269 
270  if ($this->isQuestionAmountColumnEnabled()) {
271  $this->addColumn($this->lng->txt("tst_question_amount"), 'tst_question_amount', '');
272  }
273 
274  if ($this->isDefinitionEditModeEnabled()) {
275  $this->addColumn($this->lng->txt("actions"), 'actions', '');
276  }
277  }
278 
279  public function init(ilTestRandomQuestionSetSourcePoolDefinitionList $sourcePoolDefinitionList): void
280  {
281  $rows = array();
282 
283  foreach ($sourcePoolDefinitionList as $sourcePoolDefinition) {
286  $set = array();
287 
288  $set['def_id'] = $sourcePoolDefinition->getId();
289  $set['sequence_position'] = $sourcePoolDefinition->getSequencePosition();
290  $set['source_pool_label'] = $sourcePoolDefinition->getPoolTitle();
291  // fau: taxFilter/typeFilter - get the type and taxonomy filter for display
292  if ($this->showMappedTaxonomyFilter) {
293  // mapped filter will be used after synchronisation
294  $set['taxonomy_filter'] = $sourcePoolDefinition->getMappedTaxonomyFilter();
295  } else {
296  // original filter will be used before synchronisation
297  $set['taxonomy_filter'] = $sourcePoolDefinition->getOriginalTaxonomyFilter();
298  }
299  #$set['filter_taxonomy'] = $sourcePoolDefinition->getMappedFilterTaxId();
300  #$set['filter_tax_node'] = $sourcePoolDefinition->getMappedFilterTaxNodeId();
301  $set['lifecycle_filter'] = $sourcePoolDefinition->getLifecycleFilter();
302  $set['type_filter'] = $sourcePoolDefinition->getTypeFilter();
303  // fau.
304  $set['question_amount'] = $sourcePoolDefinition->getQuestionAmount();
305  $set['ref_id'] = $sourcePoolDefinition->getPoolRefId();
306  $rows[] = $set;
307  }
308 
309  $this->setData($rows);
310  }
311 
312  public function applySubmit(ilTestRandomQuestionSetSourcePoolDefinitionList $sourcePoolDefinitionList): void
313  {
314  foreach ($sourcePoolDefinitionList as $sourcePoolDefinition) {
317  $orderNumber = $this->fetchOrderNumberParameter($sourcePoolDefinition);
318  $sourcePoolDefinition->setSequencePosition($orderNumber);
319 
320  if ($this->isQuestionAmountColumnEnabled()) {
321  $questionAmount = $this->fetchQuestionAmountParameter($sourcePoolDefinition);
322  $sourcePoolDefinition->setQuestionAmount($questionAmount);
323  } else {
324  $sourcePoolDefinition->setQuestionAmount(null);
325  }
326  }
327  }
328 
330  {
331  return array_key_exists($definition->getId(), $this->defined_order) ? (int) $this->defined_order[$definition->getId()] : 0;
332  }
333 
335  {
336  return array_key_exists($definition->getId(), $this->question_amount) ? (int) $this->question_amount[$definition->getId()] : 0;
337  }
338 }
setData(array $a_data)
static appendUrlParameterString(string $a_url, string $a_par, bool $xml_style=false)
enable(string $a_module_name)
setFormAction(string $a_form_action, bool $a_multipart=false)
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
setFormName(string $a_name="")
setId(string $a_val)
__construct(ilTestRandomQuestionSetConfigGUI $parent_obj, string $parent_cmd, private ilAccess $access, private UIFactory $ui_factory, private UIRenderer $ui_renderer, private array $defined_order, private array $question_amount)
__construct(VocabulariesInterface $vocabularies)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
setLimit(int $a_limit=0, int $a_default_limit=0)
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)
disable(string $a_module_name)
addMultiCommand(string $a_cmd, string $a_text)
setExternalSegmentation(bool $a_val)
setPrefix(string $a_prefix)