19declare(strict_types=1);
27use Psr\Http\Message\ServerRequestInterface;
28use Psr\Http\Message\RequestInterface;
44 private readonly ServerRequestInterface|RequestInterface
$request;
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();
85 $this->irss =
$DIC[
'resource_storage'];
86 $this->object_data_cache =
$DIC[
'ilObjDataCache'];
91 array $visible_column_ids,
94 mixed $additional_viewcontrol_data,
96 mixed $additional_parameters
101 [$order_field, $order_direction] = $order->
join(
103 fn($ret, $key, $value) => [$key, $value]
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';
118 if ($order_field ===
'active') {
119 return $right[$order_field] <=> $left[$order_field];
122 return $left[$order_field] <=> $right[$order_field];
125 if ($order_direction === Order::DESC) {
126 $records = array_reverse($records);
136 $parent_obj_ids = [];
137 $identifications = [];
139 foreach ($records as $record) {
140 $badge = $record[
'badge'];
141 $parent_obj_ids[] = $badge->getParentId();
142 $identifications[] = $badge->getImageRid();
144 $this->irss->preload(array_filter($identifications));
145 $this->object_data_cache->preloadObjectCache(array_unique($parent_obj_ids));
147 foreach ($records as $record) {
172 array &$access_cache,
175 $badge = $record[
'badge'];
176 $ass = $record[
'assignment'];
179 if ($badge->getParentId()) {
180 if (isset($this->parent_metadata_cache[$badge->getParentId()])) {
181 $parent = $this->parent_metadata_cache[$badge->getParentId()];
183 $parent = $badge->getParentMeta();
184 $this->parent_metadata_cache[$badge->getParentId()] = $parent;
186 if ($parent[
'type'] ===
'bdga') {
192 if ($parent !==
null) {
193 if (isset($ref_id_cache[$parent[
'id']])) {
194 $ref_id = $ref_id_cache[$parent[
'id']];
197 $ref_id_cache[$parent[
'id']] =
$ref_id;
200 $awarded_by = $parent[
'title'];
203 if (!isset($access_cache[
$ref_id])) {
204 $access_cache[
$ref_id] = $access;
208 $awarded_by = $this->
renderer->render(
211 (
string)
new URI(ilLink::_getLink(
$ref_id, $parent[
'type']))
216 $awarded_by = implode(
' ', [
218 $this->factory->symbol()->icon()->standard(
229 $this->tile->asImage(
230 $this->tile->modalContentWithAssignment($badge, $ass),
231 ilBadgeImage::IMAGE_SIZE_XS
235 $this->tile->asTitle(
236 $this->tile->modalContentWithAssignment($badge, $ass)
239 'awarded_by' => $awarded_by,
246 mixed $additional_viewcontrol_data,
248 mixed $additional_parameters
250 return count($this->getRecords());
266 if ($this->cached_records !==
null) {
267 return $this->cached_records;
271 $a_user_id = $this->
user->getId();
274 $badge =
new ilBadge($ass->getBadgeId());
277 if ($badge->getParentId()) {
278 if (isset($this->parent_metadata_cache[$badge->getParentId()])) {
279 $parent = $this->parent_metadata_cache[$badge->getParentId()];
281 $parent = $badge->getParentMeta();
282 $this->parent_metadata_cache[$badge->getParentId()] = $parent;
284 if ($parent[
'type'] ===
'bdga') {
289 $awarded_by_sortable =
'';
290 if ($parent !==
null) {
291 $awarded_by_sortable = $parent[
'title'];
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,
307 $this->cached_records = $rows;
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'),
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')
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'),
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'),
361 $df = new \ILIAS\Data\Factory();
363 $table_uri = $df->uri(
$url);
365 $query_params_namespace = [
'badge'];
367 [$url_builder, $action_parameter_token, $row_id_token] = $url_builder->acquireParameters(
368 $query_params_namespace,
377 $this->
lng->txt(
'badge_personal_badges'),
378 $this->getColumns($this->user->getDateTimeFormat()),
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);
387 $pres->show($this->
lng->txt(
'table_view'));
390 $this->tpl->setContent($this->
renderer->render(
391 $content_wrapper->wrap(
This class provides a central helper method to wrap the content of a KS/UI > Table > Data into a spec...
Customizing of pimple-DIC for ILIAS.
Builds a Color from either hex- or rgb values.
Both the subject and the direction need to be specified when expressing an order.
join($init, callable $fn)
A simple class to express a naive range of whole positive numbers.
The scope of this class is split ilias-conform URI's into components.
static getInstancesByUserId(int $a_user_id)
readonly Renderer $renderer
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....
getColumns(\ILIAS\Data\DateFormat\DateFormat $date_format)
getActions(URLBuilder $url_builder, URLBuilderToken $action_parameter_token, URLBuilderToken $row_id_token)
readonly Factory $factory
enrichRecord(array $record, array &$access_cache, array &$ref_id_cache)
readonly ServerRequestInterface RequestInterface $request
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...
ilObjectDataCache $object_data_cache
readonly ILIAS DI Container $dic
readonly ilGlobalTemplateInterface $tpl
readonly ilAccessHandler $access
static _getAllReferences(int $id)
get all reference ids for object ID
static strCmp(string $a, string $b)
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
A Column describes the form of presentation for a certain aspect of data, i.e.
buildDataRow(string $id, array $record)
This is how the factory for UI elements looks.
An entity that renders components to a string output.
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.