/** * @param $name * * @return bool * @throws \Exception */ public function delete($name) : bool { $fullName = 'preference' . auth()->user()->id . $name; if (Cache::has($fullName)) { Cache::forget($fullName); } Preference::where('user_id', auth()->user()->id)->where('name', $name)->delete(); return true; }
/** * @param $name * @param string $value * * @return Preference */ public function set($name, $value) { $fullName = 'preference' . Auth::user()->id . $name; Cache::forget($fullName); $pref = Preference::where('user_id', Auth::user()->id)->where('name', $name)->first(['id', 'name', 'data_encrypted']); if ($pref) { $pref->data = $value; } else { $pref = new Preference(); $pref->name = $name; $pref->data = $value; $pref->user()->associate(Auth::user()); } $pref->save(); Cache::forever($fullName, $pref); return $pref; }
/** * @covers FireflyIII\Support\Amount::getCurrencyCode */ public function testGetCurrencyCodeNoSuchCurrency() { $user = FactoryMuffin::create('FireflyIII\\User'); $this->be($user); // delete any currency preferences: Preference::where('user_id', $user->id)->delete(); // delete transaction currencies: foreach (TransactionCurrency::get() as $c) { $c->delete(); } $preference = FactoryMuffin::create('FireflyIII\\Models\\Preference'); $preference->user_id = $user->id; $preference->name = 'currencyPreference'; $preference->data = 'SOM'; $preference->save(); Preferences::shouldReceive('get')->withArgs(['currencyPreference', 'EUR'])->andReturn($preference); $code = $this->object->getCurrencyCode(); $this->assertEquals('EUR', $code); }
/** * @param \FireflyIII\User $user * @param $name * @param string $value * * @return Preference */ public function setForUser(User $user, $name, $value) : Preference { $fullName = 'preference' . $user->id . $name; Cache::forget($fullName); $pref = Preference::where('user_id', $user->id)->where('name', $name)->first(['id', 'name', 'data']); if (!is_null($pref)) { $pref->data = $value; $pref->save(); Cache::forever($fullName, $pref); return $pref; } $pref = new Preference(); $pref->name = $name; $pref->data = $value; $pref->user()->associate($user); $pref->save(); Cache::forever($fullName, $pref); return $pref; }