19 declare(strict_types=1);
77 private readonly ?
int $parent_ref_id =
null,
79 private readonly ?
int $parent_obj_id =
null,
80 private readonly ?
int $restrict_badge_id =
null 84 $this->
lng = $DIC->language();
85 $this->tpl = $DIC->ui()->mainTemplate();
86 $this->
factory = $DIC->ui()->factory();
87 $this->
renderer = $DIC->ui()->renderer();
88 $this->request = $DIC->http()->request();
89 $this->tree = $DIC->repositoryTree();
90 $this->
user = $DIC->user();
92 if ($this->parent_ref_id) {
94 if (\in_array($parent_type, [
'grp',
'crs'],
true)) {
95 $this->is_container_context = $this->parent_obj_id ===
null && $this->award_badge ===
null;
113 private function getRecords(): array
115 if ($this->cached_records !==
null) {
125 $parent_obj_id = $this->parent_obj_id;
126 if (!$parent_obj_id && $this->parent_ref_id) {
130 if ($this->parent_ref_id) {
134 $obj_ids = [$parent_obj_id];
135 if ($this->is_container_context) {
136 foreach ($this->tree->getSubTree($this->tree->getNodeData($this->parent_ref_id)) as $node) {
137 $obj_ids[] = (
int) $node[
'obj_id'];
139 $obj_ids = array_unique($obj_ids);
142 foreach ($obj_ids as $obj_id) {
144 $badges[$badge->getId()] = $badge;
148 if ($this->restrict_badge_id && $this->restrict_badge_id !== $ass->getBadgeId()) {
152 if ($this->award_badge instanceof
ilBadge &&
153 $ass->getBadgeId() !== $this->award_badge->getId()) {
157 $assignments[$ass->getUserId()][] = $ass;
162 $user_ids = array_keys($assignments);
166 if (\count($user_ids) > 0) {
168 $uquery->setLimit(9999);
169 $uquery->setUserFilter($user_ids);
170 $tmp = $uquery->query();
173 foreach ($tmp[
'set'] as $user) {
174 if (\array_key_exists($user[
'usr_id'], $assignments)) {
175 foreach ($assignments[$user[
'usr_id']] as $user_ass) {
176 $idx = $user_ass->getBadgeId() .
'_' . $user_ass->getUserId();
178 $badge = $badges[$user_ass->getBadgeId()];
181 $paren_sortable =
null;
182 if ($this->is_container_context) {
183 $parent_metadata = $badge->getParentMeta();
185 $parent = implode(
' ', [
187 $this->factory->symbol()->icon()->custom(
189 $this->
lng->txt(
'obj_' . $parent_metadata[
'type'])
192 $parent_metadata[
'title']
194 $paren_sortable = $parent_metadata[
'title'];
199 'name' => $user[
'lastname'] .
', ' . $user[
'firstname'],
200 'login' => $user[
'login'],
202 'title' => $badge->getTitle(),
204 ->setTimestamp($user_ass->getTimestamp())
206 ->format($this->date_format->toString()),
208 ->setTimestamp($user_ass->getTimestamp())
211 'parent_sortable' => $paren_sortable,
214 } elseif ($this->award_badge) {
215 $idx = $this->award_badge->getId() .
'_' . $user[
'usr_id'];
219 'name' => $user[
'lastname'] .
', ' . $user[
'firstname'],
220 'login' => $user[
'login'],
224 'issued_sortable' =>
null,
226 'parent_sortable' =>
null,
231 $this->cached_records = $rows;
237 DataRowBuilder $row_builder,
238 array $visible_column_ids,
242 ?array $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 293 ?array $additional_parameters
295 return \count($this->getRecords());
304 'name' => $this->
factory->table()->column()->text($this->
lng->txt(
'name')),
305 'login' => $this->
factory->table()->column()->text($this->
lng->txt(
'login')),
306 'type' => $this->
factory->table()->column()->text($this->
lng->txt(
'type')),
307 'title' => $this->
factory->table()->column()->text($this->
lng->txt(
'title')),
309 'issued' => $this->
factory->table()->column()->text($this->
lng->txt(
'badge_issued_on'))
312 if ($this->is_container_context) {
313 $columns[
'parent'] = $this->
factory->table()->column()->text($this->
lng->txt(
'object'));
327 return ($this->award_badge instanceof
ilBadge) ? [
328 'badge_award_badge' =>
329 $this->
factory->table()->action()->multi(
330 $this->
lng->txt(
'badge_award_badge'),
331 $url_builder->
withParameter($action_parameter_token,
'assignBadge'),
334 'badge_revoke_badge' =>
335 $this->
factory->table()->action()->multi(
336 $this->
lng->txt(
'badge_remove_badge'),
337 $url_builder->
withParameter($action_parameter_token,
'revokeBadge'),
345 $df = new \ILIAS\Data\Factory();
347 $this->date_format = $df->dateFormat()->withTime12($this->
user->getDateFormat());
349 $this->date_format = $df->dateFormat()->withTime24($this->
user->getDateFormat());
352 $table_uri = $df->uri($this->request->getUri()->__toString());
354 $query_params_namespace = [
'tid'];
356 [$url_builder, $action_parameter_token, $row_id_token] = $url_builder->acquireParameters(
357 $query_params_namespace,
362 if ($this->award_badge instanceof
ilBadge) {
363 $title = $this->
lng->txt(
'badge_award_badge') .
': ' . $this->award_badge->getTitle();
366 if ($this->parent_obj_id) {
371 $title = $title[
'title'];
375 if ($this->restrict_badge_id) {
376 $badge =
new ilBadge($this->restrict_badge_id);
377 $title .=
' - ' . $badge->getTitle();
380 $parent = $title .
': ';
382 $title = $parent . $this->
lng->txt(
'users');
388 ->withId(self::class .
'_' . $this->parent_ref_id)
390 ->withActions($this->
getActions($url_builder, $action_parameter_token, $row_id_token))
391 ->withRequest($this->request);
join($init, callable $fn)
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
readonly Renderer $renderer
static getInstancesByParentId(int $a_parent_id, ?array $a_filter=null)
getActions(URLBuilder $url_builder, URLBuilderToken $action_parameter_token, URLBuilderToken $row_id_token,)
bool $is_container_context
Both the subject and the direction need to be specified when expressing an order. ...
static _lookupObjId(int $ref_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static _lookupTitle(int $obj_id)
static getExtendedTypeCaption(ilBadgeType $a_type)
readonly ServerRequestInterface RequestInterface $request
__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)
static getInstancesByParentId(int $a_parent_obj_id)
readonly ilGlobalTemplateInterface $tpl
readonly Factory $factory
withParameter(URLBuilderToken $token, string|array $value)
Change an acquired parameter's value if the supplied token is valid.
static get(int $a_object_id)
getRows(DataRowBuilder $row_builder, array $visible_column_ids, Range $range, Order $order, ?array $filter_data, ?array $additional_parameters)
static _lookupType(int $id, bool $reference=false)
A simple class to express a naive range of whole positive numbers.
getTotalRowCount(?array $filter_data, ?array $additional_parameters)
Mainly for the purpose of pagination-support, it is important to know about the total number of recor...