mirror of
https://github.com/linuxserver/Heimdall.git
synced 2025-11-01 05:27:45 +09:00
trying to get session settings to work
This commit is contained in:
@@ -80,7 +80,9 @@ class SettingsController extends Controller
|
|||||||
$setting_value = $data->value;
|
$setting_value = $data->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
$user->settings()->updateExistingPivot($setting->id, ['value' => $setting_value]);
|
$user->settings()->detach($setting->id);
|
||||||
|
$user->settings()->save($setting, ['uservalue' => $setting_value]);
|
||||||
|
|
||||||
$route = route('settings.index', [], false);
|
$route = route('settings.index', [], false);
|
||||||
return redirect($route)
|
return redirect($route)
|
||||||
->with([
|
->with([
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ use Illuminate\Support\ServiceProvider;
|
|||||||
use Artisan;
|
use Artisan;
|
||||||
use Schema;
|
use Schema;
|
||||||
use App\Setting;
|
use App\Setting;
|
||||||
|
use App\User;
|
||||||
|
use Session;
|
||||||
|
|
||||||
class AppServiceProvider extends ServiceProvider
|
class AppServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
@@ -32,7 +34,9 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
}
|
}
|
||||||
if(is_file(database_path('app.sqlite'))) {
|
if(is_file(database_path('app.sqlite'))) {
|
||||||
if(Schema::hasTable('settings')) {
|
if(Schema::hasTable('settings')) {
|
||||||
if($bg_image = Setting::fetch('background_image')) {
|
die("s: ".\Session::get('current_user'));
|
||||||
|
//die("c: ".User::currentUser());
|
||||||
|
if($bg_image = Setting::_fetch('background_image', User::currentUser())) {
|
||||||
$alt_bg = ' style="background-image: url(/storage/'.$bg_image.')"';
|
$alt_bg = ' style="background-image: url(/storage/'.$bg_image.')"';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -157,10 +157,10 @@ class Setting extends Model
|
|||||||
*/
|
*/
|
||||||
public static function _fetch($key, $user=null)
|
public static function _fetch($key, $user=null)
|
||||||
{
|
{
|
||||||
$cachekey = ($user === null) ? $key : $key.'-'.$user->id;
|
#$cachekey = ($user === null) ? $key : $key.'-'.$user->id;
|
||||||
if (Setting::cached($cachekey)) {
|
#if (Setting::cached($cachekey)) {
|
||||||
return Setting::$cache[$cachekey];
|
# return Setting::$cache[$cachekey];
|
||||||
} else {
|
#} else {
|
||||||
$find = self::where('key', '=', $key)->first();
|
$find = self::where('key', '=', $key)->first();
|
||||||
|
|
||||||
if (!is_null($find)) {
|
if (!is_null($find)) {
|
||||||
@@ -168,25 +168,33 @@ class Setting extends Model
|
|||||||
$value = $find->value;
|
$value = $find->value;
|
||||||
} else { // not system variable so use user specific value
|
} else { // not system variable so use user specific value
|
||||||
// check if user specified value has been set
|
// check if user specified value has been set
|
||||||
$usersetting = $user->settings->where('id', $find->id)->first();
|
//print_r($user);
|
||||||
//die(print_r($usersetting));
|
$usersetting = $user->settings()->where('id', $find->id)->first();
|
||||||
|
//print_r($user->settings);
|
||||||
|
//die(var_dump($usersetting));
|
||||||
//->pivot->value;
|
//->pivot->value;
|
||||||
|
//echo "user: ".$user->id." --- ".$usersettings;
|
||||||
if(isset($usersetting) && !empty($usersetting)) {
|
if(isset($usersetting) && !empty($usersetting)) {
|
||||||
$value = $usersetting->pivot->value;
|
$value = $usersetting->pivot->uservalue;
|
||||||
} else { // if not get default from base setting
|
} else { // if not get default from base setting
|
||||||
//$user->settings()->save($find, ['value' => $find->value]);
|
//$user->settings()->save($find, ['value' => $find->value]);
|
||||||
$user->settings()->updateExistingPivot($find->id, ['value' => $find->value]);
|
#$has_setting = $user->settings()->where('id', $find->id)->exists();
|
||||||
|
#if($has_setting) {
|
||||||
|
# $user->settings()->updateExistingPivot($find->id, ['uservalue' => (string)$find->value]);
|
||||||
|
#} else {
|
||||||
|
# $user->settings()->save($find, ['uservalue' => (string)$find->value]);
|
||||||
|
#}
|
||||||
$value = $find->value;
|
$value = $find->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Setting::add($cachekey, $value);
|
#Setting::add($cachekey, $value);
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
#}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -267,7 +275,7 @@ class Setting extends Model
|
|||||||
*/
|
*/
|
||||||
public function users()
|
public function users()
|
||||||
{
|
{
|
||||||
return $this->belongsToMany('App\User')->withPivot('value');
|
return $this->belongsToMany('App\User')->using('App\SettingUser')->withPivot('uservalue');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function user()
|
public static function user()
|
||||||
|
|||||||
10
app/SettingUser.php
Normal file
10
app/SettingUser.php
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||||
|
|
||||||
|
class SettingUser extends Pivot
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
@@ -40,7 +40,7 @@ class User extends Authenticatable
|
|||||||
*/
|
*/
|
||||||
public function settings()
|
public function settings()
|
||||||
{
|
{
|
||||||
return $this->belongsToMany('App\Setting')->withPivot('value');
|
return $this->belongsToMany('App\Setting')->withPivot('uservalue');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function currentUser()
|
public static function currentUser()
|
||||||
|
|||||||
Reference in New Issue
Block a user