mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2026-02-13 11:15:21 +01:00
NEW pagination data for interventions API get (#34113)
* Added get interventions pagination data * Fixed PHPDoc --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
This commit is contained in:
@@ -131,13 +131,14 @@ class Interventions extends DolibarrApi
|
||||
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
|
||||
* @param string $properties Restrict the data returned to these properties. Ignored if empty. Comma separated list of property names
|
||||
* @param string $contact_type {@choice '',thirdparty,internal,external} Type of contacts
|
||||
* @param 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 array Array of order objects
|
||||
* @phan-return array<object>
|
||||
* @phpstan-return array<object>
|
||||
*
|
||||
* @throws RestException
|
||||
*/
|
||||
public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '', $properties = '', $contact_type = '')
|
||||
public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '', $properties = '', $contact_type = '', $pagination_data = false)
|
||||
{
|
||||
if (!DolibarrApiAccess::$user->hasRight('ficheinter', 'lire')) {
|
||||
throw new RestException(403);
|
||||
@@ -177,6 +178,9 @@ class Interventions extends DolibarrApi
|
||||
}
|
||||
}
|
||||
|
||||
//this query will return total interventions with the filters given
|
||||
$sqlTotals = str_replace('SELECT t.rowid', 'SELECT count(t.rowid) as total', $sql);
|
||||
|
||||
$sql .= $this->db->order($sortfield, $sortorder);
|
||||
if ($limit) {
|
||||
if ($page < 0) {
|
||||
@@ -209,6 +213,23 @@ class Interventions extends DolibarrApi
|
||||
throw new RestException(503, 'Error when retrieve intervention list : '.$this->db->lasterror());
|
||||
}
|
||||
|
||||
//if $pagination_data is true the response will contain element data with all values and element pagination with pagination data(total,page,limit)
|
||||
if ($pagination_data) {
|
||||
$totalsResult = $this->db->query($sqlTotals);
|
||||
$total = $this->db->fetch_object($totalsResult)->total;
|
||||
|
||||
$tmp = $obj_ret;
|
||||
$obj_ret = [];
|
||||
|
||||
$obj_ret['data'] = $tmp;
|
||||
$obj_ret['pagination'] = [
|
||||
'total' => (int) $total,
|
||||
'page' => $page, //count starts from 0
|
||||
'page_count' => ceil((int) $total / $limit),
|
||||
'limit' => $limit
|
||||
];
|
||||
}
|
||||
|
||||
return $obj_ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user