/** Datei: plugins/agents/library/ARUNOX/Plugins/Agents/Processing/Model.php **/ Agents\Model::getValue( $agentId, "id" ), ])); } } /** Datei: plugins/agents/library/ARUNOX/Plugins/Agents/Processing/API/v1/Routes.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Agents\Processing\API\v1; use ARUNOX\Core\Hooks; use ARUNOX\Core\Router; class Routes { public static function register() : void { Router::get('/api/v1/agents/{id}/processing', [ Controller::class, 'getByAgent' ]); Router::get('/api/v1/agents/{id}/processing/create', [ Controller::class, 'restConfigCreate' ]); Router::post('/api/v1/agents/{id}/processing', [ Controller::class, 'create' ]); Router::get('/api/v1/agents/{id}/processing/{id}', [ Controller::class, 'get' ]); Router::put('/api/v1/agents/{id}/processing/{id}', [ Controller::class, 'save' ]); Router::patch('/api/v1/agents/{id}/processing/{id}/status', [ Controller::class, 'toggleStatus' ]); Router::get('/api/v1/agents/{id}/processing/{id}/delete', [ Controller::class, 'restConfigDelete' ]); Router::delete('/api/v1/agents/{id}/processing/{id}', [ Controller::class, 'delete' ]); Hooks::add('router::get->api.v1.rest.routes', function( $routes ) { $routes[] = [ "path" => "/agents/processing/{id}", "label" => "Bearbeiten", ]; return $routes; }); } } /** Datei: plugins/agents/library/ARUNOX/Plugins/Agents/Processing/API/v1/Controller.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Agents\Processing\API\v1; use ARUNOX\HTTP; use ARUNOX\Core\Hooks; use ARUNOX\Plugins\REST; use ARUNOX\Plugins\Agents; use ARUNOX\API\BaseController; class Controller extends BaseController { /* ### VARIABLES ################################################ # */ protected static array $NOTIFY = [ "notfound" => "Tool nicht gefunden", "saved" => "Tool wurde erfolgreich gespeichert", "deleted" => "Tool wurde erfolgreich gelöscht", "created" => "Tool wurde erfolgreich erstellt", "notcreated" => "Tool konnte nicht erstellt werden", ]; /* ### PUBLIC FUNCTIONS ######################################### # */ public function getByAgent( int $id ) : HTTP\Response { $results = Agents\Processing\Model::getByAgent( $id ); return $this->jsonResponse( $results ); } public function get( int $origin, int $id ) : HTTP\Response { if( $result = Agents\Processing\Model::get([ "id" => $id, "origin_id" => $origin ]) ) { $this->restConfigDetails( $result ); } else REST\Response::addNotify( "danger", static::$NOTIFY["notfound"] ); return REST\Response::jsonResponse(); } /* ### PUBLIC SAVE FUNCTIONS #################################### # */ public function save( int $origin, int $id, array $data ) : HTTP\Response { if( $result = Agents\Processing\Model::get([ "id" => $id, "origin_id" => $origin ]) ) { $result->save( $data ); REST\Response::addNotify( "success", static::$NOTIFY["saved"] ); REST\Response::closeModals(); REST\Response::addUpdater( [ "data/table/row", "/api/v1/agents/{$result->origin_id}/processing", $id ], $result ); } else REST\Response::addNotify( "danger", static::$NOTIFY["notfound"] ); return REST\Response::jsonResponse(); } public function create( int $origin, array $data ) : HTTP\Response { $data[ "origin_id" ] = $origin; if( $id = Agents\Model::save( $data ) ) { $result = Agents\Processing\Model::get( $id ); REST\Response::addNotify( "success", static::$NOTIFY["created"] ); REST\Response::closeModals(); REST\Response::redirect( "/agents/agents/{$result->origin_id}#processing" ); } else REST\Response::addNotify( "danger", static::$NOTIFY["notcreated"] ); return REST\Response::jsonResponse(); } public function delete( int $origin, int $id ) : HTTP\Response { $result = Agents\Processing\Model::get([ "id" => $id, "origin_id" => $origin ]); REST\Response::closeModals(); if( $result && Agents\Model::delete( $id ) ) { REST\Response::addNotify( "success", static::$NOTIFY["deleted"] ); REST\Response::redirect( "/agents/agents/{$result->origin_id}#processing" ); } else REST\Response::addNotify( "danger", static::$NOTIFY["notfound"] ); return REST\Response::jsonResponse(); } public function toggleStatus( int $origin, int $id ) : HTTP\Response { if( $result = Agents\Processing\Model::get([ "id" => $id, "origin_id" => $origin ]) ) { $result->toggleStatus( TRUE ); REST\Response::addUpdater( [ "data/table/row", "/api/v1/agents/{$result->origin_id}/processing", $id ], $result ); } else REST\Response::addNotify( "danger", static::$NOTIFY["notfound"] ); return REST\Response::jsonResponse(); } /* ### PUBLIC VALIDATE FUNCTIONS ################################ # */ /* ### PUBLIC REST FUNCTIONS #################################### # */ public function restConfigDetails( Agents\Processing\Entity $data ) : HTTP\Response { $form = REST\Response::addModal( "details", "Tool bearbeiten" ) ->setData( $data ) ->setTitle( $data->type->getLabel() ) ->setIcon( $data->type->getIcon() ) ->setColor( $data->type->getColor() ) ->get() ->setAction( "/api/v1/agents/{origin_id}/processing/{id}", "PUT" ) ->addButton(...Hooks::filter( "rest.generator::button.type->submit", [], "Speichern", "agents/{origin_id}/processing" )) ->addText( "Geben Sie diesem Tool eine für Sie passende Beschreibung, zur besseren Wiedererkennung." ) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "description", TRUE, "agents/{origin_id}/processing" )) ->addHeadline( "Einstellungen", "3" ); switch( $data->type->getValue() ) { case Agents\Processing\Type::EmailDelivery : static::restConfigFormTypeEmailDelivery( $form ); break; case Agents\Processing\Type::SMSDelivery : static::restConfigFormTypeSMSDelivery( $form ); break; case Agents\Processing\Type::APIRequest : static::restConfigFormTypeApi( $form ); break; } return REST\Response::jsonResponse(); } public function restConfigCreate( $args ) : HTTP\Response { $option = Agents\Processing\Type::get( $args["type"] ); $form = REST\Response::addModal( "details", "Tool erstellen" ) ->setTitle( $option["label"] ) ->setIcon( $option["icon"] ) ->setColor( $option["color"] ) ->get() ->setAction( "/api/v1/agents/{id}/processing", "POST" ) ->addButton(...Hooks::filter( "rest.generator::button.type->submit", [], "Erstellen", "agents/{origin_id}/processing" )) ->addText( "Geben Sie diesem Tool eine für Sie passende Beschreibung, zur besseren Wiedererkennung." ) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "description", TRUE, "agents/{origin_id}/processing" )) ->addHeadline( "Einstellungen", "3" ); switch( $_GET["type"] ) { case Agents\Processing\Type::EmailDelivery : static::restConfigFormTypeEmailDelivery( $form ); break; case Agents\Processing\Type::SMSDelivery : static::restConfigFormTypeSMSDelivery( $form ); break; case Agents\Processing\Type::APIRequest : static::restConfigFormTypeApi( $form ); break; } return REST\Response::jsonResponse(); } public function restConfigDeleteOwn( int $origin, int $id ) : HTTP\Response { REST\Response::addModal( "details", "Tool Löschen" ) ->setData([ "id" => $id ]) ->setSize( REST\Wrapper\Modal\Size::sm ) ->get() ->setAction( "/api/v1/agents/{origin_id}/processing/{id}", "DELETE" ) ->addText( "Möchtest du wirklich den Datensatz (#{$id}) löschen? " ) ->addButton(...Hooks::filter( "rest.generator::button.type->cancel", [], NULL, "agents/{origin_id}/processing" )) ->addButton(...Hooks::filter( "rest.generator::button.type->delete", [], NULL, "agents/{origin_id}/processing" )); return REST\Response::jsonResponse(); } /* ### PUBLIC REST STATIC FUNCTIONS ############################# # */ public static function restConfigTable() : REST\Generator\Base\BaseGenerator { $table = REST\Generator\Data\Table::create() ->setApi( "/api/v1/agents/{id}/processing" ) ->setAction( "/api/v1/agents/{origin_id}/processing/{id}" ) ->setOrder( "name", "asc" ) ->setSearch( TRUE ) ->addButton(...Hooks::filter( "rest.generator::button.name->create", [], "agents/{id}/processing" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "type", TRUE, TRUE, TRUE, "agents/{origin_id}/processing" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->status", [], "status", [], "agents/{origin_id}/processing" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "description", TRUE, FALSE, TRUE, "agents/{origin_id}/processing" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->datetime", [], "date_edit", FALSE, FALSE, TRUE, "agents/{origin_id}/processing" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->actions", [], [], FALSE, "agents/{origin_id}/processing" ))->get() ->addButton(...Hooks::filter( "rest.generator::action.name->edit", [], "agents/{origin_id}/processing" )) ->addButton(...Hooks::filter( "rest.generator::action.name->delete", [], "agents/{origin_id}/processing" )) ->top(); $buttons = $table->getButtons(); foreach( Agents\Processing\Type::getAll() as $type ) { $type["name"] = "type"; $buttons->addDropdown( ...Hooks::filter( "rest.generator::button.name->create", $type, "agents/{id}/processing" ) ); } return $table; } public static function restConfigFormTypeEmailDelivery( REST\Generator\Base\BaseGenerator $form ) : void { $form ->addField(...Hooks::filter( "rest.generator::control.type->tel", [], "phone", TRUE, "agents/{origin_id}/processing" )) ->top(); } public static function restConfigFormTypeSMSDelivery( REST\Generator\Base\BaseGenerator $form ) : void { $form ->get() ->addField(...Hooks::filter( "rest.generator::control.type->tel", [], "phone", TRUE, "agents/{origin_id}/processing" )) ->setTitle( "Aktuell nur Platzhalter / Muster") ->top(); } public static function restConfigFormTypeApi( REST\Generator\Base\BaseGenerator $form ) : void { $form ->get() ->setTitle( "Aktuell nur Platzhalter / Muster") ->top(); } } /** Datei: plugins/agents/library/ARUNOX/Plugins/Agents/Processing/Type.php **/ [ "color" => REST\Generator\Config\Color::Primary, "icon" => "bi bi-envelope-at", "label" => "E-Mail-Versand" ], 2 => [ "color" => REST\Generator\Config\Color::Secondary, "icon" => "bi bi-phone-vibrate", "label" => "SMS-Versand" ], 3 => [ "color" => REST\Generator\Config\Color::Danger, "icon" => "bi bi-plugin", "label" => "API Request" ], ]; /* ### PUBLIC FUNCTIONS ######################################### # */ } /** Datei: plugins/agents/library/ARUNOX/Plugins/Agents/Processing/Entity.php **/ Attribute\Status::class, "date_create" => Attribute\DateTime::class, "date_edit" => Attribute\DateTime::class, "type" => Type::class, ]; /* ### PUBLIC FUNCTIONS ######################################### # */ public function toggleStatus( bool $save = FALSE ) { $this->status->toggle(); if( $save ) $this->save(); } }