Merge pull request #21677 from ptibogxiv/patch-33

New filter by category for knowledgemanagement API
This commit is contained in:
Laurent Destailleur 2022-08-10 04:25:25 +02:00 committed by GitHub
commit a41db80c6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -125,18 +125,19 @@ class KnowledgeManagement extends DolibarrApi
*
* Get a list of knowledgerecords
*
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Limit for list
* @param int $page Page number
* @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')"
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Limit for list
* @param int $page Page number
* @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 order objects
*
* @throws RestException
*
* @url GET /knowledgerecords/
*/
public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '')
public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $category = 0, $sqlfilters = '')
{
global $db, $conf;
@ -166,6 +167,9 @@ class KnowledgeManagement extends DolibarrApi
if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $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
}
if ($category > 0) {
$sql .= ", ".$this->db->prefix()."categorie_knowledgemanagement as c";
}
$sql .= " WHERE 1 = 1";
// Example of use $mode
@ -188,6 +192,11 @@ class KnowledgeManagement extends DolibarrApi
if ($restrictonsocid && $search_sale > 0) {
$sql .= " AND sc.fk_user = ".((int) $search_sale);
}
// Select products of given category
if ($category > 0) {
$sql .= " AND c.fk_categorie = ".((int) $category);
$sql .= " AND c.fk_knowledgemanagement = t.rowid";
}
if ($sqlfilters) {
$errormessage = '';
if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {