Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Public Member Functions | Static Public Member Functions | Public Attributes | Static Protected Attributes | List of all members
user_picture Class Reference
Inheritance diagram for user_picture:
renderable

Public Member Functions

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

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. More...
 
static unalias (stdClass $record, array $extrafields=null, $idalias='id', $fieldprefix='')
 Extract the aliased user fields from a given record. More...
 

Public Attributes

bool $alttext = true
 Add non-blank alt-text to the image. More...
 
string $class = 'userpicture'
 Image class attribute.
 
int $courseid
 The course id. More...
 
bool $includefullname = false
 Whether to include the fullname in the user picture link.
 
mixed $includetoken = false
 Include user authentication token. More...
 
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. More...
 
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.
 

Static Protected Attributes

static array $fields
 List of mandatory fields in user record here. More...
 

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

◆ 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.

◆ $fields

array user_picture::$fields
staticprotected
Initial value:
= array('id', 'picture', 'firstname', 'lastname', 'firstnamephonetic', 'lastnamephonetic',
'middlename', 'alternatename', 'imagealt', 'email')

List of mandatory fields in user record here.

(do not include TEXT columns because it would break SELECT DISTINCT in MSSQL and ORACLE)

◆ $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.


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