class Projects extends DolibarrApi (View source)

API class for projects

Properties

protected DoliDB $db from  DolibarrApi
Restler $r from  DolibarrApi
static string[] $FIELDS
Project $project
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 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 properties of a project object

object
getByRef(string $ref)

Get properties of a project object

object
getByRefExt(string $ref_ext)

Get properties of a project object

object
getByMsgId(string $email_msgid)

Get properties of a project object

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

List projects

int
post(array $request_data = null)

Create project object

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

Adds a contact to an project

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

Delete a contact type of given project

array
getLines(int $id, int $includetimespent = 0)

Get tasks of a project.

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

Get roles a user is assigned to a project with

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

Update project general fields (won't touch lines of project)

array
delete(int $id)

Delete project

array
validate(int $id, int $notrigger = 0)

Validate a project.

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

Get all timespent

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

Get contacts of given project

object
addToContact(int $id, int $fk_socpeople, string $type_contact, string $source, int $notrigger = 0, int[] $affect_to_tasks = null)

Adds a contact to a project

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

Delete a contact type of given project

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

Get timespent of a project (from all its tasks)

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)

Get properties of a project object

Return an array with project information

Parameters

int $id

ID of project

Return Value

object

Object with cleaned properties

Exceptions

RestException

object getByRef(string $ref)

Get properties of a project object

Return an array with project information

Parameters

string $ref

Ref of project

Return Value

object

Object with cleaned properties

Exceptions

RestException

object getByRefExt(string $ref_ext)

Get properties of a project object

Return an array with project information

Parameters

string $ref_ext

Ref_Ext of project

Return Value

object

Object with cleaned properties

Exceptions

RestException

object getByMsgId(string $email_msgid)

Get properties of a project object

Return an array with project information

Parameters

string $email_msgid

Email msgid of project

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 $thirdparty_ids = '', int $category = 0, string $sqlfilters = '', string $properties = '', bool $pagination_data = false)

List projects

Get a list of projects

Parameters

string $sortfield

Sort field

string $sortorder

Sort order

int $limit

Limit for list

int $page

Page number

string $thirdparty_ids

Thirdparty ids to filter projects 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')"

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

int post(array $request_data = null)

Create project object

Parameters

array $request_data

Request data

Return Value

int

ID of project

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

Adds a contact to an project

Parameters

int $id

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

Parameters

int $id

Id of project 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

array getLines(int $id, int $includetimespent = 0)

Get tasks of a project.

See also API /tasks

Parameters

int $id

Id of project

int $includetimespent

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

Return Value

array

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

Get roles a user is assigned to a project with

Parameters

int $id

Id of project

int $userid

Id of user (0 = connected user)

Return Value

array

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

Update project general fields (won't touch lines of project)

Parameters

int $id

Id of project to update

array $request_data Datas

Return Value

object

Updated object

array delete(int $id)

Delete project

Parameters

int $id

Project ID

Return Value

array

array validate(int $id, int $notrigger = 0)

Validate a project.

You can test this API with the following input message { "notrigger": 0 }

Parameters

int $id

Project ID

int $notrigger

1=Does not execute triggers, 0= execute triggers

Return Value

array

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

Get all timespent

Parameters

string $sortfield

Sort field

string $sortorder

Sort order

int $limit

Limit for list

int $page

Page number

string $thirdparty_ids

Thirdparty ids to filter projects 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')"

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

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

Get contacts of given project

Return an array with contact information

Parameters

int $id

ID of project

string $type

Type of the contact

Return Value

array<int, mixed>

Array with cleaned properties

Exceptions

RestException

object addToContact(int $id, int $fk_socpeople, string $type_contact, string $source, int $notrigger = 0, int[] $affect_to_tasks = null)

Adds a contact to a project

Parameters

int $id

Project 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

int[] $affect_to_tasks

Array of task IDs to also add the contact to (empty array = all tasks, null = no tasks)

Return Value

object

Exceptions

RestException
RestException
RestException
RestException

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

Delete a contact type of given project

Parameters

int $id

Id of project 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

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

Get timespent of a project (from all its tasks)

Parameters

int $id

ID of project

Return Value

array<int, mixed>

Array of timespent objects

Exceptions

RestException