ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
SkillUsagesTable.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28use ILIAS\UI\Factory as UIFactory;
29
31{
32 public function __construct(
33 private readonly UIFactory $ui_factory,
34 private readonly \ilLanguage $lng,
35 private readonly \ilAssQuestionSkillAssignmentList $assignment_list
36 ) {
37 }
38
39 public function getComponent(): Data
40 {
41 return $this->ui_factory->table()->data(
42 $this,
43 $this->lng->txt('qpl_skl_sub_tab_usages'),
44 $this->getColumns()
45 );
46 }
47
48 public function getColumns(): array
49 {
50 $column_factory = $this->ui_factory->table()->column();
51
52 return [
53 'skill_title' => $column_factory->text($this->lng->txt('qpl_qst_skl_usg_skill_col')),
54 'skill_path' => $column_factory->text($this->lng->txt('tst_competence_tree')),
55 'num_assigns' => $column_factory->number($this->lng->txt('qpl_qst_skl_usg_numq_col')),
56 'max_points' => $column_factory->number($this->lng->txt('qpl_qst_skl_usg_sklpnt_col'))
57 ];
58 }
59
60 public function collectRecords(?array $filter_data, ?array $additional_parameters): array
61 {
62 return $this->assignment_list->getUniqueAssignedSkills();
63 }
64
65 private function orderRecords(array $records, Order $order): array
66 {
67 [$order_field, $order_direction] = $order->join(
68 '',
69 static fn(string $index, string $key, string $value): array => [$key, $value]
70 );
71
72 usort(
73 $records,
74 static fn(array $a, array $b): int => ($a[$order_field] ?? '') <=> ($b[$order_field] ?? '')
75 );
76
77 return $order_direction === $order::DESC ? array_reverse($records) : $records;
78 }
79
80 private function limitRecords(array $records, Range $range): array
81 {
82 return array_slice($records, $range->getStart(), $range->getLength());
83 }
84
85 private function getRecords(Order $order, Range $range, ?array $filter_data, ?array $additional_parameters): array
86 {
87 return $this->limitRecords(
88 $this->orderRecords(
89 $this->collectRecords($filter_data, $additional_parameters),
90 $order
91 ),
92 $range
93 );
94 }
95
96 public function getRows(
97 DataRowBuilder $row_builder,
98 array $visible_column_ids,
100 Order $order,
101 mixed $additional_viewcontrol_data,
102 mixed $filter_data,
103 mixed $additional_parameters
104 ): \Generator {
105 foreach ($this->getRecords($order, $range, $filter_data, $additional_parameters) as $row_id => $record) {
106 yield $row_builder->buildDataRow((string) $row_id, $record);
107 }
108 }
109
110 public function getTotalRowCount(
111 mixed $additional_viewcontrol_data,
112 mixed $filter_data,
113 mixed $additional_parameters
114 ): ?int {
115 return count($this->collectRecords($filter_data, $additional_parameters));
116 }
117}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:29
join($init, callable $fn)
Definition: Order.php:75
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:29
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....
__construct(private readonly UIFactory $ui_factory, private readonly \ilLanguage $lng, private readonly \ilAssQuestionSkillAssignmentList $assignment_list)
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 recor...
getRecords(Order $order, Range $range, ?array $filter_data, ?array $additional_parameters)
collectRecords(?array $filter_data, ?array $additional_parameters)
language handling
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
buildDataRow(string $id, array $record)
This describes a Data Table.
Definition: Data.php:33
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
global $lng
Definition: privfeed.php:31