From be4a5ccd2f7077949db7b97ba77d7c31bc6a4d27 Mon Sep 17 00:00:00 2001 From: ptibogxiv Date: Wed, 15 Apr 2020 18:30:13 +0200 Subject: [PATCH] NEW API filter user by category --- htdocs/user/class/api_users.class.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/htdocs/user/class/api_users.class.php b/htdocs/user/class/api_users.class.php index fb1da988ce4..bb8a816b17c 100644 --- a/htdocs/user/class/api_users.class.php +++ b/htdocs/user/class/api_users.class.php @@ -1,5 +1,6 @@ +/* Copyright (C) 2030 Thibault FOUCART * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -62,10 +63,11 @@ class Users extends DolibarrApi * @param int $limit Limit for list * @param int $page Page number * @param string $user_ids User ids filter field. Example: '1' or '1,2,3' {@pattern /^[0-9,]*$/i} + * @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 User objects */ - public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $user_ids = 0, $sqlfilters = '') + public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $user_ids = 0, $category = 0, $sqlfilters = '') { global $db, $conf; @@ -80,8 +82,18 @@ class Users extends DolibarrApi $sql = "SELECT t.rowid"; $sql .= " FROM ".MAIN_DB_PREFIX."user as t"; + if ($category > 0) { + $sql .= ", ".MAIN_DB_PREFIX."categorie_user as c"; + } $sql .= ' WHERE t.entity IN ('.getEntity('user').')'; if ($user_ids) $sql .= " AND t.rowid IN (".$user_ids.")"; + + // Select products of given category + if ($category > 0) { + $sql .= " AND c.fk_categorie = ".$db->escape($category); + $sql .= " AND c.fk_user = t.rowid "; + } + // Add sql filters if ($sqlfilters) {