コード例 #1
0
 /**
  * @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;
 }
コード例 #2
0
 /**
  * @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;
 }
コード例 #3
0
 /**
  * @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);
 }
コード例 #4
0
 /**
  * @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;
 }