dolibarr 25.0.0-alpha
Dolresources Class Reference
Inheritance diagram for Dolresources:
Collaboration diagram for Dolresources:

Public Member Functions

 __construct ()
 Constructor.
 
 get ($id)
 Get properties of a resource object by id.
 
 index ($sortfield="t.ref", $sortorder='ASC', $limit=100, $page=0, $sqlfilters='', $properties='')
 List resources.
 
 post ($request_data=null)
 Create resource object.
 
 put ($id, $request_data=null)
 Update resource.
 
 delete ($id)
 Delete resource.
 
 getElementResources ($element_type, $element_id)
 Get the resources linked to an element.
 
 postElementResources ($element_type, $element_id, $request_data=null)
 Link a resource to an element.
 
 deleteElementResources ($element_type, $element_id, $id)
 Unlink a resource from an element.
 
 getBookingConflicts ($id, $date_start, $date_end)
 Get the bookings that conflict with a period for a resource.
 
- Public Member Functions inherited from DolibarrApi
 __construct ($db, $cachedir='', $refreshCache=false)
 Constructor.
 

Protected Member Functions

 _cleanObjectDatas ($object)
 Clean sensible object datas.
 
- Protected Member Functions inherited from DolibarrApi
 _checkValForAPI ($field, $value, $object)
 Check and convert a string depending on its type/name.
 
 _checkValExtrafieldsForAPI ($field, $value, $object)
 Check and convert a string depending on its type/name.
 
 _filterObjectProperties ($object, $properties)
 Filter properties that will be returned on object.
 
 _checkFilters ($sqlfilters, &$error='')
 Return if a $sqlfilters parameter is valid Function no more used.
 

Private Member Functions

 _fetchElement ($element_type, $element_id)
 Load the element carrying the resources and check the access to it.
 
 _formatLink ($link)
 Format a link of llx_element_resources for the answer.
 
 _describeConflicts ($conflicts)
 Describe conflicting bookings for an error message.
 
 _toTimestamp ($value, $name)
 Convert a date given to the API into a timestamp.
 
 _validate ($data)
 Validate fields before create or update object.
 

Additional Inherited Members

- Static Protected Member Functions inherited from DolibarrApi
static _checkAccessToResource ($resource, $resource_id=0, $dbtablename='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $parenttableforentity='')
 Check access by user to a given resource.
 
static _forge_criteria_callback ($matches)
 Function to forge a SQL criteria from a Generic filter string.
 

Detailed Description

Definition at line 40 of file api_dolresources.class.php.

Member Function Documentation

◆ _cleanObjectDatas()

Dolresources::_cleanObjectDatas ( $object)
protected

Clean sensible object datas.

Parameters
Object$objectObject to clean
Returns
Object Object with cleaned properties

Reimplemented from DolibarrApi.

Definition at line 510 of file api_dolresources.class.php.

References $object.

Referenced by _formatLink(), get(), and index().

◆ _describeConflicts()

Dolresources::_describeConflicts ( $conflicts)
private

Describe conflicting bookings for an error message.

Parameters
array<int,array{element_type:string,element_id:int,ref:string}>$conflicts Conflicting bookings
Returns
string Description

Definition at line 637 of file api_dolresources.class.php.

Referenced by postElementResources().

◆ _fetchElement()

Dolresources::_fetchElement ( $element_type,
$element_id )
private

Load the element carrying the resources and check the access to it.

Parameters
string$element_typeType of the element, as stored in element_type
int$element_idID of the element
Returns
CommonObject The loaded element
Exceptions
RestException400 Bad element type
RestException403 Access denied
RestException404 Element not found

Definition at line 543 of file api_dolresources.class.php.

References DolibarrApi\_checkAccessToResource().

Referenced by deleteElementResources(), getElementResources(), and postElementResources().

◆ _formatLink()

Dolresources::_formatLink ( $link)
private

Format a link of llx_element_resources for the answer.

Parameters
array<string,mixed>$link Link as returned by getElementResources()
Returns
array<string,mixed> Formatted link

Definition at line 573 of file api_dolresources.class.php.

References _cleanObjectDatas().

Referenced by getElementResources(), and postElementResources().

◆ _toTimestamp()

Dolresources::_toTimestamp ( $value,
$name )
private

Convert a date given to the API into a timestamp.

Parameters
string$valueDate, format YYYY-MM-DD HH:MM:SS or a Unix timestamp
string$nameName of the parameter, for the error message
Returns
int Timestamp
Exceptions
RestException400 Bad date

Definition at line 656 of file api_dolresources.class.php.

References dol_stringtotime().

Referenced by getBookingConflicts().

◆ _validate()

Dolresources::_validate ( $data)
private

Validate fields before create or update object.

Parameters
?array<string,string>$data Datas to validate
Returns
array<string,string>
Exceptions
RestException400 Mandatory field missing

Definition at line 678 of file api_dolresources.class.php.

Referenced by post().

◆ delete()

Dolresources::delete ( $id)

Delete resource.

Parameters
int$idResource ID
Returns
array @phan-return array{success:array{code:int,message:string}} @phpstan-return array{success:array{code:int,message:string}}
Exceptions
RestException403 Access denied
RestException404 Resource not found
RestException500 Error when deleting the resource

Definition at line 276 of file api_dolresources.class.php.

References $id, and DolibarrApi\_checkAccessToResource().

◆ deleteElementResources()

Dolresources::deleteElementResources ( $element_type,
$element_id,
$id )

Unlink a resource from an element.

Parameters
string$element_typeType of the element, as stored in element_type (for example "action" for an agenda event)
int$element_idID of the element
int$idID of the link to delete (the id returned by the GET, not the id of the resource)
Returns
array @phan-return array{success:array{code:int,message:string}} @phpstan-return array{success:array{code:int,message:string}}

@url DELETE {element_type}/{element_id}/resources/{id}

Exceptions
RestException403 Access denied
RestException404 Element or link not found
RestException500 Error when deleting the link

Definition at line 426 of file api_dolresources.class.php.

References $id, and _fetchElement().

◆ get()

Dolresources::get ( $id)

Get properties of a resource object by id.

Return an array with resource information.

Parameters
int$idID of resource
Returns
array|mixed Data without useless information

@url GET {id}

Exceptions
RestException403 Access denied
RestException404 Resource not found

Definition at line 78 of file api_dolresources.class.php.

References $id, DolibarrApi\_checkAccessToResource(), and _cleanObjectDatas().

◆ getBookingConflicts()

Dolresources::getBookingConflicts ( $id,
$date_start,
$date_end )

Get the bookings that conflict with a period for a resource.

Answers the availability question without having to create a link first. Only the links flagged busy are considered, as in the interface.

Parameters
int$idID of resource
string$date_startStart of the period, format YYYY-MM-DD HH:MM:SS or a Unix timestamp
string$date_endEnd of the period, format YYYY-MM-DD HH:MM:SS or a Unix timestamp
Returns
array Conflicting bookings, empty if the resource is free @phan-return array<int,array{element_type:string,element_id:int,ref:string}> @phpstan-return array<int,array{element_type:string,element_id:int,ref:string}>

@url GET {id}/bookingconflicts

Exceptions
RestException400 Bad date
RestException403 Access denied
RestException404 Resource not found
RestException500 Error when searching the conflicts

Definition at line 479 of file api_dolresources.class.php.

References $date_start, $id, and _toTimestamp().

◆ getElementResources()

Dolresources::getElementResources ( $element_type,
$element_id )

Get the resources linked to an element.

Return the links stored in llx_element_resources for an element, so the endpoint works for any element type that can carry resources (agenda events, interventions, ...) and not only for one module.

Parameters
string$element_typeType of the element, as stored in element_type (for example "action" for an agenda event)
int$element_idID of the element
Returns
array Array of links @phan-return array<int,array{id:int,resource_id:int,resource_type:string,busy:int,mandatory:int,resource:array<string,mixed>|null}> @phpstan-return array<int,array{id:int,resource_id:int,resource_type:string,busy:int,mandatory:int,resource:array<string,mixed>|null}>

@url GET {element_type}/{element_id}/resources

Exceptions
RestException403 Access denied
RestException404 Element not found

Definition at line 321 of file api_dolresources.class.php.

References _fetchElement(), and _formatLink().

◆ index()

Dolresources::index ( $sortfield = "t.ref",
$sortorder = 'ASC',
$limit = 100,
$page = 0,
$sqlfilters = '',
$properties = '' )

List resources.

Get a list of resources

Parameters
string$sortfieldSort field
string$sortorderSort order
int$limitLimit for list
int$pagePage number
string$sqlfiltersOther criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'A%')"
string$propertiesRestrict the data returned to these properties. Ignored if empty. Comma separated list of properties names
Returns
array Array of resource objects @phan-return Dolresource[] @phpstan-return Dolresource[]
Exceptions
RestException400 Error on the sqlfilters
RestException403 Access denied
RestException503 Error when retrieving the list

