Moodle APIs 4.3
Moodle 4.3.6 (Build: 20240812)
user_picture Class Reference

Data structure representing a user picture. More...

Inheritance diagram for user_picture:

Public Member Functions

 __construct (stdClass $user)
 User picture constructor.
 
 get_url (moodle_page $page, renderer_base $renderer=null)
 Works out the URL for the users picture.
 

Static Public Member Functions

static fields ($tableprefix='', array $extrafields=NULL, $idalias='id', $fieldprefix='')
 Returns a list of required user fields, useful when fetching required user info from db.
 
static unalias (stdClass $record, array $extrafields=null, $idalias='id', $fieldprefix='')
 Extract the aliased user fields from a given record.
 

Public Attributes

bool $alttext = true
 Add non-blank alt-text to the image.
 
string $class = 'userpicture'
 Image class attribute.
 
int $courseid
 The course id.
 
bool $includefullname = false
 Whether to include the fullname in the user picture link.
 
mixed $includetoken = false
 Include user authentication token.
 
bool $link = true
 Add course profile link to image.
 
bool $popup = false
 Whether or not to open the link in a popup window.
 
int $size = 35
 Size in pixels.
 
stdClass $user
 A user object with at least fields all columns specified in $fields array constant set.
 
bool $visibletoscreenreaders = true
 Whether to be visible to screen readers.
 

Detailed Description

Data structure representing a user picture.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
Since
Modle 2.0

Constructor & Destructor Documentation

◆ __construct()

user_picture::__construct ( stdClass $user)

User picture constructor.

Parameters
stdClass$useruser record with at least id, picture, imagealt, firstname and lastname set. It is recommended to add also contextid of the user for performance reasons.

Member Function Documentation

◆ fields()

static user_picture::fields ( $tableprefix = '',
array $extrafields = NULL,
$idalias = 'id',
$fieldprefix = '' )
static

Returns a list of required user fields, useful when fetching required user info from db.

In some cases we have to fetch the user data together with some other information, the idalias is useful there because the id would otherwise override the main id of the result record. Please note it has to be converted back to id before rendering.

Parameters
string$tableprefixname of database table prefix in query
array$extrafieldsextra fields to be included in result (do not include TEXT columns because it would break SELECT DISTINCT in MSSQL and ORACLE)
string$idaliasalias of id field
string$fieldprefixprefix to add to all columns in their aliases, does not apply to 'id'
Return values
string
Deprecated
since Moodle 3.11 MDL-45242
See also
core_user\fields

◆ get_url()

user_picture::get_url ( moodle_page $page,
renderer_base $renderer = null )

Works out the URL for the users picture.

This method is recommended as it avoids costly redirects of user pictures if requests are made for non-existent files etc.

Parameters
moodle_page$page
renderer_base$renderer
Return values
moodle_url

◆ unalias()

static user_picture::unalias ( stdClass $record,
array $extrafields = null,
$idalias = 'id',
$fieldprefix = '' )
static

Extract the aliased user fields from a given record.

Given a record that was previously obtained using self::fields() with aliases, this method extracts user related unaliased fields.

Parameters
stdClass$recordcontaining user picture fields
array$extrafieldsextra fields included in the $record
string$idaliasalias of the id field
string$fieldprefixprefix added to all columns in their aliases, does not apply to 'id'
Return values
stdClassobject with unaliased user fields

Member Data Documentation

◆ $alttext

bool user_picture::$alttext = true

Add non-blank alt-text to the image.

Default true, set to false when image alt just duplicates text in screenreaders.

◆ $courseid

int user_picture::$courseid

The course id.

Used when constructing the link to the user's profile, page course id used if not specified.

◆ $includetoken

mixed user_picture::$includetoken = false

Include user authentication token.

True indicates to generate a token for current user, and integer value indicates to generate a token for the user whose id is the value indicated.

◆ $size

int user_picture::$size = 35

Size in pixels.

Special values are (true/1 = 100px) and (false/0 = 35px) for backward compatibility. Recommended values (supporting user initials too): 16, 35, 64 and 100.


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