mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Fixed the range thing
This commit is contained in:
58
app/Support/Preferences.php
Normal file
58
app/Support/Preferences.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Support;
|
||||
|
||||
use \FireflyIII\Models\Preference;
|
||||
use Auth;
|
||||
|
||||
/**
|
||||
* Class Preferences
|
||||
*
|
||||
* @package FireflyIII\Support
|
||||
*/
|
||||
class Preferences
|
||||
{
|
||||
/**
|
||||
* @param $name
|
||||
* @param null $default
|
||||
*
|
||||
* @return null|\Preference
|
||||
*/
|
||||
public function get($name, $default = null)
|
||||
{
|
||||
$pref = Preference::where('user_id', Auth::user()->id)->where('name', $name)->first();
|
||||
if (is_null($pref) && is_null($default)) {
|
||||
// return NULL
|
||||
return null;
|
||||
}
|
||||
if (!is_null($pref)) {
|
||||
return $pref;
|
||||
}
|
||||
|
||||
return $this->set($name, $default);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $value
|
||||
*
|
||||
* @return \Preference
|
||||
*/
|
||||
public function set($name, $value)
|
||||
{
|
||||
$pref = Preference::where('user_id', Auth::user()->id)->where('name', $name)->first();
|
||||
if (is_null($pref)) {
|
||||
$pref = new Preference;
|
||||
$pref->name = $name;
|
||||
$pref->user()->associate(Auth::user());
|
||||
|
||||
}
|
||||
$pref->data = $value;
|
||||
$pref->save();
|
||||
|
||||
|
||||
return $pref;
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user