/** Datei: plugins/websites/library/ARUNOX/Plugins/Websites/Domains/API/v1/Routes.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Websites\Domains\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 ); /* ### MENU ROUTES ############################## # */ Hooks::add('router::get->api.v1.rest.routes', function( $routes ) { $routes[] = [ "path" => Controller::getRoute(), "label" => Controller::getPlural(), "icon" => Controller::getIcon(), "menu" => "websites", ]; return $routes; }, 50 ); } } /** Datei: plugins/websites/library/ARUNOX/Plugins/Websites/Domains/API/v1/Controller.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Websites\Domains\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( "Domain", "Domains" )] #[PHP\Attributes\Controller\Icon( REST\Generator\Config\Icon::Link45deg )] #[PHP\Attributes\Controller\Route( "domains", Websites\API\v1\Controller::class )] #[PHP\Attributes\Database\Definitions\Model( Websites\Domains\Model::class )] class Controller extends BaseController { /* ### PUBLIC GET FUNCTIONS ##################################### # */ /** * @api * @method GET * * @route.path /websites/domains * @route.description Listet alle Logeinträge */ public static function getAllPrepared() : array { return parent::getAllPrepared(); } /** * @api * @method GET * * @route.path /websites/{origin}/domains * @route.description Listet alle Logeinträge */ public static function getByOriginPrepared( string $origin ) : array { return parent::getByOriginPrepared( $origin ); } /** * @api * @method GET * * @route.path /websites/domains/{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/domains/{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/domains * @route.description Erstellt einen neuen Kalender */ public static function createPrepared( array $data ) : HTTP\Response { return parent::createPrepared( $data ); } /** * @api * @method DELETE * * @route.path /websites/domains/{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/domains/{hashid}/status * @route.description Wechselt den Status (aktiv/inaktiv) eines Kalenders */ public static function toggleStatusPrepared( string $hashid ) : HTTP\Response { return parent::toggleStatusPrepared( $hashid ); } /** * @api * @method PATCH * * @route.path /websites/domains/{hashid}/generate * @route.description Wechselt den Status (aktiv/inaktiv) eines Kalenders */ public static function generate( string $hashid ) : HTTP\Response { Websites\Domains\Model::generate( $hashid ); header("Content-Type: application/json"); header("Cache-Control: no-cache"); header("X-Accel-Buffering: no"); for ($i = 0; $i <= 100; $i += 10) { $data = [ 'value' => $i, // 'color' => $i < 50 ? '#f00' : ($i < 100 ? '#ff0' : '#0f0'), 'label' => "Fortschritt: $i%" ]; echo json_encode($data) . "\n"; ob_flush(); flush(); } exit; } /** * @api * @method GET * * @route.path /websites/domains/{hashid}/generate * @route.description Wechselt den Status (aktiv/inaktiv) eines Kalenders */ public static function generateGET( string $hashid ) : HTTP\Response { Websites\Domains\Model::generate( $hashid ); exit; } /* ### PUBLIC VALIDATE FUNCTIONS ################################ # */ /* ### PUBLIC REST RESPONSE FUNCTIONS ########################### # */ /** * @internal rest * @method POST * * @route.path /websites/domains * @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( "/websites/domains/{$result->getBody("data", "hashid")}" ); } return static::restResponse( $result ); } /** * @internal rest * @method DELETE * * @route.path /websites/domains/{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( "/websites/domains" ); } return static::restResponse( $result ); } /** * @internal rest * @method PATCH * * @route.path /websites/domains/{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/domains/{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/domains/{$hashid}" ) ->setAction( "/websites/domains/{$hashid}", "PUT" ) ->addTab( static::getSingular() )->get() ->addChildren( static::restConfigInputs() ) ->parent() // ->addCallable( [ Calendars\Entries\API\v1\Controller::class, "restConfigTab" ], $hashid ) // ->addCallable( [ Calendars\Tasks\API\v1\Controller::class, "restConfigTab" ], $hashid ) ->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/domains/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/{origin}/domains/create * @route.description REST-Konfiguration für das Erstellen eines Kalenders (Formular) */ public static function restConfigCreateByOriginPrepared( bool | string $origin = FALSE ) : REST\Generator\Base\BaseGenerator { return parent::restConfigCreateByOriginPrepared( $origin ); } /** * @internal rest * @method GET * * @route.path /websites/domains/{hashid}/directory * @route.description REST-Konfiguration für Detailansicht eines Logeintrags */ public static function restConfigDirectory( string $hashid ) : REST\Generator\Base\BaseGenerator { // show( $hashid ); return REST\Response::addModal( "details", static::getSingular( "%t bearbeiten" ) ) ->get() // ->setApi( "/websites/domains/{$hashid}" ) ->setAction( "/websites/domains/{$hashid}/directory", "PATCH" ) ->addButton(...Hooks::filter( "rest.generator::button.type->cancel", [], NULL, "websites/domains" )) ->addButton(...Hooks::filter( "rest.generator::button.type->submit", [], NULL, "websites/domains" )) ; } /** * @internal rest * @method GET * * @route.path /websites/domains/{hashid}/generate * @route.description REST-Konfiguration für Detailansicht eines Logeintrags */ public static function restConfigGenerate( string $hashid ) : REST\Generator\Base\BaseGenerator { // show( $hashid ); return REST\Response::addModal( "details", Websites\API\v1\Controller::getSingular( "%t erstellen" ) ) ->get() // ->setApi( "/websites/domains/{$hashid}" ) ->setAction( "/websites/domains/{$hashid}/directory", "PATCH" ) ->addField(...Hooks::filter( "rest.generator::control.type->progress", [ "api" => [ "route" => static::getRoute( $hashid, "generate" ), "method" => "PATCH", ], ], "domain", TRUE, "websites/domains" )) // ->addButton(...Hooks::filter( "rest.generator::button.type->cancel", [], NULL, "websites/domains" )) // ->addButton(...Hooks::filter( "rest.generator::button.type->submit", [], NULL, "websites/domains" )) ; } /** * @internal rest * @method GET * * @route.path /websites/domains/{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 parent::restConfigDeletePrepared( $hashid ); } /* ### PUBLIC REST EXTENSION FUNCTIONS ########################## # */ public static function restConfigTab( REST\Generator\Base\BaseGenerator $rest, null|string $hashid = NULL ) : void { parent::restConfigTabPrepared( $rest, $hashid ); } public static function restConfigTable( null|string $hashid = NULL ) : REST\Generator\Base\BaseGenerator { $rest = REST\Generator\Data\Table::create() ->setApi( static::getRoute( "1:{$hashid}" ) ) ->setAction( static::getRoute( "{hashid}" ) ) ->setOrder( "title", "asc" ) ->setSearch( TRUE ) ->addButton(...Hooks::filter( "rest.generator::button.name->create", [], "websites/domains" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->status", [ "options" => Websites\Domains\Status::getAll(), ], "status", [], "websites/domains", "hashid" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "url", TRUE, TRUE, TRUE, "websites/domains" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "target_dir", TRUE, TRUE, TRUE, "websites/domains" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "connection.host", TRUE, TRUE, TRUE, "websites/domains" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->datetime", [], "date_edit", TRUE, FALSE, TRUE, "websites/domains" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->actions", [], [], FALSE, "websites/domains" ))->get() ->addButton(...Hooks::filter( "rest.generator::action.name->edit", [], "websites/domains", "hashid" )) ->addButton(...Hooks::filter( "rest.generator::action.name->delete", [], "websites/domains", "hashid" )) ->addButton(...Hooks::filter( "rest.generator::action.name->default", [ "label" => Websites\API\v1\Controller::getSingular( "%t erstellen" ), "action" => static::getRoute( "{hashid}", "generate" ), "icon" => REST\Generator\Config\Icon::Gear, "color" => REST\Generator\Config\Color::Warning, ], "websites/domains", "hashid" )) ->addButton(...Hooks::filter( "rest.generator::action.name->link", [ "action" => "{url}", ], "websites/domains", "hashid" )) ; return $rest; } public static function restConfigInputs() : array { $rest = REST\Generator\Data\Form::create() ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "domain", TRUE, "websites/domains" )) ->addField(...Hooks::filter( "rest.generator::control.type->select", [ "label" => Websites\Connections\API\v1\Controller::getSingular(), "options" => Websites\Connections\Model::getAsOptions( "name" ), ], "connection_id", TRUE, TRUE, "websites/domains" )) ->addField(...Hooks::filter( "rest.generator::control.type->text", [ // "action" => static::getRoute( "{hashid}", "directory" ) ], "target_dir", TRUE, "websites/domains" )) ; return $rest->top()->getChildren(); } public static function restConfigOrigin( bool|string $origin ) : REST\Generator\Base\BaseGenerator { $rest = REST\Generator\Data\Form::create(); if( $origin === FALSE ) { return $rest->addField(...Hooks::filter( "rest.generator::control.type->select", [ "label" => Websites\API\v1\Controller::getSingular(), "options" => Websites\Model::getAsOptions( "title" ), ], "origin_id", TRUE, FALSE, "websites/domains" )); } $origin_id = Websites\Model::getValue( $origin, "id" ); return $rest->addField(...Hooks::filter( "rest.generator::control.type->hidden", [], "origin_id", $origin_id ?? $origin, "websites/domains" )); } }