ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ProfileBadge.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25use Psr\Http\Message\RequestInterface;
26
31{
32 public function __construct(
33 private readonly Language $lng,
34 private readonly \ilSetting $setting,
35 private readonly RequestInterface $request,
36 private readonly Profile $profile
37 ) {
38 }
39
40 public function getId(): string
41 {
42 return 'profile';
43 }
44
45 public function getCaption(): string
46 {
47 return $this->lng->txt('badge_user_profile');
48 }
49
50 public function isSingleton(): bool
51 {
52 return false;
53 }
54
55 public function getValidObjectTypes(): array // Missing array type.
56 {
57 return ['bdga'];
58 }
59
61 {
62 return new ProfileBadgeGUI(
63 $this->lng,
64 $this->request
65 );
66 }
67
68 public function evaluate(int $user_id, array $params, ?array $config): bool
69 {
70 $user = new \ilObjUser($user_id);
71
72 if ($this->setting->get('user_portfolios') !== '1'
73 || array_filter(
75 static fn(array $v): bool => $v['is_default'] === 1
76 ) !== []) {
77 // is profile public?
78 if (!in_array($user->getPref('public_profile'), ['y', 'g'])) {
79 return false;
80 }
81 }
82
83 if ($config === null || !isset($config['profile'])) {
84 return true;
85 }
86
87 foreach ($config['profile'] as $long_field_id) {
88 $field_id = substr($long_field_id, 4);
89 if (substr($field_id, 0, 4) === 'udf_') {
90 $field_id = substr($field_id, 4);
91 }
92
93 $field = $this->profile->getFieldByIdentifier($field_id);
94 if ($field === null) {
95 continue;
96 }
97 if (!$field->isPublishedByUser($user)
98 || empty($field->retrieveValueFromUser($user))) {
99 return false;
100 }
101 }
102
103 return true;
104 }
105}
getId()
Get typ id (unique for component)
isSingleton()
Can only be created once?
getConfigGUIInstance()
Get GUI config instance.
__construct(private readonly Language $lng, private readonly \ilSetting $setting, private readonly RequestInterface $request, private readonly Profile $profile)
evaluate(int $user_id, array $params, ?array $config)
Evaluate if given user has earned badge.
getValidObjectTypes()
Get valid (repository) "parent" object types.
ilSetting $setting
Definition: class.ilias.php:68
static getPortfoliosOfUser(int $a_user_id)
Get portfolios of user.
ILIAS Setting Class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:31
global $lng
Definition: privfeed.php:31