ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilUserAvatarResolver Class Reference

Class ilUserAvatarResolver. More...

+ Collaboration diagram for ilUserAvatarResolver:

Public Member Functions

 __construct (private int $user_id)
 
 hasProfilePicture ()
 
 getAvatar (bool $name_as_set_as_text_closely=false)
 
 getUserPictureForVCard ()
 
 getLegacyPictureURL ()
 This method returns the URL to the Profile Picture of a User. More...
 
 setForcePicture (bool $force_image)
 There are places where we want wo show the Profile Picture of a User, even if the user doesn't want to show it. More...
 
 setSize (string $size)
 There are the Sizes 'big', 'small', 'xsmall', 'xxsmall',. More...
 

Private Member Functions

 readUserSettings ()
 
 resolveProfilePicturePath ()
 

Private Attributes

ilDBInterface $db
 
ILIAS ResourceStorage Services $irss
 
Factory $ui
 
Language $lng
 
bool $letter_avatars_activated
 
ilUserProfilePictureDefinition $flavour_definition
 
string $size
 
bool $is_current_user
 
ilObjUser $for_user
 
bool $has_public_upload = false
 
bool $has_public_profile = false
 
ilUserAvatarFactory $avatar_factory
 
string $abbreviation = ''
 
string $rid = null
 
bool $force_image = false
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilUserAvatarResolver::__construct ( private int  $user_id)

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

49 {
50 global $DIC;
51 $this->is_current_user = $DIC->user()->getId() === $this->user_id;
52 $this->for_user = $this->is_current_user ? $DIC->user() : new ilObjUser($this->user_id);
53
54 $this->db = $DIC->database();
55 $this->irss = $DIC->resourceStorage();
56 $this->ui = $DIC->ui()->factory();
57 $this->lng = $DIC->language();
58 $this->avatar_factory = $DIC["user.avatar.factory"];
59
60 $this->letter_avatars_activated = (bool) $DIC->settings()->get('letter_avatars');
61 $this->flavour_definition = new ilUserProfilePictureDefinition();
62 $this->size = 'small';
63 $this->readUserSettings();
64 }
User class.
global $DIC
Definition: shib_login.php:26

References $DIC, $user_id, ILIAS\Repository\lng(), readUserSettings(), and ILIAS\Repository\ui().

+ Here is the call graph for this function:

Member Function Documentation

◆ getAvatar()

ilUserAvatarResolver::getAvatar ( bool  $name_as_set_as_text_closely = false)
Parameters
bool$name_as_set_as_text_closelyif the name is set as text close to the Avatar, the alternative text for screenreaders will be set differently, to reduce redundancy for screenreaders. See rules on the Avatar Symbol in the UI Components

Definition at line 134 of file class.ilUserAvatarResolver.php.

134 : Avatar
135 {
136 if ($name_as_set_as_text_closely) {
137 $alternative_text = $this->lng->txt("user_avatar");
138 } elseif ($this->is_current_user && !$this->for_user->isAnonymous()) {
139 $alternative_text = $this->lng->txt("current_user_avatar");
140 } else {
141 $alternative_text = $this->lng->txt("user_avatar_of") . " " . $this->for_user->getLogin();
142 }
143
144 if ($this->hasProfilePicture()) {
145 $picture = $this->getLegacyPictureURL();
146 return $this->ui->symbol()->avatar()->picture(
147 $picture,
148 $this->for_user->getLogin()
149 )->withLabel($alternative_text);
150 }
151
152 // Fallback Image
153 if ($this->letter_avatars_activated === false) {
154 return $this->ui->symbol()->avatar()->picture(
155 \ilUtil::getImagePath('placeholder/no_photo_xsmall.jpg'),
156 $this->for_user->getLogin()
157 );
158 }
159
160 return $this->ui->symbol()->avatar()->letter($this->abbreviation)->withLabel($alternative_text);
161 }
getLegacyPictureURL()
This method returns the URL to the Profile Picture of a User.
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
This describes how a letter or a picture avatar could be modified during construction of UI.
Definition: Avatar.php:29

References ilUtil\getImagePath(), getLegacyPictureURL(), hasProfilePicture(), ILIAS\Repository\lng(), and ILIAS\Repository\ui().

+ Here is the call graph for this function:

◆ getLegacyPictureURL()

ilUserAvatarResolver::getLegacyPictureURL ( )

This method returns the URL to the Profile Picture of a User.

Depending on Settings and the Availability of a Prodile Picture, there's a Fallback to the Letter Avatar as well (as data-URL).

Deprecated:
use getAvatar() instead

Definition at line 193 of file class.ilUserAvatarResolver.php.

193 : string
194 {
195 if ($this->hasProfilePicture()
196 && $this->rid !== null && $this->rid !== '-') {
197 return $this->resolveProfilePicturePath();
198 }
199
200 // LETTER AVATAR
201 $avatar = $this->avatar_factory->avatar($this->size);
202 $avatar->setName($this->abbreviation);
203 $avatar->setUsrId($this->user_id);
204
205 return $avatar->getUrl();
206 }

References hasProfilePicture(), and resolveProfilePicturePath().

Referenced by getAvatar().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUserPictureForVCard()

ilUserAvatarResolver::getUserPictureForVCard ( )

Definition at line 163 of file class.ilUserAvatarResolver.php.

163 : array
164 {
165 if (!$this->hasProfilePicture()) {
166 return [null, null];
167 }
168
169 if ($this->rid !== null
170 && $this->rid !== '-'
171 && ($identification = $this->irss->manage()->find($this->rid)) !== null) {
172 $flavour_streams = $this->irss->flavours()
173 ->get($identification, $this->flavour_definition)
174 ->getStreamResolvers();
175 $available_sizes = array_flip(array_keys($this->flavour_definition->getSizes()));
176 $size_index = $available_sizes[$this->size];
177 if (!isset($flavour_streams[$size_index])) {
178 return [null, null];
179 }
180 return [$flavour_streams[$size_index]->getStream()->__toString(), 'image/jpeg'];
181 }
182
183 return [null, null];
184 }

References $size, and hasProfilePicture().

+ Here is the call graph for this function:

◆ hasProfilePicture()

ilUserAvatarResolver::hasProfilePicture ( )

Definition at line 99 of file class.ilUserAvatarResolver.php.

99 : bool
100 {
101 if (!$this->force_image) {
102 if (!$this->has_public_profile || !$this->has_public_upload) {
103 return false;
104 }
105 }
106
107 if ($this->rid !== null && $this->irss->manage()->find($this->rid) !== null) {
108 return true;
109 }
110
111 return false;
112 }

Referenced by getAvatar(), getLegacyPictureURL(), and getUserPictureForVCard().

+ Here is the caller graph for this function:

◆ readUserSettings()

ilUserAvatarResolver::readUserSettings ( )
private

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

66 : void
67 {
68 $in = $this->db->in('usr_pref.keyword', ['public_upload', 'public_profile'], false, 'text');
69 $res = $this->db->queryF(
70 "
71 SELECT usr_data.rid, usr_pref.*
72 FROM usr_data LEFT JOIN usr_pref ON usr_pref.usr_id = usr_data.usr_id AND $in
73 WHERE usr_data.usr_id = %s",
74 ['integer'],
75 [$this->user_id]
76 );
77
78 while ($row = $this->db->fetchAssoc($res)) { // MUST be loop
79 $this->rid = $row['rid'] ?? null;
80 switch ($row['keyword']) {
81 case 'public_upload':
82 $this->has_public_upload = $row['value'] === 'y';
83 break;
84 case 'public_profile':
85 $this->has_public_profile = ($row['value'] === 'y' || $row['value'] === 'g');
86 break;
87 }
88 }
89
90 if ($this->has_public_profile) {
91 $sub_str_firstname = ilStr::subStr($this->for_user->getFirstname(), 0, 1);
92 $sub_str_lastname = ilStr::subStr($this->for_user->getLastname(), 0, 1);
93 $this->abbreviation = $sub_str_firstname . $sub_str_lastname;
94 } else {
95 $this->abbreviation = ilStr::subStr($this->for_user->getLogin(), 0, 2);
96 }
97 }
static subStr(string $a_str, int $a_start, ?int $a_length=null)
Definition: class.ilStr.php:21
$res
Definition: ltiservices.php:69

References $res, and ilStr\subStr().

Referenced by __construct().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resolveProfilePicturePath()

ilUserAvatarResolver::resolveProfilePicturePath ( )
private

Definition at line 114 of file class.ilUserAvatarResolver.php.

114 : string
115 {
116 $rid = $this->irss->manage()->find($this->rid);
117 if ($rid === null) {
118 return '';
119 }
120 $flavour = $this->irss->flavours()->get($rid, $this->flavour_definition);
121 $urls = $this->irss->consume()->flavourUrls($flavour)->getURLsAsArray(false);
122
123 $available_sizes = array_flip(array_keys($this->flavour_definition->getSizes()));
124 $size_index = $available_sizes[$this->size];
125
126 return $urls[$size_index] ?? '';
127 }

References $rid, and $size.

Referenced by getLegacyPictureURL().

+ Here is the caller graph for this function:

◆ setForcePicture()

ilUserAvatarResolver::setForcePicture ( bool  $force_image)

There are places where we want wo show the Profile Picture of a User, even if the user doesn't want to show it.

(e.g. in Administration)

Definition at line 212 of file class.ilUserAvatarResolver.php.

212 : void
213 {
214 $this->force_image = $force_image;
215 }

References $force_image.

◆ setSize()

ilUserAvatarResolver::setSize ( string  $size)

There are the Sizes 'big', 'small', 'xsmall', 'xxsmall',.

See also
ilUserProfilePictureDefinition

Definition at line 220 of file class.ilUserAvatarResolver.php.

220 : void
221 {
222 $this->size = $size;
223 }

References $size.

Field Documentation

◆ $abbreviation

string ilUserAvatarResolver::$abbreviation = ''
private

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

◆ $avatar_factory

ilUserAvatarFactory ilUserAvatarResolver::$avatar_factory
private

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

◆ $db

ilDBInterface ilUserAvatarResolver::$db
private

Definition at line 31 of file class.ilUserAvatarResolver.php.

◆ $flavour_definition

ilUserProfilePictureDefinition ilUserAvatarResolver::$flavour_definition
private

Definition at line 36 of file class.ilUserAvatarResolver.php.

◆ $for_user

ilObjUser ilUserAvatarResolver::$for_user
private

Definition at line 39 of file class.ilUserAvatarResolver.php.

◆ $force_image

bool ilUserAvatarResolver::$force_image = false
private

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

Referenced by setForcePicture().

◆ $has_public_profile

bool ilUserAvatarResolver::$has_public_profile = false
private

Definition at line 41 of file class.ilUserAvatarResolver.php.

◆ $has_public_upload

bool ilUserAvatarResolver::$has_public_upload = false
private

Definition at line 40 of file class.ilUserAvatarResolver.php.

◆ $irss

ILIAS ResourceStorage Services ilUserAvatarResolver::$irss
private

Definition at line 32 of file class.ilUserAvatarResolver.php.

◆ $is_current_user

bool ilUserAvatarResolver::$is_current_user
private

Definition at line 38 of file class.ilUserAvatarResolver.php.

◆ $letter_avatars_activated

bool ilUserAvatarResolver::$letter_avatars_activated
private

Definition at line 35 of file class.ilUserAvatarResolver.php.

◆ $lng

Language ilUserAvatarResolver::$lng
private

Definition at line 34 of file class.ilUserAvatarResolver.php.

◆ $rid

string ilUserAvatarResolver::$rid = null
private

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

Referenced by resolveProfilePicturePath().

◆ $size

string ilUserAvatarResolver::$size
private

◆ $ui

Factory ilUserAvatarResolver::$ui
private

Definition at line 33 of file class.ilUserAvatarResolver.php.


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