/** Datei: plugins/messages/library/ARUNOX/Plugins/Messages/Model.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Messages\API\v1; use ARUNOX\Core\Hooks; use ARUNOX\Core\Router; use ARUNOX\Plugins\Users; class Routes { public static function register() : void { Router::get('/api/v1/messages', [ Controller::class, 'getAll' ]); Router::get('/api/v1/messages/create', [ Controller::class, 'restConfigCreate' ]); Router::post('/api/v1/messages', [ Controller::class, 'create' ]); Router::get('/api/v1/messages/{id}', [ Controller::class, 'get' ]); Router::put('/api/v1/messages/{id}', [ Controller::class, 'save' ]); Router::patch('/api/v1/messages/{id}/status', [ Controller::class, 'toggleStatus' ]); Router::get('/api/v1/messages/{id}/delete', [ Controller::class, 'restConfigDelete' ]); Router::delete('/api/v1/messages/{id}', [ Controller::class, 'delete' ]); Hooks::add('router::get->api.v1.rest.routes', function( $routes ) { if( !Users\Model::isSuperadmin() ) return $routes; $routes[] = [ "path" => "/messages", "label" => "Messages", "icon" => "bi bi-chat-left-text", "menu" => "management", ]; return $routes; }); } } /** Datei: plugins/messages/library/ARUNOX/Plugins/Messages/API/v1/Controller.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Messages\API\v1; use ARUNOX\HTTP; use ARUNOX\Core\Hooks; use ARUNOX\Plugins\REST; use ARUNOX\Plugins\Messages; use ARUNOX\API\BaseController; class Controller extends BaseController { /* ### VARIABLES ################################################ # */ protected static array $NOTIFY = [ "notfound" => "Message nicht gefunden", "saved" => "Message wurde erfolgreich gespeichert", "deleted" => "Message wurde erfolgreich gelöscht", "created" => "Message wurde erfolgreich erstellt", "notcreated" => "Message konnte nicht erstellt werden", ]; /* ### PUBLIC GET FUNCTIONS ##################################### # */ public function getAll() : HTTP\Response { $results = Messages\Model::getAll(); static::restConfigOverview( $results ); return REST\Response::jsonResponse(); } public function get( int $id ) : HTTP\Response { if( $result = Messages\Model::get( $id ) ) { static::restConfigDetails( $result ); } else REST\Response::addNotify( "danger", static::getNotify("notfound") ); return REST\Response::jsonResponse(); } /* ### PUBLIC SAVE FUNCTIONS #################################### # */ public function save( int $id, array $data ) : HTTP\Response { if( $result = Messages\Model::get( $id ) ) { $result->save( $data ); REST\Response::addNotify( "success", static::getNotify("saved") ); REST\Response::closeModals(); REST\Response::addUpdater( [ "data/table/row", $id ], $result ); } else REST\Response::addNotify( "danger", static::getNotify("notfound") ); return REST\Response::jsonResponse(); } public function create( array $data ) : HTTP\Response { if( $id = Messages\Model::save( $data ) ) { REST\Response::addNotify( "success", static::getNotify("created") ); REST\Response::closeModals(); REST\Response::redirect( "/messages" ); } else REST\Response::addNotify( "danger", static::getNotify("notcreated") ); return REST\Response::jsonResponse(); } public function delete( int $id ) : HTTP\Response { REST\Response::closeModals(); if( Messages\Model::delete( $id ) ) { REST\Response::addNotify( "success", static::getNotify("deleted") ); REST\Response::redirect( "/messages" ); } else REST\Response::addNotify( "danger", static::getNotify("notfound") ); return REST\Response::jsonResponse(); } public function toggleStatus( int $id ) : HTTP\Response { if( $result = Messages\Model::get( $id ) ) { $result->toggleStatus( TRUE ); REST\Response::addUpdater( [ "data/table/row", $id ], $result ); } else REST\Response::addNotify( "danger", static::getNotify("notfound") ); return REST\Response::jsonResponse(); } /* ### PUBLIC VALIDATE FUNCTIONS ################################ # */ /* ### PUBLIC REST FUNCTIONS #################################### # */ public static function restConfigOverview( array $data = [] ) : REST\Generator\Base\BaseGenerator { return REST\Response::addWrapper( "overview", "Messages" ) ->setList( $data ) ->get() ->setAction( "/messages/{id}" ) ->setOrder( "name", "asc" ) ->setSearch( TRUE ) ->addButton(...Hooks::filter( "rest.generator::button.name->create", [], "messages" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "name", TRUE, TRUE, TRUE, "messages" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->status", [], "status", [], "messages" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->icon", [], "type", [], "messages" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "identifier", TRUE, TRUE, TRUE, "messages" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "subject", TRUE, TRUE, TRUE, "messages" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->datetime", [], "date_edit", TRUE, TRUE, TRUE, "messages" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->actions", [], [], FALSE, "messages" ))->get() ->addButton(...Hooks::filter( "rest.generator::action.name->edit", [], "messages" )) ->addButton(...Hooks::filter( "rest.generator::action.name->delete", [], "messages" )) ->top(); } public static function restConfigDetails( Messages\Entity $data ) : REST\Generator\Base\BaseGenerator { $form = REST\Response::addModal( "details", "Message bearbeiten" ) ->setData( $data ) ->setTitle( $data->type->getLabel() ) ->setIcon( $data->type->getIcon() ) ->setColor( $data->type->getColor() ) ->get() ->setAction( "/api/v1/messages/{id}", "PUT" ) ->addButton(...Hooks::filter( "rest.generator::button.type->submit", [], "Speichern", "messages" )) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "name", TRUE, "messages" )); switch( $data->type->getValue() ) { case Messages\Type::Unknown : static::restConfigFormTypeUnknown( $form ); break; case Messages\Type::Value : static::restConfigFormTypeValue( $form ); break; case Messages\Type::List : static::restConfigFormTypeList( $form ); break; case Messages\Type::Switch : static::restConfigFormTypeSwitch( $form ); break; case Messages\Type::Mail : static::restConfigFormTypeMail( $form ); break; case Messages\Type::Url : static::restConfigFormTypeUrl( $form ); break; case Messages\Type::Number : static::restConfigFormTypeNumber( $form ); break; } return $form; } public static function restConfigCreate() : REST\Generator\Base\BaseGenerator { return REST\Response::addModal( "details", "Message erstellen" ) ->setData([ "id" => 0 ]) ->get() ->setAction( "/api/v1/messages", "POST" ) ->addButton(...Hooks::filter( "rest.generator::button.type->submit", [], "Erstellen", "messages" )) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "name", TRUE, "messages" )) ->top(); } public static function restConfigDelete( int $id ) : REST\Generator\Base\BaseGenerator { return REST\Response::addModal( "details", "Message Löschen" ) ->setData([ "id" => $id ]) ->setSize( REST\Wrapper\Modal\Size::sm ) ->get() ->setAction( "/api/v1/messages/{id}", "DELETE" ) ->addText( "Möchtest du wirklich den Datensatz (#{$id}) löschen? " ) ->addButton(...Hooks::filter( "rest.generator::button.type->cancel", [], NULL, "messages" )) ->addButton(...Hooks::filter( "rest.generator::button.type->delete", [], NULL, "messages" )) ->top(); } /* ### PUBLIC REST EXTENSION FUNCTIONS ########################## # */ public static function restConfigFormTypeUnknown( REST\Generator\Base\BaseGenerator $form ) : void { $form ->addField(...Hooks::filter( "rest.generator::control.type->textarea", [], "setting", TRUE, "messages" )) ->top(); } public static function restConfigFormTypeValue( REST\Generator\Base\BaseGenerator $form ) : void { $form ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "setting", TRUE, "messages" )) ->top(); } public static function restConfigFormTypeList( REST\Generator\Base\BaseGenerator $form ) : void { $form ->addField(...Hooks::filter( "rest.generator::control.type->textarea", [], "setting", TRUE, "messages" )) ->top(); } public static function restConfigFormTypeSwitch( REST\Generator\Base\BaseGenerator $form ) : void { $form ->addField(...Hooks::filter( "rest.generator::control.type->select", [], "setting", TRUE, TRUE, "messages" )) ->top(); } public static function restConfigFormTypeMail( REST\Generator\Base\BaseGenerator $form ) : void { $form ->addField(...Hooks::filter( "rest.generator::control.type->email", [], "setting", TRUE, "messages" )) ->top(); } public static function restConfigFormTypeUrl( REST\Generator\Base\BaseGenerator $form ) : void { $form ->addField(...Hooks::filter( "rest.generator::control.type->url", [], "setting", TRUE, "messages" )) ->top(); } public static function restConfigFormTypeNumber( REST\Generator\Base\BaseGenerator $form ) : void { $form ->addField(...Hooks::filter( "rest.generator::control.type->number", [], "setting", TRUE, "messages" )) ->top(); } } /** Datei: plugins/messages/library/ARUNOX/Plugins/Messages/Identifier.php **/ [ "color" => REST\Generator\Config\Color::Info, "label" => "E-Mail", "icon" => "bi bi-envelope-at" ], 1 => [ "color" => REST\Generator\Config\Color::Warning, "label" => "SMS", "icon" => "bi bi-phone-vibrate" ], 2 => [ "color" => REST\Generator\Config\Color::Danger, "label" => "Plugin", "icon" => "bi bi-code-slash" ], ]; /* ### PUBLIC FUNCTIONS ######################################### # */ /* ### MAGIC FUNCTIONS ########################################## # */ } /** Datei: plugins/messages/library/ARUNOX/Plugins/Messages/Entity.php **/ Attribute\Status::class, "date_create" => Attribute\DateTime::class, "date_edit" => Attribute\DateTime::class, "type" => Type::class, "identifier" => Identifier::class, ]; /* ### PUBLIC FUNCTIONS ######################################### # */ public function toggleStatus( bool $save = FALSE ) { $this->status->toggle(); if( $save ) $this->save(); } /* ### MAGIC FUNCTIONS ########################################## # */ } /** Datei: plugins/messages/hooks/generator/columns.php **/ type.messages", function( array $config ) { return array_replace_recursive( $config, [ "icon" => "bi-send", "options" => Messages\Type::getAll(), ]); }); /** Datei: plugins/messages/hooks/init.php **/ * @copyright 2025 ARUNOX * @version 1.0.0 * @since 1.0.0 File is created */ use ARUNOX\Core\Hooks; use ARUNOX\Plugins\Messages; Hooks::add('public::api->init', [ Messages\API\v1\Routes::class, "register" ] ); /** Datei: plugins/messages/hooks/config.php **/ * @copyright 2025 ARUNOX * @version 1.0.0 * @since 1.0.0 File is created */ use ARUNOX\Core\Hooks; use ARUNOX\Plugins\REST; use ARUNOX\Plugins\Settings; // Hooks::add('config::constants', function() { // define( "TEMPLATE_CONSTANT", Hooks::filter( 'config::constants->TEMPLATE_CONSTANT', FALSE ) ); // }); // // Hooks::add( 'config::constants.type->TEMPLATE_CONSTANT', function( $type ) { return Settings\Type::Unknown; }); Hooks::add( 'messages.identifier::options', function( $options ) { $options[6] = [ "color" => REST\Generator\Config\Color::Danger, "label" => "TEST", "icon" => "bi bi-house-fill" ]; return $options; }); /** Datei: plugins/messages/config.php **/ * @copyright 2025 ARUNOX * @version 1.0.0 * @since 1.0.0 File is created */ /** Datei: plugins/messages/config/schema/v1.0.0.php **/ array ( 'columns' => array ( 'id' => 'INT NOT NULL AUTO_INCREMENT', 'date_create' => 'DATETIME DEFAULT_GENERATED DEFAULT \'CURRENT_TIMESTAMP\'', 'date_edit' => 'DATETIME DEFAULT_GENERATED ON UPDATE CURRENT_TIMESTAMP DEFAULT \'CURRENT_TIMESTAMP\'', 'status' => 'TINYINT(1) DEFAULT \'0\'', 'type' => 'TINYINT(1) DEFAULT \'0\'', 'name' => 'VARCHAR(255)', 'subject' => 'VARCHAR(255)', 'message' => 'TEXT', 'identifier' => 'VARCHAR(50)', ), 'primary' => array ( 0 => 'id', ), 'indexes' => array ( ), 'engine' => 'InnoDB', 'charset' => 'utf8mb3', ), 'messages_meta' => array ( 'columns' => array ( 'id' => 'INT NOT NULL AUTO_INCREMENT', 'date_create' => 'DATETIME DEFAULT_GENERATED DEFAULT \'CURRENT_TIMESTAMP\'', 'date_edit' => 'DATETIME DEFAULT_GENERATED ON UPDATE CURRENT_TIMESTAMP DEFAULT \'CURRENT_TIMESTAMP\'', 'origin_id' => 'INT NOT NULL', 'meta_key' => 'VARCHAR(255) NOT NULL', 'meta_value' => 'TEXT', ), 'primary' => array ( 0 => 'id', ), 'indexes' => array ( 'origin_id' => array ( 0 => 'origin_id', 1 => 'meta_key', ), ), 'engine' => 'InnoDB', 'charset' => 'utf8mb3', ), );