ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilLTIConsumerProviderUsageTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
29
39{
40 protected ilLanguage $lng;
42 protected \ILIAS\UI\Renderer $ui_renderer;
43 protected $request;
44 protected array $records;
45
46 public function __construct()
47 {
48 global $DIC;
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 public function getRows(
57 DataRowBuilder $row_builder,
58 array $visible_column_ids,
60 Order $order,
61 mixed $additional_viewcontrol_data,
62 mixed $filter_data,
63 mixed $additional_parameters
64 ): Generator {
65 global $DIC;
66
68 $static_url = $DIC["static_url"];
69
70 $records = $this->applyOrdering($this->records, $order, $range);
71 foreach ($records as $record) {
72 $record['icon'] = $record['icon'] ?? "lti";
73 $record['icon'] = $this->ui_factory->symbol()->icon()->standard($record['icon'], $record['icon'], Icon::SMALL);
74
75 $link = (string) $static_url->builder()->build(
76 ilObject::_lookupType($record['usedByObjId']),
77 new ReferenceId($record['usedByRefId'])
78 );
79
80 $record['used_by'] = $this->ui_factory->link()->standard(
81 $record['usedByTitle'],
82 $link
83 );
84
85 yield $row_builder->buildDataRow((string) $record['id'], $record);
86 }
87 }
88
89 public function getTotalRowCount(
90 mixed $additional_viewcontrol_data,
91 mixed $filter_data,
92 mixed $additional_parameters
93 ): ?int {
94 return count($this->records);
95 }
96
97 public function setData(array $data): void
98 {
99 $this->records = $data;
100 }
101
102 protected function applyOrdering(array $records, Order $order, ?Range $range = null): array
103 {
104 [$order_field, $order_direction] = $order->join(
105 [],
106 fn($ret, $key, $value) => [$key, $value]
107 );
108
109 usort($records, static function (array $left, array $right) use ($order_field): int {
110 $left_val = $left[$order_field] ?? '';
111 $right_val = $right[$order_field] ?? '';
112 return ilStr::strCmp($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->lng->txt('tbl_provider_usage_header'), $this->getColumns())
130 ->withOrder(new Order('title', Order::ASC))
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 return [
140 "icon" => $this->ui_factory->table()->column()->statusIcon($this->lng->txt('tbl_lti_prov_icon')),
141 "title" => $this->ui_factory->table()->column()->text($this->lng->txt('tbl_lti_prov_title')),
142 "usedByIsTrashed" => $this->ui_factory->table()->column()->boolean(
143 $this->lng->txt('tbl_lti_prov_usages_trashed'),
144 $this->ui_factory->symbol()->icon()->custom('assets/images/standard/icon_ok.svg', $this->lng->txt('icon_ok'), Icon::SMALL),
145 $this->ui_factory->symbol()->icon()->custom('assets/images/standard/icon_not_ok.svg', $this->lng->txt('icon_not_ok'), Icon::SMALL)
146 ),
147 "used_by" => $this->ui_factory->table()->column()->link($this->lng->txt('tbl_lti_prov_used_by'))
148 ];
149 }
150}
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
Class Services.
Definition: Services.php:38
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...
applyOrdering(array $records, Order $order, ?Range $range=null)
language handling
static _lookupType(int $id, bool $reference=false)
static strCmp(string $a, string $b)
Definition: class.ilStr.php:87
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$static_url
Definition: goto.php:29
This describes how an icon could be modified during construction of UI.
Definition: Icon.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....
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