method fromPath documentation in bbn\User\Permissions
Returns the option's ID corresponds to the given path.
function(string $path, $type = 'access', $create = false)
{
$parent = null;
$root = false;
if (($type === 'access') && $this->plugins && !empty($path)) {
foreach ($this->plugins as $plugin) {
if (strpos($path, $plugin['url'].'/') === 0) {
if (strpos($plugin['name'], 'appui-') === 0) {
$root = $this->opt->fromCode(
'access',
'permissions',
substr($plugin['name'], 6),
BBN_APPUI
);
$path = substr($path, strlen($plugin['url']) + 1);
}
elseif ($plugin['name']) {
$root = $this->opt->fromCode(
'access',
'permissions',
$plugin['name'],
'plugins',
);
$path = substr($path, strlen($plugin['url']) + 1);
}
break;
}
}
}
if (!$root) {
$root = $this->opt->fromCode($type, self::$option_root_id);
}
if (!$root) {
throw new Exception(X::_("Impossible to find the permission code for $path"));
}
$parts = explode('/', trim($path, '/'));
$parent = $root;
$path = '';
foreach ($parts as $i => $p){
$is_last = $i === (\count($parts) - 1);
if (!empty($p)) {
$prev_parent = $parent;
// Adds a slash for each bit of the path except the last one
$parent = $this->opt->fromCode($p.($is_last ? '' : '/'), $prev_parent);
// If not found looking for a subpermission
if (!$parent && !$is_last) {
$parent = $this->opt->fromCode($p, $prev_parent);
}
elseif ($is_last && $prev_parent && !$parent && $create) {
if ($this->_add(
[
'code' => $p,
'text' => $p
],
$prev_parent
)
) {
$parent = $this->db->lastId();
}
}
}
}
return $parent ?: null;
}
Returns the option's ID corresponds to the given path. BBN is a suite of PHP and JS libraries and VueJS components - all open-source! bbn.io, build applications, the quick way
This website uses cookies to ensure you get the best experience on our website.
© 2011-2025
BBN Solutions