2016-09-01 16:23:39 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
use App\Album;
|
2016-09-05 15:28:56 +01:00
|
|
|
use App\Configuration;
|
2016-09-02 10:42:05 +01:00
|
|
|
use App\Facade\Theme;
|
2016-09-05 15:28:56 +01:00
|
|
|
use App\Facade\UserConfig;
|
|
|
|
use App\Helpers\ConfigHelper;
|
2016-09-01 16:23:39 +01:00
|
|
|
use App\Http\Controllers\Controller;
|
2016-09-05 15:28:56 +01:00
|
|
|
use App\Http\Requests\SaveSettingsRequest;
|
2016-09-05 16:46:11 +01:00
|
|
|
use App\Photo;
|
2016-09-05 15:28:56 +01:00
|
|
|
use Illuminate\Http\Request;
|
2016-09-01 16:23:39 +01:00
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
class DefaultController extends Controller
|
|
|
|
{
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
|
|
|
|
|
|
|
$albumCount = Album::all()->count();
|
2016-09-05 16:46:11 +01:00
|
|
|
$photoCount = Photo::all()->count();
|
2016-09-01 16:23:39 +01:00
|
|
|
|
2016-09-02 10:42:05 +01:00
|
|
|
return Theme::render('admin.index', [
|
2016-09-05 16:46:11 +01:00
|
|
|
'album_count' => $albumCount,
|
|
|
|
'photo_count' => $photoCount
|
2016-09-01 16:23:39 +01:00
|
|
|
]);
|
|
|
|
}
|
2016-09-05 15:28:56 +01:00
|
|
|
|
|
|
|
public function saveSettings(SaveSettingsRequest $request)
|
|
|
|
{
|
|
|
|
$updateKeys = [
|
|
|
|
'app_name',
|
2016-09-05 15:36:46 +01:00
|
|
|
'date_format',
|
|
|
|
'theme'
|
2016-09-05 15:28:56 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($updateKeys as $key)
|
|
|
|
{
|
|
|
|
$config = UserConfig::getOrCreateModel($key);
|
|
|
|
$config->value = $request->request->get($key);
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
2016-09-05 15:36:46 +01:00
|
|
|
$themeNamesLookup = UserConfig::allowedThemeNames();
|
|
|
|
|
2016-09-05 15:28:56 +01:00
|
|
|
return Theme::render('admin.settings', [
|
|
|
|
'config' => $config,
|
|
|
|
'date_formats' => $dateFormatsLookup,
|
2016-09-05 15:36:46 +01:00
|
|
|
'success' => $request->session()->get('success'),
|
|
|
|
'theme_names' => $themeNamesLookup
|
2016-09-05 15:28:56 +01:00
|
|
|
]);
|
|
|
|
}
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|