-
Côme Chilliet authoredcbf9e1b1
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2017-2018 FusionDirectory
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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*!
* \brief Action base class
*/
class Action
{
protected $name;
protected $label;
protected $icon;
/* 0, 1, ?, + or * */
protected $targets;
protected $acl;
/* Booleans */
protected $inmenu;
protected $inline;
protected $callable;
protected $enabledCallable;
protected $minTargets;
protected $maxTargets;
protected $separator = FALSE;
protected $parent;
function __construct($name, $label, $icon, $targets, $callable, array $acls = array(), $inmenu = TRUE, $inline = TRUE)
{
if ($targets == '0') {
$inline = FALSE;
}
$this->name = $name;
$this->label = $label;
$this->icon = $icon;
$this->targets = $targets;
$this->callable = $callable;
$this->inmenu = $inmenu;
$this->inline = $inline;
$this->acl = array();
/*
* acl may be of the form:
* acl (ex: 'd')
* attribute:acl (ex: 'userPassword:r')
* category/class/acl (ex: 'user/template/r')
* category/class/attribute:acl (ex: 'user/user/userPassword:r')
* /class/acl (ex: '/snapshot/c')
* /class/attribute:acl (ex: '/template/template_cn:w')
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
* */
foreach ($acls as $acl) {
$category = NULL;
$class = NULL;
$attribute = '0';
if (strpos($acl, '/') !== FALSE) {
list($category, $class, $acl) = explode('/', $acl, 3);
}
if (strpos($acl, ':') !== FALSE) {
list($attribute, $acl) = explode(':', $acl, 2);
}
$this->acl[] = array(
'category' => $category,
'class' => $class,
'attribute' => $attribute,
'acl' => str_split($acl),
);
}
switch ($targets) {
case '0':
$this->minTargets = 0;
$this->maxTargets = 0;
break;
case '1':
$this->minTargets = 1;
$this->maxTargets = 1;
break;
case '?':
$this->minTargets = 0;
$this->maxTargets = 1;
break;
case '+':
$this->minTargets = 1;
$this->maxTargets = FALSE;
break;
case '*':
$this->minTargets = 0;
$this->maxTargets = FALSE;
break;
default:
throw new Exception('Invalid targets value for action '.$name.': '.$targets);
}
}
function setParent(management $parent)
{
$this->parent = $parent;
}
function getName()
{
return $this->name;
}
function getLabel()
{
return $this->label;
}
function setSeparator($bool)
{
$this->separator = $bool;
}
function setEnableFunction(callable $callable)
{
$this->enabledCallable = $callable;
}