Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
core_user

Namespaces

namespace  core_user
  
 
namespace  core_user\analytics\indicator
  
 
namespace  core_user\external
  
 
namespace  core_user\form
  
 
namespace  core_user\hook
  
 
namespace  core_user\output
  
 
namespace  core_user\output\myprofile
  
 
namespace  core_user\privacy
  
 
namespace  core_user\reportbuilder\datasource
  
 
namespace  core_user\search
  
 
namespace  core_user\table
  
 

Classes

class  behat_user
 Steps definitions for users. More...
 
class  core_user\analytics\indicator\user_profile_set
 User profile set indicator. More...
 
class  core_user\analytics\indicator\user_track_forums
 User tracks forums indicator. More...
 
class  core_user\external\search_identity
 
class  core_user\external\user_summary_exporter
 Class for exporting a user summary from an stdClass. More...
 
class  core_user\fields
 
class  core_user\form\calendar_form
 Class user_edit_calendar_form. More...
 
class  core_user\form\contactsitesupport_form
 
class  core_user\form\contentbank_user_preferences_form
 
class  core_user\form\defaulthomepage_form
 Form class. More...
 
class  core_user\form\private_files
 
class  core_user\form\profile_category_form
 
class  core_user\form\profile_field_form
 
class  core_user\hook\after_login_completed
 
class  core_user\hook\before_user_deleted
 
class  core_user\hook\before_user_updated
 
class  core_user\hook\extend_bulk_user_actions
 
class  core_user\output\myprofile\manager
 Defines MAnager class for myprofile navigation tree. More...
 
class  core_user\output\myprofile\node
 Defines a node in my profile page navigation. More...
 
class  core_user\output\myprofile\renderer
 Report log renderer's for printing reports. More...
 
class  core_user\output\participants_filter
 Class for rendering user filters on the course participants page. More...
 
class  core_user\output\status_field
 Class containing the data for the status field. More...
 
class  core_user\output\user_roles_editable
 
class  core_user\privacy\provider
 Privacy class for requesting user data. More...
 
class  core_user\reportbuilder\datasource\users
 
class  core_user\search\course_teacher
 Search for user role assignment in a course. More...
 
class  core_user\search\user
 Search area for Users for whom I have access to view profile. More...
 
class  core_user\table\participants
 Class for the displaying the participants table. More...
 
class  core_user\table\participants_search
 Class used to fetch participants based on a filterset. More...
 
class  core_user_external
 
class  core_user_renderer
 Provides user rendering functionality such as printing private files tree and displaying a search utility. More...
 
class  group_members_selector
 User selector subclass for the list of users who are in a certain group. More...
 
class  group_non_members_selector
 User selector subclass for the list of users who are not in a certain group. More...
 
class  groups_user_selector_base
 Base class to avoid duplicating code. More...
 
class  profile_define_base
 Class profile_define_base. More...
 
class  user_active_filter_form
 Class user_active_filter_form. More...
 
class  user_add_filter_form
 Class user_add_filter_form. More...
 
class  user_edit_editor_form
 Class user_edit_editor_form. More...
 
class  user_edit_form
 Class user_edit_form. More...
 
class  user_edit_forum_form
 Class user_edit_forum_form. More...
 
class  user_edit_language_form
 Class user_edit_form. More...
 
class  user_editadvanced_form
 Class user_editadvanced_form. More...
 
class  user_filter_anycourses
 User filter to distinguish users with no or any enroled courses. More...
 
class  user_filter_checkbox
 Generic filter based for checkbox and can be used for disabling items. More...
 
class  user_filter_cohort
 Generic filter for cohort membership. More...
 
class  user_filter_courserole
 User filter based on roles in a course identified by its shortname. More...
 
class  user_filter_date
 Generic filter based on a date. More...
 
class  user_filter_globalrole
 User filter based on global roles. More...
 
class  user_filter_profilefield
 User filter based on values of custom profile fields. More...
 
class  user_filter_select
 Generic filter based on a list of values. More...
 
class  user_filter_simpleselect
 Generic filter based on a list of values. More...
 
class  user_filter_text
 Generic filter for text fields. More...
 
class  user_filter_type
 The base user filter class. More...
 
class  user_filter_yesno
 Generic yes/no filter with radio buttons for integer fields. More...
 
class  user_filtering
 User filtering wrapper class. More...
 
class  user_selector_base
 Base class for user selectors. More...
 

Functions

static add_user_device ($appid, $name, $model, $platform, $version, $pushid, $uuid, $publickey=null)
 Add a user device in Moodle database (for PUSH notifications usually).
 
static add_user_device_parameters ()
 Returns description of method parameters.
 
static add_user_device_returns ()
 Returns description of method result value.
 
