Merge remote-tracking branch 'origin/develop' into develop

# Conflicts:
#	Draw/Controller.js
#	Draw/Models/DrawType.enum.js
#	Draw/Models/Editor.js
#	Media/Models/UploadFile.php
This commit is contained in:
Dennis Eichhorn 2017-01-26 16:42:29 +01:00
commit 3dce57e942
22 changed files with 476 additions and 39 deletions

View File

@ -2,7 +2,7 @@
/**
* Orange Management
*
* PHP Version 7.0
* PHP Version 7.1
*
* @category TBD
* @package TBD
@ -16,7 +16,7 @@
namespace Modules\Draw\Admin;
use phpOMS\DataStorage\Database\Pool;
use phpOMS\DataStorage\Database\DatabasePool;
use phpOMS\Module\ActivateAbstract;
use phpOMS\Module\InfoManager;
@ -37,7 +37,7 @@ class Activate extends ActivateAbstract
/**
* {@inheritdoc}
*/
public static function activate(Pool $dbPool, InfoManager $info)
public static function activate(DatabasePool $dbPool, InfoManager $info)
{
parent::activate($dbPool, $info);
}

View File

@ -2,7 +2,7 @@
/**
* Orange Management
*
* PHP Version 7.0
* PHP Version 7.1
*
* @category TBD
* @package TBD
@ -16,7 +16,7 @@
namespace Modules\Draw\Admin;
use phpOMS\DataStorage\Database\Pool;
use phpOMS\DataStorage\Database\DatabasePool;
use phpOMS\Module\DeactivateAbstract;
use phpOMS\Module\InfoManager;
@ -37,7 +37,7 @@ class Deactivate extends DeactivateAbstract
/**
* {@inheritdoc}
*/
public static function deactivate(Pool $dbPool, InfoManager $info)
public static function deactivate(DatabasePool $dbPool, InfoManager $info)
{
parent::deactivate($dbPool, $info);
}

View File

@ -2,7 +2,7 @@
/**
* Orange Management
*
* PHP Version 7.0
* PHP Version 7.1
*
* @category TBD
* @package TBD
@ -14,7 +14,7 @@
* @link http://orange-management.com
*/
namespace Modules\Draw\Admin\Install;
use phpOMS\DataStorage\Database\Pool;
use phpOMS\DataStorage\Database\DatabasePool;
/**
* Navigation class.
@ -29,7 +29,7 @@ use phpOMS\DataStorage\Database\Pool;
*/
class Navigation
{
public static function install(Pool $dbPool)
public static function install(string $path, DatabasePool $dbPool)
{
$navData = json_decode(file_get_contents(__DIR__ . '/Navigation.install.json'), true);

View File

@ -2,7 +2,7 @@
/**
* Orange Management
*
* PHP Version 7.0
* PHP Version 7.1
*
* @category TBD
* @package TBD
@ -16,7 +16,7 @@
namespace Modules\Draw\Admin;
use phpOMS\DataStorage\Database\DatabaseType;
use phpOMS\DataStorage\Database\Pool;
use phpOMS\DataStorage\Database\DatabasePool;
use phpOMS\Module\InfoManager;
use phpOMS\Module\InstallerAbstract;
@ -37,12 +37,41 @@ class Installer extends InstallerAbstract
/**
* {@inheritdoc}
*/
public static function install(Pool $dbPool, InfoManager $info)
public static function install(string $path, DatabasePool $dbPool, InfoManager $info)
{
parent::install($dbPool, $info);
parent::install($path, $dbPool, $info);
switch ($dbPool->get('core')->getType()) {
case DatabaseType::MYSQL:
$dbPool->get('core')->con->prepare(
'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->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;'
)->execute();
$dbPool->get('core')->con->prepare(
'ALTER TABLE `' . $dbPool->get('core')->prefix . 'draw_image`
ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'draw_image_ibfk_1` FOREIGN KEY (`draw_image_media`) REFERENCES `' . $dbPool->get('core')->prefix . 'media` (`media_id`);'
)->execute();
$dbPool->get('core')->con->prepare(
'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->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('core')->con->prepare(
'ALTER TABLE `' . $dbPool->get('core')->prefix . 'editor_tag`
ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'editor_tag_ibfk_1` FOREIGN KEY (`editor_tag_doc`) REFERENCES `' . $dbPool->get('core')->prefix . 'draw_image` (`draw_image_id`);'
)->execute();
break;
}
}

12
Admin/Routes/Web/Api.php Normal file
View File

@ -0,0 +1,12 @@
<?php
use phpOMS\Router\RouteVerb;
return [
'^.*/api/draw.*$' => [
[
'dest' => '\Modules\Draw\Controller:apiDrawCreate',
'verb' => RouteVerb::SET,
],
],
];

View File

@ -19,4 +19,10 @@ return [
'verb' => RouteVerb::GET,
],
],
'^.*/backend/draw/single.*$' => [
[
'dest' => '\Modules\Draw\Controller:viewDrawSingle',
'verb' => RouteVerb::GET,
],
],
];

