Can get order by ref, ref_ext, ref_int

This commit is contained in:
c3do
2019-10-19 23:42:55 +02:00
parent ae3ce37a57
commit 4292d72ea3

View File

@@ -52,7 +52,7 @@ class Orders extends DolibarrApi
}
/**
* Get properties of an order object
* Get properties of an order object by id
*
* Return an array with order informations
*
@@ -64,26 +64,97 @@ class Orders extends DolibarrApi
*/
public function get($id, $contact_list = 1)
{
if(! DolibarrApiAccess::$user->rights->commande->lire) {
throw new RestException(401);
}
return $this->_fetch($id, '', '', '', $contact_list);
}
$result = $this->commande->fetch($id);
/**
* Get properties of an order object by ref
*
* Return an array with order 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 byRef/{ref}
*
* @throws RestException
*/
public function getByRef($ref, $contact_list = 1)
{
return $this->_fetch('', $ref, '', '', $contact_list);
}
/**
* Get properties of an order object by ref_ext
*
* Return an array with order 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 byRefExt/{ref_ext}
*
* @throws RestException
*/
public function getByRefExt($ref_ext, $contact_list = 1)
{
return $this->_fetch('', '', $ref_ext, '', $contact_list);
}
/**
* Get properties of an order object by ref_int
*
* Return an array with order informations
*
* @param string $ref_int Internal 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 byRefInt/{ref_int}
*
* @throws RestException
*/
public function getByRefInt($ref_int, $contact_list = 1)
{
return $this->_fetch('', '', '', $ref_int, $contact_list);
}
/**
* Get properties of an order object
*
* Return an array with order 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->commande->lire) {
throw new RestException(401);
}
$result = $this->commande->fetch($id, $ref, $ref_ext, $ref_int);
if( ! $result ) {
throw new RestException(404, 'Order not found');
}
if( ! DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
// Add external contacts ids
$this->commande->contacts_ids = $this->commande->liste_contact(-1, 'external', $contact_list);
$this->commande->fetchObjectLinked();
return $this->_cleanObjectDatas($this->commande);
}
if( ! DolibarrApi::_checkAccessToResource('commande', $this->commande->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
// Add external contacts ids
$this->commande->contacts_ids = $this->commande->liste_contact(-1, 'external', $contact_list);
$this->commande->fetchObjectLinked();
return $this->_cleanObjectDatas($this->commande);
}
/**
* List orders