/** Datei: plugins/cards/library/ARUNOX/Plugins/Locations/Cards/API/v1/Routes.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Locations\Cards\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/cards/library/ARUNOX/Plugins/Locations/Cards/API/v1/Controller.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Locations\Cards\API\v1; use ARUNOX\HTTP; use ARUNOX\Plugins; use ARUNOX\API\PHP; use ARUNOX\Core\Hooks; use ARUNOX\API\BaseController; use ARUNOX\Database\BaseEntity; use ARUNOX\Plugins\REST\Generator\Base\BaseGenerator; #[PHP\Attributes\Controller\Label( "Karte", "Karten" )] #[PHP\Attributes\Controller\Icon( Plugins\REST\Generator\Config\Icon::CreditCard2Front )] #[PHP\Attributes\Controller\Route( "cards", Plugins\Locations\API\v1\Controller::class )] #[PHP\Attributes\Controller\Notifications( "rolechanged.0", '{$LABEL.singular} geändert zu Default' )] #[PHP\Attributes\Controller\Notifications( "rolechanged.1", '{$LABEL.singular} geändert zu User' )] #[PHP\Attributes\Controller\Notifications( "rolechanged.2", '{$LABEL.singular} geändert zu Admin' )] #[PHP\Attributes\Database\Definitions\Model( Plugins\Locations\Cards\Model::class )] class Controller extends BaseController { /* ### PUBLIC GET FUNCTIONS ##################################### # */ /** * @api * @method GET * * @route.path /locations/{origin}/cards * @route.description Listet alle Logeinträge */ public static function getAll( string $origin ) : array { $origin = Plugins\Locations\Cards\Model::resolveHashIDPrefix( $origin ); return Plugins\Locations\Cards\Model::getAll([ "origin_id" => $origin->id ] ); } /** * @api * @method GET * * @route.path /locations/cards/{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 /locations/cards/{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 /locations/cards * @route.description Erstellt einen neuen Kalender */ public static function createPrepared( array $data ) : HTTP\Response { return parent::createPrepared( $data ); } /** * @api * @method DELETE * * @route.path /locations/cards/{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 /locations/cards/{hashid}/role * @route.description Wechselt den Status (aktiv/inaktiv) eines Kalenders */ public static function toggleRole( string $hashid ) : HTTP\Response { return static::togglePrepared( "role", $hashid ); } /* ### PUBLIC VALIDATE FUNCTIONS ################################ # */ /* ### PUBLIC REST RESPONSE FUNCTIONS ########################### # */ /** * @internal rest * @method PUT * * @route.path /locations/cards/{hashid} * @route.description REST-Antwort nach dem Speichern eines Termins */ public static function restResponseSavePrepared( string $hashid, array $data ) : HTTP\Response { return parent::restResponseSavePrepared( $hashid, $data ); } /** * @internal rest * @method POST * * @route.path /locations/cards * @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 ) ) { Plugins\REST\Response::closeModals(); Plugins\REST\Response::refresh( "#cards" ); } return static::restResponse( $result ); } /** * @internal rest * @method DELETE * * @route.path /locations/cards/{hashid} * @route.description REST-Antwort nach dem Löschen eines Logeintrag */ public static function restResponseDelete( string $hashid ) : HTTP\Response { Plugins\REST\Response::closeModals(); $result = static::deletePrepared( $hashid ); if( $result->isStatus( 200 ) ) { Plugins\REST\Response::redirect( "/locations/cards" ); } return static::restResponse( $result ); } /** * @internal rest * @method PATCH * * @route.path /locations/cards/{hashid}/status * @route.description REST-Antwort zur Status-Umschaltung eines Kalenders */ public static function restResponseToggleStatusPrepared( string $hashid ) : HTTP\Response { $card = Plugins\Locations\Cards\Model::resolveHashIDPrefix( $hashid ); $result = Plugins\Cards\API\v1\Controller::toggleStatusPrepared( $card->card->hashid ); $card = Plugins\Locations\Cards\Model::resolveHashIDPrefix( $hashid ); if( $result->isStatus( 200 ) ) { Plugins\REST\Response::addUpdater( [ "data/table/row", $hashid ], $card ); } return static::restResponse( $result ); } /** * @internal rest * @method PATCH * * @route.path /locations/cards/{hashid}/role * @route.description REST-Antwort zur Status-Umschaltung eines Kalenders */ public static function restResponseToggleRole( string $hashid ) : BaseGenerator { return Plugins\REST\Response::addModal( "details", Plugins\Locations\Cards\Role::getSingular( "%t ändern" ) ) ->get() ->setApi( static::getRoute( $hashid ) ) ->setAction( static::getRoute( $hashid ), "PUT" ) ->addButton(...Hooks::filter( "rest.generator::button.type->submit", [], "Speichern", static::getRoute() )) ->addField(...Hooks::filter( "rest.generator::control.type->radio", [ "options" => Plugins\Locations\Cards\Role::getAll(), ], "role", TRUE, TRUE, "locations/cards" )) ; } /* ### PUBLIC REST CONFIG FUNCTIONS ############################# # */ /** * @internal rest * @method GET * * @route.path /locations/cards * @route.description REST-Konfiguration für Logbuch-Tabelle */ public static function restConfigOverview() : BaseGenerator { return Plugins\REST\Response::addWrapper( "details", static::getPlural() )->get() ->addTab( "Übersicht", FALSE )->get() ->setIcon( static::getIcon() ) ->addHeadline( static::getPlural(), 2 ) ->addCallable( [ static::class, "restConfigTable" ] ) ->addButton(...Hooks::filter( "rest.generator::button.name->create", [], "locations" )) ->parent() ; } /** * @internal rest * @method GET * * @route.path /locations/{origin}/cards/{$hashid} * @route.description REST-Konfiguration für Detailansicht eines Logeintrags */ public static function restConfigDetails( string $origin, string $hashid ) : BaseGenerator { return Plugins\REST\Response::addModal( "details", static::getSingular( "%t bearbeiten" ) ) ->setSize( "equal" ) ->setWidth("lg") ->get() ->setApi( static::getRoute( $hashid ) ) ->setAction( static::getRoute( $hashid ), "PUT" ) ->addTab( static::getSingular() )->get() ->addHeadline( static::getSingular(), 2 ) ->addCallable( [ static::class, "restConfigOrigin" ], $origin, $hashid ) ->addCallable( [ static::class, "restConfigInputs" ], $origin, $hashid ) ->parent() ->addCallable( [ Plugins\Logs\API\v1\Controller::class, "restConfigTab" ], $hashid ) ->addTab( "Speichern" )->get() ->setColor( Plugins\REST\Generator\Config\Color::Primary ) ->setIcon( "bi bi-save" ) ->setType( "submit" ); } /** * @internal rest * @method GET * * @route.path /locations/{origin}/cards/create * @route.description REST-Konfiguration für das Erstellen eines Kalenders (Formular) */ public static function restConfigCreateByOriginPrepared( bool | string $origin = FALSE ) : BaseGenerator { return parent::restConfigCreateByOriginPrepared( $origin ); } /** * @internal rest * @method GET * * @route.path /locations/cards/{hashid}/delete * @route.description REST-Konfiguration für die Lösch-Bestätigung eines Logeintrags */ public static function restConfigDeletePrepared( string $hashid ) : BaseGenerator { return parent::restConfigDeletePrepared( $hashid ); } /* ### PUBLIC REST EXTENSION FUNCTIONS ########################## # */ public static function restConfigTab( BaseGenerator $rest, null|string $hashid = NULL ) : void { $rest ->addTab( static::getPlural(), "cards" )->get() ->setIcon( static::getIcon() ) ->addCallable( [ static::class, "restConfigTable" ], $hashid ) ; } public static function restConfigTable( BaseGenerator $rest, null|string $hashid = NULL ) : BaseGenerator { return $rest ->addTable()->get() ->setApi( Plugins\Locations\API\v1\Controller::class::getRoute( $hashid, "cards" ) ) ->setAction( Plugins\Locations\API\v1\Controller::class::getRoute( $hashid, "cards", "{hashid}") ) ->setOrder( "uuid", "asc" ) ->setSearch( TRUE ) ->addButton(...Hooks::filter( "rest.generator::button.name->create", [], "locations/{$hashid}/cards" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->status", [ "label" => Plugins\Cards\Status::getSingular(), "icon" => Plugins\Cards\Status::getIcon(), "options" => Plugins\Cards\Status::getAll(), ], "status", [], "locations/cards", "hashid" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->icon", [ "label" => Plugins\Cards\Type::getSingular(), "icon" => Plugins\Cards\Type::getIcon(), "options" => Plugins\Cards\Type::getAll(), ], "card.type", [], "locations/cards", "hashid" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->status", [ "label" => Plugins\Locations\Cards\Role::getSingular(), "icon" => Plugins\Locations\Cards\Role::getIcon(), "options" => Plugins\Locations\Cards\Role::getAll(), ], "role", [], "locations/cards", "hashid" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [ "label" => "UUID", ], "card.uuid", TRUE, TRUE, TRUE, "locations/cards" )) ; } public static function restConfigInputs( BaseGenerator $rest, bool|string $origin, bool|string $hashid = FALSE ) : BaseGenerator { return $rest->addField(...Hooks::filter( "rest.generator::control.type->select", [ "options" => Plugins\Locations\Cards\Role::getAll(), ], "role", TRUE, TRUE, "locations/cards" )); } public static function restConfigOrigin( BaseGenerator $rest, bool|string $origin, bool|string $hashid = FALSE ) : BaseGenerator { $origin = Plugins\Locations\Cards\Model::resolveHashIDPrefix( $origin ); $current = Plugins\Locations\Cards\Model::resolveHashIDPrefix( $hashid ); $excluded = Plugins\Locations\Cards\Model::getAllValue([ "origin_id" => $origin->id ], "card_id" ); $rest->addField(...Hooks::filter( "rest.generator::control.type->hidden", [], "origin_id", $origin->id, "locations/cards" )); if( $hashid === FALSE ) { return $rest->addField(...Hooks::filter( "rest.generator::control.type->select", [ "options" => Plugins\Cards\Model::getAsOptions( "uuid", excluded: $excluded ) , ], "card_id", TRUE, TRUE, "locations/cards" )); } return $rest->addField(...Hooks::filter( "rest.generator::control.type->hidden", [], "card_id", $current->id, "locations/cards" )); } }