AclHelper::linkIsAllowedByUserId PHP Method

linkIsAllowedByUserId() public method

Check if url is allowed for the User
public linkIsAllowedByUserId ( integer $userId, array | string $url ) : boolean
$userId integer User Id
$url array | string link/url to check
return boolean
    public function linkIsAllowedByUserId($userId, $url)
    {
        if (is_array($url)) {
            if (isset($url['admin']) && $url['admin'] == true && strpos($url['action'], 'admin_') === false) {
                $url['action'] = 'admin_' . $url['action'];
            }
            $plugin = empty($url['plugin']) ? null : Inflector::camelize($url['plugin']) . '/';
            $path = '/:plugin/:controller/:action';
            $path = str_replace(array(':controller', ':action', ':plugin/'), array(Inflector::camelize($url['controller']), $url['action'], $plugin), 'controllers/' . $path);
        } else {
            if ($this->_isWhitelist($url)) {
                return true;
            }
            $path = $url;
        }
        $linkAction = str_replace('//', '/', $path);
        if (in_array($linkAction, $this->getAllowedActionsByUserId($userId))) {
            return true;
        } else {
            $userAro = array('model' => 'User', 'foreign_key' => $userId);
            $nodes = $this->AclPermission->Aro->node($userAro);
            if (isset($nodes[0]['Aro'])) {
                if ($this->AclPermission->check($nodes[0]['Aro'], $linkAction)) {
                    return true;
                }
            }
        }
        return false;
    }