/** Datei: plugins/systems/library/ARUNOX/Plugins/Systems/Plugins/API/v1/Routes.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Systems\Plugins\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::addAll( Controller::class ); } } /** Datei: plugins/systems/library/ARUNOX/Plugins/Systems/Plugins/API/v1/Controller.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Systems\Plugins\API\v1; use ARUNOX\HTTP; use ARUNOX\API\PHP; use ARUNOX\Core\Hooks; use ARUNOX\API\Method; use ARUNOX\Core\Router; use ARUNOX\Plugins\REST; use ARUNOX\Plugins\Systems; use ARUNOX\Database\Attribute; use ARUNOX\API\BaseController; use ARUNOX\Database\BaseEntity; #[PHP\Attributes\Controller\Label( "Plugin", "Plugins" )] #[PHP\Attributes\Database\Definitions\Model( Systems\Plugins\Model::class )] class Controller extends BaseController { /* ### VARIABLES ################################################ # */ protected static array $NOTIFY = [ "notfound" => "Plugin nicht gefunden", "saved" => "Plugin wurde erfolgreich gespeichert", "deleted" => "Plugin wurde erfolgreich gelöscht", "created" => "Plugin wurde erfolgreich erstellt", "statuschanged.0" => "Plugin wurde erfolgreich deaktiviert", "statuschanged.1" => "Plugin wurde erfolgreich aktiviert", "statuschanged.2" => "Plugin wurde als notwendig markiert", "notcreated" => "Plugin konnte nicht erstellt werden", "notsaved" => "Plugin konnte nicht gespeichert werden", "systemneeded" => "Plugin wird vom System benötigt", ]; /* ### PUBLIC GET FUNCTIONS ##################################### # */ /** * @api * @method GET * * @route.path /systems/plugins * @route.description Gibt eine Liste aller verfügbaren System-Plugins zurück */ public static function getAll() : array { return Systems\Plugins\Model::getAll([ "status" => "1", "system_id" => SYSTEM->id, ]); } /** * @api * @method GET * * @route.path /systems/plugins/routes * @route.description Gibt alle verfügbaren Routen der Plugins zurück */ public static function getAllRoutes() : array { $routes = Router::getRoutes(); $routes = array_filter( $routes, fn( $item ) => $item["method"] == Method::GET ); $routes = array_filter( $routes, fn( $item ) => $item["config"] ?? FALSE ); $routes = array_map( fn( $item ) => [ "name" => "{$item["method"]} {$item["path"]}", "method" => $item["method"], "route" => $item["path"], "api" => $item["config"]["api"] ?? $item["config"]["internal"] ?? FALSE, "link" => $item["config"]["route"]["link"] ?? false, "query" => $item["config"]["route"]["query"] ?? false, "alternatives" => $item["config"]["route"]["alternative"] ?? false, "description" => $item["config"]["route"]["description"], ], $routes ); // Aktualisiere Dich! Ich brauche keine Auswertung $routes = array_filter( $routes, fn( $item ) => $item["api"] ); // show( $rest ); // show( $routes ); return $routes; } /** * @api * @method GET * * @route.path /systems/plugins/{id} * @route.description Gibt die Details eines einzelnen System-Plugins zurück */ public static function get( int $id ) : BaseEntity | HTTP\Response { if( $result = Systems\Plugins\Model::get( $id ) ) return $result; return REST\Response::jsonResponse( 404, static::$NOTIFY["notfound"] ); } /* ### PUBLIC SAVE FUNCTIONS #################################### # */ /** * @api * @method PATCH * * @route.path /systems/plugins/{id}/status * @route.description Aktiviert oder deaktiviert ein Plugin (Status-Umschaltung) */ public static function toggleStatus( int $id ) : HTTP\Response { if( $result = Systems\Plugins\Model::get( $id ) ) { if( $result->system_need ) { return REST\Response::autoResponse( "409", static::$NOTIFY["systemneeded"] ); } $result->toggleStatus( TRUE ); return REST\Response::autoResponse( 200, static::$NOTIFY["statuschanged.{$result->status->getValue()}"], [ "data" => $result ] ); } return REST\Response::autoResponse( 404, static::$NOTIFY["notfound"] ); } /* ### PUBLIC VALIDATE FUNCTIONS ################################ # */ /* ### PUBLIC REST RESPONSE FUNCTIONS ########################### # */ /** * @internal rest * @method PATCH * * @route.path /systems/plugins/{id}/status * @route.description Gibt die REST-Antwort zur Status-Umschaltung eines Plugins zurück (z. B. für Notifications) */ public static function restResponseToggleStatusPrepared( string $hashid ) : HTTP\Response { return parent::restResponseToggleStatusPrepared( $hashid ); } /* ### PUBLIC REST CONFIG FUNCTIONS ############################# # */ /** * @internal rest * @method GET * * @route.path /systems/plugins * @route.description Liefert die UI-Konfiguration für die Plugin-Tabelle im REST-Frontend */ public static function restConfigOverview() : REST\Generator\Base\BaseGenerator { return REST\Response::addWrapper( "overview", "Setting" ) ->get() ->setApi( "/systems/plugins" ) ->setAction( "/systems/plugins/{id}" ) ->setOrder( "plugin", "asc" ) ->setSearch( TRUE ) ->addButton(...Hooks::filter( "rest.generator::button.name->create", [], "systems/plugins" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "plugin", TRUE, TRUE, TRUE, "systems/plugins" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->icon", [], "type", [], "systems/plugins" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "setting", TRUE, TRUE, TRUE, "systems/plugins" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->actions", [], [], FALSE, "systems/plugins" ))->get() ->addButton(...Hooks::filter( "rest.generator::action.name->edit", [], "systems/plugins" )) ->addButton(...Hooks::filter( "rest.generator::action.name->delete", [], "systems/plugins" )) ->top(); } /* ### PUBLIC REST EXTENSION FUNCTIONS ########################## # */ public static function restConfigTable( int|string $hashid ) : REST\Generator\Base\BaseGenerator { return REST\Generator\Data\Table::create() ->setApi( "/api/v1/systems/{$hashid}/plugins" ) ->setOrder( "plugin", "asc" ) ->setSearch( TRUE ) ->addColumn(...Hooks::filter( "rest.generator::column.type->status", [ "options" => Systems\Plugins\Status::getAll(), ], "status", [], "systems/plugins", "hashid" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->icon", [ "icon" => "bi-lightning-charge-fill", "options" => Attribute\Status::getAll(), ], "preload", [], "systems/plugins" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "plugin", TRUE, TRUE, TRUE, "systems/plugins" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "description", TRUE, TRUE, TRUE, "systems/plugins" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "version", TRUE, TRUE, TRUE, "systems/plugins" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "author", TRUE, TRUE, TRUE, "systems/plugins" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "dependencies", TRUE, TRUE, TRUE, "systems/plugins" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->datetime", [], "date_edit", FALSE, FALSE, TRUE, "systems/plugins" )) ->top(); } }