diff --git a/htdocs/adherents/class/api_members.class.php b/htdocs/adherents/class/api_members.class.php index 99a4f401171..2be24fb5d03 100644 --- a/htdocs/adherents/class/api_members.class.php +++ b/htdocs/adherents/class/api_members.class.php @@ -91,7 +91,7 @@ class Members extends DolibarrApi * * @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(); diff --git a/htdocs/adherents/class/api_memberstypes.class.php b/htdocs/adherents/class/api_memberstypes.class.php index c6adaf50142..8e545e6d784 100644 --- a/htdocs/adherents/class/api_memberstypes.class.php +++ b/htdocs/adherents/class/api_memberstypes.class.php @@ -86,7 +86,7 @@ class MembersTypes extends DolibarrApi * * @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(); diff --git a/htdocs/adherents/class/api_subscriptions.class.php b/htdocs/adherents/class/api_subscriptions.class.php index 4e1d58971cb..2cdf7a59ff3 100644 --- a/htdocs/adherents/class/api_subscriptions.class.php +++ b/htdocs/adherents/class/api_subscriptions.class.php @@ -85,7 +85,7 @@ class Subscriptions extends DolibarrApi * * @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(); @@ -98,7 +98,7 @@ class Subscriptions extends DolibarrApi $sql.= " FROM ".MAIN_DB_PREFIX."subscription as t"; $sql.= ' WHERE 1 = 1'; // Add sql filters - if ($sqlfilters) + if ($sqlfilters) { if (! DolibarrApi::_checkFilters($sqlfilters)) { @@ -107,7 +107,7 @@ class Subscriptions extends DolibarrApi $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; } - + $sql.= $db->order($sortfield, $sortorder); if ($limit) { if ($page < 0) diff --git a/htdocs/categories/class/api_categories.class.php b/htdocs/categories/class/api_categories.class.php index 1c8d9fcfe50..edbc4fa68ce 100644 --- a/htdocs/categories/class/api_categories.class.php +++ b/htdocs/categories/class/api_categories.class.php @@ -103,7 +103,7 @@ class Categories extends DolibarrApi * * @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(); diff --git a/htdocs/comm/propal/class/api_proposals.class.php b/htdocs/comm/propal/class/api_proposals.class.php index 40af3d72292..364f63bd4e4 100644 --- a/htdocs/comm/propal/class/api_proposals.class.php +++ b/htdocs/comm/propal/class/api_proposals.class.php @@ -94,7 +94,7 @@ class Proposals extends DolibarrApi * @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(); diff --git a/htdocs/commande/class/api_deprecated_commande.class.php b/htdocs/commande/class/api_deprecated_commande.class.php index 1b84876c3af..f494709e441 100644 --- a/htdocs/commande/class/api_deprecated_commande.class.php +++ b/htdocs/commande/class/api_deprecated_commande.class.php @@ -107,7 +107,7 @@ class CommandeApi extends DolibarrApi * @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(); diff --git a/htdocs/compta/bank/class/api_bankaccounts.class.php b/htdocs/compta/bank/class/api_bankaccounts.class.php index c6fd3f72def..fa540f43401 100644 --- a/htdocs/compta/bank/class/api_bankaccounts.class.php +++ b/htdocs/compta/bank/class/api_bankaccounts.class.php @@ -61,7 +61,7 @@ class BankAccounts extends DolibarrApi * * @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(); diff --git a/htdocs/compta/facture/class/api_deprecated_invoice.class.php b/htdocs/compta/facture/class/api_deprecated_invoice.class.php index 360c065a5f2..ac2086fc87e 100644 --- a/htdocs/compta/facture/class/api_deprecated_invoice.class.php +++ b/htdocs/compta/facture/class/api_deprecated_invoice.class.php @@ -23,7 +23,7 @@ * 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) */ @@ -31,7 +31,7 @@ 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' @@ -46,7 +46,7 @@ class InvoiceApi extends DolibarrApi * Constructor Warning: Deprecated * * @url GET invoice/ - * + * */ function __construct() { @@ -59,7 +59,7 @@ class InvoiceApi extends DolibarrApi * Get properties of a invoice object Warning: Deprecated * * Return an array with invoice informations - * + * * @param int $id ID of invoice * @return array|mixed data without useless information * @@ -67,16 +67,16 @@ class InvoiceApi extends DolibarrApi * @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); } @@ -86,9 +86,9 @@ class InvoiceApi extends DolibarrApi /** * List invoices Warning: Deprecated - * + * * Get a list of invoices - * + * * @param string $sortfield Sort field * @param string $sortorder Sort order * @param int $limit Limit for list @@ -101,15 +101,15 @@ class InvoiceApi extends DolibarrApi * @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; @@ -117,27 +117,27 @@ class InvoiceApi extends DolibarrApi $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)) { @@ -180,10 +180,10 @@ class InvoiceApi extends DolibarrApi } return $obj_ret; } - + /** * Create invoice object Warning: Deprecated - * + * * @param array $request_data Request datas * @return int ID of invoice * @@ -196,7 +196,7 @@ class InvoiceApi extends DolibarrApi } // Check mandatory fields $result = $this->_validate($request_data); - + foreach($request_data as $field => $value) { $this->invoice->$field = $value; } @@ -213,9 +213,9 @@ class InvoiceApi extends DolibarrApi * Update invoice Warning: Deprecated * * @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) @@ -223,12 +223,12 @@ class InvoiceApi extends DolibarrApi 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); } @@ -237,20 +237,20 @@ class InvoiceApi extends DolibarrApi if ($field == 'id') continue; $this->invoice->$field = $value; } - + if($this->invoice->update($id, DolibarrApiAccess::$user)) return $this->get ($id); - + return false; } - + /** * Delete invoice Warning: Deprecated * * @param int $id Invoice ID * @return type - * - * @url DELETE invoice/{id} + * + * @url DELETE invoice/{id} */ function delete($id) { @@ -261,31 +261,31 @@ class InvoiceApi extends DolibarrApi 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) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index 7ef28f87d27..344a5d280c7 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -95,7 +95,7 @@ class Invoices extends DolibarrApi * * @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(); diff --git a/htdocs/expensereport/class/api_expensereports.class.php b/htdocs/expensereport/class/api_expensereports.class.php index 3085c3659be..e89f4e35cdc 100644 --- a/htdocs/expensereport/class/api_expensereports.class.php +++ b/htdocs/expensereport/class/api_expensereports.class.php @@ -94,7 +94,7 @@ class ExpenseReports 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')" * @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(); diff --git a/htdocs/fourn/class/api_supplier_invoices.class.php b/htdocs/fourn/class/api_supplier_invoices.class.php index 4a2c5876b0e..1d7efb236a2 100644 --- a/htdocs/fourn/class/api_supplier_invoices.class.php +++ b/htdocs/fourn/class/api_supplier_invoices.class.php @@ -96,7 +96,7 @@ class SupplierInvoices extends DolibarrApi * * @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(); diff --git a/htdocs/fourn/class/api_supplier_orders.class.php b/htdocs/fourn/class/api_supplier_orders.class.php index 1dce6cd3ef4..22cd4eb191c 100644 --- a/htdocs/fourn/class/api_supplier_orders.class.php +++ b/htdocs/fourn/class/api_supplier_orders.class.php @@ -96,7 +96,7 @@ class SupplierOrders extends DolibarrApi * * @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(); diff --git a/htdocs/modulebuilder/template/class/api_myobject.class.php b/htdocs/modulebuilder/template/class/api_myobject.class.php index e4a02468557..29596df2d96 100644 --- a/htdocs/modulebuilder/template/class/api_myobject.class.php +++ b/htdocs/modulebuilder/template/class/api_myobject.class.php @@ -102,7 +102,7 @@ class MyObjectApi extends DolibarrApi * * @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(); diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php index 25071801fe3..7b297fcbdc4 100644 --- a/htdocs/product/class/api_products.class.php +++ b/htdocs/product/class/api_products.class.php @@ -96,7 +96,7 @@ class Products extends DolibarrApi * @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(); diff --git a/htdocs/product/stock/class/api_stockmovements.class.php b/htdocs/product/stock/class/api_stockmovements.class.php index e1d1ccd7888..cb861f78575 100644 --- a/htdocs/product/stock/class/api_stockmovements.class.php +++ b/htdocs/product/stock/class/api_stockmovements.class.php @@ -23,13 +23,13 @@ require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; /** * API class for stock movements * - * @access protected + * @access protected * @class DolibarrApiAccess {@requires user,external} */ class StockMovements 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( 'product_id', @@ -59,21 +59,21 @@ class StockMovements extends DolibarrApi * * @param int $id ID of movement * @return array|mixed data without useless information - * + * * @throws RestException */ /* function get($id) - { + { if(! DolibarrApiAccess::$user->rights->stock->lire) { throw new RestException(401); } - + $result = $this->stockmovement->fetch($id); if( ! $result ) { throw new RestException(404, 'warehouse not found'); } - + if( ! DolibarrApi::_checkAccessToResource('warehouse',$this->stockmovement->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } @@ -93,21 +93,21 @@ class StockMovements extends DolibarrApi * * @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(); - + if(! DolibarrApiAccess::$user->rights->stock->lire) { throw new RestException(401); } - + $sql = "SELECT t.rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."stock_mouvement as t"; //$sql.= ' WHERE t.entity IN ('.getEntity('stock').')'; $sql.= ' WHERE 1 = 1'; // Add sql filters - if ($sqlfilters) + if ($sqlfilters) { if (! DolibarrApi::_checkFilters($sqlfilters)) { @@ -116,7 +116,7 @@ class StockMovements extends DolibarrApi $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; } - + $sql.= $db->order($sortfield, $sortorder); if ($limit) { if ($page < 0) @@ -162,13 +162,13 @@ class StockMovements extends DolibarrApi * @param string $movementlabel Movement label {@example Inventory number 123} * @param string $price To update AWP (Average Weighted Price) when you make a stock increase (qty must be higher then 0). */ - - + + /** * Create stock movement object. * You can use the following message to test this RES API: * { "product_id": 1, "warehouse_id": 1, "qty": 1, "lot": "", "movementcode": "INV123", "movementlabel": "Inventory 123", "price": 0 } - * + * * @param array $request_data Request data * @return int ID of stock movement */ @@ -181,7 +181,7 @@ class StockMovements extends DolibarrApi // Check mandatory fields //$result = $this->_validate($request_data); - + foreach($request_data as $field => $value) { //$this->stockmovement->$field = $value; if ($field == 'product_id') $product_id = $value; @@ -192,7 +192,7 @@ class StockMovements extends DolibarrApi if ($field == 'movementlabel') $movementlabel = $value; if ($field == 'price') $price = $value; } - + // Type increase or decrease if ($qty >= 0) $type = 3; else $type = 2; @@ -200,16 +200,16 @@ class StockMovements extends DolibarrApi if($this->stockmovement->_create(DolibarrApiAccess::$user, $product_id, $warehouse_id, $qty, $type, $price, $movementlabel, $movementcode, '', '', '', $lot) <= 0) { throw new RestException(503, 'Error when create stock movement : '.$this->stockmovement->error); } - + return $this->stockmovement->id; } /** * Update stock movement - * + * * @param int $id Id of warehouse to update - * @param array $request_data Datas - * @return int + * @param array $request_data Datas + * @return int */ /* function put($id, $request_data = NULL) @@ -217,12 +217,12 @@ class StockMovements extends DolibarrApi if(! DolibarrApiAccess::$user->rights->stock->creer) { throw new RestException(401); } - + $result = $this->stockmovement->fetch($id); if( ! $result ) { throw new RestException(404, 'stock movement not found'); } - + if( ! DolibarrApi::_checkAccessToResource('stock',$this->stockmovement->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } @@ -231,13 +231,13 @@ class StockMovements extends DolibarrApi if ($field == 'id') continue; $this->stockmovement->$field = $value; } - + if($this->stockmovement->update($id, DolibarrApiAccess::$user)) return $this->get ($id); - + return false; }*/ - + /** * Delete stock movement * @@ -254,15 +254,15 @@ class StockMovements extends DolibarrApi if( ! $result ) { throw new RestException(404, 'stock movement not found'); } - + if( ! DolibarrApi::_checkAccessToResource('stock',$this->stockmovement->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - + if (! $this->stockmovement->delete(DolibarrApiAccess::$user)) { throw new RestException(401,'error when delete stock movement'); } - + return array( 'success' => array( 'code' => 200, @@ -270,9 +270,9 @@ class StockMovements extends DolibarrApi ) ); }*/ - - - + + + /** * Clean sensible object datas * @@ -280,9 +280,9 @@ class StockMovements extends DolibarrApi * @return array Array of cleaned object properties */ function _cleanObjectDatas($object) { - + $object = parent::_cleanObjectDatas($object); - + // Remove useless data unset($object->civility_id); unset($object->firstname); @@ -321,19 +321,19 @@ class StockMovements extends DolibarrApi unset($object->fk_project); unset($object->project); unset($object->canvas); - + //unset($object->eatby); Filled correctly in read mode //unset($object->sellby); Filled correctly in read mode - + return $object; } - + /** * Validate fields before create or update object - * + * * @param array|null $data Data to validate * @return array - * + * * @throws RestException */ function _validate($data) diff --git a/htdocs/product/stock/class/api_warehouses.class.php b/htdocs/product/stock/class/api_warehouses.class.php index 6eccf805b41..fd2dc4b2328 100644 --- a/htdocs/product/stock/class/api_warehouses.class.php +++ b/htdocs/product/stock/class/api_warehouses.class.php @@ -23,13 +23,13 @@ /** * API class for warehouses * - * @access protected + * @access protected * @class DolibarrApiAccess {@requires user,external} */ class Warehouses 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( 'label', @@ -57,20 +57,20 @@ class Warehouses extends DolibarrApi * * @param int $id ID of warehouse * @return array|mixed data without useless information - * + * * @throws RestException */ function get($id) - { + { if(! DolibarrApiAccess::$user->rights->stock->lire) { throw new RestException(401); } - + $result = $this->warehouse->fetch($id); if( ! $result ) { throw new RestException(404, 'warehouse not found'); } - + if( ! DolibarrApi::_checkAccessToResource('warehouse',$this->warehouse->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } @@ -80,7 +80,7 @@ class Warehouses extends DolibarrApi /** * List warehouses - * + * * Get a list of warehouses * * @param string $sortfield Sort field @@ -92,20 +92,20 @@ class Warehouses extends DolibarrApi * * @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(); - + if(! DolibarrApiAccess::$user->rights->stock->lire) { throw new RestException(401); } - + $sql = "SELECT t.rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."entrepot as t"; $sql.= ' WHERE t.entity IN ('.getEntity('stock').')'; // Add sql filters - if ($sqlfilters) + if ($sqlfilters) { if (! DolibarrApi::_checkFilters($sqlfilters)) { @@ -114,7 +114,7 @@ class Warehouses extends DolibarrApi $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; } - + $sql.= $db->order($sortfield, $sortorder); if ($limit) { if ($page < 0) @@ -154,7 +154,7 @@ class Warehouses extends DolibarrApi /** * Create warehouse object - * + * * @param array $request_data Request data * @return int ID of warehouse */ @@ -166,7 +166,7 @@ class Warehouses extends DolibarrApi // Check mandatory fields $result = $this->_validate($request_data); - + foreach($request_data as $field => $value) { $this->warehouse->$field = $value; } @@ -178,22 +178,22 @@ class Warehouses extends DolibarrApi /** * Update warehouse - * + * * @param int $id Id of warehouse to update - * @param array $request_data Datas - * @return int + * @param array $request_data Datas + * @return int */ function put($id, $request_data = NULL) { if(! DolibarrApiAccess::$user->rights->stock->creer) { throw new RestException(401); } - + $result = $this->warehouse->fetch($id); if( ! $result ) { throw new RestException(404, 'warehouse not found'); } - + if( ! DolibarrApi::_checkAccessToResource('stock',$this->warehouse->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } @@ -202,13 +202,13 @@ class Warehouses extends DolibarrApi if ($field == 'id') continue; $this->warehouse->$field = $value; } - + if($this->warehouse->update($id, DolibarrApiAccess::$user)) return $this->get ($id); - + return false; } - + /** * Delete warehouse * @@ -224,15 +224,15 @@ class Warehouses extends DolibarrApi if( ! $result ) { throw new RestException(404, 'warehouse not found'); } - + if( ! DolibarrApi::_checkAccessToResource('stock',$this->warehouse->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - + if (! $this->warehouse->delete(DolibarrApiAccess::$user)) { throw new RestException(401,'error when delete warehouse'); } - + return array( 'success' => array( 'code' => 200, @@ -240,8 +240,8 @@ class Warehouses extends DolibarrApi ) ); } - - + + /** * Clean sensible object datas * @@ -249,22 +249,22 @@ class Warehouses extends DolibarrApi * @return array Array of cleaned object properties */ function _cleanObjectDatas($object) { - + $object = parent::_cleanObjectDatas($object); - + // Remove the subscriptions because they are handled as a subresource. //unset($object->subscriptions); - + return $object; } - - + + /** * Validate fields before create or update object - * + * * @param array|null $data Data to validate * @return array - * + * * @throws RestException */ function _validate($data) diff --git a/htdocs/societe/class/api_contacts.class.php b/htdocs/societe/class/api_contacts.class.php index baac1d5ed1f..652f66380d3 100644 --- a/htdocs/societe/class/api_contacts.class.php +++ b/htdocs/societe/class/api_contacts.class.php @@ -102,7 +102,7 @@ class Contacts extends DolibarrApi * * @throws RestException */ - 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(); diff --git a/htdocs/user/class/api_users.class.php b/htdocs/user/class/api_users.class.php index f119fa36ffa..ceade000872 100644 --- a/htdocs/user/class/api_users.class.php +++ b/htdocs/user/class/api_users.class.php @@ -22,14 +22,14 @@ use Luracast\Restler\RestException; /** * API class for users * - * @access protected + * @access protected * @class DolibarrApiAccess {@requires user,external} */ class Users 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( 'login' @@ -49,7 +49,7 @@ class Users extends DolibarrApi $this->useraccount = new User($this->db); } - + /** * List Users * @@ -63,24 +63,24 @@ class Users 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')" * @return array Array of User 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(); - + if(! DolibarrApiAccess::$user->rights->user->user->lire) { throw new RestException(401, "You are not allowed to read list of users"); } - + // case of external user, $societe param is ignored and replaced by user's socid //$socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $societe; - + $sql = "SELECT t.rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."user as t"; $sql.= ' WHERE t.entity IN ('.getEntity('user').')'; if ($user_ids) $sql.=" AND t.rowid IN (".$user_ids.")"; // Add sql filters - if ($sqlfilters) + if ($sqlfilters) { if (! DolibarrApi::_checkFilters($sqlfilters)) { @@ -89,7 +89,7 @@ class Users extends DolibarrApi $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; } - + $sql.= $db->order($sortfield, $sortorder); if ($limit) { if ($page < 0) @@ -97,12 +97,12 @@ class Users extends DolibarrApi $page = 0; } $offset = $limit * $page; - + $sql.= $db->plimit($limit + 1, $offset); } - + $result = $db->query($sql); - + if ($result) { $num = $db->num_rows($result); @@ -125,7 +125,7 @@ class Users extends DolibarrApi } return $obj_ret; } - + /** * Get properties of an user object * @@ -133,7 +133,7 @@ class Users extends DolibarrApi * * @param int $id ID of user * @return array|mixed data without useless information - * + * * @throws RestException */ function get($id) { @@ -154,8 +154,8 @@ class Users extends DolibarrApi return $this->_cleanObjectDatas($this->useraccount); } - - + + /** * Create user account * @@ -185,14 +185,14 @@ class Users extends DolibarrApi } return $this->useraccount->id; } - - + + /** * Update account * * @param int $id Id of account to update - * @param array $request_data Datas - * @return int + * @param array $request_data Datas + * @return int */ function put($id, $request_data = NULL) { //if (!DolibarrApiAccess::$user->rights->user->user->creer) { @@ -228,7 +228,7 @@ class Users extends DolibarrApi * @param int $id User ID * @param int $group Group ID * @return int 1 if success - * + * * @url GET {id}/setGroup/{group} */ function setGroup($id, $group) { @@ -240,18 +240,18 @@ class Users extends DolibarrApi { throw new RestException(404, 'User not found'); } - + if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) { throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login); } - + $result = $this->useraccount->SetInGroup($group,1); if (! ($result > 0)) { throw new RestException(500, $this->useraccount->error); } - + return 1; } @@ -286,25 +286,25 @@ class Users extends DolibarrApi * @return array Array of cleaned object properties */ function _cleanObjectDatas($object) { - + $object = parent::_cleanObjectDatas($object); - + unset($object->default_values); unset($object->lastsearch_values); unset($object->lastsearch_values_tmp); - + unset($object->total_ht); unset($object->total_tva); unset($object->total_localtax1); unset($object->total_localtax2); unset($object->total_ttc); - + return $object; - } - + } + /** * Validate fields before create or update object - * + * * @param array|null $data Data to validate * @return array * @throws RestException