/** * @dataProvider getDefaultSettingData * * @param string $method * @param string $type * @param mixed $expected */ public function testGetDefaultSetting($method, $type, $expected) { $this->assertEquals($expected, $this->userSettings->getDefaultSetting($method, $type)); }
/** * Filters the given user array by their notification setting * * @param array $users * @param string $method * @param string $type * @return array Returns a "username => b:true" Map for method = stream * Returns a "username => i:batchtime" Map for method = email */ public static function filterUsersBySetting($users, $method, $type) { if (empty($users) || !is_array($users)) { return array(); } $preferences = new \OC\Preferences(\OC_DB::getConnection()); $filteredUsers = array(); $potentialUsers = $preferences->getValueForUsers('activity', 'notify_' . $method . '_' . $type, $users); foreach ($potentialUsers as $user => $value) { if ($value) { $filteredUsers[$user] = true; } unset($users[array_search($user, $users)]); } // Get the batch time setting from the database if ($method == 'email') { $potentialUsers = $preferences->getValueForUsers('activity', 'notify_setting_batchtime', array_keys($filteredUsers)); foreach ($potentialUsers as $user => $value) { $filteredUsers[$user] = $value; } } if (empty($users)) { return $filteredUsers; } // If the setting is enabled by default, // we add all users that didn't set the preference yet. if (UserSettings::getDefaultSetting($method, $type)) { foreach ($users as $user) { if ($method == 'stream') { $filteredUsers[$user] = true; } else { $filteredUsers[$user] = self::getDefaultSetting('setting', 'batchtime'); } } } return $filteredUsers; }