static add_user_private_files ($draftid)
 Copy files from a draft area to users private files area.
 
static add_user_private_files_parameters ()
 Returns description of method parameters.
 
static add_user_private_files_returns ()
 Returns description of method result value.
 
static agree_site_policy ()
 Agree the site policy for the current user.
 
static agree_site_policy_parameters ()
 Returns description of method parameters.
 
static agree_site_policy_returns ()
 Returns description of method result value.
 
 can_view_user_details_cap ($user, $course=null)
 Check if $USER have the necessary capabilities to obtain user details.
 
 cancel_email_update ($userid)
 Cancels the requirement for a user to update their email address.
 
 core_user_inplace_editable ($itemtype, $itemid, $newvalue)
 Callback for inplace editable API.
 
static get_course_user_profiles ($userlist)
 Get course participant's details.
 
static get_course_user_profiles_parameters ()
 Returns description of method parameters.
 
static get_course_user_profiles_returns ()
 Returns description of method result value.
 
static get_private_files_info ($userid=0)
 Returns general information about files in the user private files area.
 
static get_private_files_info_parameters ()
 Returns description of method parameters.
 
static get_private_files_info_returns ()
 Returns description of method result value.
 
static get_user_preferences ($name='', $userid=0)
 Return user preferences.
 
static get_user_preferences_parameters ()
 Returns description of method parameters.
 
static get_user_preferences_returns ()
 Returns description of method result value.
 
static get_users ($criteria=array())
 Retrieve matching user.
 
static get_users_by_field_returns ()
 Returns description of method result value.
 
static get_users_parameters ()
 Returns description of get_users() parameters.
 
static get_users_returns ()
 Returns description of get_users result value.
 
 profile_delete_category ($id)
 Delete a profile category.
 
 profile_delete_field ($id)
 Deletes a profile field.
 
 profile_list_categories ()
 Retrieve a list of categories and ids suitable for use in a form.
 
 profile_list_datatypes ()
 Retrieve a list of all the available data types.
 
 profile_move_category ($id, $move)
 Change the sort order of a category.
 
 profile_move_field ($id, $move)
 Change the sort order of a field.
 
 profile_purge_user_fields_cache ()
 Purge the cache for the user profile fields.
 
 profile_reorder_categories ()
 Reorder the profile categoriess starting at the category at the given startorder.
 
 profile_reorder_fields ()
 Reorder the profile fields within a given category starting at the field at the given startorder.
 
 profile_save_category (stdClass $data)
 Create or update a profile category.
 
 profile_save_field (stdClass $data, array $editors)
 Save updated field definition or create a new field.
 
static remove_user_device ($uuid, $appid="")
 Remove a user device from the Moodle database (for PUSH notifications usually).
 
static remove_user_device_parameters ()
 Returns description of method parameters.
 
static remove_user_device_returns ()
 Returns description of method result value.
 
static set_user_preferences ($preferences)
 Set user preferences.
 
static set_user_preferences_parameters ()
 Returns description of method parameters.
 
static set_user_preferences_returns ()
 Returns description of method result value.
 
static update_picture ($draftitemid, $delete=false, $userid=0)
 Update or delete the user picture in the site.
 
static update_picture_parameters ()
 Returns description of method parameters.
 