Definition at line 115 of file api_dolresources.class.php.

References _cleanObjectDatas(), DolibarrApi\_filterObjectProperties(), and forgeSQLFromUniversalSearchCriteria().

◆ post()

Dolresources::post ( $request_data = null)

Create resource object.

Parameters
array$request_dataRequest data @phan-param ?array<string,string> $request_data @phpstan-param ?array<string,string> $request_data
Returns
int ID of resource
Exceptions
RestException400 Mandatory field missing
RestException403 Access denied
RestException500 Error when creating the resource

Definition at line 178 of file api_dolresources.class.php.

References DolibarrApi\_checkValForAPI(), _validate(), and sanitizeVal().

◆ postElementResources()

Dolresources::postElementResources ( $element_type,
$element_id,
$request_data = null )

Link a resource to an element.

Parameters
string$element_typeType of the element, as stored in element_type (for example "action" for an agenda event)
int$element_idID of the element
array$request_dataRequest data. Mandatory: resource_id. Optional: busy, mandatory @phan-param ?array<string,string> $request_data @phpstan-param ?array<string,string> $request_data
Returns
array The created link @phan-return array{id:int,resource_id:int,resource_type:string,busy:int,mandatory:int,resource:array<string,mixed>|null} @phpstan-return array{id:int,resource_id:int,resource_type:string,busy:int,mandatory:int,resource:array<string,mixed>|null}

@url POST {element_type}/{element_id}/resources

Exceptions
RestException400 Mandatory field missing
RestException403 Access denied
RestException404 Element or resource not found
RestException409 Resource already linked to this element, or already busy on the period
RestException500 Error when creating the link

Definition at line 357 of file api_dolresources.class.php.

References _describeConflicts(), _fetchElement(), and _formatLink().

◆ put()

Dolresources::put ( $id,
$request_data = null )

Update resource.

Parameters
int$idID of resource to update
array$request_dataDatas @phan-param ?array<string,string> $request_data @phpstan-param ?array<string,string> $request_data
Returns
array|mixed Data without useless information
Exceptions
RestException403 Access denied
RestException404 Resource not found
RestException500 Error when updating the resource

Definition at line 220 of file api_dolresources.class.php.

References $id, DolibarrApi\_checkAccessToResource(), DolibarrApi\_checkValForAPI(), dol_clone(), and sanitizeVal().


The documentation for this class was generated from the following file: