ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilLTIProviderReleasedObjectsTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
30use Psr\Http\Message\ServerRequestInterface;
31use Psr\Http\Message\RequestInterface;
32
40{
41 protected ilLanguage $lng;
43 protected \ILIAS\UI\Renderer $ui_renderer;
44 private ServerRequestInterface|RequestInterface $request;
45 protected \ILIAS\Data\Factory $data_factory;
48 protected \ILIAS\Refinery\Factory $refinery;
49 private array $records;
50 private string $id;
51
52 public function __construct(string $a_id = '')
53 {
54 global $DIC;
55
56 $this->lng = $DIC->language();
57 $this->ui_factory = $DIC->ui()->factory();
58 $this->ui_renderer = $DIC->ui()->renderer();
59 $this->request = $DIC->http()->request();
60 $this->data_factory = new \ILIAS\Data\Factory();
61 $this->ctrl = $DIC->ctrl();
62 $this->wrapper = $DIC->http()->wrapper();
63 $this->refinery = $DIC->refinery();
64 $this->id = $a_id ?: 'lti_released_objects';
65
66 $this->records = $this->getRecords();
67 }
68
69 public function getColumns(): array
70 {
71 return [
72 'type' => $this->ui_factory->table()->column()->statusIcon($this->lng->txt('type')),
73 'title' => $this->ui_factory->table()->column()->link($this->lng->txt('title')),
74 'consumer' => $this->ui_factory->table()->column()->text($this->lng->txt('lti_consumer'))
75 ];
76 }
77
78 private function getRecords(): array
79 {
81
82 $result = array();
83 foreach ($rows as $row) {
84 $ref_id = (int) $row['ref_id'];
85
87 if ($type == 'rolf') {
88 continue;
89 }
90
91 $result[] = array(
92 'id' => $ref_id,
93 'ref_id' => $ref_id,
95 'type' => $type,
97 'consumer' => $row['title']
98 );
99 }
100
101 return $result;
102 }
103
107 public function getRows(
108 DataRowBuilder $row_builder,
109 array $visible_column_ids,
111 Order $order,
112 mixed $additional_viewcontrol_data,
113 mixed $filter_data,
114 mixed $additional_parameters
115 ): Generator {
116 global $DIC;
117
119 $static_url = $DIC["static_url"];
120
121 $records = $this->applyOrdering($this->records, $order, $range);
122 foreach ($records as $record) {
123 $link = (string) $static_url->builder()->build(
124 $record['type'],
125 new ReferenceId($record['ref_id'])
126 );
127
128 $display_record = [
129 'type' => $this->ui_factory->symbol()->icon()->standard($record['type'], $record['type'], Icon::SMALL),
130 'title' => $this->ui_factory->link()->standard($record['title'], $link),
131 'consumer' => $record['consumer']
132 ];
133
134 yield $row_builder->buildDataRow((string) $record['id'], $display_record);
135 }
136 }
137
138 public function getTotalRowCount(
139 mixed $additional_viewcontrol_data,
140 mixed $filter_data,
141 mixed $additional_parameters
142 ): ?int {
143 return count($this->records);
144 }
145
148 public function getHtml(): string
149 {
150 $table = $this->ui_factory->table()
151 ->data($this, $this->lng->txt('lti_released_objects'), $this->getColumns())
152 ->withOrder(new Order('title', Order::ASC))
153 ->withRange(new Range(0, 20))
154 ->withRequest($this->request);
155
156 return $this->ui_renderer->render($table);
157 }
158
159 public function getId(): string
160 {
161 return $this->id;
162 }
163
164 protected function applyOrdering(array $records, Order $order, ?Range $range = null): array
165 {
166 [$order_field, $order_direction] = $order->join(
167 [],
168 fn($ret, $key, $value) => [$key, $value]
169 );
170
171 usort($records, static function (array $left, array $right) use ($order_field): int {
172 $left_val = $left[$order_field] ?? '';
173 $right_val = $right[$order_field] ?? '';
174 return ilStr::strCmp($left_val, $right_val);
175 });
176
177 if ($order_direction === Order::DESC) {
178 $records = array_reverse($records);
179 }
180
181 if ($range !== null) {
182 $records = array_slice($records, $range->getStart(), $range->getLength());
183 }
184
185 return $records;
186 }
187}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
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
Description of class ilLTIProviderReleasedObjectsTableGUI.
applyOrdering(array $records, Order $order, ?Range $range=null)
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...
language handling
static readReleaseObjects()
Read released objects.
static _lookupType(int $id, bool $reference=false)
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
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
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:66
global $DIC
Definition: shib_login.php:26