/** Datei: plugins/calendars/library/ARUNOX/Plugins/Calendars/Tasks/Model.php **/ * @copyright 2025 ARUNOX * @version 1.0.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Calendars\Tasks; use ARUNOX\API\PHP; use ARUNOX\Plugins\Calendars; use ARUNOX\Database\BaseModel; #[PHP\Attributes\Database\Definitions\Table( "calendars_tasks" )] #[PHP\Attributes\Database\Definitions\HashID( "ctsk" )] #[PHP\Attributes\Database\Definitions\Entity( Entity::class )] #[PHP\Attributes\Database\Definitions\Origin( Calendars\Model::class )] class Model extends BaseModel { /* ### VARIABLES ################################################ # */ /* ### PUBLIC STATIC FUNCTIONS ################################## # */ public static function getByOrigin( int|string|array $origin, null|string $column = NULL ) { $origin = Calendars\Model::getValue( $origin ); if( $column ) return Model::getAllValue([ "origin_id" => $origin ], $column ); return Model::getAll([ "origin_id" => $origin ] ); } public static function save( array $data ) : mixed { if( isset( $data["origin_id"] ) ) { if( !is_numeric( $data["origin_id"] ) ) { if( !$origin_id = Calendars\Model::resolveHashID( $data["origin_id"] ) ) { $origin = static::resolveHashIDPrefix( $data["origin_id"] ); $origin_id = Calendars\Model::save([ "titlt" => $origin->name, "target_hid" => $data["origin_id"], ]); } $data["origin_id"] = $origin_id; } } return parent::save( $data ); } /* ### PUBLIC STATIC LOG FUNCTIONS ############################## # */ public static function getLogRulesUpdated( int $id ) { $current = static::get( $id ); $calendar = $current->origin; $hashids = [ $calendar->hashid, $calendar->target_hid, ]; return [ "status" => [ "options" => Status::getAll(), "message" => "Status wurde auf '%4\$t' gesetzt", "target_hids" => $hashids, ], "date_due" => [ "message" => "Fälligkeit wurde auf '%4\$FORMAT_DATETIME\$D' gesetzt", "target_hids" => $hashids, ], ]; } public static function getLogRulesCreated( int $id ) { $current = static::get( $id ); $calendar = $current->origin; return [ "__self" => [ "target_hids" => [ $calendar->hashid, $calendar->target_hid, ], ], ]; } } /** 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" ); } } } /** 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 ) ) ; } } /** Datei: plugins/calendars/library/ARUNOX/Plugins/Calendars/Tasks/Assignments/Model.php **/ * @copyright 2025 ARUNOX * @version 1.0.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Calendars\Tasks\Assignments; use ARUNOX\API\PHP; use ARUNOX\Plugins\Calendars; use ARUNOX\Database\BaseModel; #[PHP\Attributes\Database\Definitions\Table( "calendars_tasks_assignments" )] #[PHP\Attributes\Database\Definitions\HashID( "ctasg" )] #[PHP\Attributes\Database\Definitions\Entity( Entity::class )] #[PHP\Attributes\Database\Definitions\Origin( Calendars\Tasks\Model::class )] class Model extends BaseModel { /* ### VARIABLES ################################################ # */ /* ### PUBLIC STATIC FUNCTIONS ################################## # */ public static function getByOrigin( int|string|array $origin, null|string $column = NULL ) { $origin = Calendars\Tasks\Model::getValue( $origin ); if( $column ) return Model::getAllValue([ "origin_id" => $origin ], $column ); return Model::getAll([ "origin_id" => $origin ] ); } /* ### PUBLIC STATIC LOG FUNCTIONS ############################## # */ public static function getLogRulesUpdated( int $id ) { $current = static::get( $id ); $task = $current->origin; $calendar = $task->origin; return [ "status" => [ "options" => Status::getAll(), "message" => "Status wurde auf '%4\$t' gesetzt", "target_hids" => [ $current->target_hid, $task->hashid, $calendar->hashid, $calendar->target_hid, ], ], ]; } public static function getLogRulesCreated( int $id ) { $current = static::get( $id ); $task = $current->origin; $calendar = $task->origin; return [ "__self" => [ "message" => "Aufgabe wurde zugewiesen", "target_hids" => [ $current->target_hid, $task->hashid, $calendar->hashid, $calendar->target_hid, ], ], ]; } } /** Datei: plugins/calendars/library/ARUNOX/Plugins/Calendars/Tasks/Assignments/API/v1/Routes.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Calendars\Tasks\Assignments\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/Tasks/Assignments/API/v1/Controller.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Calendars\Tasks\Assignments\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( "Zuweisung", "Zuweisungen" )] #[PHP\Attributes\Controller\Route( "assignments", Calendars\Tasks\API\v1\Controller::class )] #[PHP\Attributes\Database\Definitions\Model( Calendars\Tasks\Assignments\Model::class )] class Controller extends BaseController { /* ### PUBLIC GET FUNCTIONS ##################################### # */ /** * @api * @method GET * * @route.path /calendars/tasks/{origin}/assignments * @route.description Listet alle Logeinträge */ public static function getByOriginPrepared( string $origin ) : array { return parent::getByOriginPrepared( $origin ); } /** * @api * @method GET * * @route.path /calendars/tasks/assignments/{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 POST * * @route.path /calendars/tasks/{origin}/assignments * @route.description Erstellt einen neuen Teilnehmer */ public static function createByOriginPrepared( string $origin, array $data ) : HTTP\Response { return parent::createByOriginPrepared( $origin, $data ); } /** * @api * @method DELETE * * @route.path /calendars/tasks/assignments/{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/tasks/assignments/{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 GET * * @route.path /calendars/tasks/assignments/{hashid} * @route.description REST-Konfiguration für Detailansicht eines Logeintrags */ public static function restResponseLog( string $hashid ) : HTTP\Response { $entry = Calendars\Tasks\Assignments\Model::get( $hashid )->origin; $route = Calendars\Tasks\API\v1\Controller::getRoute( $entry->hashid, "#assignments" ); REST\Response::redirect( $route ); return REST\Response::jsonResponse(); } /** * @internal rest * @method POST * * @route.path /calendars/tasks/{origin}/assignments * @route.description REST-Antwort nach dem Erstellen eines Kalenders */ public static function restResponseCreate( string $origin, array $data ) : HTTP\Response { $result = static::createByOriginPrepared( $origin, $data ); if( $result->isStatus( 200 ) ) { REST\Response::closeModals(); REST\Response::redirect( "/calendars/tasks/{$origin}#assignments" ); } return static::restResponse( $result ); } /** * @internal rest * @method DELETE * * @route.path /calendars/tasks/assignments/{hashid} * @route.description REST-Antwort nach dem Löschen eines Logeintrag */ public static function restResponseDelete( string $hashid ) : HTTP\Response { REST\Response::closeModals(); $current = Calendars\Tasks\Assignments\Model::get( $hashid ); $origin = Calendars\Tasks\Model::get( $current->origin_id ); $result = static::deletePrepared( $hashid ); if( $result->isStatus( 200 ) ) { REST\Response::addClick( [ "data/table/row", $origin->hashid ], "assignments" ); } return static::restResponse( $result ); } /** * @internal rest * @method PATCH * * @route.path /calendars/tasks/assignments/{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/{origin}/assignments/create * @route.description REST-Konfiguration für das Erstellen eines Teilnehmers (Formular) */ public static function restConfigCreate( string $origin ) : REST\Generator\Base\BaseGenerator { $exclude = Calendars\Tasks\Assignments\Model::getByOrigin( $origin , "target_hid" ); return REST\Response::addModal( "details", static::getSingular( "%t hinzufügen" ) ) ->get() ->setAction( "/calendars/tasks/{$origin}/assignments", "POST" ) ->addButton(...Hooks::filter( "rest.generator::button.type->submit", [], "Hinzufügen", "calendars/tasks/assignments" )) ->addField(...Hooks::filter( "rest.generator::control.type->select", [ "options" => Users\Model::getAsOptions( "username", "hashid", $exclude ), ], "target_hid", TRUE, TRUE, "calendars/tasks/assignments" )) ; } /** * @internal rest * @method GET * * @route.path /calendars/tasks/assignments/{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/tasks/assignments/{$hashid}", "DELETE" ) ->addText( "Möchtest du wirklich den Datensatz (#{$hashid}) löschen? " ) ->addButton(...Hooks::filter( "rest.generator::button.type->cancel", [], NULL, "calendars/tasks/assignments" )) ->addButton(...Hooks::filter( "rest.generator::button.type->delete", [], NULL, "calendars/tasks/assignments" )); } /* ### PUBLIC REST EXTENSION FUNCTIONS ########################## # */ public static function restConfigTable( string $origin ) : REST\Generator\Base\BaseGenerator { $exclude = Calendars\Tasks\Assignments\Model::getByOrigin( $origin , "target_hid" ); $options = Users\Model::getAsOptions( "username", "hashid", $exclude ); $rest = REST\Generator\Data\Table::create() ->setApi( "/calendars/tasks/{$origin}/assignments" ) ->setOrder( "date_create", "desc" ) ->setSearch( TRUE ) ; if( !empty( $options ) ) { $rest->addButton(...Hooks::filter( "rest.generator::button.name->create", [], "calendars/tasks/{$origin}/assignments" )); } $rest->addColumn(...Hooks::filter( "rest.generator::column.type->status", [ "options" => Calendars\Tasks\Assignments\Status::getAll(), ], "status", [], "calendars/tasks/assignments", "hashid" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [ "label" => "Name", ], "target.username", TRUE, TRUE, TRUE, "calendars/tasks/assignments" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->datetime", [ "label" => "Zugewiesen am", ], "date_create", TRUE, FALSE, TRUE, "calendars/tasks/assignments" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->datetime", [ "label" => "Erledigt am", ], "date_done", TRUE, FALSE, TRUE, "calendars/tasks/assignments" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [ "label" => "Aufgabe", ], "task", TRUE, FALSE, TRUE, "calendars/tasks/assignments" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->actions", [], [], FALSE, "calendars/tasks/assignments" ))->get() ->addButton(...Hooks::filter( "rest.generator::action.name->delete", [], "calendars/tasks/assignments", "hashid" )) ; return $rest; } } /** Datei: plugins/calendars/library/ARUNOX/Plugins/Calendars/Tasks/Assignments/Entity.php **/ * @copyright 2025 ARUNOX * @version 1.0.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Calendars\Tasks\Assignments; use ARUNOX\API\PHP; use ARUNOX\Plugins\Calendars; use ARUNOX\Database\BaseEntity; #[PHP\Attributes\Database\Attributes( "status", Status::class )] #[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 getTarget() { return \ARUNOX\Plugins\Users\Model::getByColumn( "hashid", $this->target_hid ); } public function getOrigin() : bool|BaseEntity { return Calendars\Tasks\Model::get( $this->origin_id ); } } /** Datei: plugins/calendars/library/ARUNOX/Plugins/Calendars/Tasks/Assignments/Status.php **/ [ "color" => REST\Generator\Config\Color::Warning, "icon" => "bi-hourglass", "label" => "Eingeladen" ], self::Accepted => [ "color" => REST\Generator\Config\Color::Success, "icon" => "bi-check-lg", "label" => "Angenommen" ], self::Rejected => [ "color" => REST\Generator\Config\Color::Danger, "icon" => "bi-x-lg", "label" => "Abgelehnt" ], ]; /* ### PUBLIC FUNCTIONS ######################################### # */ } /** Datei: plugins/calendars/library/ARUNOX/Plugins/Calendars/Tasks/Entity.php **/ * @copyright 2025 ARUNOX * @version 1.0.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Calendars\Tasks; use ARUNOX\API\PHP; use ARUNOX\Plugins\Calendars; use ARUNOX\Database\BaseEntity; #[PHP\Attributes\Database\Attributes( "status", Status::class )] #[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 toggleStatus() { if( $this->status->toggle() === Status::Done ) { $this->date_done = date( "Y-m-d H:i:s" ); } } public function getAssignments() : array { $list = Assignments\Model::getByOrigin( $this->id ); $status = Assignments\Status::getAll(); $count = array_map( fn( $item ) => count( array_filter( $list, fn( $entry ) => $entry->status->getValue() == $item["value"] ) ), $status ); $status = array_map( fn( $count, $status ) => "{$count}x {$status["emoji"]}", $count, $status ); $return = [ "count" => count( $list ), "output" => implode( " | ", $status ), "status" => $count, "list" => $list, ]; return $return; } public function getOrigin() : bool|BaseEntity { return Calendars\Model::get( $this->origin_id ); } } /** Datei: plugins/calendars/library/ARUNOX/Plugins/Calendars/Tasks/Status.php **/ [ "color" => REST\Generator\Config\Color::Danger, "icon" => "bi-hourglass", "label" => "Offen" ], self::Done => [ "color" => REST\Generator\Config\Color::Success, "icon" => "bi-check-lg", "label" => "Erledigt" ], ]; /* ### PUBLIC FUNCTIONS ######################################### # */ }