diff --git a/Admin/Activate.php b/Admin/Activate.php index e6e1b9f..562c5bd 100644 --- a/Admin/Activate.php +++ b/Admin/Activate.php @@ -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); } diff --git a/Admin/Deactivate.php b/Admin/Deactivate.php index 42ad34e..c457b6e 100644 --- a/Admin/Deactivate.php +++ b/Admin/Deactivate.php @@ -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); } diff --git a/Admin/Install/Navigation.php b/Admin/Install/Navigation.php index 40157f5..1d43c47 100644 --- a/Admin/Install/Navigation.php +++ b/Admin/Install/Navigation.php @@ -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); diff --git a/Admin/Installer.php b/Admin/Installer.php index 2118a59..b851096 100644 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -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; } } diff --git a/Admin/Routes/Web/Api.php b/Admin/Routes/Web/Api.php new file mode 100644 index 0000000..19c303e --- /dev/null +++ b/Admin/Routes/Web/Api.php @@ -0,0 +1,12 @@ + [ + [ + 'dest' => '\Modules\Draw\Controller:apiDrawCreate', + 'verb' => RouteVerb::SET, + ], + ], +]; diff --git a/Admin/Routes/Web/Backend.php b/Admin/Routes/Web/Backend.php index c48aa85..f5f14b2 100644 --- a/Admin/Routes/Web/Backend.php +++ b/Admin/Routes/Web/Backend.php @@ -19,4 +19,10 @@ return [ 'verb' => RouteVerb::GET, ], ], + '^.*/backend/draw/single.*$' => [ + [ + 'dest' => '\Modules\Draw\Controller:viewDrawSingle', + 'verb' => RouteVerb::GET, + ], + ], ]; diff --git a/Admin/Uninstall.php b/Admin/Uninstall.php index c053e8a..415894b 100644 --- a/Admin/Uninstall.php +++ b/Admin/Uninstall.php @@ -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); } diff --git a/Admin/Update.php b/Admin/Update.php index e343416..32aa5f1 100644 --- a/Admin/Update.php +++ b/Admin/Update.php @@ -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'); diff --git a/Controller.js b/Controller.js index bf6ad90..ef3f5fe 100644 --- a/Controller.js +++ b/Controller.js @@ -2,7 +2,7 @@ "use strict"; /** @namespace jsOMS.Modules */ jsOMS.Autoloader.defineNamespace('jsOMS.Modules'); - + jsOMS.Modules.Draw = function (app) { this.app = app; this.editors = []; diff --git a/Controller.php b/Controller.php index 9f18e06..68afb31 100644 --- a/Controller.php +++ b/Controller.php @@ -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 + */ + 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 + */ + 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; + } + } diff --git a/Models/DrawImage.php b/Models/DrawImage.php new file mode 100644 index 0000000..1527409 --- /dev/null +++ b/Models/DrawImage.php @@ -0,0 +1,154 @@ + + * @author Dennis Eichhorn + * @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 + * @author Dennis Eichhorn + * @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 + */ + public function __construct() + { + } + + /** + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getId() : int + { + return $this->id; + } + + /** + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getPath() : string + { + return $this->path; + } + + /** + * @param string $path + * + * @return mixed + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setPath(string $path) + { + $this->path = $path; + } + + /** + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getMedia() + { + return $this->media; + } + + /** + * @param string $media + * + * @return mixed + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + 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; + } +} diff --git a/Models/DrawImageMapper.php b/Models/DrawImageMapper.php new file mode 100644 index 0000000..5338320 --- /dev/null +++ b/Models/DrawImageMapper.php @@ -0,0 +1,126 @@ + + * @author Dennis Eichhorn + * @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 + */ + 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 + */ + 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); + } +} diff --git a/Models/DrawType.enum.js b/Models/DrawType.enum.js index abba85d..c437285 100644 --- a/Models/DrawType.enum.js +++ b/Models/DrawType.enum.js @@ -17,6 +17,6 @@ DRAW: 0, LINE: 1, RECTANGLE: 2, - CIRCLE: 3, + CIRCLE: 3 }); }(window.jsOMS = window.jsOMS || {})); diff --git a/Theme/Backend/Lang/Navigation.en.lang.php b/Theme/Backend/Lang/Navigation.en.lang.php index b9551f1..dbf546b 100644 --- a/Theme/Backend/Lang/Navigation.en.lang.php +++ b/Theme/Backend/Lang/Navigation.en.lang.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Theme/Backend/Lang/api.en.lang.php b/Theme/Backend/Lang/api.en.lang.php index 6d5bdff..d28b242 100644 --- a/Theme/Backend/Lang/api.en.lang.php +++ b/Theme/Backend/Lang/api.en.lang.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Theme/Backend/Lang/en.lang.php b/Theme/Backend/Lang/en.lang.php index 15008df..e3078e5 100644 --- a/Theme/Backend/Lang/en.lang.php +++ b/Theme/Backend/Lang/en.lang.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Theme/backend/Lang/Navigation.en.lang.php b/Theme/backend/Lang/Navigation.en.lang.php index b9551f1..dbf546b 100644 --- a/Theme/backend/Lang/Navigation.en.lang.php +++ b/Theme/backend/Lang/Navigation.en.lang.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Theme/backend/Lang/api.en.lang.php b/Theme/backend/Lang/api.en.lang.php index 6d5bdff..d28b242 100644 --- a/Theme/backend/Lang/api.en.lang.php +++ b/Theme/backend/Lang/api.en.lang.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Theme/backend/Lang/en.lang.php b/Theme/backend/Lang/en.lang.php index 15008df..e3078e5 100644 --- a/Theme/backend/Lang/en.lang.php +++ b/Theme/backend/Lang/en.lang.php @@ -2,7 +2,7 @@ /** * Orange Management * - * PHP Version 7.0 + * PHP Version 7.1 * * @category TBD * @package TBD diff --git a/Theme/backend/draw-create.tpl.php b/Theme/backend/draw-create.tpl.php index dc84350..36dfebb 100644 --- a/Theme/backend/draw-create.tpl.php +++ b/Theme/backend/draw-create.tpl.php @@ -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(); ?>
-
- + +
@@ -63,7 +63,7 @@ echo $this->getData('nav')->render(); ?>
- +
diff --git a/Theme/backend/draw-list.tpl.php b/Theme/backend/draw-list.tpl.php index 4d295c5..527e675 100644 --- a/Theme/backend/draw-list.tpl.php +++ b/Theme/backend/draw-list.tpl.php @@ -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(); ?>
@@ -35,7 +37,12 @@ echo $this->getData('nav')->render(); ?> - $value) : $count++; ?> + $value) : $count++; + $url = \phpOMS\Uri\UriFactory::build('/{/lang}/backend/draw/single?id=' . $value->getId()); ?> + +
render(); ?>
getMedia()->getName(); ?> + getMedia()->getCreatedBy(); ?> + getMedia()->getCreatedAt()->format('Y-m-d'); ?>
getText('Empty', 0, 0); ?> diff --git a/info.json b/info.json index 39a23c2..ccf9c08 100644 --- a/info.json +++ b/info.json @@ -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": "*"