Acl\Shell\AclShell::view PHP Method

view() public method

Show a specific ARO/ACO node.
public view ( ) : void
return void
    public function view()
    {
        extract($this->_dataVars());
        $alias = $this->Acl->{$class}->alias();
        if (isset($this->args[1])) {
            $identity = $this->parseIdentifier($this->args[1]);
            $topNode = $this->Acl->{$class}->find('all', ['conditions' => [$alias . '.id' => $this->_getNodeId($class, $identity)]])->first();
            $nodes = $this->Acl->{$class}->find('all', ['conditions' => [$alias . '.lft >=' => $topNode->lft, $alias . '.lft <=' => $topNode->rght], 'order' => $alias . '.lft ASC']);
        } else {
            $nodes = $this->Acl->{$class}->find('all', ['order' => $alias . '.lft ASC']);
        }
        if ($nodes->count() === 0) {
            if (isset($this->args[1])) {
                $this->error(__d('cake_acl', '{0} not found', [$this->args[1]]), __d('cake_acl', 'No tree returned.'));
            } elseif (isset($this->args[0])) {
                $this->error(__d('cake_acl', '{0} not found', [$this->args[0]]), __d('cake_acl', 'No tree returned.'));
            }
        }
        $this->out($class . ' tree:');
        $this->hr();
        $stack = [];
        $last = null;
        $rows = $nodes->hydrate(false)->toArray();
        foreach ($rows as $n) {
            $stack[] = $n;
            if (!empty($last)) {
                $end = end($stack);
                if ($end['rght'] > $last) {
                    foreach ($stack as $k => $v) {
                        $end = end($stack);
                        if ($v['rght'] < $end['rght']) {
                            unset($stack[$k]);
                        }
                    }
                }
            }
            $last = $n['rght'];
            $count = count($stack);
            $this->_outputNode($class, $n, $count);
        }
        $this->hr();
    }