class user_service implements user_service_interface

internal  
 

User Service.

Provides orchestration logic for user lifecycle operations (create, update, delete). Applies sensible defaults and validation before delegating to the Support layer.

For simple user lookups (get_user, get_user_by_email, etc.) and profile field operations, use the Support layer directly:

Methods

int
create_user(stdClass $userobj, bool $updatepassword = false, bool $nologin = false)

Create a new Moodle user with sensible defaults.

bool
update_user(stdClass $userobj, bool $updatepassword = true, bool $triggerevent = true)

Update an existing Moodle user with validation.

bool
delete_user(int $userid)

Delete (soft-delete) a user with existence check.

Details

at line 55
int create_user(stdClass $userobj, bool $updatepassword = false, bool $nologin = false)

Create a new Moodle user with sensible defaults.

Applies default values for auth, confirmed, and mnethostid if not provided, then delegates to the Support layer.

Parameters

stdClass $userobj

Object containing user properties (username, email, etc)

bool $updatepassword

Force password change on first login

bool $nologin

If true, user cannot login

Return Value

int

New User ID

at line 74
bool update_user(stdClass $userobj, bool $updatepassword = true, bool $triggerevent = true)

Update an existing Moodle user with validation.

Validates that the user ID is present before delegating to Support.

Parameters

stdClass $userobj

Object with at least 'id' property

bool $updatepassword

Hash password if changed

bool $triggerevent

Fire \core\event\user_updated

Return Value

bool

True on success

Exceptions

moodle_exception

at line 95
bool delete_user(int $userid)

Delete (soft-delete) a user with existence check.

Verifies the user exists before attempting deletion.

Parameters

int $userid

Return Value

bool

True on success, false if user not found