ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilBadgePersonalTableGUI Class Reference
+ Inheritance diagram for ilBadgePersonalTableGUI:
+ Collaboration diagram for ilBadgePersonalTableGUI:

Public Member Functions

 __construct ()
 
 getRows (DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, ?array $filter_data, ?array $additional_parameters)
 This is called by the table to retrieve rows; map data-records to rows using the $row_builder e.g. More...
 
 getTotalRowCount (?array $filter_data, ?array $additional_parameters)
 Mainly for the purpose of pagination-support, it is important to know about the total number of records available. More...
 
 renderTable (string $url)
 
 getRows (DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, ?array $filter_data, ?array $additional_parameters)
 This is called by the table to retrieve rows; map data-records to rows using the $row_builder e.g. More...
 
 getTotalRowCount (?array $filter_data, ?array $additional_parameters)
 Mainly for the purpose of pagination-support, it is important to know about the total number of records available. More...
 

Protected Member Functions

 getActions (URLBuilder $url_builder, URLBuilderToken $action_parameter_token, URLBuilderToken $row_id_token)
 

Private Member Functions

 enrichRecord (array $record, array &$access_cache, array &$ref_id_cache)
 
 getRecords ()
 
 getColumns (\ILIAS\Data\DateFormat\DateFormat $date_format)
 

Private Attributes

readonly Factory $factory
 
readonly Renderer $renderer
 
readonly ServerRequestInterface RequestInterface $request
 
readonly ilLanguage $lng
 
readonly ilGlobalTemplateInterface $tpl
 
readonly ILIAS DI Container $dic
 
readonly ilObjUser $user
 
readonly ilAccessHandler $access
 
readonly Tile $tile
 
readonly IRSS $irss
 
array $cached_records = null
 
ilObjectDataCache $object_data_cache
 
 $parent_metadata_cache = []
 

Detailed Description

Definition at line 39 of file class.ilBadgePersonalTableGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilBadgePersonalTableGUI::__construct ( )

Definition at line 72 of file class.ilBadgePersonalTableGUI.php.

73 {
74 global $DIC;
75 $this->dic = $DIC;
76 $this->lng = $DIC->language();
77 $this->tpl = $DIC->ui()->mainTemplate();
78 $this->factory = $DIC->ui()->factory();
79 $this->renderer = $DIC->ui()->renderer();
80 $this->request = $DIC->http()->request();
81 $this->user = $DIC->user();
82 $this->access = $DIC->access();
83 $this->tile = new Tile($DIC);
84 $this->irss = $DIC['resource_storage'];
85 $this->object_data_cache = $DIC['ilObjDataCache'];
86 }
renderer()
factory()
global $DIC
Definition: shib_login.php:26

