Skip to content

Commit

Permalink
Set default limit to 100 on all rest api that list
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Oct 22, 2017
1 parent 98674f6 commit c6e5115
Show file tree
Hide file tree
Showing 18 changed files with 161 additions and 161 deletions.
2 changes: 1 addition & 1 deletion htdocs/adherents/class/api_members.class.php
Expand Up @@ -91,7 +91,7 @@ function get($id)
*
* @throws RestException
*/
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $typeid = '', $sqlfilters = '') {
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $typeid = '', $sqlfilters = '') {
global $db, $conf;

$obj_ret = array();
Expand Down
2 changes: 1 addition & 1 deletion htdocs/adherents/class/api_memberstypes.class.php
Expand Up @@ -86,7 +86,7 @@ function get($id)
*
* @throws RestException
*/
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $sqlfilters = '') {
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '') {
global $db, $conf;

$obj_ret = array();
Expand Down
6 changes: 3 additions & 3 deletions htdocs/adherents/class/api_subscriptions.class.php
Expand Up @@ -85,7 +85,7 @@ function get($id)
*
* @throws RestException
*/
function index($sortfield = "dateadh", $sortorder = 'ASC', $limit = 0, $page = 0, $sqlfilters = '') {
function index($sortfield = "dateadh", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '') {
global $db, $conf;

$obj_ret = array();
Expand All @@ -98,7 +98,7 @@ function index($sortfield = "dateadh", $sortorder = 'ASC', $limit = 0, $page = 0
$sql.= " FROM ".MAIN_DB_PREFIX."subscription as t";
$sql.= ' WHERE 1 = 1';
// Add sql filters
if ($sqlfilters)
if ($sqlfilters)
{
if (! DolibarrApi::_checkFilters($sqlfilters))
{
Expand All @@ -107,7 +107,7 @@ function index($sortfield = "dateadh", $sortorder = 'ASC', $limit = 0, $page = 0
$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
}

$sql.= $db->order($sortfield, $sortorder);
if ($limit) {
if ($page < 0)
Expand Down
2 changes: 1 addition & 1 deletion htdocs/categories/class/api_categories.class.php
Expand Up @@ -103,7 +103,7 @@ function get($id)
*
* @throws RestException
*/
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $type = '', $sqlfilters = '') {
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $type = '', $sqlfilters = '') {
global $db, $conf;

$obj_ret = array();
Expand Down
2 changes: 1 addition & 1 deletion htdocs/comm/propal/class/api_proposals.class.php
Expand Up @@ -94,7 +94,7 @@ function get($id)
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.datec:<:'20160101')"
* @return array Array of order objects
*/
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $thirdparty_ids = '', $sqlfilters = '') {
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '') {
global $db, $conf;

$obj_ret = array();
Expand Down
2 changes: 1 addition & 1 deletion htdocs/commande/class/api_deprecated_commande.class.php
Expand Up @@ -107,7 +107,7 @@ function get($id='',$ref='', $ref_ext='', $ref_int='')
* @url GET /order/list
* @return array Array of order objects
*/
function getList($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $mode=0, $societe = 0) {
function getList($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $mode=0, $societe = 0) {
global $db, $conf;

$obj_ret = array();
Expand Down
2 changes: 1 addition & 1 deletion htdocs/compta/bank/class/api_bankaccounts.class.php
Expand Up @@ -61,7 +61,7 @@ function __construct()
*
* @throws RestException
*/
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $sqlfilters = '')
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '')
{
$list = array();

Expand Down
78 changes: 39 additions & 39 deletions htdocs/compta/facture/class/api_deprecated_invoice.class.php
Expand Up @@ -23,15 +23,15 @@
* API class for invoice object
*
* @smart-auto-routing false
* @access protected
* @access protected
* @class DolibarrApiAccess {@requires user,external}
* @deprecated Use Invoices instead (defined in api_invoices.class.php)
*/
class InvoiceApi extends DolibarrApi
{
/**
*
* @var array $FIELDS Mandatory fields, checked when create and update object
* @var array $FIELDS Mandatory fields, checked when create and update object
*/
static $FIELDS = array(
'socid'
Expand All @@ -46,7 +46,7 @@ class InvoiceApi extends DolibarrApi
* Constructor <b>Warning: Deprecated</b>
*
* @url GET invoice/
*
*
*/
function __construct()
{
Expand All @@ -59,24 +59,24 @@ function __construct()
* Get properties of a invoice object <b>Warning: Deprecated</b>
*
* Return an array with invoice informations
*
*
* @param int $id ID of invoice
* @return array|mixed data without useless information
*
* @url GET invoice/{id}
* @throws RestException
*/
function get($id)
{
{
if(! DolibarrApiAccess::$user->rights->facture->lire) {
throw new RestException(401);
}

$result = $this->invoice->fetch($id);
if( ! $result ) {
throw new RestException(404, 'Facture not found');
}

if( ! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
Expand All @@ -86,9 +86,9 @@ function get($id)

/**
* List invoices <b>Warning: Deprecated</b>
*
*
* Get a list of invoices
*
*
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Limit for list
Expand All @@ -101,43 +101,43 @@ function get($id)
* @url GET invoice/list
* @url GET invoice/list/{mode}
* @url GET thirdparty/{socid}/invoice/list
* @url GET thirdparty/{socid}/invoice/list/{mode}
* @url GET thirdparty/{socid}/invoice/list/{mode}
*/
function getList($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $socid=0, $mode='') {
function getList($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $socid=0, $mode='') {
global $db, $conf;

$obj_ret = array();

$socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $socid;

// If the internal user must only see his customers, force searching by him
$search_sale = 0;
if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;

$sql = "SELECT s.rowid";
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects)
$sql.= " FROM ".MAIN_DB_PREFIX."facture as s";

if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale

$sql.= ' WHERE s.entity IN ('.getEntity('facture').')';
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND s.fk_soc = sc.fk_soc";
if ($socid) $sql.= " AND s.fk_soc = ".$socid;
if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale


// Example of use $mode
if ($mode == 'draft') $sql.= " AND s.fk_statut IN (0)";
if ($mode == 'unpaid') $sql.= " AND s.fk_statut IN (1)";
if ($mode == 'paid') $sql.= " AND s.fk_statut IN (2)";
if ($mode == 'cancelled') $sql.= " AND s.fk_statut IN (3)";

// Insert sale filter
if ($search_sale > 0)
{
$sql .= " AND sc.fk_user = ".$search_sale;
}

$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{
Expand Down Expand Up @@ -180,10 +180,10 @@ function getList($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page =
}
return $obj_ret;
}

/**
* Create invoice object <b>Warning: Deprecated</b>
*
*
* @param array $request_data Request datas
* @return int ID of invoice
*
Expand All @@ -196,7 +196,7 @@ function post($request_data = NULL)
}
// Check mandatory fields
$result = $this->_validate($request_data);

foreach($request_data as $field => $value) {
$this->invoice->$field = $value;
}
Expand All @@ -213,22 +213,22 @@ function post($request_data = NULL)
* Update invoice <b>Warning: Deprecated</b>
*
* @param int $id Id of invoice to update
* @param array $request_data Datas
* @return int
*
* @param array $request_data Datas
* @return int
*
* @url PUT invoice/{id}
*/
function put($id, $request_data = NULL)
{
if(! DolibarrApiAccess::$user->rights->facture->creer) {
throw new RestException(401);
}

$result = $this->invoice->fetch($id);
if( ! $result ) {
throw new RestException(404, 'Facture not found');
}

if( ! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
Expand All @@ -237,20 +237,20 @@ function put($id, $request_data = NULL)
if ($field == 'id') continue;
$this->invoice->$field = $value;
}

if($this->invoice->update($id, DolibarrApiAccess::$user))
return $this->get ($id);

return false;
}

/**
* Delete invoice <b>Warning: Deprecated</b>
*
* @param int $id Invoice ID
* @return type
*
* @url DELETE invoice/{id}
*
* @url DELETE invoice/{id}
*/
function delete($id)
{
Expand All @@ -261,31 +261,31 @@ function delete($id)
if( ! $result ) {
throw new RestException(404, 'Facture not found');
}

if( ! DolibarrApi::_checkAccessToResource('facture',$this->facture->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}

if( !$this->invoice->delete(DolibarrApiAccess::$user))
{
throw new RestException(500);
}

return array(
'success' => array(
'code' => 200,
'message' => 'Facture deleted'
)
);

}

/**
* Validate fields before create or update object
*
*
* @param array $data Datas to validate
* @return array
*
*
* @throws RestException
*/
function _validate($data)
Expand Down
2 changes: 1 addition & 1 deletion htdocs/compta/facture/class/api_invoices.class.php
Expand Up @@ -95,7 +95,7 @@ function get($id)
*
* @throws RestException
*/
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $thirdparty_ids='', $status='', $sqlfilters = '') {
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids='', $status='', $sqlfilters = '') {
global $db, $conf;

$obj_ret = array();
Expand Down
2 changes: 1 addition & 1 deletion htdocs/expensereport/class/api_expensereports.class.php
Expand Up @@ -94,7 +94,7 @@ function get($id)
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
* @return array Array of Expense Report objects
*/
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $user_ids = 0, $sqlfilters = '') {
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $user_ids = 0, $sqlfilters = '') {
global $db, $conf;

$obj_ret = array();
Expand Down
2 changes: 1 addition & 1 deletion htdocs/fourn/class/api_supplier_invoices.class.php
Expand Up @@ -96,7 +96,7 @@ function get($id)
*
* @throws RestException
*/
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $thirdparty_ids='', $status='', $sqlfilters = '') {
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids='', $status='', $sqlfilters = '') {
global $db, $conf;

$obj_ret = array();
Expand Down
2 changes: 1 addition & 1 deletion htdocs/fourn/class/api_supplier_orders.class.php
Expand Up @@ -96,7 +96,7 @@ function get($id)
*
* @throws RestException
*/
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $thirdparty_ids='', $status='', $sqlfilters = '') {
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids='', $status='', $sqlfilters = '') {
global $db, $conf;

$obj_ret = array();
Expand Down
2 changes: 1 addition & 1 deletion htdocs/modulebuilder/template/class/api_myobject.class.php
Expand Up @@ -102,7 +102,7 @@ function get($id)
*
* @url GET /myobjects/
*/
function index($mode, $sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $sqlfilters = '') {
function index($mode, $sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '') {
global $db, $conf;

$obj_ret = array();
Expand Down
2 changes: 1 addition & 1 deletion htdocs/product/class/api_products.class.php
Expand Up @@ -96,7 +96,7 @@ function get($id)
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.tobuy:=:0) and (t.tosell:=:1)"
* @return array Array of product objects
*/
function index($sortfield = "t.ref", $sortorder = 'ASC', $limit = 0, $page = 0, $mode=0, $category=0, $sqlfilters = '') {
function index($sortfield = "t.ref", $sortorder = 'ASC', $limit = 100, $page = 0, $mode=0, $category=0, $sqlfilters = '') {
global $db, $conf;

$obj_ret = array();
Expand Down

0 comments on commit c6e5115

Please sign in to comment.