Since: 3.8.0 Initial implementation

class Contacts extends DolibarrApi (View source)

API class for contacts

Properties

protected DoliDB $db from  DolibarrApi
Restler $r from  DolibarrApi
static string[] $FIELDS
Contact $contact

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 data

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.

object
get(int $id, int $includecount = 0, int $includeroles = 0)

Get a contact

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

Get a contact by Email

index(string $sortfield = "t.rowid", string $sortorder = 'ASC', int $limit = 100, int $page = 0, string $thirdparty_ids = '', int $category = 0, string $sqlfilters = '', int $includecount = 0, int $includeroles = 0, string $properties = '', bool $pagination_data = false)

List contacts

int
post(array $request_data = null)

Create a contact

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

Update a contact

array[]
delete(int $id)

Delete a contact

int
createUser(int $id, array $request_data = null)

Create a user account object from contact (external user)

mixed
getCategories(int $id, string $sortfield = "s.rowid", string $sortorder = 'ASC', int $limit = 0, int $page = 0)

Get categories of a contact

mixed
addCategory(int $id, int $category_id)

Add a category to a contact

mixed
deleteCategory(int $id, int $category_id)

Remove the link between a category and a contact

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 data

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%'"

object get(int $id, int $includecount = 0, int $includeroles = 0)

Since: 3.8.0 Initial implementation

Get a contact

Return an array with contact information

Parameters

int $id

ID of contact

int $includecount

Include count of elements the contact is used as a link for

int $includeroles

Includes roles of the contact

Return Value

object

Cleaned contact object

Exceptions

RestException

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

Since: 13.0.0 Initial implementation

Get a contact by Email

Parameters

string $email

Email of contact

int $includecount

Include count of elements the contact is used as a link for

int $includeroles

Includes roles of the contact

Return Value

array|mixed

Cleaned contact object

Exceptions

RestException
RestException

Contact[] index(string $sortfield = "t.rowid", string $sortorder = 'ASC', int $limit = 100, int $page = 0, string $thirdparty_ids = '', int $category = 0, string $sqlfilters = '', int $includecount = 0, int $includeroles = 0, string $properties = '', bool $pagination_data = false)

Since: 3.8.0 Initial implementation

List contacts

Get a list of contacts

Parameters

string $sortfield

Sort field

string $sortorder

Sort order

int $limit

Limit for list

int $page

Page number

string $thirdparty_ids

Third party ids to filter contacts of (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')"

int $includecount

Include count of elements the contact is used as a link for

int $includeroles

Includes roles of the contact

string $properties

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

bool $pagination_data

If this parameter is set to true, the response will include pagination data. Default value is false. Page starts from 0*

Return Value

Contact[]

Array of contact objects

Exceptions

RestException

int post(array $request_data = null)

Since: 3.8.0 Initial implementation

Create a contact

Parameters

array $request_data

Request data

Return Value

int

ID of contact

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

Since: 3.8.0 Initial implementation

Update a contact

Parameters

int $id

ID of contact to update

array $request_data

Request data

Return Value

object|false

Updated object, false when error updating contact

Exceptions

RestException
RestException
RestException

array[] delete(int $id)

Since: 3.8.0 Initial implementation

Delete a contact

Parameters

int $id

Contact ID

Return Value

array[]

int createUser(int $id, array $request_data = null)

Since: 5.0.0 Initial implementation

Create a user account object from contact (external user)

Parameters

int $id

ID of contact

array $request_data

Request data

Return Value

int

ID of user

mixed getCategories(int $id, string $sortfield = "s.rowid", string $sortorder = 'ASC', int $limit = 0, int $page = 0)

Since: 5.0.0 Initial implementation

Get categories of a contact

Parameters

int $id

ID of contact

string $sortfield

Sort field

string $sortorder

Sort order

int $limit

Limit for list

int $page

Page number

Return Value

mixed

mixed addCategory(int $id, int $category_id)

Since: 11.0.0 Initial implementation

Add a category to a contact

Parameters

int $id

ID of contact

int $category_id

ID of category

Return Value

mixed

Exceptions

RestException
RestException

mixed deleteCategory(int $id, int $category_id)

Since: 11.0.0 Initial implementation

Remove the link between a category and a contact

Parameters

int $id

ID of contact

int $category_id

ID of category

Return Value

mixed

Exceptions

RestException
RestException