References $DIC, ILIAS\Repository\access(), factory(), ILIAS\Repository\lng(), renderer(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

Member Function Documentation

◆ enrichRecord()

ilBadgePersonalTableGUI::enrichRecord ( array  $record,
array &  $access_cache,
array &  $ref_id_cache 
)
private
Parameters
array{id: int, title_sortable: string, awarded_by_sortable: string, badge_issued_on: DateTimeImmutable, active: bool, assignment: ilBadgeAssignment, badge: ilBadge } $record
array<int,bool>$access_cache
array<int,int>$ref_id_cache
Returns
array

Definition at line 168 of file class.ilBadgePersonalTableGUI.php.

172 : array {
173 $badge = $record['badge'];
174 $ass = $record['assignment'];
175
176 $parent = null;
177 if ($badge->getParentId()) {
178 if (isset($this->parent_metadata_cache[$badge->getParentId()])) {
179 $parent = $this->parent_metadata_cache[$badge->getParentId()];
180 } else {
181 $parent = $badge->getParentMeta();
182 $this->parent_metadata_cache[$badge->getParentId()] = $parent;
183 }
184 if ($parent['type'] === 'bdga') {
185 $parent = null;
186 }
187 }
188
189 $awarded_by = '';
190 if ($parent !== null) {
191 if (isset($ref_id_cache[$parent['id']])) {
192 $ref_id = $ref_id_cache[$parent['id']];
193 } else {
194 $ref_id = current(ilObject::_getAllReferences($parent['id']));
195 $ref_id_cache[$parent['id']] = $ref_id;
196 }
197
198 $awarded_by = $parent['title'];
199 if ($ref_id) {
200 $access = $access_cache[$ref_id] ?? $this->access->checkAccess('read', '', $ref_id);
201 if (!isset($access_cache[$ref_id])) {
202 $access_cache[$ref_id] = $access;
203 }
204 }
205 if ($ref_id && $access) {
206 $awarded_by = $this->renderer->render(
207 new Standard(
208 $awarded_by,
209 (string) new URI(ilLink::_getLink($ref_id, $parent['type']))
210 )
211 );
212 }
213
214 $awarded_by = implode(' ', [
215 $this->renderer->render(
216 $this->factory->symbol()->icon()->standard(
217 $parent['type'],
218 $parent['title']
219 )
220 ),
221 $awarded_by
222 ]);
223 }
224
225 $record += [
226 'image' => $this->renderer->render(
227 $this->tile->asImage(
228 $this->tile->modalContentWithAssignment($badge, $ass),
229 ilBadgeImage::IMAGE_SIZE_XS
230 )
231 ),
232 'title' => $this->renderer->render(
233 $this->tile->asTitle(
234 $this->tile->modalContentWithAssignment($badge, $ass)
235 )
236 ),
237 'awarded_by' => $awarded_by,
238 ];
239
240 return $record;
241 }
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
static _getAllReferences(int $id)
get all reference ids for object ID
$ref_id
Definition: ltiauth.php:66

◆ getActions()

ilBadgePersonalTableGUI::getActions ( URLBuilder  $url_builder,
URLBuilderToken  $action_parameter_token,
URLBuilderToken  $row_id_token 
)
protected
Returns
array<string,\ILIAS\UI\Component\Table\Action\Action>

Definition at line 336 of file class.ilBadgePersonalTableGUI.php.

340 : array {
341 return [
342 'obj_badge_activate' => $this->factory->table()->action()->multi(
343 $this->lng->txt('badge_add_to_profile'),
344 $url_builder->withParameter($action_parameter_token, 'obj_badge_activate'),
345 $row_id_token
346 ),
347 'obj_badge_deactivate' =>
348 $this->factory->table()->action()->multi(
349 $this->lng->txt('badge_remove_from_profile'),
350 $url_builder->withParameter($action_parameter_token, 'obj_badge_deactivate'),
351 $row_id_token
352 )
353 ];
354 }
withParameter(URLBuilderToken $token, string|array $value)
Change an acquired parameter's value if the supplied token is valid.
Definition: URLBuilder.php:166

◆ getColumns()

ilBadgePersonalTableGUI::getColumns ( \ILIAS\Data\DateFormat\DateFormat  $date_format)
private
Returns
array<string, Column>

Definition at line 312 of file class.ilBadgePersonalTableGUI.php.

312 : array
313 {
314 return [
315 'image' => $this->factory->table()->column()->text($this->lng->txt('image'))->withIsSortable(false),
316 'title' => $this->factory->table()->column()->text($this->lng->txt('title')),
317 'awarded_by' => $this->factory->table()->column()->text($this->lng->txt('awarded_by')),
318 'badge_issued_on' => $this->factory->table()->column()->date(
319 $this->lng->txt('badge_issued_on'),
320 $date_format
321 ),
322 'active' => $this->factory->table()->column()->boolean(
323 $this->lng->txt('badge_in_profile'),
324 $this->lng->txt('yes'),
325 $this->lng->txt('no')
326 )->withOrderingLabels(
327 $this->lng->txt('badge_sort_added_to_profile_first'),
328 $this->lng->txt('badge_sort_excluded_from_profile_first')
329 )
330 ];
331 }

References factory(), and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ getRecords()

ilBadgePersonalTableGUI::getRecords ( )
private
Returns
list<array{ id: int, title_sortable: string, awarded_by_sortable: string, badge_issued_on: DateTimeImmutable, active: bool, assignment: ilBadgeAssignment, badge: ilBadge }>

Definition at line 261 of file class.ilBadgePersonalTableGUI.php.

261 : array
262 {
263 if ($this->cached_records !== null) {
265 }
266
267 $rows = [];
268 $a_user_id = $this->user->getId();
269
270 foreach (ilBadgeAssignment::getInstancesByUserId($a_user_id) as $ass) {
271 $badge = new ilBadge($ass->getBadgeId());
272
273 $parent = null;
274 if ($badge->getParentId()) {
275 if (isset($this->parent_metadata_cache[$badge->getParentId()])) {
276 $parent = $this->parent_metadata_cache[$badge->getParentId()];
277 } else {
278 $parent = $badge->getParentMeta();
279 $this->parent_metadata_cache[$badge->getParentId()] = $parent;
280 }
281 if ($parent['type'] === 'bdga') {
282 $parent = null;
283 }
284 }
285
286 $awarded_by_sortable = '';
287 if ($parent !== null) {
288 $awarded_by_sortable = $parent['title'];
289 }
290
291 $rows[] = [
292 'id' => $badge->getId(),
293 'title_sortable' => $badge->getTitle(),
294 'awarded_by_sortable' => $awarded_by_sortable,
295 'badge_issued_on' => (new DateTimeImmutable())
296 ->setTimestamp($ass->getTimestamp())
297 ->setTimezone(new DateTimeZone($this->user->getTimeZone())),
298 'active' => (bool) $ass->getPosition(),
299 'assignment' => $ass,
300 'badge' => $badge
301 ];
302 }
303
304 $this->cached_records = $rows;
305
306 return $rows;
307 }
static getInstancesByUserId(int $a_user_id)

References ilBadgeAssignment\getInstancesByUserId(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ getRows()

ilBadgePersonalTableGUI::getRows ( DataRowBuilder  $row_builder,
array  $visible_column_ids,
Range  $range,
Order  $order,
?array  $filter_data,
?array  $additional_parameters 
)

This is called by the table to retrieve rows; map data-records to rows using the $row_builder e.g.

yield $row_builder->buildStandardRow($row_id, $record).

Parameters
string[]$visible_column_ids

Implements ILIAS\UI\Component\Table\DataRetrieval.

Definition at line 88 of file class.ilBadgePersonalTableGUI.php.

95 : Generator {
96 $records = $this->getRecords();
97
98 if ($order) {
99 [$order_field, $order_direction] = $order->join(
100 [],
101 fn($ret, $key, $value) => [$key, $value]
102 );
103
104 usort($records, static function (array $left, array $right) use ($order_field): int {
105 if (in_array($order_field, ['title', 'awarded_by'], true)) {
106 if (in_array($order_field, ['title', 'awarded_by'], true)) {
107 $order_field .= '_sortable';
108 }
109
110 return ilStr::strCmp(
111 $left[$order_field],
112 $right[$order_field]
113 );
114 }
115
116 if ($order_field === 'active') {
117 return $right[$order_field] <=> $left[$order_field];
118 }
119
120 return $left[$order_field] <=> $right[$order_field];
121 });
122
123 if ($order_direction === Order::DESC) {
124 $records = array_reverse($records);
125 }
126 }
127
128 if ($range) {
129 $records = \array_slice($records, $range->getStart(), $range->getLength());
130 }
131
132 $access_cache = [];
133 $ref_id_cache = [];
134 $parent_obj_ids = [];
135 $identifications = [];
136
137 foreach ($records as $record) {
138 $badge = $record['badge'];
139 $parent_obj_ids[] = $badge->getParentId();
140 $identifications[] = $badge->getImageRid();
141 }
142 $this->irss->preload(array_filter($identifications));
143 $this->object_data_cache->preloadObjectCache(array_unique($parent_obj_ids));
144
145 foreach ($records as $record) {
146 yield $row_builder->buildDataRow((string) $record['id'], $this->enrichRecord(
147 $record,
148 $access_cache,
149 $ref_id_cache
150 ));
151 }
152 }
join($init, callable $fn)
Definition: Order.php:75
enrichRecord(array $record, array &$access_cache, array &$ref_id_cache)
static strCmp(string $a, string $b)
Definition: class.ilStr.php:87
buildDataRow(string $id, array $record)

References ILIAS\Data\Order\join(), and ilStr\strCmp().

+ Here is the call graph for this function:

◆ getTotalRowCount()

ilBadgePersonalTableGUI::getTotalRowCount ( ?array  $filter_data,
?array  $additional_parameters 
)

Mainly for the purpose of pagination-support, it is important to know about the total number of records available.

Given the nature of a DataTable, which is, opposite to a PresentationTable, rather administrative than explorative, this information will increase user experience quite a bit. However, you may return null, if the call is to costly, but expect the View Control to look a little different in this case.

Make sure that potential filters or user restrictions are being applied to the count.

Implements ILIAS\UI\Component\Table\DataRetrieval.

Definition at line 243 of file class.ilBadgePersonalTableGUI.php.

246 : ?int {
247 return count($this->getRecords());
248 }

◆ renderTable()

ilBadgePersonalTableGUI::renderTable ( string  $url)

Definition at line 356 of file class.ilBadgePersonalTableGUI.php.

356 : void
357 {
358 $df = new \ILIAS\Data\Factory();
359
360 $table_uri = $df->uri($url);
361 $url_builder = new URLBuilder($table_uri);
362 $query_params_namespace = ['badge'];
363
364 [$url_builder, $action_parameter_token, $row_id_token] = $url_builder->acquireParameters(
365 $query_params_namespace,
366 'table_action',
367 'id',
368 );
369
370 $table = $this->factory
371 ->table()
372 ->data(
373 $this,
374 $this->lng->txt('badge_personal_badges'),
375 $this->getColumns($this->user->getDateTimeFormat()),
376 )
377 ->withId(self::class)
378 ->withOrder(new Order('title', Order::ASC))
379 ->withActions($this->getActions($url_builder, $action_parameter_token, $row_id_token))
380 ->withRequest($this->request);
381
382 $pres = new PresentationHeader($this->dic, ilBadgeProfileGUI::class);
383 $pres->show($this->lng->txt('table_view'));
384
385 $this->tpl->setContent($this->renderer->render($table));
386 }
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:29
getActions(URLBuilder $url_builder, URLBuilderToken $action_parameter_token, URLBuilderToken $row_id_token)
$url
Definition: shib_logout.php:68

References $url, factory(), ILIAS\Repository\lng(), and renderer().

+ Here is the call graph for this function:

Field Documentation

◆ $access

readonly ilAccessHandler ilBadgePersonalTableGUI::$access
private

Definition at line 48 of file class.ilBadgePersonalTableGUI.php.

◆ $cached_records

array ilBadgePersonalTableGUI::$cached_records = null
private
Returns
null|list<array{ id: int, active: bool, image: string, awarded_by: string, awarded_by_sortable: string, badge_issued_on: DateTimeImmutable, title: string, title_sortable: string }>

Definition at line 64 of file class.ilBadgePersonalTableGUI.php.

◆ $dic

readonly ILIAS DI Container ilBadgePersonalTableGUI::$dic
private

Definition at line 46 of file class.ilBadgePersonalTableGUI.php.

◆ $factory

readonly Factory ilBadgePersonalTableGUI::$factory
private

Definition at line 41 of file class.ilBadgePersonalTableGUI.php.

◆ $irss

readonly IRSS ilBadgePersonalTableGUI::$irss
private

Definition at line 50 of file class.ilBadgePersonalTableGUI.php.

◆ $lng

readonly ilLanguage ilBadgePersonalTableGUI::$lng
private

Definition at line 44 of file class.ilBadgePersonalTableGUI.php.

◆ $object_data_cache

ilObjectDataCache ilBadgePersonalTableGUI::$object_data_cache
private

Definition at line 65 of file class.ilBadgePersonalTableGUI.php.

◆ $parent_metadata_cache

ilBadgePersonalTableGUI::$parent_metadata_cache = []
private

Definition at line 70 of file class.ilBadgePersonalTableGUI.php.

◆ $renderer

readonly Renderer ilBadgePersonalTableGUI::$renderer
private

Definition at line 42 of file class.ilBadgePersonalTableGUI.php.

◆ $request

readonly ServerRequestInterface RequestInterface ilBadgePersonalTableGUI::$request
private

Definition at line 43 of file class.ilBadgePersonalTableGUI.php.

◆ $tile

readonly Tile ilBadgePersonalTableGUI::$tile
private

Definition at line 49 of file class.ilBadgePersonalTableGUI.php.

◆ $tpl

readonly ilGlobalTemplateInterface ilBadgePersonalTableGUI::$tpl
private

Definition at line 45 of file class.ilBadgePersonalTableGUI.php.

◆ $user

readonly ilObjUser ilBadgePersonalTableGUI::$user
private

Definition at line 47 of file class.ilBadgePersonalTableGUI.php.


The documentation for this class was generated from the following file: