ILIAS  release_8 Revision v8.24
ilUserAvatarResolver Class Reference

Class ilUserAvatarResolver. More...

+ Collaboration diagram for ilUserAvatarResolver:

Public Member Functions

 __construct (int $user_id)
 
 getAvatar (bool $name_as_set_as_text_closely=false)
 
 setForcePicture (bool $force_image)
 
 setSize (string $size)
 

Protected Attributes

ilObjUser $user
 
ilLanguage $lng
 
ilDBInterface $db
 
Factory $ui
 
bool $letter_avatars_activated
 

Private Member Functions

 init ()
 
 useUploadedFile ()
 

Private Attributes

int $user_id = 0
 
string $login = ""
 
string $firstname = ""
 
string $lastname = ""
 
bool $has_public_profile = false
 
bool $has_public_upload = false
 
string $uploaded_file = ""
 
string $abbreviation = ""
 
bool $force_image = false
 
string $size = 'small'
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilUserAvatarResolver::__construct ( int  $user_id)

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

45 {
46 global $DIC;
47
48 $this->db = $DIC->database();
49 $this->ui = $DIC->ui()->factory();
50 $this->lng = $DIC->language();
51 $this->user = $DIC->user();
52 $this->user_id = $user_id;
53 $this->letter_avatars_activated = (bool) $DIC->settings()->get('letter_avatars');
54 $this->init();
55 }
global $DIC
Definition: feed.php:28

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

+ 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 111 of file class.ilUserAvatarResolver.php.

111 : Avatar
112 {
113 if ($name_as_set_as_text_closely) {
114 $alternative_text = $this->lng->txt("user_avatar");
115 } elseif ($this->user_id == $this->user->getId() && !$this->user::_isAnonymous($this->user_id)) {
116 $alternative_text = $this->lng->txt("current_user_avatar");
117 } else {
118 $alternative_text = $this->lng->txt("user_avatar_of") . " " . $this->login;
119 }
120
121 if ($this->useUploadedFile()) {
122 $picture = ilWACSignedPath::signFile($this->uploaded_file);
123 return $this->ui->symbol()->avatar()->picture($picture, $this->login)
124 ->withLabel($alternative_text);
125 }
126
127 if ($this->letter_avatars_activated === false) {
128 return $this->ui->symbol()->avatar()->picture(
129 \ilUtil::getImagePath('no_photo_xsmall.jpg'),
130 ilObjUser::_lookupLogin($this->user_id)
131 );
132 }
133
134 return $this->ui->symbol()->avatar()->letter($this->abbreviation)->withLabel($alternative_text);
135 }
static _lookupLogin(int $a_user_id)
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static signFile(string $path_to_file)
This describes how a letter or a picture avatar could be modified during construction of UI.
Definition: Avatar.php:29

References $login, ilObjUser\_lookupLogin(), ilUtil\getImagePath(), ILIAS\Repository\lng(), ILIAS\UI\examples\Symbol\Glyph\Login\login(), ilWACSignedPath\signFile(), ILIAS\Repository\ui(), ILIAS\Repository\user(), and useUploadedFile().

+ Here is the call graph for this function:

◆ init()

ilUserAvatarResolver::init ( )
private

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

57 : void
58 {
59 $in = $this->db->in('usr_pref.keyword', array('public_upload', 'public_profile'), false, 'text');
60 $res = $this->db->queryF(
61 "
62 SELECT usr_pref.*, ud.login, ud.firstname, ud.lastname
63 FROM usr_data ud LEFT JOIN usr_pref ON usr_pref.usr_id = ud.usr_id AND $in
64 WHERE ud.usr_id = %s",
65 array('integer'),
66 array($this->user_id)
67 );
68
69 while ($row = $this->db->fetchAssoc($res)) { // MUST be loop
70 $this->login = $row['login'] ?? '';
71 $this->firstname = $row['firstname'] ?? '';
72 $this->lastname = $row['lastname'] ?? '';
73
74 switch ($row['keyword']) {
75 case 'public_upload':
76 $this->has_public_upload = $row['value'] === 'y';
77 break;
78 case 'public_profile':
79 $this->has_public_profile = ($row['value'] === 'y' || $row['value'] === 'g');
80 break;
81 }
82 }
83
84 // Uploaded file
85 $webspace_dir = '';
86 if (defined('ILIAS_MODULE')) {
87 $webspace_dir = ('.' . $webspace_dir);
88 }
89 $webspace_dir .= ('./' . ltrim(ilFileUtils::getWebspaceDir(), "./"));
90
91 $image_dir = $webspace_dir . '/usr_images';
92 $this->uploaded_file = $image_dir . '/usr_' . $this->user_id . '.jpg';
93
94 if ($this->has_public_profile) {
95 $this->abbreviation = ilStr::subStr($this->firstname, 0, 1) . ilStr::subStr($this->lastname, 0, 1);
96 } else {
97 $this->abbreviation = ilStr::subStr($this->login, 0, 2);
98 }
99 }
static getWebspaceDir(string $mode="filesystem")
get webspace directory
static subStr(string $a_str, int $a_start, ?int $a_length=null)
Definition: class.ilStr.php:24
$res
Definition: ltiservices.php:69

References $res, ilFileUtils\getWebspaceDir(), ILIAS\UI\examples\Symbol\Glyph\Login\login(), and ilStr\subStr().

Referenced by __construct().

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

◆ setForcePicture()

ilUserAvatarResolver::setForcePicture ( bool  $force_image)

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

152 : void
153 {
154 $this->force_image = $force_image;
155 }

References $force_image.

◆ setSize()

ilUserAvatarResolver::setSize ( string  $size)

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

157 : void
158 {
159 if ($size === 'small' || $size === 'big') {
160 $size = 'xsmall';
161 }
162
163 $this->size = $size;
164 }

References $size.

◆ useUploadedFile()

ilUserAvatarResolver::useUploadedFile ( )
private

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

101 : bool
102 {
103 return (($this->has_public_upload && $this->has_public_profile) || $this->force_image) && is_file($this->uploaded_file);
104 }

Referenced by getAvatar().

+ Here is the caller graph for this function:

Field Documentation

◆ $abbreviation

string ilUserAvatarResolver::$abbreviation = ""
private

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

◆ $db

ilDBInterface ilUserAvatarResolver::$db
protected

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

◆ $firstname

string ilUserAvatarResolver::$firstname = ""
private

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

◆ $force_image

bool ilUserAvatarResolver::$force_image = false
private

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

Referenced by setForcePicture().

◆ $has_public_profile

bool ilUserAvatarResolver::$has_public_profile = false
private

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

◆ $has_public_upload

bool ilUserAvatarResolver::$has_public_upload = false
private

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

◆ $lastname

string ilUserAvatarResolver::$lastname = ""
private

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

◆ $letter_avatars_activated

bool ilUserAvatarResolver::$letter_avatars_activated
protected

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

◆ $lng

ilLanguage ilUserAvatarResolver::$lng
protected

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

◆ $login

string ilUserAvatarResolver::$login = ""
private

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

Referenced by getAvatar().

◆ $size

string ilUserAvatarResolver::$size = 'small'
private

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

Referenced by setSize().

◆ $ui

Factory ilUserAvatarResolver::$ui
protected

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

◆ $uploaded_file

string ilUserAvatarResolver::$uploaded_file = ""
private

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

◆ $user

ilObjUser ilUserAvatarResolver::$user
protected

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

◆ $user_id

int ilUserAvatarResolver::$user_id = 0
private

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

Referenced by __construct().


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