Uniformize code.

This commit is contained in:
Laurent Destailleur 2016-09-26 02:13:58 +02:00
parent 48b188d200
commit d39d7d92c9
20 changed files with 109 additions and 78 deletions

View File

@ -79,18 +79,18 @@ class Members extends DolibarrApi
*
* Get a list of members
*
* @param string $typeid ID of the type of member
* @param string $login To filter the members by login
* @param string $name To filter the members by name (firstname, lastname or company name matching the filter)
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Limit for list
* @param int $page Page number
* @param string $typeid ID of the type of member
* @param string $login To filter the members by login
* @param string $name To filter the members by name (firstname, lastname or company name matching the filter)
* @return array Array of member objects
*
* @throws RestException
*/
function index($typeid = '', $login = '', $name = '', $sortfield = "a.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) {
function index($sortfield = "a.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $typeid = '', $login = '', $name = '') {
global $db, $conf;
$obj_ret = array();
@ -136,7 +136,7 @@ class Members extends DolibarrApi
{
$i=0;
$num = $db->num_rows($result);
while ($i < $num)
while ($i < min($limit, $num))
{
$obj = $db->fetch_object($result);
$member = new Adherent($this->db);

View File

@ -119,7 +119,7 @@ class Subscriptions extends DolibarrApi
{
$i=0;
$num = $db->num_rows($result);
while ($i < $num)
while ($i < min($limit, $num))
{
$obj = $db->fetch_object($result);
$subscription = new Subscription($this->db);

View File

@ -27,7 +27,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/ccountry.class.php';
* @access protected
* @class DolibarrApiAccess {@requires user,external}
*/
class Countries extends DolibarrApi
class DictionnaryCountries extends DolibarrApi
{
private $translations = null;
@ -48,22 +48,33 @@ class Countries extends DolibarrApi
* code supported by Dolibarr, for example 'en_US' or 'fr_FR'.
* The returned list is sorted by country ID.
*
* @param string $filter To filter the countries by name
* @param int $limit Number of items per page
* @param int $page Page number (starting from zero)
* @param string $lang Code of the language the names of the
* countries must be translated to
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Number of items per page
* @param int $page Page number (starting from zero)
* @param string $filter To filter the countries by name
* @param string $lang Code of the language the label of the countries must be translated to
* @return List of countries
*
* @throws RestException
*/
function index($filter = '', $limit = 0, $page = 0, $lang = '')
function index($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $filter = '', $lang = '')
{
$list = array();
// Note: The filter is not applied in the SQL request because it must
// be applied to the translated names, not to the names in database.
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."c_country ORDER BY rowid";
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."c_country";
$nbtotalofrecords = 0;
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{
$result = $this->db->query($sql);
$nbtotalofrecords = $this->db->num_rows($result);
}
$sql.= $this->db->order($sortfield, $sortorder);
if ($limit) {
if ($page < 0) {

View File

@ -27,7 +27,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/ccountry.class.php';
* @access protected
* @class DolibarrApiAccess {@requires user,external}
*/
class Towns
class DictionnaryTowns extends DolibarrApi
{
/**
* Constructor
@ -41,23 +41,44 @@ class Towns
/**
* Get the list of towns.
*
* @param string $zipcode To filter the towns by zipcode
* @param string $town To filter the towns by name
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Number of items per page
* @param int $page Page number (starting from zero)
* @param string $zipcode To filter on zipcode
* @param string $town To filter on city name
* @return List of towns
*
* @throws RestException
*/
function index($zipcode = '', $town = '')
function index($sortfield = "zip,town", $sortorder = 'ASC', $limit = 100, $page = 0, $zipcode = '', $town = '')
{
$list = array();
$sql = "SELECT rowid AS id, zip, town, fk_county, fk_pays AS fk_country";
$sql.= " FROM ".MAIN_DB_PREFIX."c_ziptown";
$sql.= " WHERE active = 1";
if ($zipcode) $sql.=" AND zip LIKE '" . $this->db->escape($zipcode) . "%'";
if ($zipcode) $sql.=" AND zip LIKE '%" . $this->db->escape($zipcode) . "%'";
if ($town) $sql.=" AND town LIKE '%" . $this->db->escape($town) . "%'";
$sql.= " ORDER BY zip, town";
$nbtotalofrecords = 0;
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{
$result = $this->db->query($sql);
$nbtotalofrecords = $this->db->num_rows($result);
}
$sql.= $this->db->order($sortfield, $sortorder);
if ($limit) {
if ($page < 0) {
$page = 0;
}
$offset = $limit * $page;
$sql .= $this->db->plimit($limit, $offset);
}
$result = $this->db->query($sql);
if ($result) {

View File

@ -93,16 +93,16 @@ class Categories extends DolibarrApi
*
* Get a list of categories
*
* @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact')
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Limit for list
* @param int $page Page number
* @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact')
* @return array Array of category objects
*
* @throws RestException
*/
function index($type = '', $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) {
function index($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $type = '') {
global $db, $conf;
$obj_ret = array();
@ -142,7 +142,7 @@ class Categories extends DolibarrApi
{
$i=0;
$num = $db->num_rows($result);
while ($i < $num)
while ($i < min($num, ($limit <= 0 ? $num : $limit)))
{
$obj = $db->fetch_object($result);
$category_static = new Categorie($db);
@ -167,17 +167,17 @@ class Categories extends DolibarrApi
* Note: This method is not directly exposed in the API, it is used
* in the GET /xxx/{id}/categories requests.
*
* @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact')
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Limit for list
* @param int $page Page number
* @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact')
* @param int $item Id of the item to get categories for
* @return array Array of category objects
*
* @access private
*/
function getListForItem($type, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $item = 0) {
function getListForItem($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $type='customer', $item = 0) {
global $db, $conf;
$obj_ret = array();
@ -228,7 +228,7 @@ class Categories extends DolibarrApi
{
$i=0;
$num = $db->num_rows($result);
while ($i < $num)
while ($i < min($num, ($limit <= 0 ? $num : $limit)))
{
$obj = $db->fetch_object($result);
$category_static = new Categorie($db);

View File

@ -147,7 +147,7 @@ class CategoryApi extends DolibarrApi
{
$i=0;
$num = $db->num_rows($result);
while ($i < $num)
while ($i < min($num, ($limit <= 0 ? $num : $limit)))
{
$obj = $db->fetch_object($result);
$category_static = new Categorie($db);
@ -228,7 +228,7 @@ class CategoryApi extends DolibarrApi
{
$i=0;
$num = $db->num_rows($result);
while ($i < $num)
while ($i < min($num, ($limit <= 0 ? $num : $limit)))
{
$obj = $db->fetch_object($result);
$category_static = new Categorie($db);

View File

@ -97,7 +97,7 @@ class AgendaEvents extends DolibarrApi
*
* @return array Array of Agenda Events objects
*/
function index($sortfield = "t.id", $sortorder = 'ASC', $limit = 100, $page = 0, $user_ids = 0) {
function index($sortfield = "t.id", $sortorder = 'ASC', $limit = 0, $page = 0, $user_ids = 0) {
global $db, $conf;
$obj_ret = array();
@ -139,7 +139,7 @@ class AgendaEvents extends DolibarrApi
if ($result)
{
$num = $db->num_rows($result);
while ($i < $num)
while ($i < min($num, ($limit <= 0 ? $num : $limit)))
{
$obj = $db->fetch_object($result);
$actioncomm_static = new ActionComm($db);

View File

@ -143,7 +143,7 @@ class Proposals extends DolibarrApi
if ($result)
{
$num = $db->num_rows($result);
while ($i < $num)
while ($i < min($num, ($limit <= 0 ? $num : $limit)))
{
$obj = $db->fetch_object($result);
$propal_static = new Propal($db);

View File

@ -97,17 +97,17 @@ class CommandeApi extends DolibarrApi
*
* Get a list of orders
*
* @param int $mode Use this param to filter list
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Limit for list
* @param int $page Page number
* @param string $societe Societe filter field
* @param int $mode Use this param to filter list
* @param string $societe Thirdparty filter field
*
* @url GET /order/list
* @return array Array of order objects
*/
function getList($mode=0, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $societe = 0) {
function getList($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $mode=0, $societe = 0) {
global $db, $conf;
$obj_ret = array();
@ -162,7 +162,7 @@ class CommandeApi extends DolibarrApi
{
$i=0;
$num = $db->num_rows($result);
while ($i < $num)
while ($i < min($num, ($limit <= 0 ? $num : $limit)))
{
$obj = $db->fetch_object($result);
$commande_static = new Commande($db);

View File

@ -92,7 +92,7 @@ class Orders extends DolibarrApi
*
* @return array Array of order objects
*/
function index($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $thirdparty_ids = '') {
function index($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '') {
global $db, $conf;
$obj_ret = array();
@ -142,7 +142,7 @@ class Orders extends DolibarrApi
if ($result)
{
$num = $db->num_rows($result);
while ($i < $num)
while ($i < min($limit, $num))
{
$obj = $db->fetch_object($result);
$commande_static = new Commande($db);

View File

@ -89,12 +89,12 @@ class InvoiceApi extends DolibarrApi
*
* Get a list of invoices
*
* @param int $socid Filter list with thirdparty ID
* @param string $mode Filter by invoice status : draft | unpaid | paid | cancelled
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Limit for list
* @param int $page Page number
* @param int $socid Filter list with thirdparty ID
* @param string $mode Filter by invoice status : draft | unpaid | paid | cancelled
*
* @return array Array of invoice objects
*
@ -103,12 +103,12 @@ class InvoiceApi extends DolibarrApi
* @url GET thirdparty/{socid}/invoice/list
* @url GET thirdparty/{socid}/invoice/list/{mode}
*/
function getList($socid=0, $mode='', $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) {
function getList($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $socid=0, $mode='') {
global $db, $conf;
$obj_ret = array();
$socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : '';
$socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $socid;
// If the internal user must only see his customers, force searching by him
if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
@ -160,7 +160,7 @@ class InvoiceApi extends DolibarrApi
{
$i=0;
$num = $db->num_rows($result);
while ($i < $num)
while ($i < min($num, ($limit <= 0 ? $num : $limit)))
{
$obj = $db->fetch_object($result);
$invoice_static = new Facture($db);

View File

@ -83,23 +83,22 @@ class Invoices extends DolibarrApi
*
* Get a list of invoices
*
* FIXME this parameter is overwritten in the code and thus ignored
* @param int $socid Filter list with thirdparty ID
* @param string $status Filter by invoice status : draft | unpaid | paid | cancelled
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Limit for list
* @param int $page Page number
* @param int $socid Filter list with thirdparty ID
* @param string $status Filter by invoice status : draft | unpaid | paid | cancelled
* @return array Array of invoice objects
*
* @throws RestException
*/
function index($socid=0, $status='', $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) {
function index($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $socid=0, $status='') {
global $db, $conf;
$obj_ret = array();
$socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : '';
$socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : $socid;
// If the internal user must only see his customers, force searching by him
if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id;
@ -151,7 +150,7 @@ class Invoices extends DolibarrApi
if ($result)
{
$num = $db->num_rows($result);
while ($i < $num)
while ($i < min($num, ($limit <= 0 ? $num : $limit)))
{
$obj = $db->fetch_object($result);
$invoice_static = new Facture($db);

View File

@ -136,7 +136,7 @@ class ExpenseReports extends DolibarrApi
if ($result)
{
$num = $db->num_rows($result);
while ($i < $num)
while ($i < min($num, ($limit <= 0 ? $num : $limit)))
{
$obj = $db->fetch_object($result);
$expensereport_static = new ExpenseReport($db);

View File

@ -94,19 +94,19 @@ class ProductApi extends DolibarrApi
*
* Get a list of products
*
* @param int $mode Use this param to filter list (0 for all, 1 for only product, 2 for only service)
* @param mixed $to_sell Filter products to sell (1) or not to sell (0)
* @param mixed $to_buy Filter products to buy (1) or not to buy (0)
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Limit for list
* @param int $page Page number
* @param int $mode Use this param to filter list (0 for all, 1 for only product, 2 for only service)
* @param mixed $to_sell Filter products to sell (1) or not to sell (0)
* @param mixed $to_buy Filter products to buy (1) or not to buy (0)
*
* @return array Array of product objects
*
* @url GET /product/list
*/
function getList($mode=0, $to_sell='', $to_buy='', $sortfield = "p.ref", $sortorder = 'ASC', $limit = 0, $page = 0) {
function getList($sortfield = "p.ref", $sortorder = 'ASC', $limit = 0, $page = 0, $mode=0, $to_sell='', $to_buy='') {
global $db, $conf;
$obj_ret = array();
@ -149,7 +149,7 @@ class ProductApi extends DolibarrApi
{
$i=0;
$num = $db->num_rows($result);
while ($i < $num)
while ($i < min($num, ($limit <= 0 ? $num : $limit)))
{
$obj = $db->fetch_object($result);
$product_static = new Product($db);
@ -174,20 +174,20 @@ class ProductApi extends DolibarrApi
*
* Get a list of products
*
* @param int $mode Use this param to filter list (0 for all, 1 for only product, 2 for only service)
* @param int $category Use this param to filter list by category
* @param mixed $to_sell Filter products to sell (1) or not to sell (0)
* @param mixed $to_buy Filter products to buy (1) or not to buy (0)
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Limit for list
* @param int $page Page number
* @param int $mode Use this param to filter list (0 for all, 1 for only product, 2 for only service)
* @param int $category Use this param to filter list by category
* @param mixed $to_sell Filter products to sell (1) or not to sell (0)
* @param mixed $to_buy Filter products to buy (1) or not to buy (0)
*
* @return array Array of product objects
*
* @url GET /product/list/category/{category}
*/
function getByCategory($mode=0, $category=0, $to_sell='', $to_buy='', $sortfield = "p.ref", $sortorder = 'ASC', $limit = 0, $page = 0) {
function getByCategory($sortfield = "p.ref", $sortorder = 'ASC', $limit = 0, $page = 0, $mode=0, $category=0, $to_sell='', $to_buy='') {
global $db, $conf;
$obj_ret = array();
@ -235,7 +235,7 @@ class ProductApi extends DolibarrApi
{
$i=0;
$num = $db->num_rows($result);
while ($i < $num)
while ($i < min($num, ($limit <= 0 ? $num : $limit)))
{
$obj = $db->fetch_object($result);
$product_static = new Product($db);

View File

@ -87,18 +87,18 @@ class Products extends DolibarrApi
*
* Get a list of products
*
* @param int $mode Use this param to filter list (0 for all, 1 for only product, 2 for only service)
* @param int $category Use this param to filter list by category
* @param mixed $to_sell Filter products to sell (1) or not to sell (0)
* @param mixed $to_buy Filter products to buy (1) or not to buy (0)
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Limit for list
* @param int $page Page number
* @param int $mode Use this param to filter list (0 for all, 1 for only product, 2 for only service)
* @param int $category Use this param to filter list by category
* @param mixed $to_sell Filter products to sell (1) or not to sell (0)
* @param mixed $to_buy Filter products to buy (1) or not to buy (0)
*
* @return array Array of product objects
*/
function index($mode=0, $category=0, $to_sell='', $to_buy='', $sortfield = "p.ref", $sortorder = 'ASC', $limit = 0, $page = 0) {
function index($sortfield = "p.ref", $sortorder = 'ASC', $limit = 0, $page = 0, $mode=0, $category=0, $to_sell='', $to_buy='') {
global $db, $conf;
$obj_ret = array();
@ -151,7 +151,7 @@ class Products extends DolibarrApi
if ($result)
{
$num = $db->num_rows($result);
while ($i < $num)
while ($i < min($num, ($limit <= 0 ? $num : $limit)))
{
$obj = $db->fetch_object($result);
$product_static = new Product($db);

View File

@ -84,16 +84,16 @@ class Contacts extends DolibarrApi
*
* Get a list of contacts
*
* @param int $socid ID of thirdparty to filter list
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Limit for list
* @param int $page Page number
* @param int $socid ID of thirdparty to filter list
* @return array Array of contact objects
*
* @throws RestException
*/
function index($socid = 0, $sortfield = "c.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) {
function index($sortfield = "c.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $socid = 0) {
global $db, $conf;
$obj_ret = array();
@ -154,7 +154,7 @@ class Contacts extends DolibarrApi
if ($result)
{
$num = $db->num_rows($result);
while ($i < $num)
while ($i < min($num, ($limit <= 0 ? $num : $limit)))
{
$obj = $db->fetch_object($result);
$contact_static = new Contact($db);

View File

@ -167,7 +167,7 @@ class ContactApi extends DolibarrApi
{
$i = 0;
$num = $db->num_rows($result);
while ($i < $num)
while ($i < min($num, ($limit <= 0 ? $num : $limit)))
{
$obj = $db->fetch_object($result);
$contact_static = new Contact($db);

View File

@ -213,7 +213,7 @@ class ThirdpartyApi extends DolibarrApi
{
$i = 0;
$num = $db->num_rows($result);
while ($i < $num)
while ($i < min($num, ($limit <= 0 ? $num : $limit)))
{
$obj = $db->fetch_object($result);
$soc_static = new Societe($db);

View File

@ -87,17 +87,17 @@ class Thirdparties extends DolibarrApi
*
* Get a list of thirdparties
*
* @param int $mode Set to 1 to show only customers
* Set to 2 to show only prospects
* Set to 3 to show only those are not customer neither prospect
* @param string $email Search by email filter
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Limit for list
* @param int $page Page number
* @param int $mode Set to 1 to show only customers
* Set to 2 to show only prospects
* Set to 3 to show only those are not customer neither prospect
* @param string $email Search by email filter
* @return array Array of thirdparty objects
*/
function index($mode=0, $email=NULL, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) {
function index($sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $mode=0, $email=NULL) {
global $db, $conf;
$obj_ret = array();
@ -152,7 +152,7 @@ class Thirdparties extends DolibarrApi
if ($result)
{
$num = $db->num_rows($result);
while ($i < $num)
while ($i < min($num, ($limit <= 0 ? $num : $limit)))
{
$obj = $db->fetch_object($result);
$soc_static = new Societe($db);

View File

@ -103,7 +103,7 @@ class Users extends DolibarrApi
if ($result)
{
$num = $db->num_rows($result);
while ($i < $num)
while ($i < min($num, ($limit <= 0 ? $num : $limit)))
{
$obj = $db->fetch_object($result);
$user_static = new User($db);