Administration/views/main/view.admin.settings.php

124 lines
4.2 KiB
PHP
Executable File

<?php
/**
* FuzeWorks Framework Administration Plugin.
*
* The FuzeWorks PHP FrameWork
*
* Copyright (C) 2013-2020 i15
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* @author i15
* @copyright Copyright (c) 2013 - 2020, i15. (https://i15.nl)
* @license https://opensource.org/licenses/MIT MIT License
*
* @since Version 1.3.0
*
* @version Version 1.3.0
*/
namespace Application\View;
use Application\Controller\SettingsController;
use FuzeWorks\Administration\AdminView;
use FuzeWorks\Administration\Attributes\DisplayAttribute;
use FuzeWorks\Administration\Attributes\HiddenAttribute;
use FuzeWorks\Administration\Attributes\IconAttribute;
use FuzeWorks\Administration\Attributes\PermissionAttribute;
use FuzeWorks\Administration\Attributes\PriorityAttribute;
use FuzeWorks\Controller;
use FuzeWorks\Exception\NotFoundException;
use FuzeWorks\Forms\Fields\CheckboxField;
use FuzeWorks\Forms\Fields\TextField;
use FuzeWorks\Forms\Forms;
use FuzeWorks\Priority;
class SettingsAdminView extends AdminView
{
/**
* @var SettingsController
*/
protected Controller $controller;
/**
* Displays a list of settings files
*/
#[DisplayAttribute("Config"), IconAttribute("cog"), PriorityAttribute(Priority::LOWEST)]
#[PermissionAttribute(["SUPER"])]
public function index()
{
$files = $this->controller->findSettingsFiles();
$this->layouts->assign('files', $files);
return $this->layouts->get('components/settings/overview');
}
/**
* @throws NotFoundException
*/
#[HiddenAttribute, DisplayAttribute("View config file")]
#[PermissionAttribute(["SUPER"])]
public function view(string $request)
{
// Determine parts
$parts = explode("/", $request);
$file = $parts[0];
$selector = intval($parts[1]);
// Select the file
$data = $this->controller->fetchFile($file, $selector);
// Create a form out of the data
/** @var Forms $forms */
$forms = $this->libraries->get("forms");
$form = $forms->getForm("ConfigEdit");
foreach ($data['data'] as $key => $value)
{
switch (gettype($value))
{
case "string":
case "integer":
$field = new TextField($key);
$field->setLabel($key)->setValue($value)->lock();
$form->field($field);
break;
case "boolean":
$field = new CheckboxField($key);
$field->setLabel($key)->setValue($value)->lock();
$form->field($field);
break;
default:
dump(gettype($value));
break;
}
}
// Assign and load layout
$this->layouts->assign('config', $data);
$this->layouts->assign('form', $form);
return $this->layouts->get('components/settings/view');
}
#[HiddenAttribute, DisplayAttribute("Edit config file")]
#[PermissionAttribute(["SUPER"])]
public function modify()
{
}
}