From 0379f0fa16af981d50c39e6fc9dc56be8e741436 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Wed, 15 Apr 2020 19:29:00 +0200 Subject: [PATCH 1/3] NEW API filter projects by category --- htdocs/projet/class/api_projects.class.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/htdocs/projet/class/api_projects.class.php b/htdocs/projet/class/api_projects.class.php index 3e9df24d237..e8b00c13f29 100644 --- a/htdocs/projet/class/api_projects.class.php +++ b/htdocs/projet/class/api_projects.class.php @@ -95,10 +95,11 @@ class Projects extends DolibarrApi * @param int $limit Limit for list * @param int $page Page number * @param string $thirdparty_ids Thirdparty ids to filter projects of (example '1' or '1,2,3') {@pattern /^[0-9,]*$/i} - * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')" + * @param int $category Use this param to filter list by category + * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')" * @return array Array of project objects */ - public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '') + public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $category = 0, $sqlfilters = '') { global $db, $conf; @@ -114,7 +115,9 @@ class Projects extends DolibarrApi $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) $sql .= " FROM ".MAIN_DB_PREFIX."projet as t"; - + if ($category > 0) { + $sql .= ", ".MAIN_DB_PREFIX."categorie_project as c"; + } 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 .= ' WHERE t.entity IN ('.getEntity('project').')'; @@ -126,6 +129,10 @@ class Projects extends DolibarrApi { $sql .= " AND sc.fk_user = ".$search_sale; } + // Select products of given category + if ($category > 0) { + $sql .= " AND c.fk_categorie = ".$db->escape($category)." AND c.fk_project = t.rowid "; + } // Add sql filters if ($sqlfilters) { From c92263ea77dde4cf77f184664d0d8c21c55b9b5a Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Wed, 15 Apr 2020 17:30:39 +0000 Subject: [PATCH 2/3] Fixing style errors. --- htdocs/projet/class/api_projects.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/projet/class/api_projects.class.php b/htdocs/projet/class/api_projects.class.php index e8b00c13f29..9dc419808c7 100644 --- a/htdocs/projet/class/api_projects.class.php +++ b/htdocs/projet/class/api_projects.class.php @@ -116,7 +116,7 @@ class Projects extends DolibarrApi 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."projet as t"; if ($category > 0) { - $sql .= ", ".MAIN_DB_PREFIX."categorie_project as c"; + $sql .= ", ".MAIN_DB_PREFIX."categorie_project as c"; } 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 @@ -131,7 +131,7 @@ class Projects extends DolibarrApi } // Select products of given category if ($category > 0) { - $sql .= " AND c.fk_categorie = ".$db->escape($category)." AND c.fk_project = t.rowid "; + $sql .= " AND c.fk_categorie = ".$db->escape($category)." AND c.fk_project = t.rowid "; } // Add sql filters if ($sqlfilters) From 84989c5cf0eceb7f6618f47b91f9df85f931003a Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Wed, 15 Apr 2020 19:33:33 +0200 Subject: [PATCH 3/3] Update api_projects.class.php --- htdocs/projet/class/api_projects.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/projet/class/api_projects.class.php b/htdocs/projet/class/api_projects.class.php index 9dc419808c7..f8a076c89ee 100644 --- a/htdocs/projet/class/api_projects.class.php +++ b/htdocs/projet/class/api_projects.class.php @@ -129,7 +129,7 @@ class Projects extends DolibarrApi { $sql .= " AND sc.fk_user = ".$search_sale; } - // Select products of given category + // Select projects of given category if ($category > 0) { $sql .= " AND c.fk_categorie = ".$db->escape($category)." AND c.fk_project = t.rowid "; }