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