Setting categorization system
This categorization system aims to prevent mixing different options together.
This commit is contained in:
@@ -22,11 +22,33 @@
|
||||
namespace App\Helpers;
|
||||
|
||||
use App\Options as Option;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* The options class. A simple wrapper around the model. Could be a repository, but we're not using that design pattern just yet
|
||||
*/
|
||||
class Options
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns an assortment of settings found in the mentioned category
|
||||
*
|
||||
* @param $category The category
|
||||
* @return Collection The settings in this category
|
||||
*/
|
||||
public function getCategory(string $category): Collection
|
||||
{
|
||||
$options = Option::where('option_category', $category)->get();
|
||||
if ($options->isEmpty())
|
||||
{
|
||||
throw new \Exception('There are no options in category ' . $category);
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
|
||||
public function getOption(string $option): string
|
||||
{
|
||||
$value = Cache::get($option);
|
||||
@@ -47,12 +69,14 @@ class Options
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function setOption(string $option, string $value, string $description)
|
||||
// Null categories are settings without categories and will appear ungrouped
|
||||
public function setOption(string $option, string $value, string $description, string $category = null)
|
||||
{
|
||||
Option::create([
|
||||
'option_name' => $option,
|
||||
'option_value' => $value,
|
||||
'friendly_name' => $description,
|
||||
'option_category' => $category
|
||||
]);
|
||||
|
||||
Cache::put($option, $value, now()->addDay());
|
||||
|
@@ -36,17 +36,17 @@ class OptionsController extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
// TODO: Obtain this from the facade
|
||||
$options = Option::all();
|
||||
|
||||
return view('dashboard.administration.settings')
|
||||
->with('options', $options)
|
||||
->with('security', [
|
||||
'secPolicy' => Options::getOption('pw_security_policy'),
|
||||
'graceperiod' => Options::getOption('graceperiod'),
|
||||
'pwExpiry' => Options::getOption('password_expiry'),
|
||||
'requiresPMC' => Options::getOption('requireGameLicense'),
|
||||
'enforce2fa' => Options::getOption('force2fa')
|
||||
->with([
|
||||
'options' => Options::getCategory('notifications'),
|
||||
'security' => [ // We could use the method above, but we need to set these names here for greater control in the template. This would nto be feasible for many options, we'd need to use a loop and the category method.
|
||||
'secPolicy' => Options::getOption('pw_security_policy'),
|
||||
'graceperiod' => Options::getOption('graceperiod'),
|
||||
'pwExpiry' => Options::getOption('password_expiry'),
|
||||
'requiresPMC' => Options::getOption('requireGameLicense'),
|
||||
'enforce2fa' => Options::getOption('force2fa')
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user