Since: 5.0.0 Initial implementation

class Users extends DolibarrApi (View source)

API class for users

Properties

protected DoliDB $db from  DolibarrApi
Restler $r from  DolibarrApi
static string[] $FIELDS
User $useraccount

Methods

__construct()

Constructor

string|array<string, mixed>
_checkValForAPI(string $field, string|string[] $value, object $object)

Check and convert a string depending on its type/name.

object
_filterObjectProperties(object $object, string $properties)

Filter properties that will be returned on object

object
_cleanObjectDatas(object $object)

Clean sensible object datas

static bool
_checkAccessToResource(string $resource, int $resource_id = 0, string $dbtablename = '', string $feature2 = '', string $dbt_keyfield = 'fk_soc', string $dbt_select = 'rowid')

Check access by user to a given resource

bool|string
_checkFilters(string $sqlfilters, string $error = '')

Return if a $sqlfilters parameter is valid Function no more used. Kept for backward compatibility with old APIs of modules

static string
_forge_criteria_callback(string[] $matches)

Function to forge a SQL criteria from a Generic filter string.

array
index(string $sortfield = "t.rowid", string $sortorder = 'ASC', int $limit = 100, int $page = 0, string $user_ids = '0', int $category = 0, string $sqlfilters = '', string $properties = '')

List users

array|mixed
get(int $id, int $includepermissions = 0)

Get a user

array|mixed
getByLogin(string $login, int $includepermissions = 0)

Get a user by login

array|mixed
getByEmail(string $email, int $includepermissions = 0)

Get a user by email

array|mixed
getInfo(int $includepermissions = 0)

Get more properties of the current user (so user of API token).

int
post(array $request_data = null)

Create a user

object
put(int $id, array $request_data = null)

Update a user

int
setPassword(int $id, bool $send_password = false)

Update a user password

array
getGroups(int $id)

List the groups of a user

int
setGroup(int $id, int $group, int $entity = 1)

Add a user to a group

int
postGroups(array $request_data = null)

Create user group

object
putGroups(int $group, array $request_data = null)

Update user group

array{success: bool, message: string}
removeUserFromGroup(int $id, int $group)

Remove user from group (only admin)

array
listGroups(string $sortfield = "t.rowid", string $sortorder = 'ASC', int $limit = 100, int $page = 0, string $group_ids = '0', string $sqlfilters = '', string $properties = '')

List groups of the current user (so user of API token)

object
infoGroups(int $group, int $load_members = 0)

Get properties of a user group

array
delete(int $id)

Delete a user

array
deleteGroups(int $group)

Delete a usergroup

array
getUserNotification(int $id)

Get notifications for a user

array|mixed
createUserNotification(int $id, array $request_data = null)

Create a notification for a user

array|mixed
createUserNotificationByCode(int $id, string $code, array $request_data = null)

Create a notification for a user using action trigger code

int
deleteUserNotification(int $id, int $notification_id)

Delete a notification attached to a user

array|mixed
updateUserNotification(int $id, int $notification_id, array $request_data = null)

Update a notification for a user

Details

__construct()

Constructor

protected string|array<string, mixed> _checkValForAPI(string $field, string|string[] $value, object $object)

Check and convert a string depending on its type/name.

Parameters

string $field

Field name

string|string[] $value

Value to check/clean

object $object Object

Return Value

string|array<string, mixed>

Value cleaned

protected object _filterObjectProperties(object $object, string $properties)

Filter properties that will be returned on object

Parameters

object $object

Object to clean

string $properties

Comma separated list of properties names

Return Value

object

Object with cleaned properties

protected object _cleanObjectDatas(object $object)

Clean sensible object datas

Parameters

object $object

Object to clean

Return Value

object

Object with cleaned properties

static protected bool _checkAccessToResource(string $resource, int $resource_id = 0, string $dbtablename = '', string $feature2 = '', string $dbt_keyfield = 'fk_soc', string $dbt_select = 'rowid')

Check access by user to a given resource

Parameters

string $resource

element to check

int $resource_id

Object ID if we want to check a particular record (optional) is linked to a owned thirdparty (optional).

