From b0c6b59eb2cad3b1b31aecefb6de278fa40a0ae1 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Fri, 28 Oct 2022 15:56:15 +0200 Subject: [PATCH 1/3] NEW translate setup/ticket API link to https://github.com/Dolibarr/dolibarr/pull/22699 & fix for multicompany --- htdocs/api/class/api_setup.class.php | 33 ++++++++++++++++++---------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/htdocs/api/class/api_setup.class.php b/htdocs/api/class/api_setup.class.php index 406172590d7..7c43b751082 100644 --- a/htdocs/api/class/api_setup.class.php +++ b/htdocs/api/class/api_setup.class.php @@ -1496,6 +1496,7 @@ class Setup extends DolibarrApi * @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 $lang Code of the language the label of the severity must be translated to * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)" * @return array List of ticket categories * @@ -1503,13 +1504,14 @@ class Setup extends DolibarrApi * * @throws RestException */ - public function getTicketsCategories($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '') + public function getTicketsCategories($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $lang = '', $sqlfilters = '') { $list = array(); $sql = "SELECT rowid, code, pos, label, use_default, description"; $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_category as t"; - $sql .= " WHERE t.active = ".((int) $active); + $sql .= " WHERE t.entity IN (".getEntity('c_ticket_category').")"; + $sql .= " AND t.active = ".((int) $active); // Add sql filters if ($sqlfilters) { $errormessage = ''; @@ -1538,7 +1540,9 @@ class Setup extends DolibarrApi $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); + $category = $this->db->fetch_object($result); + $this->translateLabel($category, $lang, 'TicketCategoryShort', 'ticket'); + $list[] = $category; } } else { throw new RestException(503, 'Error when retrieving list of ticket categories : '.$this->db->lasterror()); @@ -1555,6 +1559,7 @@ class Setup extends DolibarrApi * @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 $lang Code of the language the label of the severity must be translated to * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)" * @return array List of ticket severities * @@ -1562,13 +1567,14 @@ class Setup extends DolibarrApi * * @throws RestException */ - public function getTicketsSeverities($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '') + public function getTicketsSeverities($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $lang = '', $sqlfilters = '') { $list = array(); $sql = "SELECT rowid, code, pos, label, use_default, color, description"; $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_severity as t"; - $sql .= " WHERE t.active = ".((int) $active); + $sql .= " WHERE t.entity IN (".getEntity('c_ticket_severity').")"; + $sql .= " AND t.active = ".((int) $active); // Add sql filters if ($sqlfilters) { $errormessage = ''; @@ -1597,7 +1603,9 @@ class Setup extends DolibarrApi $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); + $severity = $this->db->fetch_object($result); + $this->translateLabel($severity, $lang, 'TicketSeverityShort', 'ticket'); + $list[] = $severity; } } else { throw new RestException(503, 'Error when retrieving list of ticket severities : '.$this->db->lasterror()); @@ -1614,6 +1622,7 @@ class Setup extends DolibarrApi * @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 $lang Code of the language the label of the severity must be translated to * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)" * @return array List of ticket types * @@ -1621,15 +1630,15 @@ class Setup extends DolibarrApi * * @throws RestException */ - public function getTicketsTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '') + public function getTicketsTypes($sortfield = "code", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $lang = '', $sqlfilters = '') { $list = array(); $sql = "SELECT rowid, code, pos, label, use_default, description"; $sql .= " FROM ".MAIN_DB_PREFIX."c_ticket_type as t"; - $sql .= " WHERE t.active = ".(int) $active; - // if ($type) $sql .= " AND t.type LIKE '%".$this->db->escape($type)."%'"; - // if ($module) $sql .= " AND t.module LIKE '%".$this->db->escape($module)."%'"; + $sql .= " WHERE t.entity IN (".getEntity('c_ticket_type').")"; + $sql .= " AND t.active = ".((int) $active); + // Add sql filters if ($sqlfilters) { $errormessage = ''; @@ -1658,7 +1667,9 @@ class Setup extends DolibarrApi $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); + $type =$this->db->fetch_object($result); + $this->translateLabel($type, $lang, 'TicketTypeShort', 'ticket'); + $list[] = $type; } } else { throw new RestException(503, 'Error when retrieving list of ticket types : '.$this->db->lasterror()); From 81bec045865eeac4f549298e581e6f31f970d0f1 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Fri, 28 Oct 2022 16:17:14 +0200 Subject: [PATCH 2/3] Update api_setup.class.php --- htdocs/api/class/api_setup.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/api/class/api_setup.class.php b/htdocs/api/class/api_setup.class.php index 7c43b751082..28c693ed87c 100644 --- a/htdocs/api/class/api_setup.class.php +++ b/htdocs/api/class/api_setup.class.php @@ -1496,7 +1496,7 @@ class Setup extends DolibarrApi * @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 $lang Code of the language the label of the severity must be translated to + * @param string $lang Code of the language the label of the category must be translated to * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)" * @return array List of ticket categories * @@ -1622,7 +1622,7 @@ class Setup extends DolibarrApi * @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 $lang Code of the language the label of the severity must be translated to + * @param string $lang Code of the language the label of the type must be translated to * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.code:like:'A%') and (t.active:>=:0)" * @return array List of ticket types * From 6dd07121937293c8d362ad20a164a588ec691ab0 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Fri, 28 Oct 2022 21:26:45 +0200 Subject: [PATCH 3/3] Update api_setup.class.php --- htdocs/api/class/api_setup.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/api/class/api_setup.class.php b/htdocs/api/class/api_setup.class.php index 28c693ed87c..ef1d7e4c512 100644 --- a/htdocs/api/class/api_setup.class.php +++ b/htdocs/api/class/api_setup.class.php @@ -1541,7 +1541,7 @@ class Setup extends DolibarrApi $min = min($num, ($limit <= 0 ? $num : $limit)); for ($i = 0; $i < $min; $i++) { $category = $this->db->fetch_object($result); - $this->translateLabel($category, $lang, 'TicketCategoryShort', 'ticket'); + $this->translateLabel($category, $lang, 'TicketCategoryShort', array('ticket')); $list[] = $category; } } else { @@ -1604,7 +1604,7 @@ class Setup extends DolibarrApi $min = min($num, ($limit <= 0 ? $num : $limit)); for ($i = 0; $i < $min; $i++) { $severity = $this->db->fetch_object($result); - $this->translateLabel($severity, $lang, 'TicketSeverityShort', 'ticket'); + $this->translateLabel($severity, $lang, 'TicketSeverityShort', array('ticket')); $list[] = $severity; } } else { @@ -1668,7 +1668,7 @@ class Setup extends DolibarrApi $min = min($num, ($limit <= 0 ? $num : $limit)); for ($i = 0; $i < $min; $i++) { $type =$this->db->fetch_object($result); - $this->translateLabel($type, $lang, 'TicketTypeShort', 'ticket'); + $this->translateLabel($type, $lang, 'TicketTypeShort', array('ticket')); $list[] = $type; } } else {