mirror of
https://github.com/Karaka-Management/oms-Exchange.git
synced 2026-02-15 17:28:41 +00:00
Split controllers per application
This commit is contained in:
parent
485b3ab488
commit
cdefe7cf62
|
|
@ -3,15 +3,15 @@
|
||||||
use phpOMS\Router\RouteVerb;
|
use phpOMS\Router\RouteVerb;
|
||||||
use phpOMS\Account\PermissionType;
|
use phpOMS\Account\PermissionType;
|
||||||
use Modules\Exchange\Models\PermissionState;
|
use Modules\Exchange\Models\PermissionState;
|
||||||
use Modules\Exchange\Controller;
|
use Modules\Exchange\Controller\ApiController;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'^.*/api/admin/exchange/import/profile.*$' => [
|
'^.*/api/admin/exchange/import/profile.*$' => [
|
||||||
[
|
[
|
||||||
'dest' => '\Modules\Exchange\Controller:apiExchangeImport',
|
'dest' => '\Modules\Exchange\Controller\ApiController:apiExchangeImport',
|
||||||
'verb' => RouteVerb::SET,
|
'verb' => RouteVerb::SET,
|
||||||
'permission' => [
|
'permission' => [
|
||||||
'module' => Controller::MODULE_NAME,
|
'module' => ApiController::MODULE_NAME,
|
||||||
'type' => PermissionType::CREATE,
|
'type' => PermissionType::CREATE,
|
||||||
'state' => PermissionState::IMPORT,
|
'state' => PermissionState::IMPORT,
|
||||||
],
|
],
|
||||||
|
|
@ -19,10 +19,10 @@ return [
|
||||||
],
|
],
|
||||||
'^.*/api/admin/exchange/export/profile.*$' => [
|
'^.*/api/admin/exchange/export/profile.*$' => [
|
||||||
[
|
[
|
||||||
'dest' => '\Modules\Exchange\Controller:apiExchangeExport',
|
'dest' => '\Modules\Exchange\Controller\ApiController:apiExchangeExport',
|
||||||
'verb' => RouteVerb::SET,
|
'verb' => RouteVerb::SET,
|
||||||
'permission' => [
|
'permission' => [
|
||||||
'module' => Controller::MODULE_NAME,
|
'module' => ApiController::MODULE_NAME,
|
||||||
'type' => PermissionType::CREATE,
|
'type' => PermissionType::CREATE,
|
||||||
'state' => PermissionState::EXPORT,
|
'state' => PermissionState::EXPORT,
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,15 @@
|
||||||
use phpOMS\Router\RouteVerb;
|
use phpOMS\Router\RouteVerb;
|
||||||
use phpOMS\Account\PermissionType;
|
use phpOMS\Account\PermissionType;
|
||||||
use Modules\Exchange\Models\PermissionState;
|
use Modules\Exchange\Models\PermissionState;
|
||||||
use Modules\Exchange\Controller;
|
use Modules\Exchange\Controller\BackendController;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'^.*/backend/admin/exchange/import/list.*$' => [
|
'^.*/backend/admin/exchange/import/list.*$' => [
|
||||||
[
|
[
|
||||||
'dest' => '\Modules\Exchange\Controller:viewExchangeImportList',
|
'dest' => '\Modules\Exchange\Controller\BackendController:viewExchangeImportList',
|
||||||
'verb' => RouteVerb::GET,
|
'verb' => RouteVerb::GET,
|
||||||
'permission' => [
|
'permission' => [
|
||||||
'module' => Controller::MODULE_NAME,
|
'module' => BackendController::MODULE_NAME,
|
||||||
'type' => PermissionType::READ,
|
'type' => PermissionType::READ,
|
||||||
'state' => PermissionState::IMPORT,
|
'state' => PermissionState::IMPORT,
|
||||||
],
|
],
|
||||||
|
|
@ -19,10 +19,10 @@ return [
|
||||||
],
|
],
|
||||||
'^.*/backend/admin/exchange/export/list.*$' => [
|
'^.*/backend/admin/exchange/export/list.*$' => [
|
||||||
[
|
[
|
||||||
'dest' => '\Modules\Exchange\Controller:viewExchangeExportList',
|
'dest' => '\Modules\Exchange\Controller\BackendController:viewExchangeExportList',
|
||||||
'verb' => RouteVerb::GET,
|
'verb' => RouteVerb::GET,
|
||||||
'permission' => [
|
'permission' => [
|
||||||
'module' => Controller::MODULE_NAME,
|
'module' => BackendController::MODULE_NAME,
|
||||||
'type' => PermissionType::READ,
|
'type' => PermissionType::READ,
|
||||||
'state' => PermissionState::EXPORT,
|
'state' => PermissionState::EXPORT,
|
||||||
],
|
],
|
||||||
|
|
@ -30,10 +30,10 @@ return [
|
||||||
],
|
],
|
||||||
'^.*/backend/admin/exchange/import/profile.*$' => [
|
'^.*/backend/admin/exchange/import/profile.*$' => [
|
||||||
[
|
[
|
||||||
'dest' => '\Modules\Exchange\Controller:viewExchangeImport',
|
'dest' => '\Modules\Exchange\Controller\BackendController:viewExchangeImport',
|
||||||
'verb' => RouteVerb::GET,
|
'verb' => RouteVerb::GET,
|
||||||
'permission' => [
|
'permission' => [
|
||||||
'module' => Controller::MODULE_NAME,
|
'module' => BackendController::MODULE_NAME,
|
||||||
'type' => PermissionType::READ,
|
'type' => PermissionType::READ,
|
||||||
'state' => PermissionState::IMPORT,
|
'state' => PermissionState::IMPORT,
|
||||||
],
|
],
|
||||||
|
|
@ -41,10 +41,10 @@ return [
|
||||||
],
|
],
|
||||||
'^.*/backend/admin/exchange/export/profile.*$' => [
|
'^.*/backend/admin/exchange/export/profile.*$' => [
|
||||||
[
|
[
|
||||||
'dest' => '\Modules\Exchange\Controller:viewExchangeExport',
|
'dest' => '\Modules\Exchange\Controller\BackendController:viewExchangeExport',
|
||||||
'verb' => RouteVerb::GET,
|
'verb' => RouteVerb::GET,
|
||||||
'permission' => [
|
'permission' => [
|
||||||
'module' => Controller::MODULE_NAME,
|
'module' => BackendController::MODULE_NAME,
|
||||||
'type' => PermissionType::READ,
|
'type' => PermissionType::READ,
|
||||||
'state' => PermissionState::EXPORT,
|
'state' => PermissionState::EXPORT,
|
||||||
],
|
],
|
||||||
|
|
@ -52,10 +52,10 @@ return [
|
||||||
],
|
],
|
||||||
'^.*/backend/admin/exchange/dashboard.*$' => [
|
'^.*/backend/admin/exchange/dashboard.*$' => [
|
||||||
[
|
[
|
||||||
'dest' => '\Modules\Exchange\Controller:viewExchangeDashboard',
|
'dest' => '\Modules\Exchange\Controller\BackendController:viewExchangeDashboard',
|
||||||
'verb' => RouteVerb::GET,
|
'verb' => RouteVerb::GET,
|
||||||
'permission' => [
|
'permission' => [
|
||||||
'module' => Controller::MODULE_NAME,
|
'module' => BackendController::MODULE_NAME,
|
||||||
'type' => PermissionType::READ,
|
'type' => PermissionType::READ,
|
||||||
'state' => PermissionState::DASHBOARD,
|
'state' => PermissionState::DASHBOARD,
|
||||||
],
|
],
|
||||||
|
|
|
||||||
98
Controller/ApiController.php
Normal file
98
Controller/ApiController.php
Normal file
|
|
@ -0,0 +1,98 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.2
|
||||||
|
*
|
||||||
|
* @package Modules\Exchange
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link http://website.orange-management.de
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Modules\Exchange\Controller;
|
||||||
|
|
||||||
|
use Modules\Navigation\Models\Navigation;
|
||||||
|
use Modules\Navigation\Views\NavigationView;
|
||||||
|
|
||||||
|
use phpOMS\Contract\RenderableInterface;
|
||||||
|
use phpOMS\Message\RequestAbstract;
|
||||||
|
use phpOMS\Message\ResponseAbstract;
|
||||||
|
use phpOMS\Message\NotificationLevel;
|
||||||
|
use phpOMS\Module\ModuleAbstract;
|
||||||
|
use phpOMS\Module\WebInterface;
|
||||||
|
use phpOMS\Views\View;
|
||||||
|
use phpOMS\Account\PermissionType;
|
||||||
|
|
||||||
|
use Modules\Exchange\Models\InterfaceManager;
|
||||||
|
use Modules\Exchange\Models\InterfaceManagerMapper;
|
||||||
|
use Modules\Exchange\Models\PermissionState;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exchange controller class.
|
||||||
|
*
|
||||||
|
* @package Modules\Exchange
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link http://website.orange-management.de
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
class ApiController extends Controller
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Api method to import data
|
||||||
|
*
|
||||||
|
* @param RequestAbstract $request Request
|
||||||
|
* @param ResponseAbstract $response Response
|
||||||
|
* @param mixed $data Generic data
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function apiExchangeImport(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
|
||||||
|
{
|
||||||
|
$import = $this->importDataFromRequest($request);
|
||||||
|
$status = NotificationLevel::ERROR;
|
||||||
|
$message = 'Import failed.';
|
||||||
|
|
||||||
|
if ($import) {
|
||||||
|
$status = NotificationLevel::OK;
|
||||||
|
$message = 'Import succeeded.';
|
||||||
|
}
|
||||||
|
|
||||||
|
$response->set($request->getUri()->__toString(), [
|
||||||
|
'status' => status,
|
||||||
|
'title' => 'Exchange',
|
||||||
|
'message' => $message
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to import data based on a request
|
||||||
|
*
|
||||||
|
* @param RequestAbstract $request Request
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
private function importDataFromRequest(RequestAbstract $request) : bool
|
||||||
|
{
|
||||||
|
$interfaces = InterfaceManagerMapper::getAll();
|
||||||
|
foreach ($interfaces as $interface) {
|
||||||
|
if ($request->getData('exchange') ?? '' === $interface->getInterfacePath()) {
|
||||||
|
$class = '\\Modules\\Exchange\\Interfaces\\' . $interface->getInterfacePath() . '\\Importer';
|
||||||
|
$importer = new $class($this->app->dbPool->get());
|
||||||
|
|
||||||
|
return $importer->importFromRequest($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
*/
|
*/
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Modules\Exchange;
|
namespace Modules\Exchange\Controller;
|
||||||
|
|
||||||
use Modules\Navigation\Models\Navigation;
|
use Modules\Navigation\Models\Navigation;
|
||||||
use Modules\Navigation\Views\NavigationView;
|
use Modules\Navigation\Views\NavigationView;
|
||||||
|
|
@ -38,58 +38,9 @@ use Modules\Exchange\Models\PermissionState;
|
||||||
* @link http://website.orange-management.de
|
* @link http://website.orange-management.de
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
final class Controller extends ModuleAbstract implements WebInterface
|
class BackendController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* Module path.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public const MODULE_PATH = __DIR__;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Module version.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public const MODULE_VERSION = '1.0.0';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Module name.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public const MODULE_NAME = 'Exchange';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Module id.
|
|
||||||
*
|
|
||||||
* @var int
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public const MODULE_ID = 1007000000;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Providing.
|
|
||||||
*
|
|
||||||
* @var string[]
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
protected static $providing = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dependencies.
|
|
||||||
*
|
|
||||||
* @var string[]
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
protected static $dependencies = [
|
|
||||||
];
|
|
||||||
|
|
||||||
public function viewExchangeDashboard(RequestAbstract $request, ResponseAbstract $response, $data = null) : \Serializable
|
public function viewExchangeDashboard(RequestAbstract $request, ResponseAbstract $response, $data = null) : \Serializable
|
||||||
{
|
{
|
||||||
$view = new View($this->app, $request, $response);
|
$view = new View($this->app, $request, $response);
|
||||||
|
|
@ -211,59 +162,4 @@ final class Controller extends ModuleAbstract implements WebInterface
|
||||||
|
|
||||||
return $view;
|
return $view;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Api method to import data
|
|
||||||
*
|
|
||||||
* @param RequestAbstract $request Request
|
|
||||||
* @param ResponseAbstract $response Response
|
|
||||||
* @param mixed $data Generic data
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function apiExchangeImport(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
|
|
||||||
{
|
|
||||||
$import = $this->importDataFromRequest($request);
|
|
||||||
$status = NotificationLevel::ERROR;
|
|
||||||
$message = 'Import failed.';
|
|
||||||
|
|
||||||
if ($import) {
|
|
||||||
$status = NotificationLevel::OK;
|
|
||||||
$message = 'Import succeeded.';
|
|
||||||
}
|
|
||||||
|
|
||||||
$response->set($request->getUri()->__toString(), [
|
|
||||||
'status' => status,
|
|
||||||
'title' => 'Exchange',
|
|
||||||
'message' => $message
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Method to import data based on a request
|
|
||||||
*
|
|
||||||
* @param RequestAbstract $request Request
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
private function importDataFromRequest(RequestAbstract $request) : bool
|
|
||||||
{
|
|
||||||
$interfaces = InterfaceManagerMapper::getAll();
|
|
||||||
foreach ($interfaces as $interface) {
|
|
||||||
if ($request->getData('exchange') ?? '' === $interface->getInterfacePath()) {
|
|
||||||
$class = '\\Modules\\Exchange\\Interfaces\\' . $interface->getInterfacePath() . '\\Importer';
|
|
||||||
$importer = new $class($this->app->dbPool->get());
|
|
||||||
|
|
||||||
return $importer->importFromRequest($request);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
92
Controller/Controller.php
Normal file
92
Controller/Controller.php
Normal file
|
|
@ -0,0 +1,92 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Orange Management
|
||||||
|
*
|
||||||
|
* PHP Version 7.2
|
||||||
|
*
|
||||||
|
* @package Modules\Exchange
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link http://website.orange-management.de
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Modules\Exchange\Controller;
|
||||||
|
|
||||||
|
use Modules\Navigation\Models\Navigation;
|
||||||
|
use Modules\Navigation\Views\NavigationView;
|
||||||
|
|
||||||
|
use phpOMS\Contract\RenderableInterface;
|
||||||
|
use phpOMS\Message\RequestAbstract;
|
||||||
|
use phpOMS\Message\ResponseAbstract;
|
||||||
|
use phpOMS\Message\NotificationLevel;
|
||||||
|
use phpOMS\Module\ModuleAbstract;
|
||||||
|
use phpOMS\Module\WebInterface;
|
||||||
|
use phpOMS\Views\View;
|
||||||
|
use phpOMS\Account\PermissionType;
|
||||||
|
|
||||||
|
use Modules\Exchange\Models\InterfaceManager;
|
||||||
|
use Modules\Exchange\Models\InterfaceManagerMapper;
|
||||||
|
use Modules\Exchange\Models\PermissionState;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exchange controller class.
|
||||||
|
*
|
||||||
|
* @package Modules\Exchange
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link http://website.orange-management.de
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
class Controller extends ModuleAbstract implements WebInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Module path.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public const MODULE_PATH = __DIR__ . '/../';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Module version.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public const MODULE_VERSION = '1.0.0';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Module name.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public const MODULE_NAME = 'Exchange';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Module id.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public const MODULE_ID = 1007000000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Providing.
|
||||||
|
*
|
||||||
|
* @var string[]
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
protected static $providing = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dependencies.
|
||||||
|
*
|
||||||
|
* @var string[]
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
protected static $dependencies = [
|
||||||
|
];
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user