Made big headway in preference management, accounts, importing stuff, etc. etc.

This commit is contained in:
James Cole
2014-07-06 15:18:11 +02:00
parent 188105492c
commit 4192f2bc8f
46 changed files with 672 additions and 187 deletions

View File

@@ -0,0 +1,39 @@
<?php
namespace Firefly\Helper\Preferences;
class PreferencesHelper implements PreferencesHelperInterface
{
public function get($name, $default = null)
{
$pref = \Preference::where('user_id', \Auth::user()->id)->where('name', $name)->first();
if (is_null($default) && is_null($pref)) {
// return NULL
return null;
}
if (!is_null($pref)) {
return $pref;
}
if (!is_null($default) && is_null($pref)) {
// create preference, return that:
return $this->set($name, $default);
}
}
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;
}
}