Piwik\Plugins\UsersManager\API::getSitesAccessFromUser PHP Method

getSitesAccessFromUser() public method

If the user doesn't have any access to a website ('noaccess'), this website will not be in the returned array. If the user doesn't have any access, the returned array will be an empty array.
public getSitesAccessFromUser ( string $userLogin ) : array
$userLogin string User that has to be valid
return array The returned array has the format array( idsite1 => 'view', idsite2 => 'admin', idsite3 => 'view', ... )
    public function getSitesAccessFromUser($userLogin)
    {
        Piwik::checkUserHasSuperUserAccess();
        $this->checkUserExists($userLogin);
        // Super users have 'admin' access for every site
        if (Piwik::hasTheUserSuperUserAccess($userLogin)) {
            $return = array();
            $siteManagerModel = new \Piwik\Plugins\SitesManager\Model();
            $sites = $siteManagerModel->getAllSites();
            foreach ($sites as $site) {
                $return[] = array('site' => $site['idsite'], 'access' => 'admin');
            }
            return $return;
        }
        return $this->model->getSitesAccessFromUser($userLogin);
    }

Usage Example

Exemplo n.º 1
0
 public function test_getSitesAccessFromUser_forSuperUser()
 {
     $user2 = 'userLogin2';
     $this->api->addUser($user2, 'password', '*****@*****.**');
     // new user doesn't have access to anything
     $access = $this->api->getSitesAccessFromUser($user2);
     $this->assertEmpty($access);
     $this->api->setSuperUserAccess($user2, true);
     // super user has admin access for every site
     $access = $this->api->getSitesAccessFromUser($user2);
     $expected = array(array('site' => 1, 'access' => 'admin'), array('site' => 2, 'access' => 'admin'), array('site' => 3, 'access' => 'admin'));
     $this->assertEquals($expected, $access);
 }
All Usage Examples Of Piwik\Plugins\UsersManager\API::getSitesAccessFromUser