ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
ilUserAvatarResolver Class Reference

Class ilUserAvatarResolver. More...

+ Collaboration diagram for ilUserAvatarResolver:

Public Member Functions

 __construct (int $user_id)
 constructor. More...
 
 getAvatar ()
 
 setForcePicture (bool $force_image)
 
 setSize (string $size)
 

Protected Attributes

 $letter_avatars_activated
 

Private Member Functions

 init ()
 
 useUploadedFile ()
 

Private Attributes

 $user_id
 
 $login
 
 $firstname
 
 $lastname
 
 $has_public_profile = false
 
 $has_public_upload = false
 
 $uploaded_file
 
 $abbreviation
 
 $force_image = false
 
 $size = 'small'
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilUserAvatarResolver::__construct ( int  $user_id)

constructor.

Parameters
int$user_id

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

References $DIC, $user_id, init(), and ui().

61  {
62  global $DIC;
63  $this->db = $DIC->database();
64  $this->ui = $DIC->ui()->factory();
65  $this->user_id = $user_id;
66  $this->letter_avatars_activated = (bool) $DIC->settings()->get('letter_avatars');
67  $this->init();
68  }
ui()
Definition: ui.php:5
$DIC
Definition: xapitoken.php:46
+ Here is the call graph for this function:

Member Function Documentation

◆ getAvatar()

ilUserAvatarResolver::getAvatar ( )

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

References $DIC, ilObjUser\_lookupLogin(), ilUtil\getImagePath(), ui(), and useUploadedFile().

119  : Avatar
120  {
121  if ($this->useUploadedFile()) {
122  return $this->ui->symbol()->avatar()->picture($this->uploaded_file, $this->abbreviation);
123  }
124 
125  if ($this->letter_avatars_activated === false) {
126  return $this->ui->symbol()->avatar()->picture(
127  \ilUtil::getImagePath('no_photo_xsmall.jpg'),
128  ilObjUser::_lookupLogin($this->user_id)
129  );
130  }
131  return $this->ui->symbol()->avatar()->letter($this->abbreviation);
132  }
static _lookupLogin($a_user_id)
lookup login
This describes how a letter or a picture avatar could be modified during construction of UI...
Definition: Avatar.php:8
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
ui()
Definition: ui.php:5
+ Here is the call graph for this function:

◆ init()

ilUserAvatarResolver::init ( )
private

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

References $in, $res, ilUtil\getWebspaceDir(), login(), and ilStr\subStr().

Referenced by __construct().

70  : void
71  {
72  $in = $this->db->in('usr_pref.keyword', array('public_upload', 'public_profile'), false, 'text');
73  $res = $this->db->queryF(
74  "
75  SELECT usr_pref.*, ud.login, ud.firstname, ud.lastname
76  FROM usr_data ud LEFT JOIN usr_pref ON usr_pref.usr_id = ud.usr_id AND $in
77  WHERE ud.usr_id = %s",
78  array('integer'),
79  array($this->user_id)
80  );
81 
82  while ($row = $this->db->fetchAssoc($res)) {
83  $this->login = $row['login'];
84  $this->firstname = $row['firstname'];
85  $this->lastname = $row['lastname'];
86 
87  switch ($row['keyword']) {
88  case 'public_upload':
89  $this->has_public_upload = $row['value'] === 'y';
90  break;
91  case 'public_profile':
92  $this->has_public_profile = ($row['value'] === 'y' || $row['value'] === 'g');
93  break;
94  }
95  }
96 
97  // Uploaded file
98  $webspace_dir = '';
99  if (defined('ILIAS_MODULE')) {
100  $webspace_dir = ('.' . $webspace_dir);
101  }
102  $webspace_dir .= ('./' . ltrim(ilUtil::getWebspaceDir(), "./"));
103 
104  $image_dir = $webspace_dir . '/usr_images';
105  $this->uploaded_file = $image_dir . '/usr_' . $this->user_id . '.jpg';
106 
107  if ($this->has_public_profile) {
108  $this->abbreviation = ilStr::subStr($this->firstname, 0, 1) . ilStr::subStr($this->lastname, 0, 1);
109  } else {
110  $this->abbreviation = ilStr::subStr($this->login, 0, 2);
111  }
112  }
login()
Definition: login.php:2
static subStr($a_str, $a_start, $a_length=null)
Definition: class.ilStr.php:15
foreach($_POST as $key=> $value) $res
if(php_sapi_name() !='cli') $in
Definition: Utf8Test.php:37
static getWebspaceDir($mode="filesystem")
get webspace directory
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setForcePicture()

ilUserAvatarResolver::setForcePicture ( bool  $force_image)
Parameters
bool$force_image

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

References $force_image.

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

◆ setSize()

ilUserAvatarResolver::setSize ( string  $size)
Parameters
string$size

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

References $size.

161  : void
162  {
163  if ($size === 'small' || $size === 'big') {
164  $size = 'xsmall';
165  }
166 
167  $this->size = $size;
168  }

◆ useUploadedFile()

ilUserAvatarResolver::useUploadedFile ( )
private

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

Referenced by getAvatar().

114  : bool
115  {
116  return (($this->has_public_upload && $this->has_public_profile) || $this->force_image) && is_file($this->uploaded_file);
117  }
+ Here is the caller graph for this function:

Field Documentation

◆ $abbreviation

ilUserAvatarResolver::$abbreviation
private

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

◆ $firstname

ilUserAvatarResolver::$firstname
private

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

◆ $force_image

ilUserAvatarResolver::$force_image = false
private

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

Referenced by setForcePicture().

◆ $has_public_profile

ilUserAvatarResolver::$has_public_profile = false
private

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

◆ $has_public_upload

ilUserAvatarResolver::$has_public_upload = false
private

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

◆ $lastname

ilUserAvatarResolver::$lastname
private

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

◆ $letter_avatars_activated

ilUserAvatarResolver::$letter_avatars_activated
protected

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

◆ $login

ilUserAvatarResolver::$login
private

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

◆ $size

ilUserAvatarResolver::$size = 'small'
private

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

Referenced by setSize().

◆ $uploaded_file

ilUserAvatarResolver::$uploaded_file
private

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

◆ $user_id

ilUserAvatarResolver::$user_id
private

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

Referenced by __construct().


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