Passed
Branch develop (2b65df)
by
unknown
40:00
created

FormCategory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 31
rs 10
c 1
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A getFilterBox() 0 22 3
1
<?php
2
/* Copyright (C) 2020		Tobias Sekan	<[email protected]>
3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16
 */
17
18
/**
19
 *	\file		htdocs/core/class/html.formcategory.class.php
20
 *	\ingroup	core
21
 *	\brief		File of class to build HTML component for category filtering
22
 */
23
24
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
25
26
class FormCategory extends Form
27
{
28
	/**
29
	 * Return a HTML filter box for a list filter view
30
	 *
31
	 * @param string $type			The categorie type (e.g Categorie::TYPE_WAREHOUSE)
32
	 * @param Array $preSelected	A list with the elements that should pre-selected
33
	 * @return string				A HTML filter box (Note: selected results can get with GETPOST("search_category_".$type."_list"))
34
	 */
35
	public function getFilterBox($type, $preSelected)
36
	{
37
		// phpcs:enable
38
		global $langs;
39
40
		if (empty($preSelected) || !is_array($preSelected))
41
		{
42
			$preSelected = array();
43
		}
44
45
		$htmlName = "search_category_".$type."_list";
46
47
		$categoryArray = $this->select_all_categories($type, "", "", 64, 0, 1);
48
		$categoryArray[-2] = "- ".$langs->trans('NotCategorized')." -";
49
50
		$filter = '';
51
		$filter .= '<div class="divsearchfield">';
52
		$filter .= $langs->trans('Categories').": ";
53
		$filter .= Form::multiselectarray($htmlName, $categoryArray, $preSelected, 0, 0, "minwidth300");
54
		$filter .= "</div>";
55
56
		return $filter;
57
	}
58
}
59