Since: 23.0.0 Initial implementation

class Mailings extends DolibarrApi (View source)

API class for mass mailings

Properties

protected DoliDB $db from  DolibarrApi
Restler $r from  DolibarrApi
static string[] $FIELDS
static string[] $TARGETFIELDS
Mailing $mailing
MailingTarget $mailing_target

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.

object
get(int $id)

Get a mass mailing

array
index(string $sortfield = "t.rowid", string $sortorder = 'ASC', int $limit = 100, int $page = 0, string $fk_projects = '', string $sqlfilters = '', string $properties = '', bool $pagination_data = false, int $loadlinkedobjects = 0)

List mass mailings

array
indexTargets(int $id, string $sortfield = "t.rowid", string $sortorder = 'ASC', int $limit = 100, int $page = 0, string $sqlfilters = '', string $properties = '', bool $pagination_data = false)

List mass mailing targets

object
clone(int $id, int $cloneContent = 1, int $cloneRecipients = 1, int $notrigger = 0)

Clone a mass mailing

int
post(array $request_data = null)

Create a mass mailing

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

Update a mass mailing general fields (won't change lines of mass mailing)

array
delete(int $id)

Delete a mass mailing

object
updateTarget(int $id, int $targetid, array $request_data = null)

Update a mass mailing general fields (won't change lines of mass mailing)

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

Create a mass mailing

object
getTarget(int $id, int $targetid)

Get a target in a mass mailing

array
deleteTarget(int $id, int $targetid)

Delete a mass mailing general fields (won't change lines of mass mailing)

array
deleteTargets(int $id)

Delete targets of a mass mailing

array
resetTargetsStatus(int $id)

reset target status of a mass mailing

object
settodraft(int $id)

Set a mass mailing to draft

object
validate(int $id)

Validate a mass mailing

object
_cleanTargetDatas(object $object)

Clean sensible object (mailing target) datas

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

object get(int $id)

Since: 23.0.0 Initial implementation

Get a mass mailing

Return an array with mass mailing information

Parameters

int $id

ID of mass mailing

Return Value

object

Object with cleaned properties

Exceptions

RestException

array index(string $sortfield = "t.rowid", string $sortorder = 'ASC', int $limit = 100, int $page = 0, string $fk_projects = '', string $sqlfilters = '', string $properties = '', bool $pagination_data = false, int $loadlinkedobjects = 0)

Since: 23.0.0 Initial implementation

List mass mailings

Get a list of mass mailings

Parameters

string $sortfield

Sort field

string $sortorder

Sort order

int $limit

Limit for list

int $page

Page number

string $fk_projects

Project ids to filter mass mailings (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.datec:<:'2016-01-01')"

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*

int $loadlinkedobjects

Load also linked object

Return Value

array

Array of order objects

Exceptions

RestException
RestException

array indexTargets(int $id, string $sortfield = "t.rowid", string $sortorder = 'ASC', int $limit = 100, int $page = 0, string $sqlfilters = '', string $properties = '', bool $pagination_data = false)

Since: 23.0.0 Initial implementation

List mass mailing targets

Get a list of mass mailing targets

Parameters

int $id

Mass mailing ID

string $sortfield

Sort field

string $sortorder

Sort order

int $limit

Limit for list

int $page

Page number

string $sqlfilters

Other criteria to filter answers separated by a comma. Syntax example "(t.lastname:like:'John Doe') and (t.statut:=:3)"

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

array

Array of order objects

Exceptions

RestException
RestException
RestException

object clone(int $id, int $cloneContent = 1, int $cloneRecipients = 1, int $notrigger = 0)

Since: 23.0.0 Initial implementation

Clone a mass mailing

Parameters

int $id

Id of object to clone

int $cloneContent

1=Clone content (default), 0=Forget content

int $cloneRecipients

1=Clone recipients (default), 0=Forget recipients

int $notrigger

1=Disable triggers, 0=Active triggers if any (default)

Return Value

object

Object with cleaned properties

Exceptions

RestException
RestException
RestException

int post(array $request_data = null)

Since: 23.0.0 Initial implementation

Create a mass mailing

Parameters

array $request_data

Request data

Return Value

int

ID of mass mailing

Exceptions

RestException
RestException

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

Since: 23.0.0 Initial implementation

Update a mass mailing general fields (won't change lines of mass mailing)

Parameters

int $id

Id of mass mailing to update

array $request_data Datas

Return Value

object

Object with cleaned properties

Exceptions

RestException
RestException
RestException

array delete(int $id)

Since: 23.0.0 Initial implementation

Delete a mass mailing

Parameters

int $id

Mass mailing ID

Return Value

array

Exceptions

RestException
RestException
RestException

object updateTarget(int $id, int $targetid, array $request_data = null)

Since: 23.0.0 Initial implementation

Update a mass mailing general fields (won't change lines of mass mailing)

Parameters

int $id

Id of mass mailing with the targetid to update

int $targetid

Id mass mailing target to update

array $request_data Datas

Return Value

object

Object with cleaned properties

Exceptions

RestException
RestException
RestException

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

Since: 23.0.0 Initial implementation

Create a mass mailing

Parameters

int $id

Id of mass mailing to create a target for

array $request_data

Request data

Return Value

int

ID of mass mailing

Exceptions

RestException
RestException
RestException
RestException

object getTarget(int $id, int $targetid)

Since: 23.0.0 Initial implementation

Get a target in a mass mailing

Return an array with info about a mass mailing target

Parameters

int $id

Id of mass mailing with the targetid to get

int $targetid

Id mass mailing target to get

Return Value

object

Object with cleaned properties

Exceptions

RestException

array deleteTarget(int $id, int $targetid)

Since: 23.0.0 Initial implementation

Delete a mass mailing general fields (won't change lines of mass mailing)

Parameters

int $id

Id of mass mailing with the targetid to delete

int $targetid

Id mass mailing target to delete

Return Value

array

Exceptions

RestException
RestException
RestException

array deleteTargets(int $id)

Since: 23.0.0 Initial implementation

Delete targets of a mass mailing

Parameters

int $id

Mass mailing ID

Return Value

array

Exceptions

RestException
RestException
RestException

array resetTargetsStatus(int $id)

Since: 23.0.0 Initial implementation

reset target status of a mass mailing

Parameters

int $id

Mass mailing ID

Return Value

array

Exceptions

RestException
RestException
RestException

object settodraft(int $id)

Since: 23.0.0 Initial implementation

Set a mass mailing to draft

Parameters

int $id

Mass mailing ID

Return Value

object

Object with cleaned properties

Exceptions

RestException
RestException
RestException
RestException

object validate(int $id)

Since: 23.0.0 Initial implementation

Validate a mass mailing

If you get a bad value for param notrigger check that ou provide this in body { "notrigger": 0 }

Parameters

int $id

Mass mailing ID

Return Value

object

Object with cleaned properties

Exceptions

RestException
RestException
RestException
RestException

protected object _cleanTargetDatas(object $object)

Clean sensible object (mailing target) datas

Parameters

object $object

Object to clean

Return Value

object

Object with cleaned properties