/** Datei: plugins/websites/library/ARUNOX/Plugins/Websites/Connections/API/v1/Routes.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Websites\Connections\API\v1; use ARUNOX\Core\Hooks; use ARUNOX\Core\Router; use ARUNOX\Plugins\REST; class Routes { public static function register() : void { /* ### MAIN ROUTES ############################## # */ Router::addAll( Controller::class ); } } /** Datei: plugins/websites/library/ARUNOX/Plugins/Websites/Connections/API/v1/Controller.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Websites\Connections\API\v1; use ARUNOX\HTTP; use ARUNOX\API\PHP; use ARUNOX\Core\Hooks; use ARUNOX\Plugins\Logs; use ARUNOX\Plugins\REST; use ARUNOX\Plugins\Websites; use ARUNOX\API\BaseController; use ARUNOX\Database\BaseEntity; #[PHP\Attributes\Controller\Label( "Verbindung", "Verbindungen" )] #[PHP\Attributes\Controller\Icon( REST\Generator\Config\Icon::Plug )] #[PHP\Attributes\Controller\Route( "connections", Websites\API\v1\Controller::class )] #[PHP\Attributes\Database\Definitions\Model( Websites\Connections\Model::class )] class Controller extends BaseController { /* ### PUBLIC GET FUNCTIONS ##################################### # */ /** * @api * @method GET * * @route.path /websites/connections * @route.description Listet alle Logeinträge */ public static function getAllPrepared() : array { return parent::getAllPrepared(); } /** * @api * @method GET * * @route.path /websites/connections/{hashid} * @route.description Gibt einen einzelnen Logeintrag anhand der ID zurück */ public static function getPrepared( string $hashid ) : BaseEntity | HTTP\Response { return parent::getPrepared( $hashid ); } /* ### PUBLIC SAVE FUNCTIONS #################################### # */ /** * @api * @method PUT * * @route.path /websites/connections/{hashid} * @route.description Speichert Änderungen an einem bestehenden Termin */ public static function savePrepared( string $hashid, array $data ) : HTTP\Response { return parent::savePrepared( $hashid, $data ); } /** * @api * @method POST * * @route.path /websites/connections * @route.description Erstellt einen neuen Kalender */ public static function createPrepared( array $data ) : HTTP\Response { return parent::createPrepared( $data ); } /** * @api * @method DELETE * * @route.path /websites/connections/{hashid} * @route.description Löscht ein Logeintrag anhand der ID */ public static function deletePrepared( string $hashid ) : HTTP\Response { return parent::deletePrepared( $hashid ); } /** * @api * @method PATCH * * @route.path /websites/connections/{hashid}/status * @route.description Wechselt den Status (aktiv/inaktiv) eines Kalenders */ public static function toggleStatusPrepared( string $hashid ) : HTTP\Response { return parent::toggleStatusPrepared( $hashid ); } /* ### PUBLIC VALIDATE FUNCTIONS ################################ # */ /* ### PUBLIC REST RESPONSE FUNCTIONS ########################### # */ /** * @internal rest * @method PUT * * @route.path /websites/connections/{hashid} * @route.description REST-Antwort nach dem Speichern eines Termins */ public static function restResponseSave( string $hashid, array $data ) : HTTP\Response { $result = static::savePrepared( $hashid, $data ); if( $result->isStatus( 200 ) ) { $data = Websites\Connections\Model::get( $hashid ); REST\Response::closeModals(); REST\Response::addUpdater( [ "data/table/row", $hashid ], $data ); } return static::restResponse( $result ); } /** * @internal rest * @method POST * * @route.path /websites/connections * @route.description REST-Antwort nach dem Erstellen eines Kalenders */ public static function restResponseCreate( array $data ) : HTTP\Response { $result = static::createPrepared( $data ); if( $result->isStatus( 200 ) ) { REST\Response::closeModals(); REST\Response::redirect( "/calendars#categories" ); } return static::restResponse( $result ); } /** * @internal rest * @method DELETE * * @route.path /websites/connections/{hashid} * @route.description REST-Antwort nach dem Löschen eines Logeintrag */ public static function restResponseDelete( string $hashid ) : HTTP\Response { REST\Response::closeModals(); $result = static::deletePrepared( $hashid ); if( $result->isStatus( 200 ) ) { REST\Response::redirect( "/calendars#categories" ); } return static::restResponse( $result ); } /** * @internal rest * @method PATCH * * @route.path /websites/connections/{hashid}/status * @route.description REST-Antwort zur Status-Umschaltung eines Kalenders */ public static function restResponseToggleStatusPrepared( string $hashid ) : HTTP\Response { return parent::restResponseToggleStatusPrepared( $hashid ); } /* ### PUBLIC REST CONFIG FUNCTIONS ############################# # */ /** * @internal rest * @method GET * * @route.path /websites/connections/{hashid} * @route.description REST-Konfiguration für Detailansicht eines Logeintrags */ public static function restConfigDetails( string $hashid ) : REST\Generator\Base\BaseGenerator { return REST\Response::addModal( "details", static::getSingular( "%t bearbeiten" ) ) ->setSize( "equal" ) ->setWidth("lg") ->get() ->setApi( "/websites/connections/{$hashid}" ) ->setAction( "/websites/connections/{$hashid}", "PUT" ) ->addTab( static::getSingular() )->get() ->addChildren( Websites\Connections\API\v1\Controller::restConfigInputs() ) ->parent() ->addCallable( [ Logs\API\v1\Controller::class, "restConfigTab" ], $hashid ) ->addTab( "Speichern" )->get() ->setColor( REST\Generator\Config\Color::Primary ) ->setIcon( "bi bi-save" ) ->setType( "submit" ) ; } /** * @internal rest * @method GET * * @route.path /websites/connections/create * @route.description REST-Konfiguration für das Erstellen eines Kalenders (Formular) */ public static function restConfigCreatePrepared() : REST\Generator\Base\BaseGenerator { return parent::restConfigCreatePrepared(); } /** * @internal rest * @method GET * * @route.path /websites/connections/{hashid}/delete * @route.description REST-Konfiguration für die Lösch-Bestätigung eines Logeintrags */ public static function restConfigDeletePrepared( string $hashid ) : REST\Generator\Base\BaseGenerator { return REST\Response::addModal( "details", static::getSingular( "%t löschen" ) ) ->setSize( REST\Wrapper\Modal\Size::sm ) ->get() ->setAction( "/websites/connections/{$hashid}", "DELETE" ) ->addText( "Möchtest du wirklich den Datensatz (#{$hashid}) löschen? " ) ->addButton(...Hooks::filter( "rest.generator::button.type->cancel", [], NULL, "websites/connections" )) ->addButton(...Hooks::filter( "rest.generator::button.type->delete", [], NULL, "websites/connections" )); } /* ### PUBLIC REST EXTENSION FUNCTIONS ########################## # */ public static function restConfigTable( null|string $hashid = NULL ) : REST\Generator\Base\BaseGenerator { $rest = REST\Generator\Data\Table::create() ->setApi( "/websites/connections?origin={$hashid}" ) ->setAction( "/websites/connections/{hashid}" ) ->setOrder( "title", "asc" ) ->setSearch( TRUE ) ->addButton(...Hooks::filter( "rest.generator::button.name->create", [], "websites/connections" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->status", [ "options" => Websites\Connections\Status::getAll(), ], "status", [], "websites/connections", "hashid" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "host", TRUE, TRUE, TRUE, "websites/connections" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "port", TRUE, TRUE, TRUE, "websites/connections" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "username", TRUE, TRUE, TRUE, "websites/connections" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->datetime", [], "date_edit", TRUE, FALSE, TRUE, "websites/connections" )) // ->addColumn(...Hooks::filter( "rest.generator::column.type->actions", [], [], FALSE, "websites/connections" ))->get() // ->addButton(...Hooks::filter( "rest.generator::action.name->edit", [], "websites/connections", "hashid" )) // ->addButton(...Hooks::filter( "rest.generator::action.name->delete", [], "websites/connections", "hashid" )); ; return $rest; } public static function restConfigInputs() : array { $rest = REST\Generator\Data\Form::create() ->addGroup() ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "title", TRUE, "websites/connections" )) ->addField(...Hooks::filter( "rest.generator::control.type->select", [ "options" => REST\Generator\Config\Icon::getAsOptions(), ], "icon_name", TRUE, TRUE, "websites/connections" )) ->addField(...Hooks::filter( "rest.generator::control.type->select", [ "options" => REST\Generator\Config\Color::getAsOptions(), ], "icon_color", TRUE, TRUE, "websites/connections" )) ->parent() ->addGroup() ->addField(...Hooks::filter( "rest.generator::control.type->textarea", [ "lines" => 3, ], "description", FALSE, "websites/connections" )) ; return $rest->top()->getChildren(); } }