/** * @param string $allPreferences * @return UserPreferences */ public static function Parse($allPreferences) { $preferences = new UserPreferences(); if (empty($allPreferences)) { return $preferences; } $pairs = explode('!sep!', $allPreferences); foreach ($pairs as $pair) { $nv = explode('=', $pair); $preferences->Add($nv[0], $nv[1]); } return $preferences; }
public function LoadPreferences($userId) { $command = new GetUserPreferencesCommand($userId); $reader = ServiceLocator::GetDatabase()->Query($command); $preferences = new UserPreferences(); while ($row = $reader->GetRow()) { $preferences->Add($row[ColumnNames::PREFERENCE_NAME], $row[ColumnNames::PREFERENCE_VALUE]); } $reader->Free(); return $preferences; }
public function testAddsAndUpdatesUserPreferences() { $userId = 987; $user = new User(); $user->WithId($userId); $preferences = new UserPreferences(); $preferences->Add('pref1', 'val1'); $preferences->Add('pref2', 'val2'); $user->WithPreferences($preferences); $user->ChangePreference('pref2', 'val3'); $user->ChangePreference('pref3', 'val4'); $repo = new UserRepository(); $repo->Update($user); $this->assertTrue($this->db->ContainsCommand(new UpdateUserPreferenceCommand($userId, 'pref2', 'val3'))); $this->assertTrue($this->db->ContainsCommand(new AddUserPreferenceCommand($userId, 'pref3', 'val4'))); }