From 77d64e4fe2d2eea9be6f5a305c28bd4251d4be87 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Sat, 25 Sep 2021 12:13:06 +0200 Subject: [PATCH 1/5] NEW API list of staff units --- htdocs/api/class/api_setup.class.php | 59 ++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/htdocs/api/class/api_setup.class.php b/htdocs/api/class/api_setup.class.php index f5f301e9c16..faccf512ed8 100644 --- a/htdocs/api/class/api_setup.class.php +++ b/htdocs/api/class/api_setup.class.php @@ -1278,6 +1278,65 @@ class Setup extends DolibarrApi return $list; } + + /** + * Get the list of staff. + * + * @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 Staff 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 array List of staff + * + * @url GET dictionary/staff + * + * @throws RestException + */ + public function getListOfStaff($sortfield = "id", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '') + { + $list = array(); + + //TODO link with multicurrency module + $sql = "SELECT t.id, t.code, t.libelle, t.active, t.module"; + $sql .= " FROM ".MAIN_DB_PREFIX."c_effectif as t"; + $sql .= " WHERE t.active = ".((int) $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 staff: '.$this->db->lasterror()); + } + + return $list; + } /** * Get the list of social networks. From 6b820ae4c5461044cad4bfc2e04d29c75ccbfd22 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Sat, 25 Sep 2021 10:16:29 +0000 Subject: [PATCH 2/5] Fixing style errors. --- htdocs/api/class/api_setup.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/api/class/api_setup.class.php b/htdocs/api/class/api_setup.class.php index faccf512ed8..b957feda82c 100644 --- a/htdocs/api/class/api_setup.class.php +++ b/htdocs/api/class/api_setup.class.php @@ -1278,7 +1278,7 @@ class Setup extends DolibarrApi return $list; } - + /** * Get the list of staff. * From 1199782d61e16da2370c9ce6a57c0f99bcd50c5a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 28 Sep 2021 13:10:46 +0200 Subject: [PATCH 3/5] Update api_setup.class.php --- htdocs/api/class/api_setup.class.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/api/class/api_setup.class.php b/htdocs/api/class/api_setup.class.php index b957feda82c..3ebb0252500 100644 --- a/htdocs/api/class/api_setup.class.php +++ b/htdocs/api/class/api_setup.class.php @@ -1298,7 +1298,6 @@ class Setup extends DolibarrApi { $list = array(); - //TODO link with multicurrency module $sql = "SELECT t.id, t.code, t.libelle, t.active, t.module"; $sql .= " FROM ".MAIN_DB_PREFIX."c_effectif as t"; $sql .= " WHERE t.active = ".((int) $active); From 1b714042252e1bde92e8eea1a555e7edc6bc6723 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Tue, 28 Sep 2021 20:27:45 +0200 Subject: [PATCH 4/5] Update api_setup.class.php --- htdocs/api/class/api_setup.class.php | 65 +++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/htdocs/api/class/api_setup.class.php b/htdocs/api/class/api_setup.class.php index 3ebb0252500..26732863dc7 100644 --- a/htdocs/api/class/api_setup.class.php +++ b/htdocs/api/class/api_setup.class.php @@ -4,7 +4,7 @@ * Copyright (C) 2017 Regis Houssin * Copyright (C) 2017 Neil Orley * Copyright (C) 2018-2021 Frédéric France - * Copyright (C) 2018-2020 Thibault FOUCART + * Copyright (C) 2018-2021 Thibault FOUCART * * * This program is free software; you can redistribute it and/or modify @@ -1239,7 +1239,6 @@ class Setup extends DolibarrApi { $list = array(); - //TODO link with multicurrency module $sql = "SELECT t.rowid, t.code, t.label,t.short_label, t.active, t.scale, t.unit_type"; $sql .= " FROM ".MAIN_DB_PREFIX."c_units as t"; $sql .= " WHERE t.active = ".((int) $active); @@ -1280,6 +1279,68 @@ class Setup extends DolibarrApi } /** + * Get the list of legal form of business. + * + * @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 $country To filter on country + * @param int $active Lega form 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 array List of legal form + * + * @url GET dictionary/legal_form + * + * @throws RestException + */ + public function getListOfLegalForm($sortfield = "rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $country = '', $active = 1, $sqlfilters = '') + { + $list = array(); + + $sql = "SELECT t.rowid, t.code, t.fk_pays, t.libelle, t.isvatexempted, t.active, t.module, t.position"; + $sql .= " FROM ".MAIN_DB_PREFIX."c_forme_juridique as t"; + $sql .= " WHERE t.active = ".((int) $active); + if ($country) { + $sql .= " AND t.fk_pays = '".$this->db->escape($country)."'"; + } + // 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 legal form: '.$this->db->lasterror()); + } + + return $list; + } + +/** * Get the list of staff. * * @param string $sortfield Sort field From 4d62aff8aa0983a59cd4be0d6f5f1d33795710c2 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Tue, 28 Sep 2021 18:29:50 +0000 Subject: [PATCH 5/5] Fixing style errors. --- htdocs/api/class/api_setup.class.php | 32 ++++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/htdocs/api/class/api_setup.class.php b/htdocs/api/class/api_setup.class.php index 26732863dc7..6892092a8a3 100644 --- a/htdocs/api/class/api_setup.class.php +++ b/htdocs/api/class/api_setup.class.php @@ -1339,22 +1339,22 @@ class Setup extends DolibarrApi return $list; } - -/** - * Get the list of staff. - * - * @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 Staff 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 array List of staff - * - * @url GET dictionary/staff - * - * @throws RestException - */ + + /** + * Get the list of staff. + * + * @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 Staff 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 array List of staff + * + * @url GET dictionary/staff + * + * @throws RestException + */ public function getListOfStaff($sortfield = "id", $sortorder = 'ASC', $limit = 100, $page = 0, $active = 1, $sqlfilters = '') { $list = array();