From ab870dd5322346e5a8b0dde5c7e7ee8b0570dffa Mon Sep 17 00:00:00 2001 From: "Sekan, Tobias" Date: Sun, 12 Apr 2020 13:30:02 +0200 Subject: [PATCH] Switch to new category API in project list view --- htdocs/core/class/html.formcategory.class.php | 9 ++--- htdocs/product/stock/list.php | 4 +- htdocs/projet/list.php | 37 ++++++++++++------- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/htdocs/core/class/html.formcategory.class.php b/htdocs/core/class/html.formcategory.class.php index 4dd8bed247b..bb7e523d1c8 100644 --- a/htdocs/core/class/html.formcategory.class.php +++ b/htdocs/core/class/html.formcategory.class.php @@ -28,13 +28,12 @@ class FormCategory extends Form /** * Return a HTML filter box for a list filter view * - * @param string $type The categorie type (e.g Categorie::TYPE_WAREHOUSE) - * @param Array $preSelected A list with the elements that should pre-selected - * @return string A HTML filter box (Note: selected results can get with GETPOST("search_category_".$type."_list")) + * @param string $type The categorie type (e.g Categorie::TYPE_WAREHOUSE) + * @param Array $preSelected A list with the elements that should pre-selected + * @return string A HTML filter box (Note: selected results can get with GETPOST("search_category_".$type."_list")) */ - public function getFilterBox($type, $preSelected) + public function getFilterBox($type, array $preSelected) { - // phpcs:enable global $langs; if (empty($preSelected) || !is_array($preSelected)) diff --git a/htdocs/product/stock/list.php b/htdocs/product/stock/list.php index a2f3da7abf0..569226a263d 100644 --- a/htdocs/product/stock/list.php +++ b/htdocs/product/stock/list.php @@ -27,10 +27,10 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcategory.class.php'; if (!empty($conf->categorie->enabled)) { + require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcategory.class.php'; require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; } @@ -185,7 +185,6 @@ if (empty($reshook)) */ $form = new Form($db); -$formcategory = new FormCategory($db); $warehouse = new Entrepot($db); $totalarray = array(); @@ -380,6 +379,7 @@ $moreforfilter = ''; if (!empty($conf->categorie->enabled)) { + $formcategory = new FormCategory($db); $moreforfilter .= $formcategory->getFilterBox(Categorie::TYPE_WAREHOUSE, $search_category_list); } diff --git a/htdocs/projet/list.php b/htdocs/projet/list.php index e04875294bf..23333419902 100644 --- a/htdocs/projet/list.php +++ b/htdocs/projet/list.php @@ -7,6 +7,7 @@ * Copyright (C) 2015 Claudio Aschieri * Copyright (C) 2018 Ferran Marcet * Copyright (C) 2019 Juanjo Menent + * Copyright (C) 2020 Tobias Sean * * 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 @@ -34,6 +35,12 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; +if (!empty($conf->categorie->enabled)) +{ + require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcategory.class.php'; + require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; +} + // Load translation files required by the page $langs->loadLangs(array('projects', 'companies', 'commercial')); @@ -72,7 +79,6 @@ $pageprev = $page - 1; $pagenext = $page + 1; $search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'); -$search_categ = GETPOST("search_categ", 'alpha'); $search_ref = GETPOST("search_ref", 'alpha'); $search_label = GETPOST("search_label", 'alpha'); $search_societe = GETPOST("search_societe", 'alpha'); @@ -101,6 +107,11 @@ $search_eyear = GETPOST('search_eyear', 'int'); if ($search_status == '') $search_status = -1; // -1 or 1 +if (!empty($conf->categorie->enabled)) +{ + $search_category_list = GETPOST("search_category_".Categorie::TYPE_PROJECT."_list", "array"); +} + // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $object = new Project($db); $hookmanager->initHooks(array('projectlist')); @@ -174,7 +185,6 @@ if (empty($reshook)) if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers { $search_all = ''; - $search_categ = ''; $search_ref = ""; $search_label = ""; $search_societe = ""; @@ -197,6 +207,7 @@ if (empty($reshook)) $search_usage_bill_time = ''; $toselect = ''; $search_array_options = array(); + $search_category_list = array(); } @@ -293,8 +304,6 @@ $sql = "SELECT ".$distinct." p.rowid as id, p.ref, p.title, p.fk_statut, p.fk_op $sql .= ", p.datec as date_creation, p.dateo as date_start, p.datee as date_end, p.opp_amount, p.opp_percent, (p.opp_amount*p.opp_percent/100) as opp_weighted_amount, p.tms as date_update, p.budget_amount, p.usage_opportunity, p.usage_task, p.usage_bill_time"; $sql .= ", s.rowid as socid, s.nom as name, s.email"; $sql .= ", cls.code as opp_status_code"; -// We'll need these fields in order to filter by categ -if ($search_categ) $sql .= ", cs.fk_categorie, cs.fk_project"; // Add fields from extrafields if (!empty($extrafields->attributes[$object->table_element]['label'])) { foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : ''); @@ -304,11 +313,12 @@ $parameters = array(); $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook $sql .= $hookmanager->resPrint; $sql .= " FROM ".MAIN_DB_PREFIX."projet as p"; -if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (p.rowid = ef.fk_object)"; +if (!empty($conf->categorie->enabled)) +{ + $sql .= Categorie::getFilterJoinQuery(Categorie::TYPE_PROJECT, "p.rowid"); +} $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on p.fk_soc = s.rowid"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_lead_status as cls on p.fk_opp_status = cls.rowid"; -// We'll need this table joined to the select in order to filter by categ -if (!empty($search_categ)) $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_project as cs ON p.rowid = cs.fk_project"; // We'll need this table joined to the select in order to filter by categ // We'll need this table joined to the select in order to filter by sale // No check is done on company permission because readability is managed by public status of project and assignement. //if ($search_sale > 0 || (! $user->rights->societe->client->voir && ! $socid)) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON sc.fk_soc = s.rowid"; @@ -318,11 +328,13 @@ if ($search_project_user > 0) $sql .= ", ".MAIN_DB_PREFIX."element_contact as ecp"; } $sql .= " WHERE p.entity IN (".getEntity('project').')'; +if (!empty($conf->categorie->enabled)) +{ + $sql .= Categorie::getFilterSelectQuery(Categorie::TYPE_PROJECT, "p.rowid", $search_category_list); +} if (!$user->rights->projet->all->lire) $sql .= " AND p.rowid IN (".$projectsListId.")"; // public and assigned to, or restricted to company for external users // No need to check if company is external user, as filtering of projects must be done by getProjectsAuthorizedForUser if ($socid > 0) $sql .= " AND (p.fk_soc = ".$socid.")"; // This filter if when we use a hard coded filter on company on url (not related to filter for external users) -if ($search_categ > 0) $sql .= " AND cs.fk_categorie = ".$db->escape($search_categ); -if ($search_categ == -2) $sql .= " AND cs.fk_categorie IS NULL"; if ($search_ref) $sql .= natural_search('p.ref', $search_ref); if ($search_label) $sql .= natural_search('p.title', $search_label); if ($search_societe) $sql .= natural_search('s.nom', $search_societe); @@ -486,11 +498,8 @@ $moreforfilter = ''; // Filter on categories if (!empty($conf->categorie->enabled)) { - require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; - $moreforfilter .= '
'; - $moreforfilter .= $langs->trans('ProjectCategories').': '; - $moreforfilter .= $formother->select_categories('project', $search_categ, 'search_categ', 1, 1, 'maxwidth300'); - $moreforfilter .= '
'; + $formcategory = new FormCategory($db); + $moreforfilter .= $formcategory->getFilterBox(Categorie::TYPE_PROJECT, $search_category_list); } // If the user can view user other than himself