/** Datei: plugins/websites/library/ARUNOX/Plugins/Websites/Pages/Model.php **/ items; // $level = ++$current->level; // } // // $results = array_sort_column( $results, "hierarchy" ); // // foreach( $results as $item ) { // if( in_array( $item->parent_id, $parents ) ) { // $parents[] = $item->id; // } // // $options[] = [ // "value" => $item->id, // "label" => html_entity_decode( $item->getHierarchicalTitle( $level ) ), // "disabled" => in_array( $item->id, $parents ), // ]; // } // // return $options; // } /* ### MAGIC FUNCTIONS ########################################## # */ } /** Datei: plugins/websites/library/ARUNOX/Plugins/Websites/Pages/API/v1/Routes.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Websites\Pages\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" => Controller::getRoute(), "label" => Controller::getPlural(), "icon" => Controller::getIcon(), "menu" => "websites", ]; return $routes; }, 50 ); } } /** Datei: plugins/websites/library/ARUNOX/Plugins/Websites/Pages/API/v1/Controller.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Websites\Pages\API\v1; use ARUNOX\HTTP; use ARUNOX\API\PHP; use ARUNOX\Core\Hooks; use ARUNOX\Plugins\Logs; use ARUNOX\Plugins\REST; use ARUNOX\Plugins\Websites; use ARUNOX\API\BaseController; use ARUNOX\Database\BaseEntity; #[PHP\Attributes\Controller\Label( "Seite", "Seiten" )] #[PHP\Attributes\Controller\Icon( REST\Generator\Config\Icon::FileEarmarkText )] #[PHP\Attributes\Controller\Route( "pages", Websites\API\v1\Controller::class )] #[PHP\Attributes\Database\Definitions\Model( Websites\Pages\Model::class )] class Controller extends BaseController { /* ### PUBLIC GET FUNCTIONS ##################################### # */ /** * @api * @method GET * * @route.path /websites/pages * @route.description Listet alle Logeinträge */ public static function getAllPrepared() : array { return parent::getAllPrepared(); } /** * @api * @method GET * * @route.path /websites/pages/{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 /websites/pages/{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 /websites/pages * @route.description Erstellt einen neuen Kalender */ public static function createPrepared( array $data ) : HTTP\Response { return parent::createPrepared( $data ); } /** * @api * @method DELETE * * @route.path /websites/pages/{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 /websites/pages/{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 /websites/pages * @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( "/websites/pages/{$result->getBody("data", "hashid")}" ); } return static::restResponse( $result ); } /** * @internal rest * @method DELETE * * @route.path /websites/pages/{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( "/websites/pages" ); } return static::restResponse( $result ); } /** * @internal rest * @method PATCH * * @route.path /websites/pages/{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 /websites/pages * @route.description REST-Konfiguration für Logbuch-Tabelle */ public static function restConfigOverview() : REST\Generator\Base\BaseGenerator { $tabs = REST\Response::addWrapper( "details", static::getPlural() )->get(); $tabs = $tabs->addTab( "Übersicht", FALSE )->get() ->setIcon( static::getIcon() ) ->addHeadline( static::getPlural(), 2 ) ->addContent( static::restConfigTable() ->addButton(...Hooks::filter( "rest.generator::button.name->create", [], "websites/pages" )) ) ->parent(); $tabs = $tabs->addTab( Websites\Menus\API\v1\Controller::getPlural(), "categories" )->get() ->setIcon( Websites\Menus\API\v1\Controller::getIcon() ) ->addHeadline( Websites\Menus\API\v1\Controller::getPlural(), 2 ) ->addContent( Websites\Menus\API\v1\Controller::restConfigTable() ) ->parent(); // $tabs = $tabs->addTab( Calendars\Tasks\Templates\API\v1\Controller::getPlural(), "templates" )->get() // ->setIcon( Calendars\Tasks\Templates\API\v1\Controller::getIcon() ) // ->addHeadline( Calendars\Tasks\Templates\API\v1\Controller::getPlural(), 2 ) // ->addContent( // Calendars\Tasks\Templates\API\v1\Controller::restConfigTable() // ->addButton(...Hooks::filter( "rest.generator::button.name->create", [], "websites/tasks/templates" )) // ) // ->parent(); // $tabs = $tabs->addTab( Calendars\Entries\API\v1\Controller::getPlural(), "appointments" )->get() // ->setIcon( Calendars\Entries\API\v1\Controller::getIcon() ) // ->addHeadline( Calendars\Entries\API\v1\Controller::getPlural(), 2 ) // ->addContent( Calendars\Entries\API\v1\Controller::restConfigTable() ) // ->parent(); // // $tabs = $tabs->addTab( Calendars\Tasks\API\v1\Controller::getPlural(), "tasks" )->get() // ->setIcon( Calendars\Tasks\API\v1\Controller::getIcon() ) // ->addHeadline( Calendars\Tasks\API\v1\Controller::getPlural(), 2 ) // ->addContent( Calendars\Tasks\API\v1\Controller::restConfigTable() ) // ->parent(); return $tabs; } /** * @internal rest * @method GET * * @route.path /websites/pages/{hashid} * @route.description REST-Konfiguration für Detailansicht eines Logeintrags */ public static function restConfigDetails( string $hashid ) : REST\Generator\Base\BaseGenerator { return REST\Response::addWrapper( "details", static::getSingular( "%t bearbeiten" ) ) ->setBacklink( "/websites/pages" ) ->get() ->setApi( "/websites/pages/{$hashid}" ) ->setAction( "/websites/pages/{$hashid}", "PUT" ) ->addTab( "Kalender" )->get() ->addHeadline( "Kalender", 2 ) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "title", FALSE, "websites/pages" )) ->addField(...Hooks::filter( "rest.generator::control.type->textarea", [], "description", FALSE, "websites/pages" )) ->parent() // ->addCallable( [ Calendars\Entries\API\v1\Controller::class, "restConfigTab" ], $hashid ) // ->addCallable( [ Calendars\Tasks\API\v1\Controller::class, "restConfigTab" ], $hashid ) ->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 /websites/pages/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 /websites/pages/{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 parent::restConfigDeletePrepared( $hashid ); } /* ### PUBLIC REST EXTENSION FUNCTIONS ########################## # */ public static function restConfigTable() : REST\Generator\Base\BaseGenerator { $rest = REST\Generator\Data\Table::create() ->setApi( "/websites/pages" ) ->setAction( "/websites/pages/{hashid}" ) ->setOrder( "title", "asc" ) ->setSearch( TRUE ) ->addColumn(...Hooks::filter( "rest.generator::column.type->status", [], "status", [], "websites/pages", "hashid" )) // ->addColumn(...Hooks::filter( "rest.generator::column.type->amount", [ // "label" => FALSE, // "title" => Calendars\Entries\API\v1\Controller::getPlural(), // "icon" => Calendars\Entries\API\v1\Controller::getIcon(), // ], "entries.status.0", TRUE, FALSE, TRUE, "websites/pages" )) // // ->addColumn(...Hooks::filter( "rest.generator::column.type->amount", [ // "label" => FALSE, // "title" => Calendars\Tasks\API\v1\Controller::getPlural(), // "icon" => "bi-clipboard-check", // ], "tasks.status.0", TRUE, FALSE, TRUE, "websites/pages" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "title", TRUE, TRUE, TRUE, "websites/pages" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "target.name", TRUE, TRUE, TRUE, "websites/pages" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "description", TRUE, TRUE, TRUE, "websites/pages" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->datetime", [], "date_create", TRUE, FALSE, TRUE, "websites/pages" )) ; return $rest; } public static function restConfigInputs() : array { $rest = REST\Generator\Data\Form::create() ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "target_hid", TRUE, "websites/pages" )) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "title", TRUE, "websites/pages" )) ->addField(...Hooks::filter( "rest.generator::control.type->textarea", [], "description", FALSE, "websites/pages" )) ; return $rest->top()->getChildren(); } } /** Datei: plugins/websites/library/ARUNOX/Plugins/Websites/Pages/Entity.php **/ status->toggle(); if( $save ) $this->save(); } public function getParent() { return Model::get( $this->parent_id ); } public function getLevel() { return count( explode( ".", $this->hierarchy ) ); } public function getHierarchicalTitle( ?int $start = NULL ) { $start = $start ?? $this->startLevel ?? 2; $title = NULL; $level = count( explode( ".", $this->hierarchy ) ); if( $level > $start ) { for( $x = ++$start; $x <= $level; $x++ ) { $title .= "|   "; } $title .= "|_ "; } return $title . $this->title; } public function getHierarchy() { $hierarchy = []; if( $this->parent_id ) { $hierarchy = explode( ".", $this->parent->hierarchy ); } $hierarchy[] = str_pad( $this->parent_id, 3, 0, STR_PAD_LEFT ); $hierarchy[] = str_pad( $this->id, 3, 0, STR_PAD_LEFT ); $hierarchy = array_unique( $hierarchy ); $hierarchy = implode( ".", $hierarchy ); return $hierarchy; } public function getUrl() { if( !$this->permalink ) return NULL; $permalink = []; if( $this->parent ) { $permalink[] = $this->parent->url ?? NULL; } $permalink[] = $this->permalink ?? NULL; $permalink = implode( "/", $permalink ); $permalink = explode( "/", $permalink ); $permalink = array_filter( $permalink ); $permalink = implode( "/", $permalink ); return "/{$permalink}"; } public function getPages( int $start = 2 ) { $pages = Model::getAll([ "parent_id" => $this->id, ]); foreach( $pages as $page ) { $page->startLevel = $start; $pages = array_merge( $pages, $page->getPages( $start ) ); } $pages = array_sort_column( $pages, "hierarchy" ); return $pages; } public function generate( string $root, callable $wrapper ) { $dirname = "{$root}/de/{$this->url}"; $dirname = preg_replace( "/\/+/", "/", $dirname ); $content = $wrapper( $this ); @mkdir( $dirname, 0755, TRUE ); file_put_contents( "{$dirname}/index.php", $content ); if( $this->parent_id ) return; $pages = $this->pages; foreach( $pages as $index => $page ) { if( $page->status->value !== Attribute\Status::Active ) continue; $page->generate( $root, $wrapper ); } } /* ### MAGIC FUNCTIONS ########################################## # */ }