ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
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, 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.g. More...
 
 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 records available. More...
 
 renderTable (string $url)
 
 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.g. More...
 
 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 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 40 of file class.ilBadgePersonalTableGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilBadgePersonalTableGUI::__construct ( )

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

74 {
75 global $DIC;
76 $this->dic = $DIC;
77 $this->lng = $DIC->language();
78 $this->tpl = $DIC->ui()->mainTemplate();
79 $this->factory = $DIC->ui()->factory();
80 $this->renderer = $DIC->ui()->renderer();
81 $this->request = $DIC->http()->request();
82 $this->user = $DIC->user();
83 $this->access = $DIC->access();
84 $this->tile = new Tile($DIC);
85 $this->irss = $DIC['resource_storage'];
86 $this->object_data_cache = $DIC['ilObjDataCache'];
87 }
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 170 of file class.ilBadgePersonalTableGUI.php.

174 : array {
175 $badge = $record['badge'];
176 $ass = $record['assignment'];
177
178 $parent = null;
179 if ($badge->getParentId()) {
180 if (isset($this->parent_metadata_cache[$badge->getParentId()])) {
181 $parent = $this->parent_metadata_cache[$badge->getParentId()];
182 } else {
183 $parent = $badge->getParentMeta();
184 $this->parent_metadata_cache[$badge->getParentId()] = $parent;
185 }
186 if ($parent['type'] === 'bdga') {
187 $parent = null;
188 }
189 }
190
191 $awarded_by = '';
192 if ($parent !== null) {
193 if (isset($ref_id_cache[$parent['id']])) {
194 $ref_id = $ref_id_cache[$parent['id']];
195 } else {
196 $ref_id = current(ilObject::_getAllReferences($parent['id']));
197 $ref_id_cache[$parent['id']] = $ref_id;
198 }
199
200 $awarded_by = $parent['title'];
201 if ($ref_id) {
202 $access = $access_cache[$ref_id] ?? $this->access->checkAccess('read', '', $ref_id);
203 if (!isset($access_cache[$ref_id])) {
204 $access_cache[$ref_id] = $access;
205 }
206 }
207 if ($ref_id && $access) {
208 $awarded_by = $this->renderer->render(
209 new Standard(
210 $awarded_by,
211 (string) new URI(ilLink::_getLink($ref_id, $parent['type']))
212 )
213 );
214 }
215
216 $awarded_by = implode(' ', [
217 $this->renderer->render(
218 $this->factory->symbol()->icon()->standard(
219 $parent['type'],
220 $parent['title']
221 )
222 ),
223 $awarded_by
224 ]);
225 }
226
227 $record += [
228 'image' => $this->renderer->render(
229 $this->tile->asImage(
230 $this->tile->modalContentWithAssignment($badge, $ass),
231 ilBadgeImage::IMAGE_SIZE_XS
232 )
233 ),
234 'title' => $this->renderer->render(
235 $this->tile->asTitle(
236 $this->tile->modalContentWithAssignment($badge, $ass)
237 )
238 ),
239 'awarded_by' => $awarded_by,
240 ];
241
242 return $record;
243 }
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 339 of file class.ilBadgePersonalTableGUI.php.

343 : array {
344 return [
345 'obj_badge_activate' => $this->factory->table()->action()->multi(
346 $this->lng->txt('badge_add_to_profile'),
347 $url_builder->withParameter($action_parameter_token, 'obj_badge_activate'),
348 $row_id_token
349 ),
350 'obj_badge_deactivate' =>
351 $this->factory->table()->action()->multi(
352 $this->lng->txt('badge_remove_from_profile'),
353 $url_builder->withParameter($action_parameter_token, 'obj_badge_deactivate'),
354 $row_id_token
355 )
356 ];
357 }
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 315 of file class.ilBadgePersonalTableGUI.php.

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

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 264 of file class.ilBadgePersonalTableGUI.php.

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

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

Parameters
string[]$visible_column_ids

Implements ILIAS\UI\Component\Table\DataRetrieval.

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

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

249 : ?int {
250 return count($this->getRecords());
251 }

◆ renderTable()

ilBadgePersonalTableGUI::renderTable ( string  $url)

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

359 : void
360 {
361 $df = new \ILIAS\Data\Factory();
362
363 $table_uri = $df->uri($url);
364 $url_builder = new URLBuilder($table_uri);
365 $query_params_namespace = ['badge'];
366
367 [$url_builder, $action_parameter_token, $row_id_token] = $url_builder->acquireParameters(
368 $query_params_namespace,
369 'table_action',
370 'id',
371 );
372
373 $table = $this->factory
374 ->table()
375 ->data(
376 $this,
377 $this->lng->txt('badge_personal_badges'),
378 $this->getColumns($this->user->getDateTimeFormat()),
379 )
380 ->withId(str_replace('\\', '', self::class))
381 ->withOrder(new Order('title', Order::ASC))
382 ->withRange(new Range(0, 50))
383 ->withActions($this->getActions($url_builder, $action_parameter_token, $row_id_token))
384 ->withRequest($this->request);
385
386 $pres = new PresentationHeader($this->dic, ilBadgeProfileGUI::class);
387 $pres->show($this->lng->txt('table_view'));
388
389 $content_wrapper = new TableContentWrapper($this->renderer, $this->factory);
390 $this->tpl->setContent($this->renderer->render(
391 $content_wrapper->wrap(
392 $table
393 )
394 ));
395 }
This class provides a central helper method to wrap the content of a KS/UI > Table > Data into a spec...
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:29
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:29
getActions(URLBuilder $url_builder, URLBuilderToken $action_parameter_token, URLBuilderToken $row_id_token)
$url
Definition: shib_logout.php:70

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 49 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 65 of file class.ilBadgePersonalTableGUI.php.

◆ $dic

readonly ILIAS DI Container ilBadgePersonalTableGUI::$dic
private

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

◆ $factory

readonly Factory ilBadgePersonalTableGUI::$factory
private

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

◆ $irss

readonly IRSS ilBadgePersonalTableGUI::$irss
private

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

◆ $lng

readonly ilLanguage ilBadgePersonalTableGUI::$lng
private

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

◆ $object_data_cache

ilObjectDataCache ilBadgePersonalTableGUI::$object_data_cache
private

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

◆ $parent_metadata_cache

ilBadgePersonalTableGUI::$parent_metadata_cache = []
private

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

◆ $renderer

readonly Renderer ilBadgePersonalTableGUI::$renderer
private

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

◆ $request

readonly ServerRequestInterface RequestInterface ilBadgePersonalTableGUI::$request
private

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

◆ $tile

readonly Tile ilBadgePersonalTableGUI::$tile
private

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

◆ $tpl

readonly ilGlobalTemplateInterface ilBadgePersonalTableGUI::$tpl
private

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

◆ $user

readonly ilObjUser ilBadgePersonalTableGUI::$user
private

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


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