method createFromId documentation in bbn\User\Permissions

function(string $id) { $opt = $this->opt->option($id); if (!$opt) { X::log($this->opt->option($id)); throw new Exception("The option $id doesn't exist"); } if ($this->optionToPermission($id)) { throw new Exception("The permission for option $id already exist"); } /** @var string The option's ID for appui */ $appui = $this->opt->fromCode('appui'); /** @var string The option's ID for plugins */ $plugins = $this->opt->fromCode('plugins'); /** @var array The parents, the first being root */ $parents = array_reverse($this->opt->parents($id)); /** @var string The root (with options code) for this option's permission */ $root = $this->optionPermissionRoot($id); $num = count($parents); if ($num < 2) { throw new Exception("The permission for option $id already exist"); } // Removing root array_shift($parents); // appui or plugins or neither (main app) $root_original = array_shift($parents); // Looking for the root of the options' permissions if (($num > 2) && \in_array($root_original, [$appui, $plugins])) { // Plugin inside a plugin if (($num > 4) && ($this->opt->code($parents[1]) === 'plugins')) { /** @var string */ $id_plugin = array_shift($parents); // dropping 'plugins' array_shift($parents); $root_parent = $this->opt->fromCode('plugins', 'permissions', $id_plugin); if (!$root_parent) { throw new Exception("Impossible to find a parent for plugin's permission ".$id_plugin); } $id_subplugin = array_shift($parents); $subplugin = $this->opt->code($id_subplugin); if ($root_original === $appui) { } $alias = $this->opt->fromCode( 'options', 'permissions', substr($subplugin, $root_original === $appui ? 6: 0), $root_original ); $id_root = $this->opt->fromCode($subplugin, $root_parent); if (!$id_root) { $id_root = $this->opt->add([ 'id_parent' => $root_parent, 'code' => $subplugin, 'text' => $subplugin, 'id_alias' => $alias ]); } } else { $id_root = $this->opt->fromCode('options', 'permissions', array_shift($parents)); } } else { $id_root = $this->opt->fromCode('options', 'permissions', $appui); } if (!$id_root) { throw new Exception("No root found for option $id"); } $parents = array_reverse($parents); // All the parents from the closest $parents = $this->opt->parents($id); // The farest parent having permissions set $id_parent = false; $perm_parents = []; $id_parent_perm = null; // Looping all the parent IDs from the deepest foreach ($parents as $i => $p) { $cfg = $this->opt->getCfg($p); $id_parent = null; // The root is the last with permnission on if (!$cfg['permissions'] ) { $parent_option = $this->opt->option($p); if (!empty($parent_option['alias'])) { $scfg = $this->opt->getCfg($parent_option['id_alias']); if ($scfg['permissions']) { $id_parent = $p; } } } else { if (!$i && ($cfg['permissions'] === 'children')) { $id_parent = $p; } elseif (in_array($cfg['permissions'], ['all', 'cascade'])) { $id_parent = $p; } } if ($id_parent) { // Looking for the permission $aliases = $this->opt->getAliasItems($id_parent); foreach ($aliases as $a) { if (in_array($root, $this->opt->parents($a))) { $id_parent_perm = $a; break; } } // We break at first permission found if ($id_parent_perm) { break; } else { $perm_parents[] = $id_parent; } } } $id_parent = $id_parent_perm ?: $id_root; foreach (array_reverse($perm_parents) as $a) { $id_parent = $this->opt->add( [ 'id_parent' => $id_parent, 'id_alias' => $a ] ); } return $this->opt->add( [ 'id_parent' => $id_parent, 'id_alias' => $id ] ); }

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.