View File

@ -2,7 +2,7 @@
/**
* Orange Management
*
* PHP Version 7.0
* PHP Version 7.1
*
* @category TBD
* @package TBD
@ -16,7 +16,7 @@
namespace Modules\Draw\Admin;
use phpOMS\DataStorage\Database\Pool;
use phpOMS\DataStorage\Database\DatabasePool;
use phpOMS\Module\UninstallAbstract;
/**
@ -36,7 +36,7 @@ class Uninstall extends UninstallAbstract
/**
* {@inheritdoc}
*/
public static function uninstall(Pool $dbPool, InfoManager $info)
public static function uninstall(DatabasePool $dbPool, InfoManager $info)
{
parent::uninstall($dbPool, $info);
}

View File

@ -2,7 +2,7 @@
/**
* Orange Management
*
* PHP Version 7.0
* PHP Version 7.1
*
* @category TBD
* @package TBD
@ -16,7 +16,7 @@
namespace Modules\Draw\Admin;
use phpOMS\DataStorage\Database\Pool;
use phpOMS\DataStorage\Database\DatabasePool;
use phpOMS\Module\UpdateAbstract;
use phpOMS\System\File\Directory;
@ -37,7 +37,7 @@ class Update extends UpdateAbstract
/**
* {@inheritdoc}
*/
public static function update(Pool $dbPool, array $info)
public static function update(DatabasePool $dbPool, array $info)
{
Directory::deletePath(__DIR__ . '/Update');
mkdir('Update');

View File

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

View File

@ -2,7 +2,7 @@
/**
* Orange Management
*
* PHP Version 7.0
* PHP Version 7.1
*
* @category TBD
* @package TBD
@ -15,12 +15,19 @@
*/
namespace Modules\Draw;
use Model\Message\FormValidation;
use Modules\Draw\Models\DrawImage;
use Modules\Draw\Models\DrawImageMapper;
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;
/**
@ -43,7 +50,7 @@ class Controller extends ModuleAbstract implements WebInterface
* @var string
* @since 1.0.0
*/
const MODULE_PATH = __DIR__;
/* public */ const MODULE_PATH = __DIR__;
/**
* Module version.
@ -51,7 +58,7 @@ class Controller extends ModuleAbstract implements WebInterface
* @var string
* @since 1.0.0
*/
const MODULE_VERSION = '1.0.0';
/* public */ const MODULE_VERSION = '1.0.0';
/**
* Module name.
@ -59,7 +66,7 @@ class Controller extends ModuleAbstract implements WebInterface
* @var string
* @since 1.0.0
*/
const MODULE_NAME = 'Draw';
/* public */ const MODULE_NAME = 'Draw';
/**
* Providing.
@ -92,7 +99,9 @@ class Controller extends ModuleAbstract implements WebInterface
{
/** @var Head $head */
$head = $response->get('Content')->getData('head');
$head->addAsset(AssetType::JS, $request->getUri()->getBase() . 'Modules/Draw/ModuleDraw.js');
$head->addAsset(AssetType::JSLATE, $request->getUri()->getBase() . 'Modules/Draw/Controller.js');
$head->addAsset(AssetType::JSLATE, $request->getUri()->getBase() . 'Modules/Draw/Models/DrawType.enum.js');
$head->addAsset(AssetType::JSLATE, $request->getUri()->getBase() . 'Modules/Draw/Models/Editor.js');
}
/**
@ -114,6 +123,25 @@ class Controller extends ModuleAbstract implements WebInterface
return $view;
}
/**
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Generic data
*
* @return \Serializable
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function viewDrawImage(RequestAbstract $request, ResponseAbstract $response, $data = null) : \Serializable
{
$view = new View($this->app, $request, $response);
$view->setTemplate('/Modules/Draw/Theme/Backend/draw-create');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1005201001, $request, $response));
return $view;
}
/**
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
@ -130,7 +158,81 @@ class Controller extends ModuleAbstract implements WebInterface
$view->setTemplate('/Modules/Draw/Theme/Backend/draw-list');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1005201001, $request, $response));
$images = DrawImageMapper::getNewest(25);
$view->addData('images', $images);
return $view;
}
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
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function apiDrawCreate(RequestAbstract $request, ResponseAbstract $response, $data = null)
{
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($request->getData('image') . $rnd);
$filename .= '.' . $extension;
$rnd = mt_rand();
} while (file_exists($path . '/' . $filename));
$fullPath = __DIR__ . '/../../' . $path . '/' . $filename;
$this->createLocalFile($fullPath, $request->getData('image'));
$status = [
'path' => $path,
'filename' => $filename,
'name' => $request->getData('title'),
'size' => File::size($fullPath),
'extension' => $extension,
'status' => UploadStatus::OK,
];
$media = MediaController::createDbEntry($status, $request->getAccount());
$draw = DrawImage::fromMedia($media);
DrawImageMapper::create($draw);
$response->set('image', $draw->jsonSerialize());
}
private function createLocalFile(string $outputPath, string $raw) : bool
{
$imageData = ImageUtils::decodeBase64Image($raw);
File::put($outputPath, $imageData);
return true;
}
}

154
Models/DrawImage.php Normal file
View File

@ -0,0 +1,154 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace Modules\Draw\Models;
use Modules\Media\Models\Media;
use phpOMS\Contract\ArrayableInterface;
/**
* News article class.
*
* @category Module
* @package Framework
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @license OMS License 1.0
* @link http://orange-management.com
* @since 1.0.0
*/
class DrawImage implements ArrayableInterface, \JsonSerializable
{
/**
* Article ID.
*
* @var int
* @since 1.0.0
*/
private $id = 0;
/**
* Doc path for organizing.
*
* @var string
* @since 1.0.0
*/
private $path = '';
/**
* Media object.
*
* @var Media
* @since 1.0.0
*/
private $media = null;
/**
* Constructor.
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct()
{
}
/**
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getId() : int
{
return $this->id;
}
/**
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getPath() : string
{
return $this->path;
}
/**
* @param string $path
*
* @return mixed
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setPath(string $path)
{
$this->path = $path;
}
/**
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getMedia()
{
return $this->media;
}
/**
* @param string $media
*
* @return mixed
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setMedia($media)
{
$this->media = $media;
}
public function toArray() : array
{
return [
'id' => $this->id,
'path' => $this->path,
'media' => $this->media->toArray(),
];
}
public function __toString()
{
return json_encode($this->toArray());
}
public function jsonSerialize()
{
return $this->toArray();
}
public static function fromMedia(Media $media)
{
$image = new self();
$image->setMedia($media);
return $image;
}
}

126
Models/DrawImageMapper.php Normal file
View File

@ -0,0 +1,126 @@
<?php
/**
* Orange Management
*
* PHP Version 7.1
*
* @category TBD
* @package TBD
* @author OMS Development Team <dev@oms.com>
* @author Dennis Eichhorn <d.eichhorn@oms.com>
* @copyright 2013 Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link http://orange-management.com
*/
namespace Modules\Draw\Models;
use Modules\Admin\Models\AccountMapper;
use phpOMS\DataStorage\Database\DataMapperAbstract;
use phpOMS\DataStorage\Database\Query\Builder;
use phpOMS\DataStorage\Database\Query\Column;
use phpOMS\DataStorage\Database\RelationType;
class DrawImageMapper extends DataMapperAbstract
{
/**
* Columns.
*
* @var array
* @since 1.0.0
*/
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'],
];
/**
* Has one relation.
*
* @var array
* @since 1.0.0
*/
protected static $ownsOne = [
'media' => [
'mapper' => \Modules\Media\Models\MediaMapper::class,
'src' => 'draw_image_media',
],
];
/**
* Primary table.
*
* @var string
* @since 1.0.0
*/
protected static $table = 'draw_image';
/**
* Primary field name.
*
* @var string
* @since 1.0.0
*/
protected static $primaryField = 'draw_image_id';
/**
* Create object.
*
* @param mixed $obj Object
* @param int $relations Behavior for relations creation
*
* @return mixed
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function create($obj, int $relations = RelationType::ALL)
{
try {
$objId = parent::create($obj, $relations);
$query = new Builder(self::$db);
$query->prefix(self::$db->getPrefix())
->insert(
'account_permission_account',
'account_permission_from',
'account_permission_for',
'account_permission_id1',
'account_permission_id2',
'account_permission_r',
'account_permission_w',
'account_permission_m',
'account_permission_d',
'account_permission_p'
)
->into('account_permission')
->values($obj->getMedia()->getCreatedBy(), 'draw', 'draw', 1, $objId, 1, 1, 1, 1, 1);
self::$db->con->prepare($query->toSql())->execute();
} catch (\Exception $e) {
return false;
}
return $objId;
}
/**
* Find.
*
* @param array $columns Columns to select
*
* @return Builder
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public static function find(...$columns) : Builder
{
return parent::find(...$columns)->from('account_permission')
->where('account_permission.account_permission_for', '=', 'editor')
->where('account_permission.account_permission_id1', '=', 1)
->where('news.news_id', '=', new Column('account_permission.account_permission_id2'))
->where('account_permission.account_permission_r', '=', 1);
}
}

View File

@ -17,6 +17,6 @@
DRAW: 0,
LINE: 1,
RECTANGLE: 2,
CIRCLE: 3,
CIRCLE: 3
});
}(window.jsOMS = window.jsOMS || {}));

View File

@ -2,7 +2,7 @@
/**
* Orange Management
*
* PHP Version 7.0
* PHP Version 7.1
*
* @category TBD
* @package TBD

View File

@ -2,7 +2,7 @@
/**
* Orange Management
*
* PHP Version 7.0
* PHP Version 7.1
*
* @category TBD
* @package TBD

View File

@ -2,7 +2,7 @@
/**
* Orange Management
*
* PHP Version 7.0
* PHP Version 7.1
*
* @category TBD
* @package TBD

View File

@ -2,7 +2,7 @@
/**
* Orange Management
*
* PHP Version 7.0
* PHP Version 7.1
*
* @category TBD
* @package TBD

View File

@ -2,7 +2,7 @@
/**
* Orange Management
*
* PHP Version 7.0
* PHP Version 7.1
*
* @category TBD
* @package TBD

View File

@ -2,7 +2,7 @@
/**
* Orange Management
*
* PHP Version 7.0
* PHP Version 7.1
*
* @category TBD
* @package TBD

View File

@ -2,7 +2,7 @@
/**
* Orange Management
*
* PHP Version 7.0
* PHP Version 7.1
*
* @category TBD
* @package TBD
@ -21,8 +21,8 @@ echo $this->getData('nav')->render(); ?>
<section class="box w-100">
<div class="inner">
<form>
<input type="text" class="wf-100">
<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"><input type="submit" value="<?= $this->getText('Create', 0, 0); ?>">
</form>
</div>
</section>
@ -63,7 +63,7 @@ echo $this->getData('nav')->render(); ?>
<div class="m-draw">
<section class="box w-100" style="height: 30%;">
<div class="inner">
<canvas></canvas>
<canvas id="canvasImage" name="image" form="drawForm"></canvas>
</div>
</section>
</div>

View File

@ -2,7 +2,7 @@
/**
* Orange Management
*
* PHP Version 7.0
* PHP Version 7.1
*
* @category TBD
* @package TBD
@ -22,6 +22,8 @@ $footerView->setTemplate('/Web/Templates/Lists/Footer/PaginationBig');
$footerView->setPages(20);
$footerView->setPage(1);
$images = $this->getData('images');
echo $this->getData('nav')->render(); ?>
<div class="box">
<table class="table">
@ -35,7 +37,12 @@ echo $this->getData('nav')->render(); ?>
<tr>
<td colspan="3"><?= $footerView->render(); ?>
<tbody>
<?php $count = 0; foreach([] as $key => $value) : $count++; ?>
<?php $count = 0; foreach($images as $key => $value) : $count++;
$url = \phpOMS\Uri\UriFactory::build('/{/lang}/backend/draw/single?id=' . $value->getId()); ?>
<tr>
<td><?= $value->getMedia()->getName(); ?>
<td><?= $value->getMedia()->getCreatedBy(); ?>
<td><?= $value->getMedia()->getCreatedAt()->format('Y-m-d'); ?>
<?php endforeach; ?>
<?php if($count === 0) : ?>
<tr><td colspan="5" class="empty"><?= $this->getText('Empty', 0, 0); ?>

View File

@ -16,7 +16,8 @@
"description": "The administration module.",
"directory": "Draw",
"dependencies": {
"Admin" : "1.0.0"
"Admin" : "1.0.0",
"Media" : "1.0.0"
},
"providing": {
"Navigation": "*"