mirror of
https://github.com/Karaka-Management/oms-Exchange.git
synced 2026-01-30 01:38: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\Account\PermissionType;
|
||||
use Modules\Exchange\Models\PermissionState;
|
||||
use Modules\Exchange\Controller;
|
||||
use Modules\Exchange\Controller\ApiController;
|
||||
|
||||
return [
|
||||
'^.*/api/admin/exchange/import/profile.*$' => [
|
||||
[
|
||||
'dest' => '\Modules\Exchange\Controller:apiExchangeImport',
|
||||
'dest' => '\Modules\Exchange\Controller\ApiController:apiExchangeImport',
|
||||
'verb' => RouteVerb::SET,
|
||||
'permission' => [
|
||||
'module' => Controller::MODULE_NAME,
|
||||
'module' => ApiController::MODULE_NAME,
|
||||
'type' => PermissionType::CREATE,
|
||||
'state' => PermissionState::IMPORT,
|
||||
],
|
||||
|
|
@ -19,10 +19,10 @@ return [
|
|||
],
|
||||
'^.*/api/admin/exchange/export/profile.*$' => [
|
||||
[
|
||||
'dest' => '\Modules\Exchange\Controller:apiExchangeExport',
|
||||
'dest' => '\Modules\Exchange\Controller\ApiController:apiExchangeExport',
|
||||
'verb' => RouteVerb::SET,
|
||||
'permission' => [
|
||||
'module' => Controller::MODULE_NAME,
|
||||
'module' => ApiController::MODULE_NAME,
|
||||
'type' => PermissionType::CREATE,
|
||||
'state' => PermissionState::EXPORT,
|
||||
],
|
||||
|
|
|
|||
|
|
@ -3,15 +3,15 @@
|
|||
use phpOMS\Router\RouteVerb;
|
||||
use phpOMS\Account\PermissionType;
|
||||
use Modules\Exchange\Models\PermissionState;
|
||||
use Modules\Exchange\Controller;
|
||||
use Modules\Exchange\Controller\BackendController;
|
||||
|
||||
return [
|
||||
'^.*/backend/admin/exchange/import/list.*$' => [
|
||||
[
|
||||
'dest' => '\Modules\Exchange\Controller:viewExchangeImportList',
|
||||
'dest' => '\Modules\Exchange\Controller\BackendController:viewExchangeImportList',
|
||||
'verb' => RouteVerb::GET,
|
||||
'permission' => [
|
||||
'module' => Controller::MODULE_NAME,
|
||||
'module' => BackendController::MODULE_NAME,
|
||||
'type' => PermissionType::READ,
|
||||
'state' => PermissionState::IMPORT,
|
||||
],
|
||||
|
|
@ -19,10 +19,10 @@ return [
|
|||
],
|
||||
'^.*/backend/admin/exchange/export/list.*$' => [
|
||||
[
|
||||
'dest' => '\Modules\Exchange\Controller:viewExchangeExportList',
|
||||
'dest' => '\Modules\Exchange\Controller\BackendController:viewExchangeExportList',
|
||||
'verb' => RouteVerb::GET,
|
||||
'permission' => [
|
||||
'module' => Controller::MODULE_NAME,
|
||||
'module' => BackendController::MODULE_NAME,
|
||||
'type' => PermissionType::READ,
|
||||
'state' => PermissionState::EXPORT,
|
||||
],
|
||||
|
|
@ -30,10 +30,10 @@ return [
|
|||
],
|
||||
'^.*/backend/admin/exchange/import/profile.*$' => [
|
||||
[
|
||||
'dest' => '\Modules\Exchange\Controller:viewExchangeImport',
|
||||
'dest' => '\Modules\Exchange\Controller\BackendController:viewExchangeImport',
|
||||
'verb' => RouteVerb::GET,
|
||||
'permission' => [
|
||||
'module' => Controller::MODULE_NAME,
|
||||
'module' => BackendController::MODULE_NAME,
|
||||
'type' => PermissionType::READ,
|
||||
'state' => PermissionState::IMPORT,
|
||||
],
|
||||
|
|
@ -41,10 +41,10 @@ return [
|
|||
],
|
||||
'^.*/backend/admin/exchange/export/profile.*$' => [
|
||||
[
|
||||
'dest' => '\Modules\Exchange\Controller:viewExchangeExport',
|
||||
'dest' => '\Modules\Exchange\Controller\BackendController:viewExchangeExport',
|
||||
'verb' => RouteVerb::GET,
|
||||
'permission' => [
|
||||
'module' => Controller::MODULE_NAME,
|
||||
'module' => BackendController::MODULE_NAME,
|
||||
'type' => PermissionType::READ,
|
||||
'state' => PermissionState::EXPORT,
|
||||
],
|
||||
|
|
@ -52,10 +52,10 @@ return [
|
|||
],
|
||||
'^.*/backend/admin/exchange/dashboard.*$' => [
|
||||
[
|
||||
'dest' => '\Modules\Exchange\Controller:viewExchangeDashboard',
|
||||
'dest' => '\Modules\Exchange\Controller\BackendController:viewExchangeDashboard',
|
||||
'verb' => RouteVerb::GET,
|
||||
'permission' => [
|
||||
'module' => Controller::MODULE_NAME,
|
||||
'module' => BackendController::MODULE_NAME,
|
||||
'type' => PermissionType::READ,
|
||||
'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);
|
||||
|
||||
namespace Modules\Exchange;
|
||||
namespace Modules\Exchange\Controller;
|
||||
|
||||
use Modules\Navigation\Models\Navigation;
|
||||
use Modules\Navigation\Views\NavigationView;
|
||||
|
|
@ -38,58 +38,9 @@ use Modules\Exchange\Models\PermissionState;
|
|||
* @link http://website.orange-management.de
|
||||
* @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
|
||||
{
|
||||
$view = new View($this->app, $request, $response);
|
||||
|
|
@ -211,59 +162,4 @@ final class Controller extends ModuleAbstract implements WebInterface
|
|||
|
||||
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