static update_picture_returns ()
 Returns description of method result value.
 
 user_add_password_history (int $userid, #[\SensitiveParameter] string $password)
 Add password to the list of used hashes for this user.
 
 user_can_view_profile ($user, $course=null, $usercontext=null)
 Check if the current user has permission to view details of the supplied user.
 
 user_convert_text_to_menu_items ($text, $page)
 Converts a string into a flat array of menu items, where each menu items is a stdClass with fields type, url, title.
 
 user_count_login_failures ($user, $reset=true)
 Count the number of failed login attempts for the given user, since last successful login.
 
 user_create_user ($user, $updatepassword=true, $triggerevent=true)
 Creates a user.
 
 user_delete_user ($user)
 Marks user deleted in internal user database and notifies the auth plugin.
 
static user_description ($additionalfields=array())
 Create user return value description.
 
 user_edit_map_field_purpose ($userid, $fieldname)
 Map an internal field name to a valid purpose from: "https://www.w3.org/TR/WCAG21/#input-purposes".
 
 user_get_course_lastaccess_sql ($accesssince=null, $tableprefix='ul', $haveaccessed=false)
 Returns SQL that can be used to limit a query to a period where the user last accessed / did not access a course.
 
 user_get_default_fields ()
 Returns the list of default 'displayable' fields.
 
 user_get_lastaccess_sql ($columnname, $accesssince, $tableprefix, $haveaccessed=false)
 Returns SQL that can be used to limit a query to a period where the user last accessed or did not access something recorded by a given table.
 
 user_get_tagged_users ($tag, $exclusivemode=false, $fromctx=0, $ctx=0, $rec=1, $page=0)
 Returns users tagged with a specified tag.
 
 user_get_user_details ($user, $course=null, array $userfields=array())
 Give user record from mdl_user, build an array contains all user details.
 
 user_get_user_details_courses ($user, array $userfields=[])
 Tries to obtain user details, either recurring directly to the user's system profile or through one of the user's course enrollments (course profile).
 
 user_get_user_lastaccess_sql ($accesssince=null, $tableprefix='u', $haveaccessed=false)
 Returns SQL that can be used to limit a query to a period where the user last accessed / did not access the system.
 
 user_get_user_navigation_info ($user, $page, $options=array())
 Get a list of essential user navigation items.
 
 user_get_users_by_id ($userids)
 Get users by id.
 
 user_is_previously_used_password ($userid, $password)
 Was this password used before on change or reset password page?
 
 user_list_view ($course, $context)
 Trigger user_list_viewed event.
 
 user_mygrades_url ($userid=null, $courseid=SITEID)
 Returns the url to use for the "Grades" link in the user navigation.
 
 user_page_type_list ($pagetype, $parentcontext, $currentcontext)
 Return a list of page types.
 
 user_remove_user_device ($uuid, $appid="")
 Remove a user device from the Moodle database (for PUSH notifications usually).
 
 user_update_device_public_key (string $uuid, string $appid, string $publickey)
 Update the users public key for the specified device and app.
 
 user_update_user ($user, $updatepassword=true, $triggerevent=true)
 Update a user with a user object (will compare against the ID)
 
 useredit_get_disabled_name_fields ($enabledadditionalusernames=null)
 Gets user name fields not enabled from the setting fullnamedisplay.
 
 useredit_get_enabled_name_fields ()
 Gets enabled (from fullnameformate setting) user name fields in appropriate order.
 
 useredit_get_required_name_fields ()
 Return required user name fields for forms.
 
 useredit_load_preferences (&$user, $reload=true)
 Loads the given users preferences into the given user object.
 
 useredit_setup_preference_page ($userid, $courseid)
 Performs the common access checks and page setup for all user preference pages.
 
 useredit_shared_definition (&$mform, $editoroptions, $filemanageroptions, $user)
 Powerful function that is used by edit and editadvanced to add common form elements/rules/etc.
 
 useredit_update_bounces ($user, $usernew)
 Updates the user email bounce + send counts when the user is edited.
 
 useredit_update_interests ($user, $interests)
 Updates a users interests.
 
 useredit_update_picture ()
 
 useredit_update_trackforums ($user, $usernew)
 Updates the forums a user is tracking when the user is edited.
 
 useredit_update_user_preference ($usernew)
 Updates the user preferences for the given user.
 
static view_user_list ($courseid)
 Trigger the user_list_viewed event.
 
static view_user_list_parameters ()
 Returns description of method parameters.
 
static view_user_list_returns ()
 Returns description of method result value.
 
static view_user_profile ($userid, $courseid=0)
 Trigger the user profile viewed event.
 
static view_user_profile_parameters ()
 Returns description of method parameters.
 
static view_user_profile_returns ()
 Returns description of method result value.
 

Variables

global core_user\table::$CFG
 
 core_user\form::if (!defined( 'MOODLE_INTERNAL'))
 
 if (!defined( 'MOODLE_INTERNAL'))
 
 if (!defined( 'MOODLE_INTERNAL'))
 
 if (!defined( 'MOODLE_INTERNAL'))
 
 if (!defined( 'MOODLE_INTERNAL'))
 
 if (!defined( 'MOODLE_INTERNAL'))
 
const PROFILE_VISIBLE_ALL '2'
 Visible to anyone who can view the user.
 
const PROFILE_VISIBLE_NONE '0'
 Only visible to users with the moodle/user:viewalldetails capability.
 
const PROFILE_VISIBLE_PRIVATE '1'
 Visible to the profile owner or anyone with the moodle/user:viewalldetails capability.
 
const PROFILE_VISIBLE_TEACHERS '3'
 Visible to anyone who has the moodle/site:viewuseridentity permission.
 
const USER_FILTER_ENROLMENT 1
 
const USER_FILTER_GROUP 2
 
const USER_FILTER_LAST_ACCESS 3
 
const USER_FILTER_ROLE 4
 
const USER_FILTER_STATUS 5
 
const USER_FILTER_STRING 6
 
const USER_SELECTOR_DEFAULT_ROWS 20
 The default size of a user selector.
 

Detailed Description

Function Documentation

◆ add_user_device()

static add_user_device ( $appid,
$name,
$model,
$platform,
$version,
$pushid,
$uuid,
$publickey = null )
static

Add a user device in Moodle database (for PUSH notifications usually).

Exceptions
moodle_exception
Parameters
string$appidThe app id, usually something like com.moodle.moodlemobile.
string$nameThe device name, occam or iPhone etc.
string$modelThe device model Nexus4 or iPad1.1 etc.
string$platformThe device platform iOs or Android etc.
string$versionThe device version 6.1.2 or 4.2.2 etc.
string$pushidThe device PUSH token/key/identifier/registration id.
string$uuidThe device UUID.
string$publickeyThe app generated public key
Return values
arrayList of possible warnings.
Since
Moodle 2.6

◆ add_user_device_parameters()

static add_user_device_parameters ( )
static

Returns description of method parameters.

Return values
external_function_parameters
Since
Moodle 2.6

◆ add_user_device_returns()

static add_user_device_returns ( )
static

Returns description of method result value.

Return values
external_multiple_structure
Since
Moodle 2.6

◆ add_user_private_files()

static add_user_private_files ( $draftid)
static

Copy files from a draft area to users private files area.

Exceptions
invalid_parameter_exception
moodle_exception
Parameters
int$draftidId of a draft area containing files.
Return values
arrayAn array of warnings
Since
Moodle 2.6

◆ add_user_private_files_parameters()

static add_user_private_files_parameters ( )
static

Returns description of method parameters.

Return values
external_function_parameters
Since
Moodle 2.6

◆ add_user_private_files_returns()

static add_user_private_files_returns ( )
static

Returns description of method result value.

Return values
external_description
Since
Moodle 2.2

◆ agree_site_policy()

static agree_site_policy ( )
static

Agree the site policy for the current user.

Return values
arrayof warnings and status result
Since
Moodle 3.2
Exceptions
moodle_exception

◆ agree_site_policy_parameters()

static agree_site_policy_parameters ( )
static

Returns description of method parameters.

Return values
external_function_parameters
Since
Moodle 3.2

◆ agree_site_policy_returns()

static agree_site_policy_returns ( )
static

Returns description of method result value.

Return values
external_description
Since
Moodle 3.2

◆ can_view_user_details_cap()

can_view_user_details_cap ( $user,
$course = null )

Check if $USER have the necessary capabilities to obtain user details.

Parameters
stdClass$user
stdClass$courseif null then only consider system profile otherwise also consider the course's profile.
Return values
booltrue if $USER can view user details.

◆ cancel_email_update()

cancel_email_update ( $userid)

Cancels the requirement for a user to update their email address.

Parameters
int$userid

◆ core_user_inplace_editable()

core_user_inplace_editable ( $itemtype,
$itemid,
$newvalue )

Callback for inplace editable API.

Parameters
string$itemtype- Only user_roles is supported.
string$itemid- Courseid and userid separated by a :
string$newvalue- json encoded list of roleids.
Return values
core\output\inplace_editable|null

◆ get_course_user_profiles()

static get_course_user_profiles ( $userlist)
static

Get course participant's details.

Parameters
array$userlistarray of user ids and according course ids
Return values
arrayAn array of arrays describing course participants
Since
Moodle 2.2

◆ get_course_user_profiles_parameters()

static get_course_user_profiles_parameters ( )
static

Returns description of method parameters.

Return values
external_function_parameters
Since
Moodle 2.2

◆ get_course_user_profiles_returns()

static get_course_user_profiles_returns ( )
static

Returns description of method result value.

Return values
external_description
Since
Moodle 2.2

◆ get_private_files_info()

static get_private_files_info ( $userid = 0)
static

Returns general information about files in the user private files area.

Parameters
int$useridId of the user, default to current user.
Return values
arrayof warnings and file area information
Since
Moodle 3.4
Exceptions
moodle_exception

◆ get_private_files_info_parameters()

static get_private_files_info_parameters ( )
static

Returns description of method parameters.

Return values
external_function_parameters
Since
Moodle 3.4

◆ get_private_files_info_returns()

static get_private_files_info_returns ( )
static

Returns description of method result value.

Return values
external_description
Since
Moodle 3.4

◆ get_user_preferences()

static get_user_preferences ( $name = '',
$userid = 0 )
static

Return user preferences.

Parameters
string$namepreference name, empty for all
int$useridid of the user, 0 for current user
Return values
arrayof warnings and preferences
Since
Moodle 3.2
Exceptions
moodle_exception

◆ get_user_preferences_parameters()

static get_user_preferences_parameters ( )
static

Returns description of method parameters.

Return values
external_function_parameters
Since
Moodle 3.2

◆ get_user_preferences_returns()

static get_user_preferences_returns ( )
static

Returns description of method result value.

Return values
external_description
Since
Moodle 3.2

◆ get_users()

static get_users ( $criteria = array())
static

Retrieve matching user.

Exceptions
moodle_exception
Parameters
array$criteriathe allowed array keys are id/lastname/firstname/idnumber/username/email/auth.
Return values
arrayAn array of arrays containing user profiles.
Since
Moodle 2.5

◆ get_users_by_field_returns()

static get_users_by_field_returns ( )
static

Returns description of method result value.

Return values
external_multiple_structure
Since
Moodle 2.4

◆ get_users_parameters()

static get_users_parameters ( )
static

Returns description of get_users() parameters.

Return values
external_function_parameters
Since
Moodle 2.5

◆ get_users_returns()

static get_users_returns ( )
static

Returns description of get_users result value.

Return values
external_description
Since
Moodle 2.5

◆ profile_delete_category()

profile_delete_category ( $id)

Delete a profile category.

Parameters
int$idof the category to be deleted
Return values
boolsuccess of operation

◆ profile_delete_field()

profile_delete_field ( $id)

Deletes a profile field.

Parameters
int$id

◆ profile_list_categories()

profile_list_categories ( )

Retrieve a list of categories and ids suitable for use in a form.

Return values
array

◆ profile_list_datatypes()

profile_list_datatypes ( )

Retrieve a list of all the available data types.

Return values
arraya list of the datatypes suitable to use in a select statement

◆ profile_move_category()

profile_move_category ( $id,
$move )

Change the sort order of a category.

Parameters
int$idof the category
string$movedirection of move
Return values
boolsuccess of operation

◆ profile_move_field()

profile_move_field ( $id,
$move )

Change the sort order of a field.

Parameters
int$idof the field
string$movedirection of move
Return values
boolsuccess of operation

◆ profile_save_category()

profile_save_category ( stdClass $data)

Create or update a profile category.

Parameters
stdClass$data

◆ profile_save_field()

profile_save_field ( stdClass $data,
array $editors )

Save updated field definition or create a new field.

Parameters
stdClass$datadata from the form profile_field_form
array$editorseditors for this form field type

◆ remove_user_device()

static remove_user_device ( $uuid,
$appid = "" )
static

Remove a user device from the Moodle database (for PUSH notifications usually).

Parameters
string$uuidThe device UUID.
string$appidThe app id, opitonal parameter. If empty all the devices fmatching the UUID or the user will be removed.
Return values
arrayList of possible warnings and removal status.
Since
Moodle 2.9

◆ remove_user_device_parameters()

static remove_user_device_parameters ( )
static

Returns description of method parameters.

Return values
external_function_parameters
Since
Moodle 2.9

◆ remove_user_device_returns()

static remove_user_device_returns ( )
static

Returns description of method result value.

Return values
external_multiple_structure
Since
Moodle 2.9

◆ set_user_preferences()

static set_user_preferences ( $preferences)
static

Set user preferences.

Parameters
array$preferenceslist of preferences including name, value and userid
Return values
arrayof warnings and preferences saved
Since
Moodle 3.2
Exceptions
moodle_exception

◆ set_user_preferences_parameters()

static set_user_preferences_parameters ( )
static

Returns description of method parameters.

Return values
external_function_parameters
Since
Moodle 3.2

◆ set_user_preferences_returns()

static set_user_preferences_returns ( )
static

Returns description of method result value.

Return values
external_description
Since
Moodle 3.2

◆ update_picture()

static update_picture ( $draftitemid,
$delete = false,
$userid = 0 )
static

Update or delete the user picture in the site.

Parameters
int$draftitemidid of the user draft file to use as image
bool$deleteif we should delete the user picture
int$useridid of the user, 0 for current user
Return values
arraywarnings and success status
Since
Moodle 3.2
Exceptions
moodle_exception

◆ update_picture_parameters()

static update_picture_parameters ( )
static

Returns description of method parameters.

Return values
external_function_parameters
Since
Moodle 3.2

◆ update_picture_returns()

static update_picture_returns ( )
static

Returns description of method result value.

Return values
external_description
Since
Moodle 3.2

◆ user_add_password_history()

user_add_password_history ( int $userid,
# string $password[\SensitiveParameter] )

Add password to the list of used hashes for this user.

This is supposed to be used from: 1/ change own password form 2/ password reset process 3/ user signup in auth plugins if password changing supported

Parameters
int$useriduser id
string$passwordplaintext password
Return values
void

◆ user_can_view_profile()

user_can_view_profile ( $user,
$course = null,
$usercontext = null )

Check if the current user has permission to view details of the supplied user.

This function supports two modes: If the optional $course param is omitted, then this function finds all shared courses and checks whether the current user has permission in any of them, returning true if so. If the $course param is provided, then this function checks permissions in ONLY that course.

Parameters
object$userThe other user's details.
object$courseif provided, only check permissions in this course.
context$usercontextThe user context if available.
Return values
booltrue for ability to view this user, else false.

◆ user_convert_text_to_menu_items()

user_convert_text_to_menu_items ( $text,
$page )

Converts a string into a flat array of menu items, where each menu items is a stdClass with fields type, url, title.

Parameters
string$textthe menu items definition
moodle_page$pagethe current page
Return values
array

◆ user_count_login_failures()

user_count_login_failures ( $user,
$reset = true )

Count the number of failed login attempts for the given user, since last successful login.

Parameters
int | stdclass$useruser id or object.
bool$resetResets failed login count, if set to true.
Return values
intnumber of failed login attempts since the last successful login.

◆ user_create_user()

user_create_user ( $user,
$updatepassword = true,
$triggerevent = true )

Creates a user.

Exceptions
moodle_exception
Parameters
stdClass | array$useruser to create
bool$updatepasswordif true, authentication plugin will update password.
bool$triggereventset false if user_created event should not be triggred. This will not affect user_password_updated event triggering.
Return values
intid of the newly created user

◆ user_delete_user()

user_delete_user ( $user)

Marks user deleted in internal user database and notifies the auth plugin.

Also unenrols user from all roles and does other cleanup.

Todo
Decide if this transaction is really needed (look for internal TODO:)
Parameters
object$userUserobject before delete (without system magic quotes)
Return values
booleansuccess

◆ user_description()

static user_description ( $additionalfields = array())
static

Create user return value description.

Parameters
array$additionalfieldssome additional field
Return values
external_description

◆ user_edit_map_field_purpose()

user_edit_map_field_purpose ( $userid,
$fieldname )

Map an internal field name to a valid purpose from: "https://www.w3.org/TR/WCAG21/#input-purposes".

Parameters
integer$userid
string$fieldname
Return values
string\$purpose(empty string if there is no mapping).

◆ user_get_course_lastaccess_sql()

user_get_course_lastaccess_sql ( $accesssince = null,
$tableprefix = 'ul',
$haveaccessed = false )

Returns SQL that can be used to limit a query to a period where the user last accessed / did not access a course.

Parameters
int$accesssinceThe unix timestamp to compare to users' last access
string$tableprefix
bool$haveaccessedWhether to match against users who HAVE accessed since $accesssince (optional)
Return values
string

◆ user_get_default_fields()

user_get_default_fields ( )

Returns the list of default 'displayable' fields.

Contains database field names but also names used to generate information, such as enrolledcourses

Return values
arrayof user fields

◆ user_get_lastaccess_sql()

user_get_lastaccess_sql ( $columnname,
$accesssince,
$tableprefix,
$haveaccessed = false )

Returns SQL that can be used to limit a query to a period where the user last accessed or did not access something recorded by a given table.

Parameters
string$columnnameThe name of the access column to check against
int$accesssinceThe unix timestamp to compare to users' last access
string$tableprefixThe query prefix of the table to check
bool$haveaccessedWhether to match against users who HAVE accessed since $accesssince (optional)
Return values
string

◆ user_get_tagged_users()

user_get_tagged_users ( $tag,
$exclusivemode = false,
$fromctx = 0,
$ctx = 0,
$rec = 1,
$page = 0 )

Returns users tagged with a specified tag.

Parameters
core_tag_tag$tag
bool$exclusivemodeif set to true it means that no other entities tagged with this tag are displayed on the page and the per-page limit may be bigger
int$fromctxcontext id where the link was displayed, may be used by callbacks to display items in the same context first
int$ctxcontext id where to search for records
bool$recsearch in subcontexts as well
int$page0-based number of page being displayed
Return values
core_tag\output\tagindex

◆ user_get_user_details()

user_get_user_details ( $user,
$course = null,
array $userfields = array() )

Give user record from mdl_user, build an array contains all user details.

Warning: description file urls are 'webservice/pluginfile.php' is use. it can be changed with $CFG->moodlewstextformatlinkstoimagesfile

Exceptions
moodle_exception
Parameters
stdClass$useruser record from mdl_user
stdClass$coursemoodle course
array$userfieldsrequired fields
Return values
array|null

◆ user_get_user_details_courses()

user_get_user_details_courses ( $user,
array $userfields = [] )

Tries to obtain user details, either recurring directly to the user's system profile or through one of the user's course enrollments (course profile).

You can use the $userfields parameter to reduce the amount of a user record that is required by the method. The minimum user fields are:

  • id
  • deleted
  • all potential fullname fields
Parameters
stdClass$userThe user.
array$userfieldsAn array of userfields to be returned, the values must be a subset of user_get_default_fields (optional)
Return values
arrayif unsuccessful or the allowed user details.

◆ user_get_user_lastaccess_sql()

user_get_user_lastaccess_sql ( $accesssince = null,
$tableprefix = 'u',
$haveaccessed = false )

Returns SQL that can be used to limit a query to a period where the user last accessed / did not access the system.

Parameters
int$accesssinceThe unix timestamp to compare to users' last access
string$tableprefix
bool$haveaccessedWhether to match against users who HAVE accessed since $accesssince (optional)
Return values
string

◆ user_get_user_navigation_info()

user_get_user_navigation_info ( $user,
$page,
$options = array() )

Get a list of essential user navigation items.

Parameters
stdclass$useruser object.
moodle_page$pagepage object.
array$optionsassociative array. options are:
  • avatarsize=35 (size of avatar image)
Return values
stdClass\$returnobjnavigation information object, where:
 $returnobj->navitems    array    array of links where each link is a
                                  stdClass with fields url, title, and
                                  pix
 $returnobj->metadata    array    array of useful user metadata to be
                                  used when constructing navigation;
                                  fields include:

     ROLE FIELDS
     asotherrole    bool    whether viewing as another role
     rolename       string  name of the role

     USER FIELDS
     These fields are for the currently-logged in user, or for
     the user that the real user is currently logged in as.

     userid         int        the id of the user in question
     userfullname   string     the user's full name
     userprofileurl moodle_url the url of the user's profile
     useravatar     string     a HTML fragment - the rendered
                               user_picture for this user
     userloginfail  string     an error string denoting the number
                               of login failures since last login

     "REAL USER" FIELDS
     These fields are for when asotheruser is true, and
     correspond to the underlying "real user".

     asotheruser        bool    whether viewing as another user
     realuserid         int        the id of the user in question
     realuserfullname   string     the user's full name
     realuserprofileurl moodle_url the url of the user's profile
     realuseravatar     string     a HTML fragment - the rendered
                                   user_picture for this user

     MNET PROVIDER FIELDS
     asmnetuser            bool   whether viewing as a user from an
                                  MNet provider
     mnetidprovidername    string name of the MNet provider
     mnetidproviderwwwroot string URL of the MNet provider

◆ user_get_users_by_id()

user_get_users_by_id ( $userids)

Get users by id.

Parameters
array$useridsid of users to retrieve
Return values
array

◆ user_is_previously_used_password()

user_is_previously_used_password ( $userid,
$password )

Was this password used before on change or reset password page?

The $CFG->passwordreuselimit setting determines how many times different password needs to be used before allowing previously used password again.

Parameters
int$useriduser id
string$passwordplaintext password
Return values
booltrue if password reused

◆ user_list_view()

user_list_view ( $course,
$context )

Trigger user_list_viewed event.

Parameters
stdClass$coursecourse object
stdClass$contextcourse context object
Since
Moodle 2.9

◆ user_mygrades_url()

user_mygrades_url ( $userid = null,
$courseid = SITEID )

Returns the url to use for the "Grades" link in the user navigation.

Parameters
int$useridThe user's ID.
int$courseidThe course ID if available.
Return values
mixedA URL to be directed to for "Grades".

◆ user_page_type_list()

user_page_type_list ( $pagetype,
$parentcontext,
$currentcontext )

Return a list of page types.

Parameters
string$pagetypecurrent page type
stdClass$parentcontextBlock's parent context
stdClass$currentcontextCurrent context of block
Return values
array

◆ user_remove_user_device()

user_remove_user_device ( $uuid,
$appid = "" )

Remove a user device from the Moodle database (for PUSH notifications usually).

Parameters
string$uuidThe device UUID.
string$appidThe app id. If empty all the devices matching the UUID for the user will be removed.
Return values
booltrue if removed, false if the device didn't exists in the database
Since
Moodle 2.9

◆ user_update_device_public_key()

user_update_device_public_key ( string $uuid,
string $appid,
string $publickey )

Update the users public key for the specified device and app.

Parameters
string$uuidThe device UUID.
string$appidThe app id, usually something like com.moodle.moodlemobile.
string$publickeyThe app generated public key.
Return values
bool
Since
Moodle 4.2

◆ user_update_user()

user_update_user ( $user,
$updatepassword = true,
$triggerevent = true )

Update a user with a user object (will compare against the ID)

Exceptions
moodle_exception
Parameters
stdClass | array$userthe user to update
bool$updatepasswordif true, authentication plugin will update password.
bool$triggereventset false if user_updated event should not be triggred. This will not affect user_password_updated event triggering.

◆ useredit_get_disabled_name_fields()

useredit_get_disabled_name_fields ( $enabledadditionalusernames = null)

Gets user name fields not enabled from the setting fullnamedisplay.

Parameters
array$enabledadditionalusernamesCurrent enabled additional user name fields.
Return values
arrayDisabled user name fields.

◆ useredit_get_enabled_name_fields()

useredit_get_enabled_name_fields ( )

Gets enabled (from fullnameformate setting) user name fields in appropriate order.

Return values
arrayEnabled user name fields.

◆ useredit_get_required_name_fields()

useredit_get_required_name_fields ( )

Return required user name fields for forms.

Return values
arrayrequired user name fields in order according to settings.

◆ useredit_load_preferences()

useredit_load_preferences ( & $user,
$reload = true )

Loads the given users preferences into the given user object.

Parameters
stdClass$userThe user object, modified by reference.
bool$reload

◆ useredit_setup_preference_page()

useredit_setup_preference_page ( $userid,
$courseid )

Performs the common access checks and page setup for all user preference pages.

Parameters
int$useridThe user id to edit taken from the page params.
int$courseidThe optional course id if we came from a course context.
Return values
arraycontaining the user and course records.

◆ useredit_shared_definition()

useredit_shared_definition ( & $mform,
$editoroptions,
$filemanageroptions,
$user )

Powerful function that is used by edit and editadvanced to add common form elements/rules/etc.

Parameters
MoodleQuickForm$mform
array$editoroptions
array$filemanageroptions
stdClass$user

◆ useredit_update_bounces()

useredit_update_bounces ( $user,
$usernew )

Updates the user email bounce + send counts when the user is edited.

Parameters
stdClass$userThe current user object.
stdClass$usernewThe updated user object.

◆ useredit_update_interests()

useredit_update_interests ( $user,
$interests )

Updates a users interests.

Parameters
stdClass$user
array$interests

◆ useredit_update_picture()

useredit_update_picture ( )
Deprecated
since Moodle 3.2
See also
core_user\update_picture()

◆ useredit_update_trackforums()

useredit_update_trackforums ( $user,
$usernew )

Updates the forums a user is tracking when the user is edited.

Parameters
stdClass$userThe original user object.
stdClass$usernewThe updated user object.

◆ useredit_update_user_preference()

useredit_update_user_preference ( $usernew)

Updates the user preferences for the given user.

Only preference that can be updated directly will be updated here. This method is called from various WS updating users and should be used when updating user details. Plugins may list preferences that can be updated by defining 'user_preferences' callback, {

See also
core_user\fill_preferences_cache()}

Some parts of code may use user preference table to store internal data, in these cases it is acceptable to call set_user_preference()

Parameters
stdClass | array$usernewobject or array that has user preferences as attributes with keys starting with preference_

◆ view_user_list()

static view_user_list ( $courseid)
static

Trigger the user_list_viewed event.

Parameters
int$courseidid of course
Return values
arrayof warnings and status result
Since
Moodle 2.9
Exceptions
moodle_exception

◆ view_user_list_parameters()

static view_user_list_parameters ( )
static

Returns description of method parameters.

Return values
external_function_parameters
Since
Moodle 2.9

◆ view_user_list_returns()

static view_user_list_returns ( )
static

Returns description of method result value.

Return values
external_description
Since
Moodle 2.9

◆ view_user_profile()

static view_user_profile ( $userid,
$courseid = 0 )
static

Trigger the user profile viewed event.

Parameters
int$useridid of user
int$courseidid of course
Return values
arrayof warnings and status result
Since
Moodle 2.9
Exceptions
moodle_exception

◆ view_user_profile_parameters()

static view_user_profile_parameters ( )
static

Returns description of method parameters.

Return values
external_function_parameters
Since
Moodle 2.9

◆ view_user_profile_returns()

static view_user_profile_returns ( )
static

Returns description of method result value.

Return values
external_description
Since
Moodle 2.9

Variable Documentation

◆ PROFILE_VISIBLE_ALL

const PROFILE_VISIBLE_ALL '2'

Visible to anyone who can view the user.

Editable by the profile owner if they have the moodle/user:editownprofile capability or any user with the moodle/user:update capability.

◆ PROFILE_VISIBLE_NONE

const PROFILE_VISIBLE_NONE '0'

Only visible to users with the moodle/user:viewalldetails capability.

Only editable by users with the moodle/user:viewalldetails and moodle/user:update capabilities.

◆ PROFILE_VISIBLE_PRIVATE

const PROFILE_VISIBLE_PRIVATE '1'

Visible to the profile owner or anyone with the moodle/user:viewalldetails capability.

Editable by the profile owner if they have the moodle/user:editownprofile capability or any user with moodle/user:viewalldetails and moodle/user:update capabilities.

◆ PROFILE_VISIBLE_TEACHERS

const PROFILE_VISIBLE_TEACHERS '3'

Visible to anyone who has the moodle/site:viewuseridentity permission.

Editable by the profile owner if they have the moodle/user:editownprofile capability or any user with the moodle/user:update capability.