ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
QuestionsTable.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\Test\Questions\Properties\Repository as TestQuestionsRepository;
25use ILIAS\Test\Questions\Properties\Properties as TestQuestionProperties;
26use ILIAS\Refinery\Factory as Refinery;
27use ILIAS\UI\Factory as UIFactory;
28use ILIAS\UI\Component\Listing\Property as PropertyListing;
33use Psr\Http\Message\ServerRequestInterface;
34
36{
37 private ?array $records = null;
41 public function __construct(
42 private readonly UIFactory $ui_factory,
43 private readonly Refinery $refinery,
44 private readonly ServerRequestInterface $request,
45 private readonly QuestionsTableActions $table_actions,
46 private readonly Language $lng,
47 private readonly \ilObjTest $test_obj,
48 private readonly TestQuestionsRepository $questionrepository,
49 private readonly TitleColumnsBuilder $title_builder,
50 ) {
51 }
52
53 public function getSummary(): PropertyListing
54 {
55 $this->loadRecords();
56
57 $listing = $this->ui_factory->listing()->property()
58 ->withProperty(
59 $this->lng->txt('tst_num_questions'),
60 $this->refinery->kindlyTo()->string()->transform(
61 $this->test_obj->getQuestionCount()
62 )
63 );
64
65 if ($this->test_obj->isRandomTest()) {
66 return $listing;
67 }
68
69 return $listing->withProperty(
70 $this->lng->txt('maximum_points'),
71 $this->refinery->kindlyTo()->string()->transform(
72 array_reduce(
73 $this->records,
74 fn(float $c, TestQuestionProperties $v): float
75 => $c + $v->getGeneralQuestionProperties()->getAvailablePoints(),
76 0.0
77 )
78 )
79 );
80
81 }
82
83 public function getTableComponent(): Ordering
84 {
85 $table = $this->ui_factory->table()->ordering(
86 $this,
87 $this->table_actions->getOrderActionUrl(),
88 '',
89 $this->getColumns()
90 )
91 ->withId((string) $this->test_obj->getId())
92 ->withActions($this->table_actions->getActions())
93 ->withRequest($this->request);
94
95
96
97 if ($this->test_obj->isRandomTest()
98 || $this->test_obj->evalTotalPersons() !== 0) {
99 return $table->withOrderingDisabled(true);
100 }
101
102 return $table;
103 }
104
105 public function getRows(
106 OrderingRowBuilder $row_builder,
107 array $visible_column_ids
108 ): \Generator {
109 foreach ($this->getRecords() as $record) {
110 $row = $record->getAsQuestionsTableRow(
111 $this->lng,
112 $this->ui_factory,
113 $this->refinery,
114 $this->table_actions->getQuestionTargetLinkBuilder(),
115 $row_builder,
116 $this->title_builder
117 );
118 yield $this->table_actions->setDisabledActions($row, $record);
119 }
120 }
121
122 private function getColumns(): array
123 {
124 $f = $this->ui_factory;
125 $columns = [
126 'question_id' => $f->table()->column()->text($this->lng->txt('question_id'))
127 ->withIsOptional(true, false),
128 'title' => $f->table()->column()->link($this->lng->txt('tst_question_title')),
129 'description' => $f->table()->column()->text($this->lng->txt('description'))
130 ->withIsOptional(true, false),
131 'complete' => $f->table()->column()->boolean(
132 $this->lng->txt('question_complete_title'),
133 $f->symbol()->icon()->custom('assets/images/standard/icon_checked.svg', '', 'small'),
134 $f->symbol()->icon()->custom('assets/images/standard/icon_alert.svg', '', 'small')
135 ),
136 'type_tag' => $f->table()->column()->text($this->lng->txt('tst_question_type')),
137 'points' => $f->table()->column()->number($this->lng->txt('points'))->withDecimals(2),
138 'author' => $f->table()->column()->text($this->lng->txt('author'))
139 ->withIsOptional(true, false),
140 'lifecycle' => $f->table()->column()->text($this->lng->txt('qst_lifecycle'))
141 ->withIsOptional(true, false),
142 'qpl' => $f->table()->column()->link($this->lng->txt('qpl')),
143 'nr_of_answers' => $f->table()->column()->number($this->lng->txt('number_of_answers'))
144 ->withIsOptional(true, false),
145 'average_points' => $f->table()->column()->number($this->lng->txt('average_reached_points'))->withDecimals(2)
146 ->withIsOptional(true, false),
147 'percentage_points_achieved' => $f->table()->column()->text($this->lng->txt('percentage_points_achieved'))
148 ->withIsOptional(true, false),
149 ];
150
151 return $columns;
152 }
153
154 private function getActions(): array
155 {
156 $this->table_actions->getActions();
157 }
158
159 private function getRecords(): \Generator
160 {
161 if ($this->records === null) {
162 $this->loadRecords();
163 }
164 yield from $this->records;
165 }
166
167 private function loadRecords(): void
168 {
169 $this->records = $this->questionrepository
170 ->getQuestionPropertiesWithAggregatedResultsForTest($this->test_obj);
171 usort(
172 $this->records,
173 static fn(TestQuestionProperties $a, TestQuestionProperties $b): int =>
174 $a->getSequenceInformation()?->getPlaceInSequence() <=> $b->getSequenceInformation()?->getPlaceInSequence()
175 );
176 }
177}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
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 UIFactory $ui_factory, private readonly Refinery $refinery, private readonly ServerRequestInterface $request, private readonly QuestionsTableActions $table_actions, private readonly Language $lng, private readonly \ilObjTest $test_obj, private readonly TestQuestionsRepository $questionrepository, private readonly TitleColumnsBuilder $title_builder,)
foreach( $report as $row)
This describes a Table to specify the order of its data (rows).
Definition: Ordering.php:29
withId(string $id)
The DataTable comes with a storage to keep e.g.
$request
@ilCtrl_Calls ilObjLearningSequenceContentGUI: ilObjLearningSequenceConditionsGUI
Definition: ltiauth.php:39
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
global $lng
Definition: privfeed.php:26