class Tasks extends DolibarrApi (View source)

API class for projects

Properties

protected DoliDB $db from  DolibarrApi
Restler $r from  DolibarrApi
static string[] $FIELDS
Task $task

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 sensitive 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.

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

Get properties of a task object

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

List tasks

int
post(array $request_data = null)

Create task object

array<int, mixed>
getTimespent(int $id)

Get time spent of a task

array
getRoles(int $id, int $userid = 0)

Get roles a user is assigned to a task with

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

Update task general fields (won't touch time spent of task)

array
delete(int $id)

Delete task

object
getTimeSpentByID(int $id, int $timespent_id)

Get time spent of a task

array
addTimeSpent(int $id, datetime|string $date, int $duration, int $product_id = null, int $user_id = 0, string $note = '', int|null $progress = -1)

Add time spent to a task of a project.

array
putTimeSpent(int $id, int $timespent_id, datetime $date, int $duration, int $product_id = null, int $user_id = 0, string $note = '')

Update time spent for a task of a project.

array
deleteTimeSpent(int $id, int $timespent_id)

Delete time spent for a task of a project.

object
_cleanTimeSpentObjectDatas(object $object)

Clean sensitive object data

array<int, mixed>
getContacts(int $id, string $type = '')

Get contacts of given task

object
addContact(int $id, int $fk_socpeople, string $type_contact, string $source, int $notrigger = 0)

Adds a contact to a task

object
deleteContact(int $id, int $contactid, string $type)

Delete a contact type of given task

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

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

Get properties of a task object

Return an array with task information

Parameters

int $id

ID of task

int $includetimespent

0=Return only task. 1=Include a summary of time spent, 2=Include details of time spent lines

Return Value

array|mixed

data without useless information

Exceptions

RestException

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

List tasks

Get a list of tasks

Parameters

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.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 project objects

int post(array $request_data = null)

Create task object

Parameters

array $request_data

Request data

Return Value

int

ID of project

array<int, mixed> getTimespent(int $id)

Get time spent of a task

Parameters

int $id

Id of task

Return Value

array<int, mixed>

Array of timespent lines

array getRoles(int $id, int $userid = 0)

Get roles a user is assigned to a task with

Parameters

int $id

Id of task

int $userid

Id of user (0 = connected user)

Return Value

array

Array of roles

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

Update task general fields (won't touch time spent of task)

Parameters

int $id

Id of task to update

array $request_data Data

Return Value

object

Updated object

array delete(int $id)

Delete task

Parameters

int $id

Task ID

Return Value

array

Exceptions

RestException

object getTimeSpentByID(int $id, int $timespent_id)

Get time spent of a task

Parameters

int $id

Id of task

int $timespent_id

Id of timespent

Return Value

object

data without useless information

Exceptions

RestException

array addTimeSpent(int $id, datetime|string $date, int $duration, int $product_id = null, int $user_id = 0, string $note = '', int|null $progress = -1)

Add time spent to a task of a project.

You can test this API with the following input message { "date": "2016-12-31 23:15:00", "duration": 1800, "user_id": 1, "note": "My time test" }

Parameters

int $id

Task ID

datetime|string $date

Date (YYYY-MM-DD HH:MI:SS in GMT)

int $duration

Duration in seconds (3600 = 1h)

int $product_id

The product id that is used, default is null

int $user_id

User (Use 0 for connected user)

string $note Note
int|null $progress

Progress percentage (0-100). If null, progress is not updated

Return Value

array

array putTimeSpent(int $id, int $timespent_id, datetime $date, int $duration, int $product_id = null, int $user_id = 0, string $note = '')

Update time spent for a task of a project.

You can test this API with the following input message { "date": "2016-12-31 23:15:00", "duration": 1800, "user_id": 1, "note": "My time test" }

Parameters

int $id

Task ID

int $timespent_id

Time spent ID (llx_element_time.rowid)

datetime $date

Date (YYYY-MM-DD HH:MI:SS in GMT)

int $duration

Duration in seconds (3600 = 1h)

int $product_id

The product id that is used, default is null

int $user_id

User (Use 0 for connected user)

string $note Note

Return Value

array

array deleteTimeSpent(int $id, int $timespent_id)

Delete time spent for a task of a project.

Parameters

int $id

Task ID

int $timespent_id

Time spent ID (llx_element_time.rowid)

Return Value

array

protected object _cleanTimeSpentObjectDatas(object $object)

Clean sensitive object data

Parameters

object $object

Object to clean

Return Value

object

Object with cleaned properties

array<int, mixed> getContacts(int $id, string $type = '')

Get contacts of given task

Return an array with contact information

Parameters

int $id

ID of task

string $type

Type of the contact

Return Value

array<int, mixed>

Array with cleaned properties

Exceptions

RestException

object addContact(int $id, int $fk_socpeople, string $type_contact, string $source, int $notrigger = 0)

Adds a contact to a task

Parameters

int $id

Task ID

int $fk_socpeople

Id of thirdparty contact (if source = 'external') or id of user (if source = 'internal') to link

string $type_contact

Type of contact (code). Must a code found into table llx_c_type_contact. For example: BILLING

string $source

external=Contact extern (llx_socpeople), internal=Contact intern (llx_user)

int $notrigger

Disable all triggers

Return Value

object

Exceptions

RestException
RestException
RestException
RestException

object deleteContact(int $id, int $contactid, string $type)

Delete a contact type of given task

Parameters

int $id

Id of task to update

int $contactid

Row key of the contact in the array contact_ids.

string $type

Type of the contact (BILLING, SHIPPING, CUSTOMER).

Return Value

object

Object with cleaned properties

Exceptions

RestException
RestException
RestException