ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
RandomQuestionSetSourcePoolDefinitionListTable.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Test\Questions;
22 
24 use ILIAS\Data\URI;
33 use ilTestRandomQuestionSetSourcePoolDefinitionList as PoolDefinitionList;
36 
38 {
39  private URI $target;
42 
43  public function __construct(
44  private readonly \ilCtrlInterface $ctrl,
45  private readonly \ilLanguage $lng,
46  private readonly UIFactory $ui_factory,
47  private readonly DataFactory $data_factory,
48  private readonly ServerRequestInterface $request,
49  private readonly TitleColumnsBuilder $title_builder,
50  private readonly \ilTestQuestionFilterLabelTranslator $taxonomy_translator,
51  private readonly PoolDefinitionList $source_pool_definition_list,
52  private readonly bool $editable,
53  private readonly bool $show_amount
54  ) {
55  $this->target = $this->data_factory->uri((string) $this->request->getUri());
56  $this->url_builder = new URLBuilder($this->target);
57  [$this->url_builder, $this->id_token] = $this->url_builder->acquireParameters(
58  ['src_pool_def'],
59  'id'
60  );
61  }
62 
63  public function getRows(OrderingRowBuilder $row_builder, array $visible_column_ids): \Generator
64  {
65  foreach ($this->getData() as $qp) {
66  $record = [
67  'sequence_position' => (int) $qp['sequence_position'],
68  'source_pool_label' => $this->title_builder->buildAccessCheckedQuestionpoolTitleAsLink(
69  $qp['pool_id'],
70  $qp['source_pool_label']
71  ),
72  'taxonomy_filter' => $this->taxonomy_translator->getTaxonomyFilterLabel(
73  $qp['taxonomy_filter'],
74  '<br />'
75  ),
76  'lifecycle_filter' => $this->taxonomy_translator->getLifecycleFilterLabel($qp['lifecycle_filter']),
77  'type_filter' => $this->taxonomy_translator->getTypeFilterLabel($qp['type_filter']),
78  'question_amount' => (int) $qp['question_amount']
79  ];
80  yield $row_builder->buildOrderingRow((string) $qp['def_id'], $record);
81  }
82  }
83 
84  private function getData(): array
85  {
86  $data = [];
87 
88  foreach ($this->source_pool_definition_list as $source_pool_definition) {
89  $taxonomie_filter = $source_pool_definition->getOriginalTaxonomyFilter();
90  if ($taxonomie_filter === []) {
91  $taxonomie_filter = $source_pool_definition->getMappedTaxonomyfilter();
92  }
93  $set = [];
94  $set['def_id'] = $source_pool_definition->getId();
95  $set['sequence_position'] = $source_pool_definition->getSequencePosition();
96  $set['source_pool_label'] = $source_pool_definition->getPoolTitle();
97  $set['taxonomy_filter'] = $taxonomie_filter;
98  $set['lifecycle_filter'] = $source_pool_definition->getLifecycleFilter();
99  $set['type_filter'] = $source_pool_definition->getTypeFilter();
100  // fau.
101  $set['question_amount'] = $source_pool_definition->getQuestionAmount();
102  $set['pool_id'] = $source_pool_definition->getPoolId();
103  $data[] = $set;
104  }
105 
106  usort($data, fn($a, $b) => $a['sequence_position'] <=> $b['sequence_position']);
107  return $data;
108  }
109 
110  public function getComponent(): OrderingTable
111  {
112  return $this->ui_factory->table()
113  ->ordering(
114  $this,
115  $this->getTarget(ConfigGUI::CMD_SAVE_SRC_POOL_DEF_LIST),
116  $this->lng->txt('tst_src_quest_pool_def_list_table'),
117  $this->getColumns(),
118  )
119  ->withActions($this->getActions())
120  ->withRequest($this->request)
121  ->withOrderingDisabled(!$this->editable)
122  ->withId('src_pool_def_list');
123  }
124 
125  public function applySubmit(RequestDataCollector $request): void
126  {
127  $quest_pos = array_flip($this->getComponent()->getData());
128 
129  foreach ($this->source_pool_definition_list as $source_pool_definition) {
130  $pool_id = $source_pool_definition->getId();
131  $sequence_pos = array_key_exists($pool_id, $quest_pos) ? $quest_pos[$pool_id] : 0;
132  $source_pool_definition->setSequencePosition($sequence_pos);
133  }
134  }
135 
139  private function getColumns(): array
140  {
141  $column_factory = $this->ui_factory->table()->column();
142  $columns_definition = [
143  'sequence_position' => $column_factory->number($this->lng->txt('position'))->withUnit('.'),
144  'source_pool_label' => $column_factory->link($this->lng->txt('tst_source_question_pool')),
145  'taxonomy_filter' => $column_factory->text(
146  $this->lng->txt('tst_filter_taxonomy') . ' / ' . $this->lng->txt('tst_filter_tax_node')
147  ),
148  'lifecycle_filter' => $column_factory->text($this->lng->txt('qst_lifecycle')),
149  'type_filter' => $column_factory->text($this->lng->txt('tst_filter_question_type')),
150  'question_amount' => $column_factory->number($this->lng->txt('tst_question_amount')),
151  ];
152 
153  $columns_conditions = [
154  'sequence_position' => !$this->editable,
155  'question_amount' => $this->show_amount,
156  ];
157 
158  return array_filter($columns_definition, function ($key) use ($columns_conditions) {
159  return !isset($columns_conditions[$key]) || $columns_conditions[$key];
160  }, ARRAY_FILTER_USE_KEY);
161  }
162 
166  private function getActions(): array
167  {
168  return [
169  'delete' => $this->ui_factory->table()->action()->standard(
170  $this->lng->txt('delete'),
171  $this->url_builder->withURI($this->getTarget(ConfigGUI::CMD_DELETE_SRC_POOL_DEF)),
173  ),
174  'edit' => $this->ui_factory->table()->action()->single(
175  $this->lng->txt('edit'),
176  $this->url_builder->withURI($this->getTarget(ConfigGUI::CMD_SHOW_EDIT_SRC_POOL_DEF_FORM)),
178  )
179  ];
180  }
181 
182  private function getTarget(string $cmd): URI
183  {
184  return $this->target->withParameter('cmd', $cmd);
185  }
186 }
getRows(OrderingRowBuilder $row_builder, array $visible_column_ids)
This is called by the (ordering-)table to retrieve rows; map data-records to rows using the $row_buil...
__construct(private readonly \ilCtrlInterface $ctrl, private readonly \ilLanguage $lng, private readonly UIFactory $ui_factory, private readonly DataFactory $data_factory, private readonly ServerRequestInterface $request, private readonly TitleColumnsBuilder $title_builder, private readonly \ilTestQuestionFilterLabelTranslator $taxonomy_translator, private readonly PoolDefinitionList $source_pool_definition_list, private readonly bool $editable, private readonly bool $show_amount)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $lng
Definition: privfeed.php:31
buildOrderingRow(string $id, array $record)
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
URLBuilder.
Definition: URLBuilder.php:40