NEW get proposal by ref with API

This commit is contained in:
ptibogxiv 2020-03-03 13:39:22 +01:00 committed by GitHub
parent 760afd6838
commit fa5aeebcd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -64,11 +64,66 @@ class Proposals extends DolibarrApi
*/
public function get($id, $contact_list = 1)
{
return $this->_fetch($id, '', '', '', $contact_list);
}
/**
* Get properties of an proposal object by ref
*
* Return an array with proposal informations
*
* @param string $ref Ref of object
* @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id
* @return array|mixed data without useless information
*
* @url GET ref/{ref}
*
* @throws RestException
*/
public function getByRef($ref, $contact_list = 1)
{
return $this->_fetch('', $ref, '', '', $contact_list);
}
/**
* Get properties of an proposal object by ref_ext
*
* Return an array with proposal informations
*
* @param string $ref_ext External reference of object
* @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id
* @return array|mixed data without useless information
*
* @url GET ref_ext/{ref_ext}
*
* @throws RestException
*/
public function getByRefExt($ref_ext, $contact_list = 1)
{
return $this->_fetch('', '', $ref_ext, '', $contact_list);
}
/**
* Get properties of an proposal object
*
* Return an array with proposal informations
*
* @param int $id ID of order
* @param string $ref Ref of object
* @param string $ref_ext External reference of object
* @param string $ref_int Internal reference of other objec
* @param int $contact_list 0: Returned array of contacts/addresses contains all properties, 1: Return array contains just id
* @return array|mixed data without useless information
*
* @throws RestException
*/
private function _fetch($id, $ref = '', $ref_ext = '', $ref_int = '', $contact_list = 1)
{
if(! DolibarrApiAccess::$user->rights->propal->lire) {
throw new RestException(401);
}
$result = $this->propal->fetch($id);
$result = $this->propal->fetch($id, $ref, $ref_ext, $ref_int);
if( ! $result ) {
throw new RestException(404, 'Commercial Proposal not found');
}