105 lines
2.7 KiB
PHP
105 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Album;
|
|
use App\Configuration;
|
|
use App\Facade\Theme;
|
|
use App\Facade\UserConfig;
|
|
use App\Helpers\ConfigHelper;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\SaveSettingsRequest;
|
|
use App\Photo;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class DefaultController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$this->authorize('admin-access');
|
|
|
|
$albumCount = Album::all()->count();
|
|
$photoCount = Photo::all()->count();
|
|
|
|
return Theme::render('admin.index', [
|
|
'album_count' => $albumCount,
|
|
'photo_count' => $photoCount
|
|
]);
|
|
}
|
|
|
|
public function saveSettings(SaveSettingsRequest $request)
|
|
{
|
|
$checkboxKeys = [
|
|
'allow_self_registration',
|
|
'require_email_verification',
|
|
];
|
|
$updateKeys = [
|
|
'app_name',
|
|
'date_format',
|
|
'sender_address',
|
|
'sender_name',
|
|
'theme'
|
|
];
|
|
|
|
$defaults = UserConfig::defaults();
|
|
|
|
foreach ($updateKeys as $key)
|
|
{
|
|
$config = UserConfig::getOrCreateModel($key);
|
|
$config->value = $request->request->get($key);
|
|
|
|
if (isset($defaults[$key]) && $defaults[$key] == $config->value)
|
|
{
|
|
$config->delete();
|
|
}
|
|
else
|
|
{
|
|
$config->save();
|
|
}
|
|
}
|
|
|
|
foreach ($checkboxKeys as $key)
|
|
{
|
|
$config = UserConfig::getOrCreateModel($key);
|
|
$config->value = ($request->request->get($key) == 'on' ? 1 : 0);
|
|
|
|
if (isset($defaults[$key]) && $defaults[$key] == $config->value)
|
|
{
|
|
$config->delete();
|
|
}
|
|
else
|
|
{
|
|
$config->save();
|
|
}
|
|
}
|
|
|
|
$request->session()->flash('success', trans('admin.settings_saved_message'));
|
|
return redirect(route('admin.settings'));
|
|
}
|
|
|
|
public function settings(Request $request)
|
|
{
|
|
$this->authorize('admin-access');
|
|
|
|
// Load the current configuration
|
|
$config = array_merge(UserConfig::defaults(), UserConfig::getAll());
|
|
|
|
$dateFormats = UserConfig::allowedDateFormats();
|
|
$dateFormatsLookup = [];
|
|
|
|
foreach ($dateFormats as $dateFormat)
|
|
{
|
|
$dateFormatsLookup[$dateFormat] = date($dateFormat);
|
|
}
|
|
|
|
$themeNamesLookup = UserConfig::allowedThemeNames();
|
|
|
|
return Theme::render('admin.settings', [
|
|
'config' => $config,
|
|
'date_formats' => $dateFormatsLookup,
|
|
'success' => $request->session()->get('success'),
|
|
'theme_names' => $themeNamesLookup
|
|
]);
|
|
}
|
|
} |