UserMetaService
in package
Provides service to store user meta
The user meta is split into two identical database tables
- 'user_meta' table for admin users, allowing them to run the training is if they are a participant. But with the feature that the training data is in real-time
- 'training_user_meta' table for participants, where the training data is static, and cloned when the training session is started.
Tags
Table of Contents
Properties
- $user : mixed
- $user_data : mixed
- $user_meta : mixed
Methods
- __construct() : mixed
- This method initializes the `User` object, retrieves the user's information, and ensures the user is valid.
- find() : mixed
- Retrieve a meta value for a given user.
- save() : void
- Save a user meta key-value pair.
Properties
$user
protected
mixed
$user
$user_data
protected
mixed
$user_data
$user_meta
protected
mixed
$user_meta
Methods
__construct()
This method initializes the `User` object, retrieves the user's information, and ensures the user is valid.
public
__construct() : mixed
If the user is not valid, the process is halted with an error message.
It also initializes the appropriate user_meta object based on whether the user has a training_id.
Allowing admins to switch between either a 'specific' training, or the Leading Training
Tags
find()
Retrieve a meta value for a given user.
public
find(string $name[, int|null $user_id = NULL ]) : mixed
This method fetches the stored value associated with a specific key (name) for the given user. If no user ID is provided, it defaults to the current user session.
Parameters
- $name : string
-
The name of the key whose value is to be retrieved.
- $user_id : int|null = NULL
-
(Optional) The ID of the user. Defaults to NULL (current user session).
Return values
mixed —The stored value associated with the specified key, or NULL if not found.
save()
Save a user meta key-value pair.
public
save(string $name, string $value[, int|null $user_id = NULL ]) : void
Stores a value associated with a specific key. If a user ID is provided, the value is saved for that user. If no user ID is provided, the value is associated with the current user session.
Parameters
- $name : string
-
The name under which the value will be stored.
- $value : string
-
The value to be stored (preferably in JSON format).
- $user_id : int|null = NULL
-
(Optional) The ID of the user. Defaults to NULL (current user session).