Docblock fixes + more tests

This commit is contained in:
Dennis Eichhorn 2018-12-15 22:36:04 +01:00
parent b1a46a10a7
commit 8f275c8e46
10 changed files with 54 additions and 82 deletions

View File

@ -43,7 +43,6 @@ class Installer extends InstallerAbstract
'CREATE TABLE if NOT EXISTS `' . $dbPool->get()->prefix . 'draw_image` (
`draw_image_id` int(11) NOT NULL AUTO_INCREMENT,
`draw_image_media` int(11) NOT NULL,
`draw_image_path` varchar(255) NOT NULL,
PRIMARY KEY (`draw_image_id`),
KEY `draw_image_media` (`draw_image_media`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;'
@ -53,21 +52,6 @@ class Installer extends InstallerAbstract
'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`);'
)->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;
}
}

View File

@ -1,7 +1,7 @@
(function (jsOMS) {
"use strict";
/** @namespace jsOMS.Modules */
jsOMS.Autoloader.defineNamespace('jsOMS.Modules');
jsOMS.Autoloader.defineNamespace('jsOMS.Modules.Draw');
jsOMS.Modules.Draw = function (app) {
this.app = app;

View File

@ -16,8 +16,9 @@ namespace Modules\Draw\Controller;
use Modules\Draw\Models\DrawImage;
use Modules\Draw\Models\DrawImageMapper;
use Modules\Media\Controller as MediaController;
use Modules\Media\Controller\ApiController as MediaController;
use Modules\Media\Models\UploadStatus;
use phpOMS\Message\NotificationLevel;
use phpOMS\Message\RequestAbstract;
use phpOMS\Message\ResponseAbstract;
use phpOMS\Model\Message\FormValidation;
@ -82,13 +83,13 @@ final class ApiController extends Controller
// todo: implement limit since this could get exploited
do {
$filename = sha1(((string) $request->getData('image')) . $rnd);
$filename = \sha1(((string) $request->getData('image')) . $rnd);
$filename .= '.' . $extension;
$rnd = mt_rand();
} while (file_exists($path . '/' . $filename));
$rnd = \mt_rand();
} while (\file_exists($path . '/' . $filename));
$fullPath = __DIR__ . '/../../' . $path . '/' . $filename;
$fullPath = __DIR__ . '/../../../' . $path . '/' . $filename;
$this->createLocalFile($fullPath, (string) $request->getData('image'));
@ -104,9 +105,8 @@ final class ApiController extends Controller
$media = MediaController::createDbEntry($status, $request->getHeader()->getAccount());
$draw = DrawImage::fromMedia($media);
DrawImageMapper::create($draw);
$response->set('image', $draw->jsonSerialize());
$this->createModel($request, $draw, DrawImageMapper::class, 'draw');
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Draw', 'Draw successfully created.', $draw);
}
/**

View File

@ -91,15 +91,6 @@ final class BackendController extends Controller
$draw = DrawImageMapper::get((int) ($request->getData('id')));
$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->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1005201001, $request, $response));

View File

@ -36,14 +36,6 @@ class DrawImage implements ArrayableInterface, \JsonSerializable
*/
private $id = 0;
/**
* Doc path for organizing.
*
* @var string
* @since 1.0.0
*/
private $path = '';
/**
* Media object.
*
@ -53,15 +45,8 @@ class DrawImage implements ArrayableInterface, \JsonSerializable
private $media = null;
/**
* Constructor.
* Get id
*
* @since 1.0.0
*/
public function __construct()
{
}
/**
* @return int
*
* @since 1.0.0
@ -72,29 +57,9 @@ class DrawImage implements ArrayableInterface, \JsonSerializable
}
/**
* @return string
* Get media
*
* @since 1.0.0
*/
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
* @return int|Media
*
* @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
*/
public function setMedia($media)
public function setMedia($media) : void
{
$this->media = $media;
}
/**
* {@inheritdoc}
*/
public function toArray() : array
{
return [
'id' => $this->id,
'path' => $this->path,
'media' => $this->media->toArray(),
];
}
/**
* {@inheritdoc}
*/
public function __toString()
{
return (string) \json_encode($this->toArray());
}
/**
* {@inheritdoc}
*/
public function jsonSerialize()
{
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->setMedia($media);

View File

@ -4,7 +4,7 @@
*
* PHP Version 7.2
*
* @package TBD
* @package Modules\Draw
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
@ -14,8 +14,17 @@ declare(strict_types=1);
namespace Modules\Draw\Models;
use Modules\Media\Models\MediaMapper;
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
{
@ -28,7 +37,6 @@ final class DrawImageMapper extends DataMapperAbstract
static protected $columns = [
'draw_image_id' => ['name' => 'draw_image_id', 'type' => 'int', 'internal' => 'id'],
'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 = [
'media' => [
'mapper' => \Modules\Media\Models\MediaMapper::class,
'mapper' => MediaMapper::class,
'src' => 'draw_image_media',
],
];

View File

@ -15,7 +15,7 @@ declare(strict_types=1);
namespace Modules\Draw\Models;
/**
* News article class.
* Null draw class.
*
* @package Modules\Draw\Models
* @license OMS License 1.0

View File

@ -40,7 +40,7 @@ echo $this->getData('nav')->render(); ?>
$url = \phpOMS\Uri\UriFactory::build('/{/lang}/backend/draw/single?{?}&id=' . $value->getId()); ?>
<tr>
<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>
<?php endforeach; ?>
<?php if ($count === 0) : ?>

View File

@ -23,7 +23,10 @@ echo $this->getData('nav')->render(); ?>
<section class="box wf-100">
<div class="inner">
<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>
</div>
</section>