Merge pull request #10345 from ptibogxiv/patch-83

NEW Api list of currencies
This commit is contained in:
Laurent Destailleur 2019-01-17 14:44:22 +01:00 committed by GitHub
commit 64c1344794
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -326,6 +326,7 @@ class Setup extends DolibarrApi
* @param int $page Page number (starting from zero) * @param int $page Page number (starting from zero)
* @param string $type To filter on type of event * @param string $type To filter on type of event
* @param string $module To filter on module events * @param string $module To filter on module events
* @param int $active Payment term is active or not {@min 0} {@max 1}
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)" * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return List of events types * @return List of events types
* *
@ -333,13 +334,13 @@ class Setup extends DolibarrApi
* *
* @throws RestException * @throws RestException
*/ */
function getListOfEventTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $type = '', $module = '', $sqlfilters = '') function getListOfEventTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $type = '', $module = '', $active = 1, $sqlfilters = '')
{ {
$list = array(); $list = array();
$sql = "SELECT id, code, type, libelle as label, module"; $sql = "SELECT id, code, type, libelle as label, module";
$sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm as t"; $sql.= " FROM ".MAIN_DB_PREFIX."c_actioncomm as t";
$sql.= " WHERE t.active = 1"; $sql.= " WHERE t.active = ".$active;
if ($type) $sql.=" AND t.type LIKE '%" . $this->db->escape($type) . "%'"; if ($type) $sql.=" AND t.type LIKE '%" . $this->db->escape($type) . "%'";
if ($module) $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'"; if ($module) $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'";
// Add sql filters // Add sql filters
@ -381,27 +382,28 @@ class Setup extends DolibarrApi
} }
/** /**
* Get the list of civility. * Get the list of civilities.
* *
* @param string $sortfield Sort field * @param string $sortfield Sort field
* @param string $sortorder Sort order * @param string $sortorder Sort order
* @param int $limit Number of items per page * @param int $limit Number of items per page
* @param int $page Page number (starting from zero) * @param int $page Page number (starting from zero)
* @param string $module To filter on module events * @param string $module To filter on module events
* @param int $active Payment term is active or not {@min 0} {@max 1}
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)" * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return List of events types * @return List of events types
* *
* @url GET dictionary/civility * @url GET dictionary/civilities
* *
* @throws RestException * @throws RestException
*/ */
function getListOfCivility($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $module = '', $sqlfilters = '') function getListOfCivilities($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $module = '', $active = 1, $sqlfilters = '')
{ {
$list = array(); $list = array();
$sql = "SELECT rowid, code, label, module"; $sql = "SELECT rowid, code, label, module";
$sql.= " FROM ".MAIN_DB_PREFIX."c_civility as t"; $sql.= " FROM ".MAIN_DB_PREFIX."c_civility as t";
$sql.= " WHERE t.active = 1"; $sql.= " WHERE t.active = ".$active;
if ($module) $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'"; if ($module) $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'";
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters)
@ -440,6 +442,66 @@ class Setup extends DolibarrApi
return $list; return $list;
} }
/**
* Get the list of currencies.
*
* @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 int $active Payment term is active or not {@min 0} {@max 1}
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return List of events types
*
* @url GET dictionary/currencies
*
* @throws RestException
*/
function getListOfCurrencies($sortfield = "code_iso", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
{
$list = array();
//TODO link with multicurrency module
$sql = "SELECT t.code_iso, t.label, t.unicode";
$sql.= " FROM ".MAIN_DB_PREFIX."c_currencies as t";
$sql.= " WHERE t.active = ".$active;
// Add sql filters
if ($sqlfilters)
{
if (! DolibarrApi::_checkFilters($sqlfilters))
{
throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
}
$regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
$sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
}
$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) {
$num = $this->db->num_rows($result);
$min = min($num, ($limit <= 0 ? $num : $limit));
for ($i = 0; $i < $min; $i++) {
$list[] = $this->db->fetch_object($result);
}
} else {
throw new RestException(503, 'Error when retrieving list of currency : '.$this->db->lasterror());
}
return $list;
}
/** /**
* Get the list of extra fields. * Get the list of extra fields.
@ -525,6 +587,7 @@ class Setup extends DolibarrApi
* @param int $page Page number (starting from zero) * @param int $page Page number (starting from zero)
* @param string $zipcode To filter on zipcode * @param string $zipcode To filter on zipcode
* @param string $town To filter on city name * @param string $town To filter on city name
* @param int $active Payment term is active or not {@min 0} {@max 1}
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)" * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return List of towns * @return List of towns
* *
@ -532,13 +595,13 @@ class Setup extends DolibarrApi
* *
* @throws RestException * @throws RestException
*/ */
function getListOfTowns($sortfield = "zip,town", $sortorder = 'ASC', $limit = 100, $page = 0, $zipcode = '', $town = '', $sqlfilters = '') function getListOfTowns($sortfield = "zip,town", $sortorder = 'ASC', $limit = 100, $page = 0, $zipcode = '', $town = '', $active = 1, $sqlfilters = '')
{ {
$list = array(); $list = array();
$sql = "SELECT rowid AS id, zip, town, fk_county, fk_pays AS fk_country"; $sql = "SELECT rowid AS id, zip, town, fk_county, fk_pays AS fk_country";
$sql.= " FROM ".MAIN_DB_PREFIX."c_ziptown as t"; $sql.= " FROM ".MAIN_DB_PREFIX."c_ziptown as t";
$sql.= " WHERE t.active = 1"; $sql.= " AND t.active = ".$active;
if ($zipcode) $sql.=" AND t.zip LIKE '%" . $this->db->escape($zipcode) . "%'"; if ($zipcode) $sql.=" AND t.zip LIKE '%" . $this->db->escape($zipcode) . "%'";
if ($town) $sql.=" AND t.town LIKE '%" . $this->db->escape($town) . "%'"; if ($town) $sql.=" AND t.town LIKE '%" . $this->db->escape($town) . "%'";
// Add sql filters // Add sql filters
@ -649,6 +712,7 @@ class Setup extends DolibarrApi
* @param string $sortorder Sort order * @param string $sortorder Sort order
* @param int $limit Number of items per page * @param int $limit Number of items per page
* @param int $page Page number (starting from zero) * @param int $page Page number (starting from zero)
* @param int $active Payment term is active or not {@min 0} {@max 1}
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)" * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return List of events types * @return List of events types
* *
@ -656,13 +720,13 @@ class Setup extends DolibarrApi
* *
* @throws RestException * @throws RestException
*/ */
function getTicketsCategories($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '') function getTicketsCategories($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
{ {
$list = array(); $list = array();
$sql = "SELECT rowid, code, pos, label, use_default, description"; $sql = "SELECT rowid, code, pos, label, use_default, description";
$sql.= " FROM ".MAIN_DB_PREFIX."c_ticket_category as t"; $sql.= " FROM ".MAIN_DB_PREFIX."c_ticket_category as t";
$sql.= " WHERE t.active = 1"; $sql.= " WHERE t.active = ".$active;
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters)
{ {
@ -708,6 +772,7 @@ class Setup extends DolibarrApi
* @param string $sortorder Sort order * @param string $sortorder Sort order
* @param int $limit Number of items per page * @param int $limit Number of items per page
* @param int $page Page number (starting from zero) * @param int $page Page number (starting from zero)
* @param int $active Payment term is active or not {@min 0} {@max 1}
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)" * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return List of events types * @return List of events types
* *
@ -715,13 +780,13 @@ class Setup extends DolibarrApi
* *
* @throws RestException * @throws RestException
*/ */
function getTicketsSeverities($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '') function getTicketsSeverities($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
{ {
$list = array(); $list = array();
$sql = "SELECT rowid, code, pos, label, use_default, color, description"; $sql = "SELECT rowid, code, pos, label, use_default, color, description";
$sql.= " FROM ".MAIN_DB_PREFIX."c_ticket_severity as t"; $sql.= " FROM ".MAIN_DB_PREFIX."c_ticket_severity as t";
$sql.= " WHERE t.active = 1"; $sql.= " WHERE t.active = ".$active;
// Add sql filters // Add sql filters
if ($sqlfilters) if ($sqlfilters)
{ {
@ -767,6 +832,7 @@ class Setup extends DolibarrApi
* @param string $sortorder Sort order * @param string $sortorder Sort order
* @param int $limit Number of items per page * @param int $limit Number of items per page
* @param int $page Page number (starting from zero) * @param int $page Page number (starting from zero)
* @param int $active Payment term is active or not {@min 0} {@max 1}
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)" * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)"
* @return List of events types * @return List of events types
* *
@ -774,13 +840,13 @@ class Setup extends DolibarrApi
* *
* @throws RestException * @throws RestException
*/ */
function getTicketsTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '') function getTicketsTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '')
{ {
$list = array(); $list = array();
$sql = "SELECT rowid, code, pos, label, use_default, description"; $sql = "SELECT rowid, code, pos, label, use_default, description";
$sql.= " FROM ".MAIN_DB_PREFIX."c_ticket_type as t"; $sql.= " FROM ".MAIN_DB_PREFIX."c_ticket_type as t";
$sql.= " WHERE t.active = 1"; $sql.= " WHERE t.active = ".$active;
if ($type) $sql.=" AND t.type LIKE '%" . $this->db->escape($type) . "%'"; if ($type) $sql.=" AND t.type LIKE '%" . $this->db->escape($type) . "%'";
if ($module) $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'"; if ($module) $sql.=" AND t.module LIKE '%" . $this->db->escape($module) . "%'";
// Add sql filters // Add sql filters