mirror of
https://github.com/Karaka-Management/oms-Draw.git
synced 2026-02-13 21:58:40 +00:00
Docblock fixes + more tests
This commit is contained in:
parent
b1a46a10a7
commit
8f275c8e46
|
|
@ -43,7 +43,6 @@ class Installer extends InstallerAbstract
|
||||||
'CREATE TABLE if NOT EXISTS `' . $dbPool->get()->prefix . 'draw_image` (
|
'CREATE TABLE if NOT EXISTS `' . $dbPool->get()->prefix . 'draw_image` (
|
||||||
`draw_image_id` int(11) NOT NULL AUTO_INCREMENT,
|
`draw_image_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`draw_image_media` int(11) NOT NULL,
|
`draw_image_media` int(11) NOT NULL,
|
||||||
`draw_image_path` varchar(255) NOT NULL,
|
|
||||||
PRIMARY KEY (`draw_image_id`),
|
PRIMARY KEY (`draw_image_id`),
|
||||||
KEY `draw_image_media` (`draw_image_media`)
|
KEY `draw_image_media` (`draw_image_media`)
|
||||||
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;'
|
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;'
|
||||||
|
|
@ -53,21 +52,6 @@ class Installer extends InstallerAbstract
|
||||||
'ALTER TABLE `' . $dbPool->get()->prefix . 'draw_image`
|
'ALTER TABLE `' . $dbPool->get()->prefix . 'draw_image`
|
||||||
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'draw_image_ibfk_1` FOREIGN KEY (`draw_image_media`) REFERENCES `' . $dbPool->get()->prefix . 'media` (`media_id`);'
|
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'draw_image_ibfk_1` FOREIGN KEY (`draw_image_media`) REFERENCES `' . $dbPool->get()->prefix . 'media` (`media_id`);'
|
||||||
)->execute();
|
)->execute();
|
||||||
|
|
||||||
$dbPool->get()->con->prepare(
|
|
||||||
'CREATE TABLE if NOT EXISTS `' . $dbPool->get()->prefix . 'editor_tag` (
|
|
||||||
`editor_tag_id` int(11) NOT NULL AUTO_INCREMENT,
|
|
||||||
`editor_tag_doc` int(11) NOT NULL,
|
|
||||||
`editor_tag_tag` varchar(20) NOT NULL,
|
|
||||||
PRIMARY KEY (`editor_tag_id`),
|
|
||||||
KEY `editor_tag_doc` (`editor_tag_doc`)
|
|
||||||
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;'
|
|
||||||
)->execute();
|
|
||||||
|
|
||||||
$dbPool->get()->con->prepare(
|
|
||||||
'ALTER TABLE `' . $dbPool->get()->prefix . 'editor_tag`
|
|
||||||
ADD CONSTRAINT `' . $dbPool->get()->prefix . 'editor_tag_ibfk_1` FOREIGN KEY (`editor_tag_doc`) REFERENCES `' . $dbPool->get()->prefix . 'draw_image` (`draw_image_id`);'
|
|
||||||
)->execute();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
(function (jsOMS) {
|
(function (jsOMS) {
|
||||||
"use strict";
|
"use strict";
|
||||||
/** @namespace jsOMS.Modules */
|
/** @namespace jsOMS.Modules */
|
||||||
jsOMS.Autoloader.defineNamespace('jsOMS.Modules');
|
jsOMS.Autoloader.defineNamespace('jsOMS.Modules.Draw');
|
||||||
|
|
||||||
jsOMS.Modules.Draw = function (app) {
|
jsOMS.Modules.Draw = function (app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,9 @@ namespace Modules\Draw\Controller;
|
||||||
|
|
||||||
use Modules\Draw\Models\DrawImage;
|
use Modules\Draw\Models\DrawImage;
|
||||||
use Modules\Draw\Models\DrawImageMapper;
|
use Modules\Draw\Models\DrawImageMapper;
|
||||||
use Modules\Media\Controller as MediaController;
|
use Modules\Media\Controller\ApiController as MediaController;
|
||||||
use Modules\Media\Models\UploadStatus;
|
use Modules\Media\Models\UploadStatus;
|
||||||
|
use phpOMS\Message\NotificationLevel;
|
||||||
use phpOMS\Message\RequestAbstract;
|
use phpOMS\Message\RequestAbstract;
|
||||||
use phpOMS\Message\ResponseAbstract;
|
use phpOMS\Message\ResponseAbstract;
|
||||||
use phpOMS\Model\Message\FormValidation;
|
use phpOMS\Model\Message\FormValidation;
|
||||||
|
|
@ -82,13 +83,13 @@ final class ApiController extends Controller
|
||||||
|
|
||||||
// todo: implement limit since this could get exploited
|
// todo: implement limit since this could get exploited
|
||||||
do {
|
do {
|
||||||
$filename = sha1(((string) $request->getData('image')) . $rnd);
|
$filename = \sha1(((string) $request->getData('image')) . $rnd);
|
||||||
$filename .= '.' . $extension;
|
$filename .= '.' . $extension;
|
||||||
|
|
||||||
$rnd = mt_rand();
|
$rnd = \mt_rand();
|
||||||
} while (file_exists($path . '/' . $filename));
|
} while (\file_exists($path . '/' . $filename));
|
||||||
|
|
||||||
$fullPath = __DIR__ . '/../../' . $path . '/' . $filename;
|
$fullPath = __DIR__ . '/../../../' . $path . '/' . $filename;
|
||||||
|
|
||||||
$this->createLocalFile($fullPath, (string) $request->getData('image'));
|
$this->createLocalFile($fullPath, (string) $request->getData('image'));
|
||||||
|
|
||||||
|
|
@ -104,9 +105,8 @@ final class ApiController extends Controller
|
||||||
$media = MediaController::createDbEntry($status, $request->getHeader()->getAccount());
|
$media = MediaController::createDbEntry($status, $request->getHeader()->getAccount());
|
||||||
$draw = DrawImage::fromMedia($media);
|
$draw = DrawImage::fromMedia($media);
|
||||||
|
|
||||||
DrawImageMapper::create($draw);
|
$this->createModel($request, $draw, DrawImageMapper::class, 'draw');
|
||||||
|
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Draw', 'Draw successfully created.', $draw);
|
||||||
$response->set('image', $draw->jsonSerialize());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -91,15 +91,6 @@ final class BackendController extends Controller
|
||||||
$draw = DrawImageMapper::get((int) ($request->getData('id')));
|
$draw = DrawImageMapper::get((int) ($request->getData('id')));
|
||||||
$accountId = $request->getHeader()->getAccount();
|
$accountId = $request->getHeader()->getAccount();
|
||||||
|
|
||||||
if ($draw->getCreatedBy()->getId() !== $accountId
|
|
||||||
&& !$this->app->accountManager->get($accountId)->hasPermission(
|
|
||||||
PermissionType::READ, $this->app->orgId, $this->app->appName, self::MODULE_NAME, PermissionState::DRAW, $draw->getId())
|
|
||||||
) {
|
|
||||||
$view->setTemplate('/Web/Backend/Error/403_inline');
|
|
||||||
$response->getHeader()->setStatusCode(RequestStatusCode::R_403);
|
|
||||||
return $view;
|
|
||||||
}
|
|
||||||
|
|
||||||
$view->setTemplate('/Modules/Draw/Theme/Backend/draw-single');
|
$view->setTemplate('/Modules/Draw/Theme/Backend/draw-single');
|
||||||
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1005201001, $request, $response));
|
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1005201001, $request, $response));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,14 +36,6 @@ class DrawImage implements ArrayableInterface, \JsonSerializable
|
||||||
*/
|
*/
|
||||||
private $id = 0;
|
private $id = 0;
|
||||||
|
|
||||||
/**
|
|
||||||
* Doc path for organizing.
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
private $path = '';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Media object.
|
* Media object.
|
||||||
*
|
*
|
||||||
|
|
@ -53,15 +45,8 @@ class DrawImage implements ArrayableInterface, \JsonSerializable
|
||||||
private $media = null;
|
private $media = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Get id
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
* @return int
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
|
|
@ -72,29 +57,9 @@ class DrawImage implements ArrayableInterface, \JsonSerializable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* Get media
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @return int|Media
|
||||||
*/
|
|
||||||
public function getPath() : string
|
|
||||||
{
|
|
||||||
return $this->path;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $path
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public function setPath(string $path)
|
|
||||||
{
|
|
||||||
$this->path = $path;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return mixed
|
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
|
|
@ -104,35 +69,56 @@ class DrawImage implements ArrayableInterface, \JsonSerializable
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mixed $media
|
* Set media
|
||||||
|
*
|
||||||
|
* @param int|Media $media
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function setMedia($media)
|
public function setMedia($media) : void
|
||||||
{
|
{
|
||||||
$this->media = $media;
|
$this->media = $media;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function toArray() : array
|
public function toArray() : array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'path' => $this->path,
|
|
||||||
'media' => $this->media->toArray(),
|
'media' => $this->media->toArray(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function __toString()
|
public function __toString()
|
||||||
{
|
{
|
||||||
return (string) \json_encode($this->toArray());
|
return (string) \json_encode($this->toArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
public function jsonSerialize()
|
public function jsonSerialize()
|
||||||
{
|
{
|
||||||
return $this->toArray();
|
return $this->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function fromMedia(Media $media)
|
/**
|
||||||
|
* Create Image from media
|
||||||
|
*
|
||||||
|
* @param Media $media Media object
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public static function fromMedia(Media $media) : self
|
||||||
{
|
{
|
||||||
$image = new self();
|
$image = new self();
|
||||||
$image->setMedia($media);
|
$image->setMedia($media);
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* PHP Version 7.2
|
* PHP Version 7.2
|
||||||
*
|
*
|
||||||
* @package TBD
|
* @package Modules\Draw
|
||||||
* @copyright Dennis Eichhorn
|
* @copyright Dennis Eichhorn
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
|
|
@ -14,8 +14,17 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Modules\Draw\Models;
|
namespace Modules\Draw\Models;
|
||||||
|
|
||||||
|
use Modules\Media\Models\MediaMapper;
|
||||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mapper class.
|
||||||
|
*
|
||||||
|
* @package Modules\Draw
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @link http://website.orange-management.de
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
final class DrawImageMapper extends DataMapperAbstract
|
final class DrawImageMapper extends DataMapperAbstract
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -28,7 +37,6 @@ final class DrawImageMapper extends DataMapperAbstract
|
||||||
static protected $columns = [
|
static protected $columns = [
|
||||||
'draw_image_id' => ['name' => 'draw_image_id', 'type' => 'int', 'internal' => 'id'],
|
'draw_image_id' => ['name' => 'draw_image_id', 'type' => 'int', 'internal' => 'id'],
|
||||||
'draw_image_media' => ['name' => 'draw_image_media', 'type' => 'int', 'internal' => 'media'],
|
'draw_image_media' => ['name' => 'draw_image_media', 'type' => 'int', 'internal' => 'media'],
|
||||||
'draw_image_path' => ['name' => 'draw_image_path', 'type' => 'string', 'internal' => 'path'],
|
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -39,7 +47,7 @@ final class DrawImageMapper extends DataMapperAbstract
|
||||||
*/
|
*/
|
||||||
protected static $ownsOne = [
|
protected static $ownsOne = [
|
||||||
'media' => [
|
'media' => [
|
||||||
'mapper' => \Modules\Media\Models\MediaMapper::class,
|
'mapper' => MediaMapper::class,
|
||||||
'src' => 'draw_image_media',
|
'src' => 'draw_image_media',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ declare(strict_types=1);
|
||||||
namespace Modules\Draw\Models;
|
namespace Modules\Draw\Models;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* News article class.
|
* Null draw class.
|
||||||
*
|
*
|
||||||
* @package Modules\Draw\Models
|
* @package Modules\Draw\Models
|
||||||
* @license OMS License 1.0
|
* @license OMS License 1.0
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ echo $this->getData('nav')->render(); ?>
|
||||||
$url = \phpOMS\Uri\UriFactory::build('/{/lang}/backend/draw/single?{?}&id=' . $value->getId()); ?>
|
$url = \phpOMS\Uri\UriFactory::build('/{/lang}/backend/draw/single?{?}&id=' . $value->getId()); ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td data-label="<?= $this->getHtml('Name') ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getMedia()->getName()); ?></a>
|
<td data-label="<?= $this->getHtml('Name') ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getMedia()->getName()); ?></a>
|
||||||
<td data-label="<?= $this->getHtml('Creator') ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getMedia()->getCreatedBy()); ?></a>
|
<td data-label="<?= $this->getHtml('Creator') ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getMedia()->getCreatedBy()->getName()); ?></a>
|
||||||
<td data-label="<?= $this->getHtml('Created') ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getMedia()->getCreatedAt()->format('Y-m-d')); ?></a>
|
<td data-label="<?= $this->getHtml('Created') ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->getMedia()->getCreatedAt()->format('Y-m-d')); ?></a>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<?php if ($count === 0) : ?>
|
<?php if ($count === 0) : ?>
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,10 @@ echo $this->getData('nav')->render(); ?>
|
||||||
<section class="box wf-100">
|
<section class="box wf-100">
|
||||||
<div class="inner">
|
<div class="inner">
|
||||||
<form id="drawForm" action="<?= \phpOMS\Uri\UriFactory::build('/{/lang}/api/draw?{?}&csrf={$CSRF}'); ?>" method="POST">
|
<form id="drawForm" action="<?= \phpOMS\Uri\UriFactory::build('/{/lang}/api/draw?{?}&csrf={$CSRF}'); ?>" method="POST">
|
||||||
<input type="text" id="iTitle" name="title" class="wf-100" value="<?= $this->printHtml($image->getMedia()->getName()); ?>"><input type="submit" value="<?= $this->getHtml('Save', 0, 0); ?>">
|
<div class="ipt-wrap">
|
||||||
|
<div class="ipt-first"><input type="text" id="iTitle" name="title" class="wf-100" value="<?= $this->printHtml($image->getMedia()->getName()); ?>"></div>
|
||||||
|
<div class="ipt-second"><input type="submit" value="<?= $this->getHtml('Save', 0, 0); ?>"></div>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user