ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilLTIConsumerGradeSynchronizationTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26
36{
37 protected ilLanguage $lng;
39 protected \ILIAS\UI\Renderer $ui_renderer;
40 protected $request;
41 protected bool $isMultiActorReport;
42 private array $records = [];
43
44 public function __construct(bool $isMultiActorReport)
45 {
46 global $DIC;
47
48 $this->isMultiActorReport = $isMultiActorReport;
49
50 $this->lng = $DIC->language();
51 $this->ui_factory = $DIC->ui()->factory();
52 $this->ui_renderer = $DIC->ui()->renderer();
53 $this->request = $DIC->http()->request();
54
55 }
56
60 public function getRows(
61 DataRowBuilder $row_builder,
62 array $visible_column_ids,
64 Order $order,
65 mixed $additional_viewcontrol_data,
66 mixed $filter_data,
67 mixed $additional_parameters
68 ): Generator {
69 $records = $this->applyOrdering($this->records, $order, $range);
70 foreach ($records as $record) {
71 $record['lti_timestamp'] = new DateTimeImmutable($record['lti_timestamp']);
72 $record['score_given'] = $record['score_given'] . ' / ' . $record['score_maximum'];
73 $record['activity_progress'] = $this->lng->txt('grade_activity_progress_' . strtolower($record['activity_progress']));
74 $record['grading_progress'] = $this->lng->txt('grade_grading_progress_' . strtolower($record['grading_progress']));
75 $record['stored'] = new DateTimeImmutable($record['stored']);
76
77 yield $row_builder->buildDataRow((string) $record['id'], $record);
78 }
79 }
80
81 public function getTotalRowCount(
82 mixed $additional_viewcontrol_data,
83 mixed $filter_data,
84 mixed $additional_parameters
85 ): ?int {
86 return count($this->records);
87 }
88
89 public function setRecords(array $records): void
90 {
91 $this->records = $records;
92 }
93
94 protected function applyOrdering(array $records, Order $order, ?Range $range = null): array
95 {
96 [$order_field, $order_direction] = $order->join(
97 [],
98 fn($ret, $key, $value) => [$key, $value]
99 );
100
101 usort($records, static function (array $left, array $right) use ($order_field): int {
102 $left_val = $left[$order_field] ?? '';
103 $right_val = $right[$order_field] ?? '';
104
105 if ($left_val instanceof DateTimeImmutable) {
106 $left_val = $left_val->getTimestamp();
107 }
108 if ($right_val instanceof DateTimeImmutable) {
109 $right_val = $right_val->getTimestamp();
110 }
111
112 return $left_val <=> $right_val;
113 });
114
115 if ($order_direction === Order::DESC) {
116 $records = array_reverse($records);
117 }
118
119 if ($range !== null) {
120 $records = array_slice($records, $range->getStart(), $range->getLength());
121 }
122
123 return $records;
124 }
125
126 public function getHTML(): string
127 {
128 $table = $this->ui_factory->table()
129 ->data($this, "", $this->getColumns())
130 ->withOrder(new Order("lti_timestamp", Order::DESC))
131 ->withRange(new Range(0, 20))
132 ->withRequest($this->request);
133
134 return $this->ui_renderer->render($table);
135 }
136
137 private function getColumns(): array
138 {
139 global $DIC;
140 $df = new \ILIAS\Data\Factory();
141
142
143 return [
144 "lti_timestamp" => $this->ui_factory->table()->column()->date($this->lng->txt('tbl_grade_date'), $df->dateFormat()->withTime24($DIC->user()->getDateFormat())),
145 "actor" => $this->ui_factory->table()->column()->text($this->lng->txt('tbl_grade_actor')),
146 "score_given" => $this->ui_factory->table()->column()->text($this->lng->txt('tbl_grade_score')),
147 "activity_progress" => $this->ui_factory->table()->column()->text($this->lng->txt('tbl_grade_activity_progress')),
148 "grading_progress" => $this->ui_factory->table()->column()->text($this->lng->txt('tbl_grade_grading_progress')),
149 "stored" => $this->ui_factory->table()->column()->date($this->lng->txt('tbl_grade_stored'), $df->dateFormat()->withTime24($DIC->user()->getDateFormat()))
150 ];
151 }
152}
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
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...
getRows(DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, mixed $additional_viewcontrol_data, mixed $filter_data, mixed $additional_parameters)
applyOrdering(array $records, Order $order, ?Range $range=null)
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 is how the factory for UI elements looks.
Definition: Factory.php:38
global $DIC
Definition: shib_login.php:26