/** Datei: plugins/calendars/library/ARUNOX/Plugins/Calendars/Categories/Model.php **/ * @copyright 2025 ARUNOX * @version 1.0.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Calendars\Categories; use ARUNOX\API\PHP; use ARUNOX\Plugins\REST; use ARUNOX\Database\BaseModel; #[PHP\Attributes\Database\Definitions\Table( "calendars_categories" )] #[PHP\Attributes\Database\Definitions\HashID( "ccat" )] #[PHP\Attributes\Database\Definitions\Entity( Entity::class )] #[PHP\Attributes\Logs\Rules\Create()] #[PHP\Attributes\Logs\Rules\Update( "icon_name", "Icon wurde auf '%4\$t' gesetzt", REST\Generator\Config\Icon::class )] #[PHP\Attributes\Logs\Rules\Update( "icon_color", "Farbe wurde auf '%4\$t' gesetzt", REST\Generator\Config\Color::class )] class Model extends BaseModel { /* ### VARIABLES ################################################ # */ /* ### PUBLIC STATIC FUNCTIONS ################################## # */ } /** Datei: plugins/calendars/library/ARUNOX/Plugins/Calendars/Categories/API/v1/Routes.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Calendars\Categories\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/calendars/library/ARUNOX/Plugins/Calendars/Categories/API/v1/Controller.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Calendars\Categories\API\v1; use ARUNOX\HTTP; use ARUNOX\API\PHP; use ARUNOX\Core\Hooks; use ARUNOX\Plugins\Logs; use ARUNOX\Plugins\REST; use ARUNOX\Plugins\Calendars; use ARUNOX\API\BaseController; use ARUNOX\Database\BaseEntity; #[PHP\Attributes\Controller\Label( "Kategorie", "Kategorien" )] #[PHP\Attributes\Controller\Icon( REST\Generator\Config\Icon::Tags )] #[PHP\Attributes\Controller\Route( "categories", Calendars\API\v1\Controller::class )] #[PHP\Attributes\Database\Definitions\Model( Calendars\Categories\Model::class )] class Controller extends BaseController { /* ### PUBLIC GET FUNCTIONS ##################################### # */ /** * @api * @method GET * * @route.path /calendars/categories * @route.description Listet alle Logeinträge */ public static function getAllPrepared() : array { return parent::getAllPrepared(); } /** * @api * @method GET * * @route.path /calendars/categories/{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 /calendars/categories/{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 /calendars/categories * @route.description Erstellt einen neuen Kalender */ public static function createPrepared( array $data ) : HTTP\Response { return parent::createPrepared( $data ); } /** * @api * @method DELETE * * @route.path /calendars/categories/{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 /calendars/categories/{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 /calendars/categories/{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 = Calendars\Categories\Model::get( $hashid ); REST\Response::closeModals(); REST\Response::addUpdater( [ "data/table/row", $hashid ], $data ); } return static::restResponse( $result ); } /** * @internal rest * @method POST * * @route.path /calendars/categories * @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 /calendars/categories/{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 /calendars/categories/{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 /calendars/categories/{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( "/calendars/categories/{$hashid}" ) ->setAction( "/calendars/categories/{$hashid}", "PUT" ) ->addTab( static::getSingular() )->get() ->addChildren( Calendars\Categories\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 /calendars/categories/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 /calendars/categories/{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( "/calendars/categories/{$hashid}", "DELETE" ) ->addText( "Möchtest du wirklich den Datensatz (#{$hashid}) löschen? " ) ->addButton(...Hooks::filter( "rest.generator::button.type->cancel", [], NULL, "calendars/categories" )) ->addButton(...Hooks::filter( "rest.generator::button.type->delete", [], NULL, "calendars/categories" )); } /* ### PUBLIC REST EXTENSION FUNCTIONS ########################## # */ public static function restConfigTable( null|string $hashid = NULL ) : REST\Generator\Base\BaseGenerator { $rest = REST\Generator\Data\Table::create() ->setApi( "/calendars/categories?origin={$hashid}" ) ->setAction( "/calendars/categories/{hashid}" ) ->setOrder( "title", "asc" ) ->setSearch( TRUE ) ->addButton(...Hooks::filter( "rest.generator::button.name->create", [], "calendars/categories" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->status", [], "status", [], "calendars/categories", "hashid" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->icon", [ "label" => "Icon", "icon" => "bi-tag", "options" => REST\Generator\Config\Icon::getAsOptions(), ], "icon", [], "calendars/categories", "hashid" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "title", TRUE, TRUE, TRUE, "calendars/categories" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "description", TRUE, TRUE, TRUE, "calendars/categories" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->datetime", [], "date_edit", TRUE, FALSE, TRUE, "calendars/categories" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->actions", [], [], FALSE, "calendars/categories" ))->get() ->addButton(...Hooks::filter( "rest.generator::action.name->edit", [], "calendars/categories", "hashid" )) ->addButton(...Hooks::filter( "rest.generator::action.name->delete", [], "calendars/categories", "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, "calendars/categories" )) ->addField(...Hooks::filter( "rest.generator::control.type->select", [ "options" => REST\Generator\Config\Icon::getAsOptions(), ], "icon_name", TRUE, TRUE, "calendars/categories" )) ->addField(...Hooks::filter( "rest.generator::control.type->select", [ "options" => REST\Generator\Config\Color::getAsOptions(), ], "icon_color", TRUE, TRUE, "calendars/categories" )) ->parent() ->addGroup() ->addField(...Hooks::filter( "rest.generator::control.type->textarea", [ "lines" => 3, ], "description", FALSE, "calendars/categories" )) ; return $rest->top()->getChildren(); } } /** Datei: plugins/calendars/library/ARUNOX/Plugins/Calendars/Categories/Entity.php **/ * @copyright 2025 ARUNOX * @version 1.0.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Calendars\Categories; use ARUNOX\API\PHP; use ARUNOX\Database\BaseEntity; #[PHP\Attributes\Database\Attributes( "status" )] #[PHP\Attributes\Database\Attributes( "date_edit" )] #[PHP\Attributes\Database\Attributes( "date_create" )] #[PHP\Attributes\Database\Definitions\Model( Model::class )] class Entity extends BaseEntity { /* ### VARIABLES ################################################ # */ /* ### PUBLIC FUNCTIONS ######################################### # */ public function getIcon() : array { return [ "icon" => $this->icon_name, "color" => $this->icon_color, ]; } }