ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ScoringByQuestionTable.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\UI\Factory as UIFactory;
29use Psr\Http\Message\ServerRequestInterface;
30
32{
33 public const ACTION_SCORING = 'getAnswerDetail';
34
35 public const COLUMN_NAME = 'name';
36 public const COLUMN_EXAMID = 'examid';
37 public const COLUMN_ATTEMPT = 'attempt';
38 public const COLUMN_POINTS_REACHED = 'points_reached';
39 public const COLUMN_POINTS_AVAILABLE = 'points_available';
40 public const COLUMN_FEEDBACK = 'feedback';
41 public const COLUMN_FINALIZED = 'finalized';
42 public const COLUMN_FINALIZED_BY = 'finalized_by';
43 public const COLUMN_FINALIZED_ON = 'finalized_on';
44
45 public const FILTER_FIELD_ONLY_ANSWERED = 'only_answered';
46
47 public function __construct(
48 private readonly Language $lng,
49 private readonly URLBuilder $url_builder,
50 private URLBuilderToken $action_parameter_token,
51 private URLBuilderToken $row_id_token,
52 private readonly UIFactory $ui_factory
53 ) {
54 }
55
56 public function getTable(
57 $title,
58 DateFormat $date_format,
59 ServerRequestInterface $request,
60 \ilUIService $ui_service,
61 string $target_url,
62 ScoringByQuestionTableBinder $data_retrieval,
63 bool $anonymity
64 ): array {
65 $filter = $this->getFilter($ui_service, $target_url, $data_retrieval->getMaxAttempts());
66
67 $f = $this->ui_factory->table();
68 $columns = $anonymity ? [] : [self::COLUMN_NAME => $f->column()->text($this->lng->txt('name'))->withIsSortable(true)];
69 $table = $f->data(
70 $data_retrieval->withFilterData($ui_service->filter()->getData($filter) ?? []),
71 $title,
72 array_merge($columns, [
73 self::COLUMN_EXAMID => $f->column()->text($this->lng->txt('exam_id_label'))->withIsSortable(true),
74 self::COLUMN_ATTEMPT => $f->column()->number($this->lng->txt('tst_attempt')),
75 self::COLUMN_POINTS_REACHED => $f
76 ->column()
77 ->number($this->lng->txt('tst_reached_points'))
78 ->withDecimals(2)
79 ->withIsSortable(true),
80 self::COLUMN_POINTS_AVAILABLE => $f
81 ->column()
82 ->number($this->lng->txt('tst_maximum_points'))
83 ->withDecimals(2)
84 ->withIsSortable(true),
85 self::COLUMN_FEEDBACK => $f->column()->text($this->lng->txt('tst_feedback')),
86 self::COLUMN_FINALIZED => $f->column()->boolean(
87 $this->lng->txt('finalized_evaluation'),
88 $this->ui_factory->symbol()->icon()->custom(
89 'assets/images/standard/icon_checked.svg',
90 $this->lng->txt('yes'),
91 'small'
92 ),
93 $this->ui_factory->symbol()->icon()->custom(
94 'assets/images/standard/icon_unchecked.svg',
95 $this->lng->txt('no'),
96 'small'
97 )
98 )->withIsSortable(true),
99 self::COLUMN_FINALIZED_BY => $f->column()->text($this->lng->txt('finalized_by'))->withIsSortable(true),
100 self::COLUMN_FINALIZED_ON => $f->column()->date($this->lng->txt('finalized_on'), $date_format)->withIsSortable(true)
101 ])
102 )->withActions(
103 [
104 self::ACTION_SCORING => $f->action()->single(
105 $this->lng->txt('grade'),
106 $this->url_builder->withParameter($this->action_parameter_token, self::ACTION_SCORING),
107 $this->row_id_token
108 )->withAsync()
109 ]
110 )->withRequest($request);
111
112 return [$filter, $table];
113 }
114
115 private function getFilter(
116 \ilUIService $ui_service,
117 string $target_url,
118 int $max_attempts
119 ): Filter {
120 $field_factory = $this->ui_factory->input()->field();
121
122 $filter_inputs = [
123 self::COLUMN_ATTEMPT => $field_factory->select(
124 $this->lng->txt('tst_attempt'),
125 $this->buildTestAttemptsOptions($max_attempts)
126 )->withValue(''),
127 self::FILTER_FIELD_ONLY_ANSWERED => $field_factory->select(
128 $this->lng->txt('tst_man_scoring_only_answered'),
129 [
130 0 => $this->lng->txt('no'),
131 1 => $this->lng->txt('yes')
132 ]
133 )->withRequired(true),
134 self::COLUMN_FINALIZED => $field_factory->select(
135 $this->lng->txt('finalized_evaluation'),
136 [
137 0 => $this->lng->txt('all_users'),
138 1 => $this->lng->txt('evaluated_users'),
139 2 => $this->lng->txt('not_evaluated_users')
140 ]
141 )->withRequired(true)
142 ];
143
144 $active = array_fill(0, count($filter_inputs), true);
145
146 $filter = $ui_service->filter()->standard(
147 'scoring_by_qst_filter_id',
148 $target_url,
149 $filter_inputs,
150 $active,
151 true,
152 true
153 );
154 return $filter;
155 }
156
157 private function buildTestAttemptsOptions(int $max_attempts): array
158 {
159 $attempts = [];
160 for ($i = 0;$i < $max_attempts;$i++) {
161 $attempts[$i] = $i + 1;
162 }
163 return $attempts;
164 }
165}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
A Date Format provides a format definition akin to PHP's date formatting options, but stores the sing...
Definition: DateFormat.php:27
getFilter(\ilUIService $ui_service, string $target_url, int $max_attempts)
getTable( $title, DateFormat $date_format, ServerRequestInterface $request, \ilUIService $ui_service, string $target_url, ScoringByQuestionTableBinder $data_retrieval, bool $anonymity)
__construct(private readonly Language $lng, private readonly URLBuilder $url_builder, private URLBuilderToken $action_parameter_token, private URLBuilderToken $row_id_token, private readonly UIFactory $ui_factory)
Filter service.
This describes a standard filter.
Definition: Standard.php:27
global $lng
Definition: privfeed.php:31