/** Datei: plugins/calendars/library/ARUNOX/Plugins/Calendars/Tasks/Templates/Model.php **/ * @copyright 2025 ARUNOX * @version 1.0.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Calendars\Tasks\Templates; use ARUNOX\API\PHP; use ARUNOX\Plugins\Calendars; use ARUNOX\Database\BaseModel; #[PHP\Attributes\Database\Definitions\Table( "calendars_tasks_templates" )] #[PHP\Attributes\Database\Definitions\HashID( "cttpl" )] #[PHP\Attributes\Database\Definitions\Entity( Entity::class )] #[PHP\Attributes\Database\Definitions\Origin( Calendars\Tasks\Model::class )] class Model extends BaseModel { /* ### VARIABLES ################################################ # */ /* ### PUBLIC STATIC FUNCTIONS ################################## # */ } /** Datei: plugins/calendars/library/ARUNOX/Plugins/Calendars/Tasks/Templates/API/v1/Routes.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Calendars\Tasks\Templates\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" => "/calendars/tasks/templates", // "label" => "Logbuch", // "icon" => "bi bi-journal-text", // "menu" => "administration", // ]; // // return $routes; // }, 99 ); } } /** Datei: plugins/calendars/library/ARUNOX/Plugins/Calendars/Tasks/Templates/API/v1/Controller.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Calendars\Tasks\Templates\API\v1; use ARUNOX\HTTP; use ARUNOX\API\PHP; use ARUNOX\Core\Hooks; use ARUNOX\Plugins\REST; use ARUNOX\Plugins\Calendars; use ARUNOX\API\BaseController; use ARUNOX\Database\BaseEntity; #[PHP\Attributes\Controller\Label( "Vorlage", "Vorlagen" )] #[PHP\Attributes\Controller\Icon( REST\Generator\Config\Icon::FileEarmarkText )] #[PHP\Attributes\Controller\Route( "templates", Calendars\Tasks\API\v1\Controller::class )] #[PHP\Attributes\Database\Definitions\Model( Calendars\Tasks\Templates\Model::class )] class Controller extends BaseController { /* ### PUBLIC GET FUNCTIONS ##################################### # */ /** * @api * @method GET * * @route.path /calendars/tasks/templates * @route.description Listet alle Vorlagen */ public static function getAllPrepared() : array { return parent::getAllPrepared(); } /** * @api * @method GET * * @route.path /calendars/tasks/templates/{hashid} * @route.description Gibt einen einzelnen Vorlage 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/tasks/templates/{hashid} * @route.description Erstellt eine neue Vorlage */ public static function savePrepared( string $hashid, array $data ) : HTTP\Response { return parent::savePrepared( $hashid, $data ); } /** * @api * @method POST * * @route.path /calendars/tasks/templates * @route.description Erstellt eine neue Vorlage */ public static function createPrepared( array $data ) : HTTP\Response { return parent::createPrepared( $data ); } /** * @api * @method DELETE * * @route.path /calendars/tasks/templates/{hashid} * @route.description Löscht ein Vorlage anhand der ID */ public static function deletePrepared( string $hashid ) : HTTP\Response { return parent::deletePrepared( $hashid ); } /** * @api * @method PATCH * * @route.path /calendars/tasks/templates/{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 POST * * @route.path /calendars/tasks/templates * @route.description REST-Antwort nach dem Erstellen einer Vorlage */ public static function restResponseCreate( array $data ) : HTTP\Response { $result = static::createPrepared( $data ); if( $result->isStatus( 200 ) ) { REST\Response::closeModals(); REST\Response::redirect( "/calendars#templates" ); } return static::restResponse( $result ); } /** * @internal rest * @method DELETE * * @route.path /calendars/tasks/templates/{hashid} * @route.description REST-Antwort nach dem Löschen eines Vorlage */ public static function restResponseDelete( string $hashid ) : HTTP\Response { REST\Response::closeModals(); $result = static::deletePrepared( $hashid ); if( $result->isStatus( 200 ) ) { REST\Response::redirect( "/calendars/tasks/templates" ); } return static::restResponse( $result ); } /** * @internal rest * @method PATCH * * @route.path /calendars/tasks/templates/{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/tasks/templates/{hashid} * @route.description REST-Konfiguration für Detailansicht eines Vorlages */ public static function restConfigDetails( string $hashid ) : REST\Generator\Base\BaseGenerator { return REST\Response::addWrapper( "details", static::getSingular( "%t bearbeiten" ) ) ->setBacklink( "/calendars/tasks/templates" ) ->get() ->setApi( "/calendars/tasks/templates/{$hashid}" ) ->setAction( "/calendars/tasks/templates/{$hashid}", "PUT" ) ->addTab( "Produkt" )->get() ->addHeadline( "Produkt", 2 ) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "company_name", FALSE, "calendars/tasks/templates" )) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "firstname", FALSE, "calendars/tasks/templates" )) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "lastname", FALSE, "calendars/tasks/templates" )) ->parent() ->addTab( "Ansprechpartner" )->get() ->addContent( // Contacts\Contacts\API\v1\Controller::restConfigTable( $hashid ) ) ->parent() ->addTab( "Adressen" )->get() ->addContent( // Contacts\Addresses\API\v1\Controller::restConfigTable( $hashid ) ) ->parent() ->addTab( "Speichern" )->get() ->setColor( REST\Generator\Config\Color::Primary ) ->setIcon( "bi bi-save" ) ->setType( "submit" ); } /** * @internal rest * @method GET * * @route.path /calendars/tasks/templates/create * @route.description REST-Konfiguration für das Erstellen einer Vorlage (Formular) */ public static function restConfigCreatePrepared() : REST\Generator\Base\BaseGenerator { return parent::restConfigCreatePrepared(); } /** * @internal rest * @method GET * * @route.path /calendars/tasks/templates/{hashid}/delete * @route.description REST-Konfiguration für die Lösch-Bestätigung eines Vorlages */ public static function restConfigDeletePrepared( string $hashid ) : REST\Generator\Base\BaseGenerator { $type = Calendars\Tasks\Templates\Model::getValue( $hashid, "type" ); return REST\Response::addModal( "details", "{$type->getLabel()} Löschen" ) ->setSize( REST\Wrapper\Modal\Size::sm ) ->get() ->setAction( "/calendars/tasks/templates/{$hashid}", "DELETE" ) ->addText( "Möchtest du wirklich den Datensatz (#{$hashid}) löschen? " ) ->addButton(...Hooks::filter( "rest.generator::button.type->cancel", [], NULL, "calendars/tasks/templates" )) ->addButton(...Hooks::filter( "rest.generator::button.type->delete", [], NULL, "calendars/tasks/templates" )); } /* ### PUBLIC REST EXTENSION FUNCTIONS ########################## # */ public static function restConfigTab( REST\Generator\Base\BaseGenerator $rest, null|string $hashid = NULL ) : void { $rest->addTab( "Logbuch", "calendars/tasks/templates" )->get() ->setIcon( "bi-journal-text" ) ->addContent( Calendars\Tasks\Templates\API\v1\Controller::restConfigTable( $hashid ) ) ; } public static function restConfigTable( null|string $hashid = NULL ) : REST\Generator\Base\BaseGenerator { $rest = REST\Generator\Data\Table::create() ->setApi( "/calendars/tasks/templates" ) ->setAction( "/calendars/tasks/templates/{hashid}" ) ->setOrder( "title", "asc" ) ->setSearch( TRUE ) ->addColumn(...Hooks::filter( "rest.generator::column.type->status", [], "status", [], "calendars/tasks/templates", "hashid" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "title", TRUE, TRUE, TRUE, "calendars/tasks/templates" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "description", TRUE, TRUE, TRUE, "calendars/tasks/templates" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->datetime", [], "date_create", TRUE, FALSE, TRUE, "calendars/tasks/templates" )) ; return $rest; } public static function restConfigInputs() : array { $rest = REST\Generator\Data\Form::create() ->addButton(...Hooks::filter( "rest.generator::button.type->submit", [], "Erstellen", "calendars/tasks/templates" )) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "title", TRUE, "calendars/tasks/templates" )) ->addField(...Hooks::filter( "rest.generator::control.type->textarea", [], "description", FALSE, "calendars/tasks/templates" )); ; return $rest->top()->getChildren(); } } /** Datei: plugins/calendars/library/ARUNOX/Plugins/Calendars/Tasks/Templates/Entity.php **/ * @copyright 2025 ARUNOX * @version 1.0.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Calendars\Tasks\Templates; use ARUNOX\Plugins; 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 getCreator() { if( $class = $this->getCreatorClass() ) { return $class::get( $this->created_by ); } } public function getCreatorClass() { if( !$this->created_by ) return NULL; $prefix = explode( "_", $this->created_by ); $prefix = current( $prefix ); if( $prefix == Plugins\Users\Model::getHashIDPrefix() ) { return Plugins\Users\Model::class; } return FALSE; } public function getCreatorName() { if( $class = $this->getCreatorClass() ) { return $class::getValue( $this->created_by, "username" ); } } }