string $dbtablename

'TableName&SharedElement' with Tablename is table where object is stored. SharedElement is an optional key to define where to check entity. Not used if objectid is null (optional)

string $feature2

Feature to check, second level of permission (optional). Can be or check with 'level1|level2'.

string $dbt_keyfield

Field name for socid foreign key if not fk_soc. Not used if objectid is null (optional)

string $dbt_select

Field name for select if not rowid. Not used if objectid is null (optional)

Return Value

bool

protected bool|string _checkFilters(string $sqlfilters, string $error = '')

Return if a $sqlfilters parameter is valid Function no more used. Kept for backward compatibility with old APIs of modules

Parameters

string $sqlfilters

sqlfilter string

string $error

Error message

Return Value

bool|string

True if valid, False if not valid

static protected string _forge_criteria_callback(string[] $matches)

Function to forge a SQL criteria from a Generic filter string.

Function no more used. Kept for backward compatibility with old APIs of modules

Parameters

string[] $matches

Array of found string by regex search. Each entry is 1 and only 1 criteria. Example: "t.ref:like:'SO-%'", "t.date_creation:<:'20160101'", "t.date_creation:<:'2016-01-01 12:30:00'", "t.nature:is:NULL", "t.field2:isnot:NULL"

Return Value

string

Forged criteria. Example: "t.field like 'abc%'"

array index(string $sortfield = "t.rowid", string $sortorder = 'ASC', int $limit = 100, int $page = 0, string $user_ids = '0', int $category = 0, string $sqlfilters = '', string $properties = '')

Since: 5.0.0 Initial implementation

List users

Get a list of Users

Parameters

string $sortfield

Sort field

string $sortorder

Sort order

int $limit

Limit for list

int $page

Page number

string $user_ids

User ids filter field. Example: '1' or '1,2,3' {@pattern /^[0-9,]*$/i}

int $category

Use this param to filter list by category

string $sqlfilters

Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"

string $properties

Restrict the data returned to these properties. Ignored if empty. Comma separated list of properties names

Return Value

array

Array of User objects

Exceptions

RestException

array|mixed get(int $id, int $includepermissions = 0)

Since: 5.0.0 Initial implementation

Get a user

Parameters

int $id

ID of user

int $includepermissions

Set this to 1 to have the array of permissions loaded (not done by default for performance purpose)

Return Value

array|mixed

data without useless information

Exceptions

RestException
RestException
RestException

array|mixed getByLogin(string $login, int $includepermissions = 0)

Since: 13.0.0 Initial implementation

Get a user by login

Parameters

string $login

Login of user

int $includepermissions

Set this to 1 to have the array of permissions loaded (not done by default for performance purpose)

Return Value

array|mixed

Data without useless information

Exceptions

RestException
RestException
RestException

array|mixed getByEmail(string $email, int $includepermissions = 0)

Since: 13.0.0 Initial implementation

Get a user by email

Parameters

string $email

Email of user

int $includepermissions

Set this to 1 to have the array of permissions loaded (not done by default for performance purpose)

Return Value

array|mixed

Data without useless information

Exceptions

RestException
RestException
RestException

array|mixed getInfo(int $includepermissions = 0)

Since: 11.0.0 Initial implementation

Get more properties of the current user (so user of API token).

This route could also ave been named "/users/me".

Parameters

int $includepermissions

Set this to 1 to have the array of permissions loaded (not done by default for performance purpose)

Return Value

array|mixed

Data without useless information

Exceptions

RestException
RestException

int post(array $request_data = null)

Since: 5.0.0 Initial implementation

Create a user

Parameters

array $request_data

New user data

Return Value

int

Exceptions

RestException

object put(int $id, array $request_data = null)

Since: 5.0.0 Initial implementation

Update a user

Parameters

int $id

Id of account to update

array $request_data Datas

Return Value

object

Updated object

Exceptions

RestException
RestException
RestException

int setPassword(int $id, bool $send_password = false)

Since: 21.0.0 Initial implementation

Update a user password

Parameters

int $id

User ID

bool $send_password

Only if set to true, the new password will send to the user

Return Value

int

