/** Datei: plugins/events/library/ARUNOX/Plugins/Events/API/v1/Routes.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Events\API\v1; use ARUNOX\Core\Hooks; use ARUNOX\Core\Router; use ARUNOX\Plugins\Users; class Routes { public static function register() : void { Router::get('/api/v1/events', [ Controller::class, 'getAll' ]); Router::get('/api/v1/events/create', [ Controller::class, 'restConfigCreate' ]); Router::post('/api/v1/events', [ Controller::class, 'create' ]); Router::get('/api/v1/events/{id}', [ Controller::class, 'get' ]); Router::put('/api/v1/events/{id}', [ Controller::class, 'save' ]); Router::patch('/api/v1/events/{id}/status', [ Controller::class, 'toggleStatus' ]); Router::get('/api/v1/events/{id}/delete', [ Controller::class, 'restConfigDelete' ]); Router::delete('/api/v1/events/{id}', [ Controller::class, 'delete' ]); Hooks::add('router::get->api.v1.rest.routes', function( $routes ) { $routes[] = [ "path" => "/events", "label" => "Events", "icon" => "bi bi-ticket-detailed", "menu" => "content", ]; return $routes; }); } } /** Datei: plugins/events/library/ARUNOX/Plugins/Events/API/v1/Controller.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Events\API\v1; use ARUNOX\HTTP; use ARUNOX\Core\Hooks; use ARUNOX\Plugins\REST; use ARUNOX\Plugins\Events; use ARUNOX\API\BaseController; class Controller extends BaseController { /* ### VARIABLES ################################################ # */ protected static array $NOTIFY = [ "notfound" => "Event nicht gefunden", "saved" => "Event wurde erfolgreich gespeichert", "deleted" => "Event wurde erfolgreich gelöscht", "created" => "Event wurde erfolgreich erstellt", "notcreated" => "Event konnte nicht erstellt werden", ]; /* ### PUBLIC GET FUNCTIONS ##################################### # */ public function getAll() : HTTP\Response { $results = Events\Model::getAll(); static::restConfigOverview( $results ); return REST\Response::jsonResponse(); } public function get( int $id ) : HTTP\Response { if( $result = Events\Model::get( $id ) ) { static::restConfigDetails( $result ); } else REST\Response::addNotify( "danger", static::getNotify("notfound") ); return REST\Response::jsonResponse(); } /* ### PUBLIC SAVE FUNCTIONS #################################### # */ public function save( int $id, array $data ) : HTTP\Response { if( $result = Events\Model::get( $id ) ) { $result->save( $data ); REST\Response::addNotify( "success", static::getNotify("saved") ); REST\Response::closeModals(); REST\Response::addUpdater( [ "data/table/row", $id ], $result ); } else REST\Response::addNotify( "danger", static::getNotify("notfound") ); return REST\Response::jsonResponse(); } public function create( array $data ) : HTTP\Response { if( $id = Events\Model::save( $data ) ) { REST\Response::addNotify( "success", static::getNotify("created") ); REST\Response::closeModals(); REST\Response::redirect( "/events" ); } else REST\Response::addNotify( "danger", static::getNotify("notcreated") ); return REST\Response::jsonResponse(); } public function delete( int $id ) : HTTP\Response { REST\Response::closeModals(); if( Events\Model::delete( $id ) ) { REST\Response::addNotify( "success", static::$NOTIFY["deleted"] ); REST\Response::redirect( "/events" ); } else REST\Response::addNotify( "danger", static::$NOTIFY["notfound"] ); return REST\Response::jsonResponse(); } public function toggleStatus( int $id ) : HTTP\Response { if( $result = Events\Model::get( $id ) ) { $result->toggleStatus( TRUE ); REST\Response::addUpdater( [ "data/table/row", $id ], $result ); } else REST\Response::addNotify( "danger", static::$NOTIFY["notfound"] ); return REST\Response::jsonResponse(); } /* ### PUBLIC VALIDATE FUNCTIONS ################################ # */ /* ### PUBLIC REST FUNCTIONS #################################### # */ public static function restConfigOverview( array $data = [] ) : REST\Generator\Base\BaseGenerator { return REST\Response::addWrapper( "overview", "Events" ) ->setList( $data ) ->get() ->setAction( "/events/{id}" ) ->setOrder( "title", "asc" ) ->setSearch( TRUE ) ->addButton(...Hooks::filter( "rest.generator::button.name->create", [], "events" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->status", [], "status", [], FALSE, "events" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->amount", [ "label" => NULL, "title" => "Tage", "icon" => "bi-calendar-day", ], "dates", TRUE, FALSE, TRUE, "events" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->amount", [ "label" => NULL, "title" => "Tickets", "icon" => "bi-tags", ], "tickets", TRUE, FALSE, TRUE, "events" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->amount", [ "label" => NULL, "title" => "Limit pro Tag", "icon" => "bi-people", ], "limit", TRUE, FALSE, TRUE, "events" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->amount", [ "label" => NULL, "title" => "Buchungen", "icon" => "bi-cart", ], "bookings", TRUE, FALSE, TRUE, "events" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->amount", [ "label" => NULL, "title" => "Eingescheckt", "icon" => "bi-clipboard-check", ], "checkedin", TRUE, FALSE, TRUE, "events" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "title", TRUE, TRUE, TRUE, "events" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->datetime", [], "date_edit", FALSE, FALSE, TRUE, "events" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->actions", [], [], FALSE, "events" ))->get() ->addButton(...Hooks::filter( "rest.generator::action.name->edit", [], "events" )) ->addButton(...Hooks::filter( "rest.generator::action.name->delete", [], "events" )) ->top(); } public static function restConfigDetails( Events\Entity $data ) : REST\Generator\Base\BaseGenerator { $form = REST\Response::addWrapper( "details", "Event bearbeiten" ) ->setData( $data ) ->setBacklink( "/events" ) ->get() ->setAction( "/api/v1/events/{id}", "PUT" ) ->addTab( "Event" )->get() ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "title", TRUE, "events" )) ->parent() ->addTab( "Tickets" ) ->get() ->setActive( TRUE ) ->addContent( Events\Tickets\API\v1\Controller::restConfigTable() ) ->parent() ->addTab( "Bookings" )->get() ->addContent( Events\Bookings\API\v1\Controller::restConfigTable() ) ->parent() ->addTab( "Vouchers" )->get() ->addContent( Events\Vouchers\API\v1\Controller::restConfigTable() ) ->parent() ->addTab( "Speichern" )->get() ->setColor( REST\Generator\Config\Color::Primary ) ->setIcon( "bi bi-save" ) ->setType( "submit" ); return $form; } public static function restConfigCreate() : REST\Generator\Base\BaseGenerator { return REST\Response::addModal( "details", "Event erstellen" ) ->setData([ "id" => 0 ]) ->get() ->setAction( "/api/v1/events", "POST" ) ->addButton(...Hooks::filter( "rest.generator::button.type->submit", [], "Erstellen", "events" )) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "title", TRUE, "events" )) ->top(); } public static function restConfigDelete( int $id ) : REST\Generator\Base\BaseGenerator { return REST\Response::addModal( "details", "Event Löschen" ) ->setData([ "id" => $id ]) ->setSize( REST\Wrapper\Modal\Size::sm ) ->get() ->setAction( "/api/v1/events/{id}", "DELETE" ) ->addText( "Möchtest du wirklich den Datensatz (#{$id}) löschen? " ) ->addButton(...Hooks::filter( "rest.generator::button.type->cancel", [], NULL, "events" )) ->addButton(...Hooks::filter( "rest.generator::button.type->delete", [], NULL, "events" )) ->top(); } /* ### PUBLIC REST EXTENSION FUNCTIONS ########################## # */ }