19declare(strict_types=1);
30use Psr\Http\Message\ServerRequestInterface;
31use Psr\Http\Message\RequestInterface;
53 private readonly ServerRequestInterface|RequestInterface
$request;
76 private readonly ?
int $parent_ref_id =
null,
77 private readonly ?
ilBadge $award_badge =
null,
78 private readonly ?
int $parent_obj_id =
null,
79 private readonly ?
int $restrict_badge_id =
null
83 $this->
lng = $DIC->language();
84 $this->tpl =
$DIC->ui()->mainTemplate();
85 $this->
factory = $DIC->ui()->factory();
86 $this->
renderer = $DIC->ui()->renderer();
87 $this->request =
$DIC->http()->request();
88 $this->tree =
$DIC->repositoryTree();
89 $this->
user = $DIC->user();
91 if ($this->parent_ref_id) {
93 if (\in_array($parent_type, [
'grp',
'crs'],
true)) {
94 $this->is_container_context = $this->parent_obj_id ===
null && $this->award_badge ===
null;
112 private function getRecords(): array
114 if ($this->cached_records !==
null) {
124 $parent_obj_id = $this->parent_obj_id;
125 if (!$parent_obj_id && $this->parent_ref_id) {
129 if ($this->parent_ref_id) {
133 $obj_ids = [$parent_obj_id];
134 if ($this->is_container_context) {
135 foreach ($this->tree->getSubTree($this->tree->getNodeData($this->parent_ref_id)) as $node) {
136 $obj_ids[] = (
int) $node[
'obj_id'];
138 $obj_ids = array_unique($obj_ids);
141 foreach ($obj_ids as $obj_id) {
143 $badges[$badge->getId()] = $badge;
147 if ($this->restrict_badge_id && $this->restrict_badge_id !== $ass->getBadgeId()) {
151 if ($this->award_badge instanceof
ilBadge &&
152 $ass->getBadgeId() !== $this->award_badge->
getId()) {
156 $assignments[$ass->getUserId()][] = $ass;
161 $user_ids = array_keys($assignments);
165 if (\count($user_ids) > 0) {
167 $uquery->setLimit(9999);
168 $uquery->setUserFilter($user_ids);
169 $tmp = $uquery->query();
172 foreach ($tmp[
'set'] as
$user) {
173 if (\array_key_exists(
$user[
'usr_id'], $assignments)) {
174 foreach ($assignments[
$user[
'usr_id']] as $user_ass) {
175 $idx = $user_ass->getBadgeId() .
'_' . $user_ass->getUserId();
177 $badge = $badges[$user_ass->getBadgeId()];
180 $paren_sortable =
null;
181 if ($this->is_container_context) {
182 $parent_metadata = $badge->getParentMeta();
184 $parent = implode(
' ', [
186 $this->factory->symbol()->icon()->custom(
188 $this->lng->txt(
'obj_' . $parent_metadata[
'type'])
191 $parent_metadata[
'title']
193 $paren_sortable = $parent_metadata[
'title'];
198 'name' =>
$user[
'lastname'] .
', ' .
$user[
'firstname'],
199 'login' =>
$user[
'login'],
201 'title' => $badge->getTitle(),
202 'issued' => (
new DateTimeImmutable())
203 ->setTimestamp($user_ass->getTimestamp())
204 ->setTimezone(
new \DateTimeZone($this->
user->getTimeZone()))
205 ->format($this->date_format->toString()),
206 'issued_sortable' => (
new DateTimeImmutable())
207 ->setTimestamp($user_ass->getTimestamp())
208 ->setTimezone(
new \DateTimeZone($this->
user->getTimeZone())),
210 'parent_sortable' => $paren_sortable,
213 } elseif ($this->award_badge) {
214 $idx = $this->award_badge->getId() .
'_' .
$user[
'usr_id'];
218 'name' =>
$user[
'lastname'] .
', ' .
$user[
'firstname'],
219 'login' =>
$user[
'login'],
223 'issued_sortable' =>
null,
225 'parent_sortable' =>
null,
230 $this->cached_records = $rows;
237 array $visible_column_ids,
240 mixed $additional_viewcontrol_data,
242 mixed $additional_parameters
244 $records = $this->getRecords();
247 [$order_field, $order_direction] = $order->
join(
249 fn($ret, $key, $value) => [$key, $value]
251 usort($records,
static function (array $left, array $right) use ($order_field):
int {
252 if (\in_array($order_field, [
'name',
'login',
'type',
'title',
'parent'],
true)) {
253 if ($order_field ===
'parent') {
254 $order_field .=
'_sortable';
257 return \ilStr::strCmp(
258 $left[$order_field] ??
'',
259 $right[$order_field] ??
''
263 if ($order_field ===
'issued') {
264 $order_field .=
'_sortable';
265 return $left[$order_field] <=> $right[$order_field];
268 return $left[$order_field] <=> $right[$order_field];
271 if ($order_direction === ORDER::DESC) {
272 $records = array_reverse($records);
280 foreach ($records as $record) {
281 yield $row_builder->
buildDataRow($record[
'id'], $record)->withDisabledAction(
283 $record[
'issued'] ===
null
284 )->withDisabledAction(
285 'badge_revoke_badge',
286 $record[
'issued'] !==
null
292 mixed $additional_viewcontrol_data,
294 mixed $additional_parameters
296 return \count($this->getRecords());
305 'name' => $this->
factory->table()->column()->text($this->
lng->txt(
'name')),
306 'login' => $this->
factory->table()->column()->text($this->
lng->txt(
'login')),
307 'type' => $this->
factory->table()->column()->text($this->
lng->txt(
'type')),
308 'title' => $this->
factory->table()->column()->text($this->
lng->txt(
'title')),
310 'issued' => $this->
factory->table()->column()->text($this->
lng->txt(
'badge_issued_on'))
313 if ($this->is_container_context) {
314 $columns[
'parent'] = $this->
factory->table()->column()->text($this->
lng->txt(
'object'));
329 'badge_award_badge' =>
330 $this->
factory->table()->action()->multi(
331 $this->
lng->txt(
'badge_award_badge'),
332 $url_builder->withParameter($action_parameter_token,
'assignBadge'),
335 'badge_revoke_badge' =>
336 $this->
factory->table()->action()->multi(
337 $this->
lng->txt(
'badge_remove_badge'),
338 $url_builder->withParameter($action_parameter_token,
'revokeBadge'),
346 $df = new \ILIAS\Data\Factory();
347 $this->date_format = $this->
user->getDateTimeFormat();
349 $table_uri = $df->uri(
$url);
351 $query_params_namespace = [
'tid'];
353 [$url_builder, $action_parameter_token, $row_id_token] = $url_builder->acquireParameters(
354 $query_params_namespace,
359 if ($this->award_badge instanceof
ilBadge) {
360 $title = $this->
lng->txt(
'badge_award_badge') .
': ' . $this->award_badge->getTitle();
363 if ($this->parent_obj_id) {
368 $title = $title[
'title'];
372 if ($this->restrict_badge_id) {
373 $badge =
new ilBadge($this->restrict_badge_id);
374 $title .=
' - ' . $badge->getTitle();
377 $parent = $title .
': ';
379 $title = $parent . $this->
lng->txt(
'users');
384 ->data($this, $title, $this->getColumns())
385 ->withId(str_replace(
'\\',
'', self::class) .
'_' . $this->parent_ref_id)
386 ->withOrder(
new Order(
'name', Order::ASC))
387 ->withRange(
new Range(0, 100))
388 ->withActions($this->getActions($url_builder, $action_parameter_token, $row_id_token))
389 ->withRequest($this->request);
bool $is_container_context
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...
__construct(private readonly ?int $parent_ref_id=null, private readonly ?ilBadge $award_badge=null, private readonly ?int $parent_obj_id=null, private readonly ?int $restrict_badge_id=null)
readonly ilGlobalTemplateInterface $tpl
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....
getActions(URLBuilder $url_builder, URLBuilderToken $action_parameter_token, URLBuilderToken $row_id_token,)
readonly ServerRequestInterface RequestInterface $request
readonly Factory $factory
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.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstancesByParentId(int $a_parent_obj_id)
static getExtendedTypeCaption(ilBadgeType $a_type)
static getInstancesByParentId(int $a_parent_id, ?array $a_filter=null)
static get(int $a_object_id)
Class ilObject Basic functions for all objects.
static _lookupType(int $id, bool $reference=false)
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
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.