class ObjectLinks extends DolibarrApi (View source)

API that gives shows links between objects in an Dolibarr instance.

Properties

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

Methods

__construct()

Constructor of the class

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
getById(int $id)

Get properties of a ObjectLink object

create(array $request_data = null)

Create object link

array
deleteById(int $id)

Delete an object link

getByValues($fk_source, string $sourcetype, $fk_target, $targettype, $relationtype = null)

GET object link(s) By Values, not id

deleteByValues($fk_source, string $sourcetype, $fk_target, $targettype, $relationtype = null, int $notrigger = 0)

Delete object link By Values, not id

Details

__construct()

Constructor of the class

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 getById(int $id)

Get properties of a ObjectLink object

Return an array with object link information

Parameters

int $id

ID of objectlink

Return Value

object

Object with cleaned properties

Exceptions

RestException
RestException

create(array $request_data = null)

Create object link

Examples: Only set "notrigger": 1 because 0 is the default value. Linking subscriptions for when you sell membership as part of another sale {"fk_source":"1679","sourcetype":"propal","fk_target":"1233","targettype":"commande"} {"fk_source":"167","sourcetype":"facture","fk_target":"123","targettype":"subscription"}

Parameters

array $request_data

Request data, see Example above for required parameters. Currently unused is relationtype. notrigger is default 0, which means to trigger, else set notrigger: 1

Exceptions

RestException
RestException
RestException

array deleteById(int $id)

Delete an object link

Parameters

int $id

object link ID

Return Value

array

Exceptions

RestException
RestException
RestException

getByValues($fk_source, string $sourcetype, $fk_target, $targettype, $relationtype = null)

GET object link(s) By Values, not id

@param int $fk_source source id of object we link from

Parameters

$fk_source
string $sourcetype

type of the source object @param int $fk_target target id of object we link to @param string $targettype type of the target object @param string $relationtype type of the relation, usually null @return Object

$fk_target
$targettype
$relationtype

Exceptions

RestException
RestException
RestException

deleteByValues($fk_source, string $sourcetype, $fk_target, $targettype, $relationtype = null, int $notrigger = 0)

Delete object link By Values, not id

@param int $fk_source source id of object we link from

Parameters

$fk_source
string $sourcetype

type of the source object @param int $fk_target target id of object we link to @param string $targettype type of the target object @param string $relationtype type of the relation, usually null

$fk_target
$targettype
$relationtype
int $notrigger

1=Does not execute triggers, 0=execute triggers {@choice 0,1} @return array

Exceptions

RestException
RestException
RestException