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

getAllUsersPreferences() public method

Returns an array of Preferences
public getAllUsersPreferences ( array $preferenceNames ) : array
$preferenceNames array array of preference names
return array
    public function getAllUsersPreferences(array $preferenceNames)
    {
        Piwik::checkUserHasSuperUserAccess();
        $userPreferences = array();
        foreach ($preferenceNames as $preferenceName) {
            $optionNameMatchAllUsers = $this->getPreferenceId('%', $preferenceName);
            $preferences = Option::getLike($optionNameMatchAllUsers);
            foreach ($preferences as $optionName => $optionValue) {
                $lastUnderscore = strrpos($optionName, self::OPTION_NAME_PREFERENCE_SEPARATOR);
                $userName = substr($optionName, 0, $lastUnderscore);
                $preference = substr($optionName, $lastUnderscore + 1);
                $userPreferences[$userName][$preference] = $optionValue;
            }
        }
        return $userPreferences;
    }

Usage Example

Exemplo n.º 1
0
 public function test_getAllUsersPreferences_whenLoginContainsUnderscore()
 {
     $user2 = 'user_Login2';
     $this->api->addUser($user2, 'password', '*****@*****.**');
     $this->api->setUserPreference($user2, 'myPreferenceName', 'valueForUser2');
     $this->api->setUserPreference($user2, 'RandomNOTREQUESTED', 'RandomNOTREQUESTED');
     $expected = array($user2 => array('myPreferenceName' => 'valueForUser2'));
     $result = $this->api->getAllUsersPreferences(array('myPreferenceName', 'otherPreferenceHere', 'randomDoesNotExist'));
     $this->assertSame($expected, $result);
 }