Moodle PHP Documentation 4.5
Moodle 4.5.5+ (Build: 20250711) (ce34e8ff087)
core\output\user_picture Class Reference
Inheritance diagram for core\output\user_picture:
core\output\renderable

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 allow_view (int $imageuserid)
 Checks if the current user is permitted to view user profile images.
 
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.
 

Constructor & Destructor Documentation

◆ __construct()

core\output\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

◆ allow_view()

static core\output\user_picture::allow_view ( int $imageuserid)
static

Checks if the current user is permitted to view user profile images.

This is based on the forcelogin and forceloginforprofileimage config settings, and the moodle/user:viewprofilepictures capability.

Logged-in users are allowed to view their own profile image regardless of capability.

Parameters
int$imageuseridUser id of profile image being viewed
Return values
boolTrue if current user can view profile images

◆ fields()

static core\output\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
null | 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()

core\output\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
null | renderer_base$renderer
Return values
moodle_url

◆ unalias()

static core\output\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 {

See also
self::fields()} with aliases, this method extracts user related unaliased fields.
Parameters
stdClass$recordcontaining user picture fields
null | 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 core\output\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 core\output\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 core\output\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 core\output\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: