ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
ILIAS\Test\Questions\Presentation\QuestionsBrowserTable Class Reference
+ Inheritance diagram for ILIAS\Test\Questions\Presentation\QuestionsBrowserTable:
+ Collaboration diagram for ILIAS\Test\Questions\Presentation\QuestionsBrowserTable:

Public Member Functions

 __construct (private readonly string $table_id, private readonly \ilObjUser $current_user, private readonly UIFactory $ui_factory, private readonly UIRenderer $ui_renderer, private readonly \ilLanguage $lng, private readonly \ilCtrl $ctrl, private readonly DataFactory $data_factory, private readonly \ilAssQuestionList $question_list, private readonly TaxonomyService $taxonomy, private readonly string $parent_title)
 
 getComponent (ServerRequestInterface $request, ?array $filter)
 
 getColumns ()
 
 getActions ()
 
 getRows (DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
 This is called by the table to retrieve rows; map data-records to rows using the $row_builder e.g. More...
 
 getTotalRowCount (mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
 Mainly for the purpose of pagination-support, it is important to know about the total number of records available. More...
 
 loadRecords (array $filters=[], ?Order $order=null, ?Range $range=null)
 
 getRows (DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
 This is called by the table to retrieve rows; map data-records to rows using the $row_builder e.g. More...
 
 getTotalRowCount (mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
 Mainly for the purpose of pagination-support, it is important to know about the total number of records available. More...
 

Data Fields

const ACTION_INSERT = 'insert'
 

Private Member Functions

 getInsertAction ()
 
 getParentObjectLink (array $record)
 
 addFiltersToQuestionList (array $filters)
 
 resolveTaxonomiesRowData (int $obj_fi, int $questionId)
 
 loadTaxonomyAssignmentData (int $parentObjId, int $questionId, array $available_taxonomy_ids)
 

Detailed Description

Definition at line 40 of file QuestionsBrowserTable.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Test\Questions\Presentation\QuestionsBrowserTable::__construct ( private readonly string  $table_id,
private readonly \ilObjUser  $current_user,
private readonly UIFactory  $ui_factory,
private readonly UIRenderer  $ui_renderer,
private readonly \ilLanguage  $lng,
private readonly \ilCtrl  $ctrl,
private readonly DataFactory  $data_factory,
private readonly \ilAssQuestionList  $question_list,
private readonly TaxonomyService  $taxonomy,
private readonly string  $parent_title 
)

Definition at line 44 of file QuestionsBrowserTable.php.

55 {
56 }

Member Function Documentation

◆ addFiltersToQuestionList()

ILIAS\Test\Questions\Presentation\QuestionsBrowserTable::addFiltersToQuestionList ( array  $filters)
private

Definition at line 208 of file QuestionsBrowserTable.php.

208 : void
209 {
210 foreach (array_filter($filters) as $key => $filter) {
211 if ($key === 'commented') {
212 $this->question_list->setCommentFilter((int) $filter);
213 continue;
214 }
215
216 $this->question_list->addFieldFilter($key, $filter);
217 }
218 }

◆ getActions()

ILIAS\Test\Questions\Presentation\QuestionsBrowserTable::getActions ( )

Definition at line 120 of file QuestionsBrowserTable.php.

120 : array
121 {
122 return [self::ACTION_INSERT => $this->getInsertAction()];
123 }

References ILIAS\Test\Questions\Presentation\QuestionsBrowserTable\getInsertAction().

Referenced by ILIAS\Test\Questions\Presentation\QuestionsBrowserTable\getComponent().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getColumns()

ILIAS\Test\Questions\Presentation\QuestionsBrowserTable::getColumns ( )

Definition at line 70 of file QuestionsBrowserTable.php.

70 : array
71 {
72 $column_factory = $this->ui_factory->table()->column();
73 $icon_factory = $this->ui_factory->symbol()->icon();
74 $iconYes = $icon_factory->custom('assets/images/standard/icon_checked.svg', 'yes');
75 $iconNo = $icon_factory->custom('assets/images/standard/icon_unchecked.svg', 'no');
76
77 $columns = [
78 'title' => $column_factory->text(
79 $this->lng->txt('tst_question_title')
80 )->withIsOptional(false, true),
81 'description' => $column_factory->text(
82 $this->lng->txt('description')
83 )->withIsOptional(true, true),
84 'question_type' => $column_factory->text(
85 $this->lng->txt('tst_question_type')
86 )->withIsOptional(false, true),
87 'points' => $column_factory->number(
88 $this->lng->txt('points')
89 )->withIsOptional(false, true),
90 'author' => $column_factory->text(
91 $this->lng->txt('author')
92 )->withIsOptional(true, false),
93 'lifecycle' => $column_factory->text(
94 $this->lng->txt('qst_lifecycle')
95 )->withIsOptional(true, false),
96 'parent_title' => $column_factory->link(
97 $this->lng->txt($this->parent_title)
98 )->withIsOptional(false, true),
99 'taxonomies' => $column_factory->text(
100 $this->lng->txt('qpl_settings_subtab_taxonomies')
101 )->withIsOptional(false, true),
102 'feedback' => $column_factory->boolean(
103 $this->lng->txt('tst_feedback'),
104 $iconYes,
105 $iconNo
106 )->withIsOptional(true, false),
107 'created' => $column_factory->date(
108 $this->lng->txt('created'),
109 $this->current_user->getDateTimeFormat()
110 )->withIsOptional(true, false),
111 'tstamp' => $column_factory->date(
112 $this->lng->txt('updated'),
113 $this->current_user->getDateTimeFormat()
114 )->withIsOptional(true, false)
115 ];
116
117 return array_map(static fn(Column $column): Column => $column->withIsSortable(true), $columns);
118 }

References ILIAS\Repository\lng(), and ILIAS\UI\Component\Table\Column\Column\withIsSortable().

+ Here is the call graph for this function:

◆ getComponent()

ILIAS\Test\Questions\Presentation\QuestionsBrowserTable::getComponent ( ServerRequestInterface  $request,
?array  $filter 
)

Definition at line 58 of file QuestionsBrowserTable.php.

58 : Data
59 {
60 return $this->ui_factory->table()->data(
61 $this,
62 $this->lng->txt('list_of_questions'),
63 $this->getColumns(),
64 )->withId($this->table_id)
65 ->withActions($this->getActions())
66 ->withRequest($request)
67 ->withFilter($filter);
68 }

References ILIAS\Test\Questions\Presentation\QuestionsBrowserTable\getActions(), ILIAS\Repository\lng(), and ILIAS\UI\Component\Table\Data\withId().

+ Here is the call graph for this function:

◆ getInsertAction()

ILIAS\Test\Questions\Presentation\QuestionsBrowserTable::getInsertAction ( )
private

Definition at line 125 of file QuestionsBrowserTable.php.

125 : TableAction
126 {
127 $url_builder = new URLBuilder($this->data_factory->uri(
128 ILIAS_HTTP_PATH . "/{$this->ctrl->getLinkTargetByClass(
129 ilTestQuestionBrowserTableGUI::class,
130 ilTestQuestionBrowserTableGUI::CMD_INSERT_QUESTIONS
131 )}"
132 ));
133
134 [$url_builder, $row_id_token] = $url_builder->acquireParameters(['qlist'], 'q_id');
135
136 return $this->ui_factory->table()->action()->standard(
137 $this->lng->txt('tst_insert_in_test'),
138 $url_builder,
139 $row_id_token
140 );
141 }

References ILIAS\Repository\lng().

Referenced by ILIAS\Test\Questions\Presentation\QuestionsBrowserTable\getActions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getParentObjectLink()

ILIAS\Test\Questions\Presentation\QuestionsBrowserTable::getParentObjectLink ( array  $record)
private

Definition at line 169 of file QuestionsBrowserTable.php.

169 : Standard
170 {
171 [$parent_class, $parent_command] = match($record['parent_type']) {
172 'qpl' => [\ilObjQuestionPoolGUI::class, \ilObjQuestionPoolGUI::DEFAULT_CMD],
173 'tst' => [\ilObjTestGUI::class, \ilObjTestGUI::SHOW_QUESTIONS_CMD],
174 default => throw new \RuntimeException("Unsupported parent type {$record['parent_type']}"),
175 };
176
177 $this->ctrl->setParameterByClass($parent_class, 'ref_id', $record['parent_ref_id']);
178 $link = $this->ui_factory->link()->standard(
179 $record['parent_title'],
180 $this->ctrl->getLinkTargetByClass($parent_class, $parent_command),
181 );
182 $this->ctrl->setParameterByClass($parent_class, 'ref_id', null);
183
184 return $link;
185 }

References ILIAS\Repository\ctrl(), ilObjQuestionPoolGUI\DEFAULT_CMD, and ilObjTestGUI\SHOW_QUESTIONS_CMD.

Referenced by ILIAS\Test\Questions\Presentation\QuestionsBrowserTable\getRows().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRows()

ILIAS\Test\Questions\Presentation\QuestionsBrowserTable::getRows ( DataRowBuilder  $row_builder,
array  $visible_column_ids,
Range  $range,
Order  $order,
mixed  $additional_viewcontrol_data,
mixed  $filter_data,
mixed  $additional_parameters 
)

This is called by the table to retrieve rows; map data-records to rows using the $row_builder e.g.

yield $row_builder->buildStandardRow($row_id, $record).

Parameters
string[]$visible_column_ids

Implements ILIAS\UI\Component\Table\DataRetrieval.

Definition at line 143 of file QuestionsBrowserTable.php.

151 : \Generator {
152 $timezone = new \DateTimeZone($this->current_user->getTimeZone());
153 foreach ($this->loadRecords($filter_data ?? [], $order, $range) as $record) {
154 $question_id = $record['question_id'];
155
156 $record['question_type'] = $record['question_type'];
157 $record['complete'] = (bool) $record['complete'];
158 $record['lifecycle'] = \ilAssQuestionLifecycle::getInstance($record['lifecycle'])->getTranslation($this->lng) ?? '';
159
160 $record['created'] = (new \DateTimeImmutable("@{$record['created']}"))->setTimezone($timezone);
161 $record['tstamp'] = (new \DateTimeImmutable("@{$record['tstamp']}"))->setTimezone($timezone);
162 $record['taxonomies'] = $this->resolveTaxonomiesRowData($record['obj_fi'], $question_id);
163 $record['parent_title'] = $this->getParentObjectLink($record);
164
165 yield $row_builder->buildDataRow((string) $question_id, $record);
166 }
167 }
loadRecords(array $filters=[], ?Order $order=null, ?Range $range=null)
buildDataRow(string $id, array $record)

References ILIAS\UI\Component\Table\DataRowBuilder\buildDataRow(), ilAssQuestionLifecycle\getInstance(), ILIAS\Test\Questions\Presentation\QuestionsBrowserTable\getParentObjectLink(), ILIAS\Repository\lng(), and ILIAS\Test\Questions\Presentation\QuestionsBrowserTable\resolveTaxonomiesRowData().

+ Here is the call graph for this function:

◆ getTotalRowCount()

ILIAS\Test\Questions\Presentation\QuestionsBrowserTable::getTotalRowCount ( mixed  $additional_viewcontrol_data,
mixed  $filter_data,
mixed  $additional_parameters 
)

Mainly for the purpose of pagination-support, it is important to know about the total number of records available.

Given the nature of a DataTable, which is, opposite to a PresentationTable, rather administrative than explorative, this information will increase user experience quite a bit. However, you may return null, if the call is to costly, but expect the View Control to look a little different in this case.

Make sure that potential filters or user restrictions are being applied to the count.

Implements ILIAS\UI\Component\Table\DataRetrieval.

Definition at line 187 of file QuestionsBrowserTable.php.

191 : int {
192 $filter_data ??= [];
193 $this->addFiltersToQuestionList($filter_data);
194 return $this->question_list->getTotalRowCount($additional_viewcontrol_data, $filter_data, $additional_parameters);
195 }

◆ loadRecords()

ILIAS\Test\Questions\Presentation\QuestionsBrowserTable::loadRecords ( array  $filters = [],
?Order  $order = null,
?Range  $range = null 
)

Definition at line 197 of file QuestionsBrowserTable.php.

197 : array
198 {
199 $this->addFiltersToQuestionList($filters);
200
201 $this->question_list->setOrder($order);
202 $this->question_list->setRange($range);
203 $this->question_list->load();
204
205 return $this->question_list->getQuestionDataArray();
206 }

References ILIAS\UI\Implementation\Component\Table\$range.

◆ loadTaxonomyAssignmentData()

ILIAS\Test\Questions\Presentation\QuestionsBrowserTable::loadTaxonomyAssignmentData ( int  $parentObjId,
int  $questionId,
array  $available_taxonomy_ids 
)
private

Definition at line 241 of file QuestionsBrowserTable.php.

241 : array
242 {
243 $taxonomyAssignmentData = [];
244
245 foreach ($available_taxonomy_ids as $taxId) {
246 $taxTree = new \ilTaxonomyTree($taxId);
247 $assignments = (new \ilTaxNodeAssignment(
248 'qpl',
249 $parentObjId,
250 'quest',
251 $taxId
252 ))->getAssignmentsOfItem($questionId);
253
254 foreach ($assignments as $assData) {
255 $taxId = $assData['tax_id'];
256 if (!isset($taxonomyAssignmentData[$taxId])) {
257 $taxonomyAssignmentData[$taxId] = [];
258 }
259
260 $nodeId = $assData['node_id'];
261 $assData['node_lft'] = $taxTree->getNodeData($nodeId)['lft'];
262 $taxonomyAssignmentData[$taxId][$nodeId] = $assData;
263 }
264 }
265
266 return $taxonomyAssignmentData;
267 }

◆ resolveTaxonomiesRowData()

ILIAS\Test\Questions\Presentation\QuestionsBrowserTable::resolveTaxonomiesRowData ( int  $obj_fi,
int  $questionId 
)
private

Definition at line 220 of file QuestionsBrowserTable.php.

220 : string
221 {
222 $available_taxonomy_ids = $this->taxonomy->getUsageOfObject($obj_fi);
223 $data = $this->loadTaxonomyAssignmentData($obj_fi, $questionId, $available_taxonomy_ids);
224
225 $taxonomies = [];
226
227 foreach ($data as $taxonomyId => $taxData) {
228 $taxonomies[] = \ilObject::_lookupTitle($taxonomyId);
229 $taxonomies[] = $this->ui_renderer->render(
230 $this->ui_factory->listing()->unordered(
231 array_map(static function ($node) {
232 return \ilTaxonomyNode::_lookupTitle($node['node_id']);
233 }, $taxData)
234 )
235 );
236 }
237
238 return implode('', $taxonomies);
239 }
loadTaxonomyAssignmentData(int $parentObjId, int $questionId, array $available_taxonomy_ids)
static _lookupTitle(int $obj_id)

References $data, and ilObject\_lookupTitle().

Referenced by ILIAS\Test\Questions\Presentation\QuestionsBrowserTable\getRows().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ ACTION_INSERT

const ILIAS\Test\Questions\Presentation\QuestionsBrowserTable::ACTION_INSERT = 'insert'

Definition at line 42 of file QuestionsBrowserTable.php.


The documentation for this class was generated from the following file: