Fix API to get country
This commit is contained in:
parent
98cf15ba0f
commit
6066a92b9d
@ -440,7 +440,7 @@ class Setup extends DolibarrApi
|
|||||||
/**
|
/**
|
||||||
* Get country by Code.
|
* Get country by Code.
|
||||||
*
|
*
|
||||||
* @param string $code Code of country
|
* @param string $code Code of country (2 characters)
|
||||||
* @param string $lang Code of the language the name of the
|
* @param string $lang Code of the language the name of the
|
||||||
* country must be translated to
|
* country must be translated to
|
||||||
* @return array Array of cleaned object properties
|
* @return array Array of cleaned object properties
|
||||||
@ -457,7 +457,7 @@ class Setup extends DolibarrApi
|
|||||||
/**
|
/**
|
||||||
* Get country by Iso.
|
* Get country by Iso.
|
||||||
*
|
*
|
||||||
* @param string $iso ISO of country
|
* @param string $iso ISO of country (3 characters)
|
||||||
* @param string $lang Code of the language the name of the
|
* @param string $lang Code of the language the name of the
|
||||||
* country must be translated to
|
* country must be translated to
|
||||||
* @return array Array of cleaned object properties
|
* @return array Array of cleaned object properties
|
||||||
@ -498,8 +498,8 @@ class Setup extends DolibarrApi
|
|||||||
* Get country.
|
* Get country.
|
||||||
*
|
*
|
||||||
* @param int $id ID of country
|
* @param int $id ID of country
|
||||||
* @param string $code Code of country
|
* @param string $code Code of country (2 characters)
|
||||||
* @param string $iso ISO of country
|
* @param string $iso ISO of country (3 characters)
|
||||||
* @param string $lang Code of the language the name of the
|
* @param string $lang Code of the language the name of the
|
||||||
* country must be translated to
|
* country must be translated to
|
||||||
* @return array Array of cleaned object properties
|
* @return array Array of cleaned object properties
|
||||||
@ -511,10 +511,11 @@ class Setup extends DolibarrApi
|
|||||||
$country = new Ccountry($this->db);
|
$country = new Ccountry($this->db);
|
||||||
|
|
||||||
$result = $country->fetch($id, $code, $iso);
|
$result = $country->fetch($id, $code, $iso);
|
||||||
|
|
||||||
if ($result < 0) {
|
if ($result < 0) {
|
||||||
throw new RestException(503, 'Error when retrieving country : '.$country->error);
|
throw new RestException(503, 'Error when retrieving country : '.$country->error);
|
||||||
} elseif ($result == 0) {
|
} elseif ($result == 0) {
|
||||||
throw new RestException(404, 'country not found');
|
throw new RestException(404, 'Country not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->translateLabel($country, $lang, 'Country');
|
$this->translateLabel($country, $lang, 'Country');
|
||||||
|
|||||||
@ -162,9 +162,9 @@ class Ccountry // extends CommonObject
|
|||||||
$sql .= " t.label,";
|
$sql .= " t.label,";
|
||||||
$sql .= " t.active";
|
$sql .= " t.active";
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."c_country as t";
|
$sql .= " FROM ".MAIN_DB_PREFIX."c_country as t";
|
||||||
if ($id) $sql .= " WHERE t.rowid = ".$id;
|
if ($id) $sql .= " WHERE t.rowid = ".((int) $id);
|
||||||
elseif ($code) $sql .= " WHERE t.code = '".$this->db->escape($code)."'";
|
elseif ($code) $sql .= " WHERE t.code = '".$this->db->escape(strtoupper($code))."'";
|
||||||
elseif ($code_iso) $sql .= " WHERE t.code_iso = '".$this->db->escape($code_iso)."'";
|
elseif ($code_iso) $sql .= " WHERE t.code_iso = '".$this->db->escape(strtoupper($code_iso))."'";
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
|
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
@ -174,11 +174,13 @@ class Ccountry // extends CommonObject
|
|||||||
{
|
{
|
||||||
$obj = $this->db->fetch_object($resql);
|
$obj = $this->db->fetch_object($resql);
|
||||||
|
|
||||||
$this->id = $obj->rowid;
|
if ($obj) {
|
||||||
$this->code = $obj->code;
|
$this->id = $obj->rowid;
|
||||||
$this->code_iso = $obj->code_iso;
|
$this->code = $obj->code;
|
||||||
$this->label = $obj->label;
|
$this->code_iso = $obj->code_iso;
|
||||||
$this->active = $obj->active;
|
$this->label = $obj->label;
|
||||||
|
$this->active = $obj->active;
|
||||||
|
}
|
||||||
|
|
||||||
$this->db->free($resql);
|
$this->db->free($resql);
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user