FusionDirectory
class_TabFilterElement.inc
1 <?php
2 /*
3  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
4 
5  Copyright (C) 2017-2019 FusionDirectory
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21 
23 {
24  protected $tabs;
25 
26  public function __construct (managementFilter $parent)
27  {
28  global $config;
29 
30  parent::__construct($parent);
31 
32  $this->tabs = [];
33  foreach ($this->parent->parent->objectTypes as $type) {
34  $infos = objects::infos($type);
35  foreach ($config->data['TABS'][$infos['tabGroup']] as $plug) {
36  $class = $plug['CLASS'];
37  if ($class == $infos['mainTab']) {
38  continue;
39  }
40  if (isset($this->tabs[$class])) {
41  continue;
42  }
43  if (class_available($class)) {
44  $classInfos = pluglist::pluginInfos($class);
45  if (isset($classInfos['plFilterObject'])) {
46  $this->tabs[$class] = [
47  'filter' => $classInfos['plFilterObject'],
48  'infos' => $classInfos,
49  'checked' => FALSE,
50  ];
51  }
52  }
53  }
54  }
55  }
56 
57  public function update ()
58  {
59  foreach ($this->tabs as $class => &$tab) {
60  $tab['checked'] = isset($_POST['filter_tab_'.$class]);
61  }
62  unset($tab);
63  }
64 
65  public function render (): string
66  {
67  if (empty($this->tabs)) {
68  return '';
69  }
70  $inputs = [];
71  foreach ($this->tabs as $class => $tab) {
72  $inputs['filter_tab_'.$class] = [
73  'name' => $tab['infos']['plShortName'],
74  'desc' => $tab['infos']['plShortName'].' '.$tab['filter'],
75  'icon' => (isset($tab['infos']['plSmallIcon']) ? $tab['infos']['plSmallIcon'] : NULL),
76  'checked' => $tab['checked'],
77  ];
78  }
79  $smarty = get_smarty();
80  $smarty->assign('NAME', _('Tabs'));
81  $smarty->assign('INPUTS', $inputs);
82  return $smarty->fetch(get_template_path('management/filter-element.tpl'));
83  }
84 
85  public function getFilters (string $type, array &$filters): bool
86  {
87  foreach ($this->tabs as $tab) {
88  if ($tab['checked']) {
89  $filters[] = $tab['filter'];
90  }
91  }
92  return FALSE;
93  }
94 }
get_template_path($filename='', $plugin=FALSE, $path='')
Return themed path for specified base file.
Definition: functions.inc:174
This class handles an element from the management filter box.
& get_smarty()
Get global smarty object.
Definition: functions.inc:324
This class handles the management filter box.
class_available($name)
Checks if a class is available.
Definition: functions.inc:92