/** Datei: plugins/settings/library/ARUNOX/Plugins/Settings/Model.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Settings\API\v1; use ARUNOX\Core\Hooks; use ARUNOX\Core\Router; use ARUNOX\Plugins\REST; use ARUNOX\Plugins\Users; class Routes { public static function register() : void { /* ### MAIN ROUTES ############################## # */ Router::get('/settings', [ Controller::class, 'getAll' ]); Router::get('/settings/{id}', [ Controller::class, 'get' ]); Router::post('/settings', [ Controller::class, 'create' ]); Router::put('/settings/{id}', [ Controller::class, 'save' ]); Router::delete('/settings/{id}', [ Controller::class, 'delete' ]); /* ### REST ROUTES ############################## # */ if( class_exists( REST\Router::class ) ) { REST\Router::get('/settings', [ Controller::class, 'restConfigOverview' ]); REST\Router::get('/settings/{id}', [ Controller::class, 'restConfigDetails' ]); REST\Router::get('/settings/create', [ Controller::class, 'restConfigCreate' ]); REST\Router::get('/settings/{id}/delete', [ Controller::class, 'restConfigDelete' ]); REST\Router::post('/settings', [ Controller::class, 'restResponseCreate' ]); REST\Router::put('/settings/{id}', [ Controller::class, 'restResponseSave' ]); REST\Router::delete('/settings/{id}', [ Controller::class, 'restResponseDelete' ]); } /* ### MENU ROUTES ############################## # */ Hooks::add('router::get->api.v1.rest.routes', function( $routes ) { if( !Users\Model::isSuperadmin() ) return $routes; $routes[] = [ "path" => "/settings", "label" => "Settings", "icon" => "bi bi-gear", "menu" => "administration", ]; return $routes; }); } } /** Datei: plugins/settings/library/ARUNOX/Plugins/Settings/API/v1/Controller.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Settings\API\v1; use ARUNOX\HTTP; use ARUNOX\Core\Hooks; use ARUNOX\Plugins\REST; use ARUNOX\Plugins\Settings; use ARUNOX\API\BaseController; class Controller extends BaseController { /* ### VARIABLES ################################################ # */ protected static array $NOTIFY = [ "notfound" => "Setting nicht gefunden", "saved" => "Setting wurde erfolgreich gespeichert", "deleted" => "Setting wurde erfolgreich gelöscht", "created" => "Setting wurde erfolgreich erstellt", "notcreated" => "Setting konnte nicht erstellt werden", "notsaved" => "Assistent konnte nicht gespeichert werden", ]; /* ### PUBLIC GET FUNCTIONS ##################################### # */ public static function getAll() : array { return Settings\Model::getAll(); } public static function get( int $id ) : BaseEntity | HTTP\Response { if( $result = Settings\Model::get( $id ) ) return $result; return REST\Response::jsonResponse( 404, static::getNotify("notfound") ); } /* ### PUBLIC SAVE FUNCTIONS #################################### # */ public static function save( int $id, array $data ) : HTTP\Response { if( $result = Settings\Model::get( $id ) ) { if( $result->save( $data ) ) { return REST\Response::jsonResponse( 200, static::getNotify("saved") ); } return REST\Response::jsonResponse( 500, static::getNotify("notsaved") ); } return REST\Response::jsonResponse( 404, static::$NOTIFY["notfound"] ); } public static function create( array $data ) : HTTP\Response { if( $id = Settings\Model::save( $data ) ) { $result = Settings\Model::get( $id ); return REST\Response::jsonResponse( 200, static::$NOTIFY["created"], [ "data" => $result ] ); } return REST\Response::jsonResponse( 500, static::$NOTIFY["notfound"] ); } public static function delete( int $id ) : HTTP\Response { if( Settings\Model::delete( $id ) ) { return REST\Response::jsonResponse( 200, static::$NOTIFY["deleted"] ); } return REST\Response::jsonResponse( 500, static::$NOTIFY["notfound"] ); } /* ### PUBLIC VALIDATE FUNCTIONS ################################ # */ /* ### PUBLIC REST FUNCTIONS #################################### # */ /* ### PUBLIC REST RESPONSE FUNCTIONS ########################### # */ public static function restResponseSave( int $id, array $data ) : HTTP\Response { $result = static::save( $id, $data ); if( $result->isStatus( 200 ) ) { $data = Settings\Model::get( $id ); REST\Response::closeModals(); REST\Response::addUpdater( [ "data/table/row", $id ], $data ); } return static::restResponse( $result ); } public static function restResponseCreate( array $data ) : HTTP\Response { $result = static::create( $data ); if( $result->isStatus( 200 ) ) { REST\Response::closeModals(); REST\Response::redirect( "/settings" ); } return static::restResponse( $result ); } public static function restResponseDelete( int $id ) : HTTP\Response { REST\Response::closeModals(); $result = static::delete( $id ); if( $result->isStatus( 200 ) ) { REST\Response::redirect( "/settings" ); } return static::restResponse( $result ); } /* ### PUBLIC REST CONFIG FUNCTIONS ############################# # */ public static function restConfigOverview() : REST\Generator\Base\BaseGenerator { return REST\Response::addWrapper( "overview", "Setting" ) ->get() ->setApi( "/settings" ) ->setAction( "/settings/{id}" ) ->setOrder( "name", "asc" ) ->setSearch( TRUE ) ->addButton(...Hooks::filter( "rest.generator::button.name->create", [], "settings" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "name", TRUE, TRUE, TRUE, "settings" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->icon", [], "type", [], "settings" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "setting", TRUE, TRUE, TRUE, "settings" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->actions", [], [], FALSE, "settings" ))->get() ->addButton(...Hooks::filter( "rest.generator::action.name->edit", [], "settings" )) ->addButton(...Hooks::filter( "rest.generator::action.name->delete", [], "settings" )); } public static function restConfigDetails( int $id ) : REST\Generator\Base\BaseGenerator { $data = Settings\Model::get( $id ); $form = REST\Response::addModal( "details", "Setting bearbeiten" ) ->setData( $data ) ->setTitle( $data->type->getLabel() ) ->setIcon( $data->type->getIcon() ) ->setColor( $data->type->getColor() ) ->get() ->setAction( "/settings/{id}", "PUT" ) ->addButton(...Hooks::filter( "rest.generator::button.type->submit", [], "Speichern", "settings" )) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "name", TRUE, "settings" )); switch( $data->type->getValue() ) { case Settings\Type::Unknown : static::restConfigFormTypeUnknown( $form ); break; case Settings\Type::Value : static::restConfigFormTypeValue( $form ); break; case Settings\Type::List : static::restConfigFormTypeList( $form ); break; case Settings\Type::Switch : static::restConfigFormTypeSwitch( $form ); break; case Settings\Type::Mail : static::restConfigFormTypeMail( $form ); break; case Settings\Type::Url : static::restConfigFormTypeUrl( $form ); break; case Settings\Type::Number : static::restConfigFormTypeNumber( $form ); break; } return $form; } public static function restConfigCreate() : REST\Generator\Base\BaseGenerator { return REST\Response::addModal( "details", "Setting erstellen" ) ->get() ->setAction( "/settings", "POST" ) ->addButton(...Hooks::filter( "rest.generator::button.type->submit", [], "Erstellen", "settings" )) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "name", TRUE, "settings" )) ->top(); } public static function restConfigDelete( int $id ) : REST\Generator\Base\BaseGenerator { return REST\Response::addModal( "details", "Setting Löschen" ) ->setSize( REST\Wrapper\Modal\Size::sm ) ->get() ->setAction( "/settings/{$id}", "DELETE" ) ->addText( "Möchtest du wirklich den Datensatz (#{$id}) löschen? " ) ->addButton(...Hooks::filter( "rest.generator::button.type->cancel", [], NULL, "settings" )) ->addButton(...Hooks::filter( "rest.generator::button.type->delete", [], NULL, "settings" )) ->top(); } /* ### PUBLIC REST EXTENSION FUNCTIONS ########################## # */ public static function restConfigFormTypeUnknown( REST\Generator\Base\BaseGenerator $form ) : void { $form ->addField(...Hooks::filter( "rest.generator::control.type->textarea", [], "setting", TRUE, "settings" )) ->top(); } public static function restConfigFormTypeValue( REST\Generator\Base\BaseGenerator $form ) : void { $form ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "setting", TRUE, "settings" )) ->top(); } public static function restConfigFormTypeList( REST\Generator\Base\BaseGenerator $form ) : void { $form ->addField(...Hooks::filter( "rest.generator::control.type->textarea", [], "setting", TRUE, "settings" )) ->top(); } public static function restConfigFormTypeSwitch( REST\Generator\Base\BaseGenerator $form ) : void { $form ->addField(...Hooks::filter( "rest.generator::control.type->select", [], "setting", TRUE, TRUE, "settings" )) ->top(); } public static function restConfigFormTypeMail( REST\Generator\Base\BaseGenerator $form ) : void { $form ->addField(...Hooks::filter( "rest.generator::control.type->email", [], "setting", TRUE, "settings" )) ->top(); } public static function restConfigFormTypeUrl( REST\Generator\Base\BaseGenerator $form ) : void { $form ->addField(...Hooks::filter( "rest.generator::control.type->url", [], "setting", TRUE, "settings" )) ->top(); } public static function restConfigFormTypeNumber( REST\Generator\Base\BaseGenerator $form ) : void { $form ->addField(...Hooks::filter( "rest.generator::control.type->number", [], "setting", TRUE, "settings" )) ->top(); } } /** Datei: plugins/settings/library/ARUNOX/Plugins/Settings/Type.php **/ [ "color" => REST\Generator\Config\Color::Danger, "label" => "Unknown", "icon" => "bi bi-question-square" ], 1 => [ "color" => REST\Generator\Config\Color::Secondary, "label" => "Value", "icon" => "bi bi-pencil-square" ], 2 => [ "color" => REST\Generator\Config\Color::Primary, "label" => "List", "icon" => "bi bi-list-ul" ], 3 => [ "color" => REST\Generator\Config\Color::Success, "label" => "Switch", "icon" => "bi bi-toggles" ], 4 => [ "color" => REST\Generator\Config\Color::Secondary, "label" => "E-Mail-Address","icon" => "bi bi-envelope-at" ], 5 => [ "color" => REST\Generator\Config\Color::Secondary, "label" => "Url", "icon" => "bi bi-globe-americas" ], 6 => [ "color" => REST\Generator\Config\Color::Secondary, "label" => "Number", "icon" => "bi bi-123" ], ]; /* ### PUBLIC FUNCTIONS ######################################### # */ /* ### MAGIC FUNCTIONS ########################################## # */ // public function __construct( mixed $value, ?BaseEntity $parent = NULL ) { // parent::__construct( $value, $parent ); // } } /** Datei: plugins/settings/library/ARUNOX/Plugins/Settings/Entity.php **/ Attribute\DateTime::class, "date_edit" => Attribute\DateTime::class, "type" => Type::class, ]; /* ### PUBLIC FUNCTIONS ######################################### # */ protected function getType() { $type = Hooks::filter( "config::constants.type->{$this->name}", Type::Unknown ); return $this->attributes["type"] = new Type( $type, $this ); } /* ### MAGIC FUNCTIONS ########################################## # */ public function __construct() { $this->getType(); } } /** Datei: plugins/settings/hooks/generator/controls.php **/ setting.settings", function( array $config ) { if( $config["type"] == ARUNOX\Plugins\REST\Generator\Data\Form\Control\Type::Select ) { return array_replace_recursive( $config, [ "options" => Attribute\Status::getAll(), ]); } // show( $config ); return $config; }); /** Datei: plugins/settings/hooks/generator/columns.php **/ username.users", function( array $config ) { return array_replace_recursive( $config, [ "label" => "Benutzername", ]); }); Hooks::add("rest.generator::column.name->type.settings", function( array $config ) { return array_replace_recursive( $config, [ "icon" => "bi-code-square", "options" => Settings\Type::getAll(), ]); }); /** Datei: plugins/settings/hooks/init.php **/ * @copyright 2025 ARUNOX * @version 1.0.0 * @since 1.0.0 File is created */ use ARUNOX\Core\Hooks; use ARUNOX\Plugins\Settings; Hooks::add('public::api->init', [ Settings\API\v1\Routes::class, "register" ] ); /** Datei: plugins/settings/hooks/config.php **/ * @copyright 2025 ARUNOX * @version 1.0.0 * @since 1.0.0 File is created */ use ARUNOX\Core\Hooks; use ARUNOX\Plugins\Settings; Hooks::add('config::constants', function() { $settings = Settings\Model::getAll(); foreach( $settings as $setting ) { Hooks::add( "config::constants->{$setting->name}", function( $value ) use( $setting ) { return match( $setting->type->getValue() ) { Settings\Type::List => array_replace( $value, $setting->setting ), Settings\Type::Switch => !!$setting->setting, default => $setting->setting, }; }); } }, 5 ); Hooks::add( 'config::constants.type->SETTING_TYPE_0', function( $type ) { return Settings\Type::Unknown; }); Hooks::add( 'config::constants.type->SETTING_TYPE_1', function( $type ) { return Settings\Type::Value; }); Hooks::add( 'config::constants.type->SETTING_TYPE_2', function( $type ) { return Settings\Type::List; }); Hooks::add( 'config::constants.type->SETTING_TYPE_3', function( $type ) { return Settings\Type::Switch; }); Hooks::add( 'config::constants.type->SETTING_TYPE_4', function( $type ) { return Settings\Type::Mail; }); Hooks::add( 'config::constants.type->SETTING_TYPE_5', function( $type ) { return Settings\Type::Url; }); Hooks::add( 'config::constants.type->SETTING_TYPE_6', function( $type ) { return Settings\Type::Number; }); /** Datei: plugins/settings/config.php **/ * @copyright 2025 ARUNOX * @version 1.0.0 * @since 1.0.0 File is created */ /** Datei: plugins/settings/config/schema/v1.0.0.php **/ array ( 'columns' => array ( 'id' => 'INT NOT NULL AUTO_INCREMENT', 'date_create' => 'DATETIME DEFAULT_GENERATED DEFAULT \'CURRENT_TIMESTAMP\'', 'date_edit' => 'DATETIME DEFAULT_GENERATED ON UPDATE CURRENT_TIMESTAMP DEFAULT \'CURRENT_TIMESTAMP\'', 'name' => 'VARCHAR(25) NOT NULL', 'setting' => 'LONGTEXT', ), 'primary' => array ( 0 => 'id', ), 'indexes' => array ( 'settings_name_uindex' => array ( 0 => 'name', ), ), 'engine' => 'InnoDB', 'charset' => 'utf8mb3', ), );