FusionDirectory
class_SubMenuAction.inc
1 <?php
2 /*
3  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
4  Copyright (C) 2017-2018 FusionDirectory
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20 
24 class SubMenuAction extends Action
25 {
26  protected $actions = [];
27  protected $handlers = [];
28 
29  function __construct (string $name, $label, $icon, array $actions, bool $inmenu = TRUE)
30  {
31  parent::__construct($name, $label, $icon, '0', FALSE, [], $inmenu, FALSE);
32  $this->actions = $actions;
33  foreach ($this->actions as $action) {
34  $names = $action->listActions();
35  foreach ($names as $name) {
36  $this->handlers[$name] = $action;
37  }
38  }
39  }
40 
41  function addAction (Action $action)
42  {
43  $this->actions[] = $action;
44  $names = $action->listActions();
45  foreach ($names as $name) {
46  $this->handlers[$name] = $action;
47  }
48  /* Rerun registerAction process */
49  $this->parent->registerAction($this);
50  }
51 
52  function setParent (management $parent)
53  {
54  parent::setParent($parent);
55  foreach ($this->actions as $action) {
56  $action->setParent($parent);
57  }
58  }
59 
60  function listActions (): array
61  {
62  return array_keys($this->handlers);
63  }
64 
65  function execute (management $management, array $action)
66  {
67  if (isset($action['subaction']) && isset($this->handlers[$action['action'].'_'.$action['subaction']])) {
68  return $this->handlers[$action['action'].'_'.$action['subaction']]->execute($management, $action);
69  } elseif (isset($this->handlers[$action['action']])) {
70  return $this->handlers[$action['action']]->execute($management, $action);
71  }
72  }
73 
74  function fillMenuItems (array &$actions)
75  {
76  if (!$this->inmenu) {
77  return;
78  }
79 
80  $subactions = [];
81  foreach ($this->actions as $action) {
82  $action->fillMenuItems($subactions);
83  }
84 
85  if (!empty($subactions)) {
86  $actions[] = [
87  'name' => $this->name,
88  'icon' => $this->icon,
89  'label' => $this->label,
90  'separator' => $this->separator,
91  'actions' => $subactions
92  ];
93  }
94  }
95 
96  function renderColumnIcons (ListingEntry $entry): string
97  {
98  return '';
99  }
100 }
Action base class.
Action which unfold a submenu.
Management base class.