Fix missing default limit

This commit is contained in:
Laurent Destailleur 2017-10-17 12:02:58 +02:00
parent 81e7f45200
commit 235817c581

View File

@ -21,15 +21,15 @@
/** /**
* API class for thirdparties * API class for thirdparties
* *
* @access protected * @access protected
* @class DolibarrApiAccess {@requires user,external} * @class DolibarrApiAccess {@requires user,external}
* *
*/ */
class Thirdparties extends DolibarrApi class Thirdparties 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( static $FIELDS = array(
'name' 'name'
@ -48,7 +48,7 @@ class Thirdparties extends DolibarrApi
global $db, $conf; global $db, $conf;
$this->db = $db; $this->db = $db;
$this->company = new Societe($this->db); $this->company = new Societe($this->db);
if (! empty($conf->global->SOCIETE_MAIL_REQUIRED)) { if (! empty($conf->global->SOCIETE_MAIL_REQUIRED)) {
static::$FIELDS[] = 'email'; static::$FIELDS[] = 'email';
} }
@ -61,20 +61,20 @@ class Thirdparties extends DolibarrApi
* *
* @param int $id ID of thirdparty * @param int $id ID of thirdparty
* @return array|mixed data without useless information * @return array|mixed data without useless information
* *
* @throws RestException * @throws RestException
*/ */
function get($id) function get($id)
{ {
if(! DolibarrApiAccess::$user->rights->societe->lire) { if(! DolibarrApiAccess::$user->rights->societe->lire) {
throw new RestException(401); throw new RestException(401);
} }
$result = $this->company->fetch($id); $result = $this->company->fetch($id);
if( ! $result ) { if( ! $result ) {
throw new RestException(404, 'Thirdparty not found'); throw new RestException(404, 'Thirdparty not found');
} }
if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
} }
@ -84,27 +84,27 @@ class Thirdparties extends DolibarrApi
/** /**
* List thirdparties * List thirdparties
* *
* Get a list of thirdparties * Get a list of thirdparties
* *
* @param string $sortfield Sort field * @param string $sortfield Sort field
* @param string $sortorder Sort order * @param string $sortorder Sort order
* @param int $limit Limit for list * @param int $limit Limit for list
* @param int $page Page number * @param int $page Page number
* @param int $mode Set to 1 to show only customers * @param int $mode Set to 1 to show only customers
* Set to 2 to show only prospects * Set to 2 to show only prospects
* Set to 3 to show only those are not customer neither prospect * Set to 3 to show only those are not customer neither prospect
* @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 $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.nom:like:'TheCompany%') and (t.date_creation:<:'20160101')"
* @return array Array of thirdparty objects * @return array Array of thirdparty objects
*/ */
function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 0, $page = 0, $mode=0, $sqlfilters = '') { function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $mode=0, $sqlfilters = '') {
global $db, $conf; global $db, $conf;
$obj_ret = array(); $obj_ret = array();
// case of external user, we force socids // case of external user, we force socids
$socids = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : ''; $socids = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : '';
// If the internal user must only see his customers, force searching by him // If the internal user must only see his customers, force searching by him
$search_sale = 0; $search_sale = 0;
if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id; if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id;
@ -112,7 +112,7 @@ class Thirdparties extends DolibarrApi
$sql = "SELECT t.rowid"; $sql = "SELECT t.rowid";
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $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) if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $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."societe as t"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as t";
if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $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 if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $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.= ", ".MAIN_DB_PREFIX."c_stcomm as st"; $sql.= ", ".MAIN_DB_PREFIX."c_stcomm as st";
$sql.= " WHERE t.fk_stcomm = st.id"; $sql.= " WHERE t.fk_stcomm = st.id";
@ -130,7 +130,7 @@ class Thirdparties extends DolibarrApi
$sql .= " AND sc.fk_user = ".$search_sale; $sql .= " AND sc.fk_user = ".$search_sale;
} }
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters)
{ {
if (! DolibarrApi::_checkFilters($sqlfilters)) if (! DolibarrApi::_checkFilters($sqlfilters))
{ {
@ -139,7 +139,7 @@ class Thirdparties extends DolibarrApi
$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
} }
$sql.= $db->order($sortfield, $sortorder); $sql.= $db->order($sortfield, $sortorder);
if ($limit) { if ($limit) {
@ -175,7 +175,7 @@ class Thirdparties extends DolibarrApi
} }
return $obj_ret; return $obj_ret;
} }
/** /**
* Create thirdparty object * Create thirdparty object
* *
@ -189,13 +189,13 @@ class Thirdparties extends DolibarrApi
} }
// Check mandatory fields // Check mandatory fields
$result = $this->_validate($request_data); $result = $this->_validate($request_data);
foreach($request_data as $field => $value) { foreach($request_data as $field => $value) {
$this->company->$field = $value; $this->company->$field = $value;
} }
if ($this->company->create(DolibarrApiAccess::$user) < 0) if ($this->company->create(DolibarrApiAccess::$user) < 0)
throw new RestException(500, 'Error creating thirdparty', array_merge(array($this->company->error), $this->company->errors)); throw new RestException(500, 'Error creating thirdparty', array_merge(array($this->company->error), $this->company->errors));
return $this->company->id; return $this->company->id;
} }
@ -203,20 +203,20 @@ class Thirdparties extends DolibarrApi
* Update thirdparty * Update thirdparty
* *
* @param int $id Id of thirdparty to update * @param int $id Id of thirdparty to update
* @param array $request_data Datas * @param array $request_data Datas
* @return int * @return int
*/ */
function put($id, $request_data = NULL) function put($id, $request_data = NULL)
{ {
if(! DolibarrApiAccess::$user->rights->societe->creer) { if(! DolibarrApiAccess::$user->rights->societe->creer) {
throw new RestException(401); throw new RestException(401);
} }
$result = $this->company->fetch($id); $result = $this->company->fetch($id);
if( ! $result ) { if( ! $result ) {
throw new RestException(404, 'Thirdparty not found'); throw new RestException(404, 'Thirdparty not found');
} }
if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) {
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
} }
@ -225,13 +225,13 @@ class Thirdparties extends DolibarrApi
if ($field == 'id') continue; if ($field == 'id') continue;
$this->company->$field = $value; $this->company->$field = $value;
} }
if($this->company->update($id, DolibarrApiAccess::$user,1,'','','update')) if($this->company->update($id, DolibarrApiAccess::$user,1,'','','update'))
return $this->get ($id); return $this->get ($id);
return false; return false;
} }
/** /**
* Delete thirdparty * Delete thirdparty
* *
@ -252,7 +252,7 @@ class Thirdparties extends DolibarrApi
} }
return $this->company->delete($id); return $this->company->delete($id);
} }
/** /**
* Get categories for a thirdparty * Get categories for a thirdparty
* *
@ -318,24 +318,24 @@ class Thirdparties extends DolibarrApi
* @return array Array of cleaned object properties * @return array Array of cleaned object properties
*/ */
function _cleanObjectDatas($object) { function _cleanObjectDatas($object) {
$object = parent::_cleanObjectDatas($object); $object = parent::_cleanObjectDatas($object);
unset($object->total_ht); unset($object->total_ht);
unset($object->total_tva); unset($object->total_tva);
unset($object->total_localtax1); unset($object->total_localtax1);
unset($object->total_localtax2); unset($object->total_localtax2);
unset($object->total_ttc); unset($object->total_ttc);
return $object; return $object;
} }
/** /**
* Validate fields before create or update object * Validate fields before create or update object
* *
* @param array $data Datas to validate * @param array $data Datas to validate
* @return array * @return array
* *
* @throws RestException * @throws RestException
*/ */
function _validate($data) function _validate($data)