1 if password changed, 2 if password changed and sent

Exceptions

RestException
RestException
RestException

array getGroups(int $id)

Since: 10.0.0 Initial implementation

List the groups of a user

Parameters

int $id

Id of user

Return Value

array

Array of group objects

Exceptions

RestException
RestException
RestException

int setGroup(int $id, int $group, int $entity = 1)

Since: 5.0.0 Initial implementation

Add a user to a group

Parameters

int $id

User ID

int $group

Group ID

int $entity

Entity ID (valid only for superadmin in multicompany transverse mode)

Return Value

int

1 if success

Exceptions

RestException
RestException
RestException

int postGroups(array $request_data = null)

Create user group

Parameters

array $request_data

New user group data

Return Value

int

Exceptions

RestException
RestException
RestException

object putGroups(int $group, array $request_data = null)

Since: 23.0.0 Initial implementation

Update user group

Parameters

int $group

Id of usergroup to update

array $request_data Datas

Return Value

object

Updated object

Exceptions

RestException
RestException
RestException

array{success: bool, message: string} removeUserFromGroup(int $id, int $group)

Since: 23.0.0 Initial implementation

Remove user from group (only admin)

Parameters

int $id

User ID

int $group

Group ID

Return Value

array{success: bool, message: string}

Exceptions

RestException
RestException

array listGroups(string $sortfield = "t.rowid", string $sortorder = 'ASC', int $limit = 100, int $page = 0, string $group_ids = '0', string $sqlfilters = '', string $properties = '')

Since: 11.0.0 Initial implementation

List groups of the current user (so user of API token)

Return an array with a list of Groups

Parameters

string $sortfield

Sort field

string $sortorder

Sort order

int $limit

Limit for list

int $page

Page number

string $group_ids

Groups ids filter field. Example: '1' or '1,2,3' {@pattern /^[0-9,]*$/i}

string $sqlfilters

Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"

string $properties

Restrict the data returned to these properties. Ignored if empty. Comma separated list of properties names

Return Value

array

Array of User objects

Exceptions

RestException
RestException
RestException

object infoGroups(int $group, int $load_members = 0)

Since: 11.0.0 Initial implementation

Get properties of a user group

Return an array with group information

Parameters

int $group

ID of group

int $load_members

Load members list or not {@min 0} {@max 1}

Return Value

object

object of User objects

Exceptions

RestException
RestException
RestException

array delete(int $id)

Since: 5.0.0 Initial implementation

Delete a user

Parameters

int $id

Account ID

Return Value

array

Exceptions

RestException
RestException

array deleteGroups(int $group)

Since: 23.0.0 Initial implementation

Delete a usergroup

Parameters

int $group

usergroup ID

Return Value

array

Exceptions

RestException
RestException

array getUserNotification(int $id)

Since: 22.0.0 Initial implementation

Get notifications for a user

Parameters

int $id

ID of the user

Return Value

array

Exceptions

RestException
RestException
RestException

array|mixed createUserNotification(int $id, array $request_data = null)

Since: 22.0.0 Initial implementation

Create a notification for a user

Parameters

int $id

ID of the user

array $request_data

Request data

Return Value

array|mixed

Notification of the user

Exceptions

RestException

array|mixed createUserNotificationByCode(int $id, string $code, array $request_data = null)

Since: 22.0.0 Initial implementation

Create a notification for a user using action trigger code

Parameters

int $id

ID of the user

string $code

Action Trigger code

array $request_data

Request data

Return Value

array|mixed

Notification for the user

Exceptions

RestException

int deleteUserNotification(int $id, int $notification_id)

Since: 22.0.0 Initial implementation

Delete a notification attached to a user

Parameters

int $id

ID of the user

int $notification_id

ID of UserNotification

Return Value

int

-1 if error, 1 if correct deletion

Exceptions

RestException

array|mixed updateUserNotification(int $id, int $notification_id, array $request_data = null)

Since: 22.0.0 Initial implementation

Update a notification for a user

Parameters

int $id

ID of the User

int $notification_id

ID of UserNotification

array $request_data

Request data

Return Value

array|mixed

Notification for the user

Exceptions

RestException