New filter by category for knowledgemanagement API

This commit is contained in:
ptibogxiv 2022-08-06 14:50:53 +02:00 committed by GitHub
parent f56abb1e5f
commit 1fac6e0ee4
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 * Get a list of knowledgerecords
* *
* @param string $sortfield Sort field * @param string $sortfield Sort field
* @param string $sortorder Sort order * @param string $sortorder Sort order
* @param int $limit Limit for list * @param int $limit Limit for list
* @param int $page Page number * @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 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 * @return array Array of order objects
* *
* @throws RestException * @throws RestException
* *
* @url GET /knowledgerecords/ * @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; global $db, $conf;
@ -166,6 +167,9 @@ class KnowledgeManagement extends DolibarrApi
if ($restrictonsocid && (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) { 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 $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"; $sql .= " WHERE 1 = 1";
// Example of use $mode // Example of use $mode
@ -188,6 +192,11 @@ class KnowledgeManagement extends DolibarrApi
if ($restrictonsocid && $search_sale > 0) { if ($restrictonsocid && $search_sale > 0) {
$sql .= " AND sc.fk_user = ".((int) $search_sale); $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) { if ($sqlfilters) {
$errormessage = ''; $errormessage = '';
if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) { if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) {