mirror of
https://github.com/Karaka-Management/oms-Draw.git
synced 2026-01-27 21:38:40 +00:00
Split controllers per application
This commit is contained in:
parent
0028d1ded9
commit
a0dd5b4aca
|
|
@ -3,15 +3,15 @@
|
|||
use phpOMS\Router\RouteVerb;
|
||||
use phpOMS\Account\PermissionType;
|
||||
use Modules\Draw\Models\PermissionState;
|
||||
use Modules\Draw\Controller;
|
||||
use Modules\Draw\Controller\ApiController;
|
||||
|
||||
return [
|
||||
'^.*/api/draw.*$' => [
|
||||
[
|
||||
'dest' => '\Modules\Draw\Controller:apiDrawCreate',
|
||||
'dest' => '\Modules\Draw\ControllerApiController:apiDrawCreate',
|
||||
'verb' => RouteVerb::SET,
|
||||
'permission' => [
|
||||
'module' => Controller::MODULE_NAME,
|
||||
'module' => ApiController::MODULE_NAME,
|
||||
'type' => PermissionType::CREATE,
|
||||
'state' => PermissionState::DRAW,
|
||||
],
|
||||
|
|
|
|||
|
|
@ -3,24 +3,24 @@
|
|||
use phpOMS\Router\RouteVerb;
|
||||
use phpOMS\Account\PermissionType;
|
||||
use Modules\Draw\Models\PermissionState;
|
||||
use Modules\Draw\Controller;
|
||||
use Modules\Draw\Controller\BackendController;
|
||||
|
||||
return [
|
||||
'^.*/backend/draw/create.*$' => [
|
||||
[
|
||||
'dest' => '\Modules\Draw\Controller:setUpDrawEditor',
|
||||
'dest' => '\Modules\Draw\Controller\BackendController:setUpDrawEditor',
|
||||
'verb' => RouteVerb::GET,
|
||||
'permission' => [
|
||||
'module' => Controller::MODULE_NAME,
|
||||
'module' => BackendController::MODULE_NAME,
|
||||
'type' => PermissionType::CREATE,
|
||||
'state' => PermissionState::DRAW,
|
||||
],
|
||||
],
|
||||
[
|
||||
'dest' => '\Modules\Draw\Controller:viewDrawCreate',
|
||||
'dest' => '\Modules\Draw\Controller\BackendController:viewDrawCreate',
|
||||
'verb' => RouteVerb::GET,
|
||||
'permission' => [
|
||||
'module' => Controller::MODULE_NAME,
|
||||
'module' => BackendController::MODULE_NAME,
|
||||
'type' => PermissionType::CREATE,
|
||||
'state' => PermissionState::DRAW,
|
||||
],
|
||||
|
|
@ -28,10 +28,10 @@ return [
|
|||
],
|
||||
'^.*/backend/draw/list.*$' => [
|
||||
[
|
||||
'dest' => '\Modules\Draw\Controller:viewDrawList',
|
||||
'dest' => '\Modules\Draw\Controller\BackendController:viewDrawList',
|
||||
'verb' => RouteVerb::GET,
|
||||
'permission' => [
|
||||
'module' => Controller::MODULE_NAME,
|
||||
'module' => BackendController::MODULE_NAME,
|
||||
'type' => PermissionType::READ,
|
||||
'state' => PermissionState::DRAW,
|
||||
],
|
||||
|
|
@ -39,19 +39,19 @@ return [
|
|||
],
|
||||
'^.*/backend/draw/single.*$' => [
|
||||
[
|
||||
'dest' => '\Modules\Draw\Controller:setUpDrawEditor',
|
||||
'dest' => '\Modules\Draw\Controller\BackendController:setUpDrawEditor',
|
||||
'verb' => RouteVerb::GET,
|
||||
'permission' => [
|
||||
'module' => Controller::MODULE_NAME,
|
||||
'module' => BackendController::MODULE_NAME,
|
||||
'type' => PermissionType::READ,
|
||||
'state' => PermissionState::DRAW,
|
||||
],
|
||||
],
|
||||
[
|
||||
'dest' => '\Modules\Draw\Controller:viewDrawSingle',
|
||||
'dest' => '\Modules\Draw\Controller\BackendController:viewDrawSingle',
|
||||
'verb' => RouteVerb::GET,
|
||||
'permission' => [
|
||||
'module' => Controller::MODULE_NAME,
|
||||
'module' => BackendController::MODULE_NAME,
|
||||
'type' => PermissionType::READ,
|
||||
'state' => PermissionState::DRAW,
|
||||
],
|
||||
|
|
|
|||
137
Controller/ApiController.php
Normal file
137
Controller/ApiController.php
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.2
|
||||
*
|
||||
* @package Modules\Draw
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://website.orange-management.de
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Draw\Controller;
|
||||
|
||||
use Model\Message\FormValidation;
|
||||
use Modules\Draw\Models\DrawImage;
|
||||
use Modules\Draw\Models\DrawImageMapper;
|
||||
use Modules\Draw\Models\PermissionState;
|
||||
use Modules\Media\Models\UploadStatus;
|
||||
use phpOMS\Asset\AssetType;
|
||||
use phpOMS\Message\RequestAbstract;
|
||||
use phpOMS\Message\ResponseAbstract;
|
||||
use phpOMS\Model\Html\Head;
|
||||
use phpOMS\Module\ModuleAbstract;
|
||||
use phpOMS\Module\WebInterface;
|
||||
use Modules\Media\Controller as MediaController;
|
||||
use phpOMS\System\File\Local\File;
|
||||
use phpOMS\Utils\ImageUtils;
|
||||
use phpOMS\Views\View;
|
||||
use phpOMS\Account\PermissionType;
|
||||
use phpOMS\Message\Http\RequestStatusCode;
|
||||
|
||||
/**
|
||||
* Calendar controller class.
|
||||
*
|
||||
* @package Modules\Draw
|
||||
* @license OMS License 1.0
|
||||
* @link http://website.orange-management.de
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class ApiController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* Validate draw create request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return array<string, bool>
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function validateDrawCreate(RequestAbstract $request) : array
|
||||
{
|
||||
$val = [];
|
||||
if (($val['title'] = empty($request->getData('title')))
|
||||
|| ($val['image'] = empty($request->getData('image')))
|
||||
) {
|
||||
return $val;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiDrawCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
|
||||
{
|
||||
if (!empty($val = $this->validateDrawCreate($request))) {
|
||||
$response->set('draw_create', new FormValidation($val));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$path = MediaController::createMediaPath();
|
||||
$extension = 'png';
|
||||
$filename = '';
|
||||
$rnd = '';
|
||||
|
||||
// todo: implement limit since this could get exploited
|
||||
do {
|
||||
$filename = sha1(((string) $request->getData('image')) . $rnd);
|
||||
$filename .= '.' . $extension;
|
||||
|
||||
$rnd = mt_rand();
|
||||
} while (file_exists($path . '/' . $filename));
|
||||
|
||||
$fullPath = __DIR__ . '/../../' . $path . '/' . $filename;
|
||||
|
||||
$this->createLocalFile($fullPath, (string) $request->getData('image'));
|
||||
|
||||
$status = [
|
||||
'path' => $path,
|
||||
'filename' => $filename,
|
||||
'name' => (string) $request->getData('title'),
|
||||
'size' => File::size($fullPath),
|
||||
'extension' => $extension,
|
||||
'status' => UploadStatus::OK,
|
||||
];
|
||||
|
||||
$media = MediaController::createDbEntry($status, $request->getHeader()->getAccount());
|
||||
$draw = DrawImage::fromMedia($media);
|
||||
|
||||
DrawImageMapper::create($draw);
|
||||
|
||||
$response->set('image', $draw->jsonSerialize());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create local image file
|
||||
*
|
||||
* @param string $outputPath Output path
|
||||
* @param string $raw Base64 encoded image string
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function createLocalFile(string $outputPath, string $raw) : bool
|
||||
{
|
||||
$imageData = ImageUtils::decodeBase64Image($raw);
|
||||
File::put($outputPath, $imageData);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Draw;
|
||||
namespace Modules\Draw\Controller;
|
||||
|
||||
use Model\Message\FormValidation;
|
||||
use Modules\Draw\Models\DrawImage;
|
||||
|
|
@ -40,58 +40,9 @@ use phpOMS\Message\Http\RequestStatusCode;
|
|||
* @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 = 'Draw';
|
||||
|
||||
/**
|
||||
* Module id.
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const MODULE_ID = 1005200000;
|
||||
|
||||
/**
|
||||
* Providing.
|
||||
*
|
||||
* @var string[]
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static $providing = [];
|
||||
|
||||
/**
|
||||
* Dependencies.
|
||||
*
|
||||
* @var string[]
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static $dependencies = [
|
||||
];
|
||||
|
||||
/**
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
|
|
@ -187,96 +138,4 @@ final class Controller extends ModuleAbstract implements WebInterface
|
|||
|
||||
return $view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate draw create request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return array<string, bool>
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function validateDrawCreate(RequestAbstract $request) : array
|
||||
{
|
||||
$val = [];
|
||||
if (($val['title'] = empty($request->getData('title')))
|
||||
|| ($val['image'] = empty($request->getData('image')))
|
||||
) {
|
||||
return $val;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiDrawCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
|
||||
{
|
||||
if (!empty($val = $this->validateDrawCreate($request))) {
|
||||
$response->set('draw_create', new FormValidation($val));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$path = MediaController::createMediaPath();
|
||||
$extension = 'png';
|
||||
$filename = '';
|
||||
$rnd = '';
|
||||
|
||||
// todo: implement limit since this could get exploited
|
||||
do {
|
||||
$filename = sha1(((string) $request->getData('image')) . $rnd);
|
||||
$filename .= '.' . $extension;
|
||||
|
||||
$rnd = mt_rand();
|
||||
} while (file_exists($path . '/' . $filename));
|
||||
|
||||
$fullPath = __DIR__ . '/../../' . $path . '/' . $filename;
|
||||
|
||||
$this->createLocalFile($fullPath, (string) $request->getData('image'));
|
||||
|
||||
$status = [
|
||||
'path' => $path,
|
||||
'filename' => $filename,
|
||||
'name' => (string) $request->getData('title'),
|
||||
'size' => File::size($fullPath),
|
||||
'extension' => $extension,
|
||||
'status' => UploadStatus::OK,
|
||||
];
|
||||
|
||||
$media = MediaController::createDbEntry($status, $request->getHeader()->getAccount());
|
||||
$draw = DrawImage::fromMedia($media);
|
||||
|
||||
DrawImageMapper::create($draw);
|
||||
|
||||
$response->set('image', $draw->jsonSerialize());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create local image file
|
||||
*
|
||||
* @param string $outputPath Output path
|
||||
* @param string $raw Base64 encoded image string
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function createLocalFile(string $outputPath, string $raw) : bool
|
||||
{
|
||||
$imageData = ImageUtils::decodeBase64Image($raw);
|
||||
File::put($outputPath, $imageData);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
94
Controller/Controller.php
Normal file
94
Controller/Controller.php
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.2
|
||||
*
|
||||
* @package Modules\Draw
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link http://website.orange-management.de
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Draw\Controller;
|
||||
|
||||
use Model\Message\FormValidation;
|
||||
use Modules\Draw\Models\DrawImage;
|
||||
use Modules\Draw\Models\DrawImageMapper;
|
||||
use Modules\Draw\Models\PermissionState;
|
||||
use Modules\Media\Models\UploadStatus;
|
||||
use phpOMS\Asset\AssetType;
|
||||
use phpOMS\Message\RequestAbstract;
|
||||
use phpOMS\Message\ResponseAbstract;
|
||||
use phpOMS\Model\Html\Head;
|
||||
use phpOMS\Module\ModuleAbstract;
|
||||
use phpOMS\Module\WebInterface;
|
||||
use Modules\Media\Controller as MediaController;
|
||||
use phpOMS\System\File\Local\File;
|
||||
use phpOMS\Utils\ImageUtils;
|
||||
use phpOMS\Views\View;
|
||||
use phpOMS\Account\PermissionType;
|
||||
use phpOMS\Message\Http\RequestStatusCode;
|
||||
|
||||
/**
|
||||
* Calendar controller class.
|
||||
*
|
||||
* @package Modules\Draw
|
||||
* @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 = 'Draw';
|
||||
|
||||
/**
|
||||
* Module id.
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const MODULE_ID = 1005200000;
|
||||
|
||||
/**
|
||||
* 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