/** Datei: plugins/calendars/library/ARUNOX/Plugins/Calendars/Tasks/API/v1/Routes.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Calendars\Tasks\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", // "label" => "Logbuch", // "icon" => "bi bi-journal-text", // "menu" => "administration", // ]; // // return $routes; // }, 99 ); } } /** Datei: plugins/calendars/library/ARUNOX/Plugins/Calendars/Tasks/API/v1/Controller.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Calendars\Tasks\API\v1; use ARUNOX\HTTP; use ARUNOX\API\PHP; use ARUNOX\Core\Hooks; use ARUNOX\Plugins\REST; use ARUNOX\Plugins\Users; use ARUNOX\Plugins\Calendars; use ARUNOX\API\BaseController; use ARUNOX\Database\BaseEntity; #[PHP\Attributes\Controller\Label( "Aufgabe", "Aufgaben" )] #[PHP\Attributes\Controller\Icon( REST\Generator\Config\Icon::ClipboardCheck )] #[PHP\Attributes\Controller\Route( "tasks", Calendars\API\v1\Controller::class )] #[PHP\Attributes\Database\Definitions\Model( Calendars\Tasks\Model::class )] class Controller extends BaseController { /* ### PUBLIC GET FUNCTIONS ##################################### # */ /** * @api * @method GET * * @route.path /calendars/tasks * @route.description Listet alle Aufgaben */ public static function getAllPrepared() : array { return parent::getAllPrepared(); } /** * @api * @method GET * * @route.path /calendars/{origin}/tasks * @route.description Listet alle Logeinträge */ public static function getByOriginPrepared( string $origin ) : array { return parent::getByOriginPrepared( $origin ); } /** * @api * @method GET * * @route.path /calendars/tasks/{hashid} * @route.description Gibt einen einzelnen Aufgabe 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/{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/tasks * @route.description Erstellt einen neuen Termin */ public static function createPrepared( array $data ) : HTTP\Response { return parent::createPrepared( $data ); } /** * @api * @method DELETE * * @route.path /calendars/tasks/{hashid} * @route.description Löscht ein Aufgabe anhand der ID */ public static function deletePrepared( string $hashid ) : HTTP\Response { return parent::deletePrepared( $hashid ); } /** * @api * @method PATCH * * @route.path /calendars/tasks/{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/tasks/{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\Tasks\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/tasks * @route.description REST-Antwort nach dem Erstellen eines Termins (inkl. Notifikation, Redirect etc.) */ public static function restResponseCreate( array $data ) : HTTP\Response { $result = static::createPrepared( $data ); if( $result->isStatus( 200 ) ) { $data = $result->getBody("data"); REST\Response::closeModals(); REST\Response::refresh( "#tasks" ); REST\Response::addClick( [ "data/table/row", $data->hashid ] ); } return static::restResponse( $result ); } /** * @internal rest * @method DELETE * * @route.path /calendars/tasks/{hashid} * @route.description REST-Antwort nach dem Löschen eines Aufgabe */ public static function restResponseDelete( string $hashid ) : HTTP\Response { REST\Response::closeModals(); $result = static::deletePrepared( $hashid ); if( $result->isStatus( 200 ) ) { REST\Response::refresh( "#tasks" ); } return static::restResponse( $result ); } /** * @internal rest * @method PATCH * * @route.path /calendars/tasks/{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/{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/tasks/{$hashid}" ) ->setAction( "/calendars/tasks/{$hashid}", "PUT" ) ->addTab( "Aufgabe" )->get() ->addChildren( Calendars\Tasks\API\v1\Controller::restConfigInputs() ) ->parent() ->addTab( "Zuweisungen", "assignments" )->get() ->addChildren( Calendars\Tasks\Assignments\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/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/{origin}/tasks/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 /calendars/tasks/{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 { $type = Calendars\Tasks\Model::getValue( $hashid, "type" ); return REST\Response::addModal( "details", "{$type->getLabel()} Löschen" ) ->setSize( REST\Wrapper\Modal\Size::sm ) ->get() ->setAction( "/calendars/tasks/{$hashid}", "DELETE" ) ->addText( "Möchtest du wirklich den Datensatz (#{$hashid}) löschen? " ) ->addButton(...Hooks::filter( "rest.generator::button.type->cancel", [], NULL, "calendars/tasks" )) ->addButton(...Hooks::filter( "rest.generator::button.type->delete", [], NULL, "calendars/tasks" )); } /* ### PUBLIC REST EXTENSION FUNCTIONS ########################## # */ public static function restConfigTable( null|string $origin = NULL ) : REST\Generator\Base\BaseGenerator { $rest = REST\Generator\Data\Table::create() ->setApi( "/calendars/{$origin}/tasks" ) ->setAction( "/calendars/tasks/{hashid}" ) ->setOrder( "date_create", "desc" ) ->setSearch( TRUE ) ->addButton(...Hooks::filter( "rest.generator::button.name->create", [], "calendars/{$origin}/tasks" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->status", [ "options" => Calendars\Tasks\Status::getAll(), ], "status", [], "calendars/tasks", "hashid" )) ; foreach( Calendars\Tasks\Assignments\Status::getAll() as $status ) { $rest->addColumn(...Hooks::filter( "rest.generator::column.type->amount", [ "action" => "/calendars/tasks/{hashid}#assignments", "label" => FALSE, "title" => $status["label"], "icon" => $status["icon"], ], "assignments.status.{$status["value"]}", TRUE, FALSE, TRUE, "calendars/tasks", "hashid" )); } $rest ->addColumn(...Hooks::filter( "rest.generator::column.type->datetime", [ "label" => "Fällig am", ], "date_due", TRUE, FALSE, TRUE, "calendars/tasks" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->datetime", [ "label" => "Erledigt am", ], "date_done", TRUE, FALSE, TRUE, "calendars/tasks" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [ "label" => "Zugewiesen an", ], "target.username", TRUE, TRUE, TRUE, "calendars/tasks" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "title", TRUE, TRUE, TRUE, "calendars/tasks" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "description", TRUE, TRUE, TRUE, "calendars/tasks" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->actions", [], [], FALSE, "calendars/tasks" ))->get() ->addButton(...Hooks::filter( "rest.generator::action.name->edit", [], "calendars/tasks", "hashid" )) ->addButton(...Hooks::filter( "rest.generator::action.name->delete", [], "calendars/tasks", "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/tasks" )) ->addField(...Hooks::filter( "rest.generator::control.type->select", [ "options" => Users\Model::getAsOptions( "username", "hashid" ), ], "target_hid", TRUE, FALSE, "calendars/tasks" )) ->addField(...Hooks::filter( "rest.generator::control.type->datetime", [], "date_due", TRUE, "calendars/tasks" )) ->parent() ->addGroup() ->addField(...Hooks::filter( "rest.generator::control.type->textarea", [ "lines" => 2, ], "description", FALSE, "calendars/tasks" )) ; 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", [ "options" => Calendars\Model::getAsOptions( "title" ), ], "origin_id", TRUE, FALSE, "calendars/tasks" )); } $origin = Calendars\Model::getValue( $origin, "id" ); return $rest->addField(...Hooks::filter( "rest.generator::control.type->hidden", [], "origin_id", $origin, "calendars/tasks" )); } public static function restConfigTab( REST\Generator\Base\BaseGenerator $rest, null|string $origin = NULL ) : void { $calendar = Calendars\Model::getByColumn( "target_hid", $origin ); $rest->addTab( static::getPlural(), "tasks" )->get() ->setIcon( static::getIcon() ) ->addContent( static::restConfigTable( $calendar ? $calendar->hashid : $origin ) ) ; } }