Merge pull request #13623 from ptibogxiv/patch-331
NEW API filter user by category
This commit is contained in:
commit
9c792060a2
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
/* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
|
||||
/* Copyright (C) 2030 Thibault FOUCART <support@ptibogxiv.net>
|
||||
*
|
||||
* 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)
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user