[Editor] Create working draft

This commit is contained in:
Dennis Eichhorn 2016-11-23 23:48:57 +01:00
parent f8ac6843e3
commit 98c1b5d50a
10 changed files with 501 additions and 16 deletions

View File

@ -47,8 +47,8 @@ class Installer extends InstallerAbstract
'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'editor_doc` (
`editor_doc_id` int(11) NOT NULL AUTO_INCREMENT,
`editor_doc_title` varchar(250) NOT NULL,
`editor_doc_plain` text NOT NULL,
`editor_doc_content` text NOT NULL,
`editor_doc_lang` varchar(2) NOT NULL,
`editor_doc_path` varchar(255) NOT NULL,
`editor_doc_created_at` datetime NOT NULL,
`editor_doc_created_by` int(11) NOT NULL,
@ -58,7 +58,7 @@ class Installer extends InstallerAbstract
)->execute();
$dbPool->get('core')->con->prepare(
'ALTER TABLE `' . $dbPool->get('core')->prefix . 'editor`
'ALTER TABLE `' . $dbPool->get('core')->prefix . 'editor_doc`
ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'editor_doc_ibfk_1` FOREIGN KEY (`editor_doc_created_by`) REFERENCES `' . $dbPool->get('core')->prefix . 'account` (`account_id`);'
)->execute();

View File

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

View File

@ -15,8 +15,11 @@
*/
namespace Modules\Editor;
use Model\Message\FormValidation;
use Modules\Navigation\Models\Navigation;
use Modules\Navigation\Views\NavigationView;
use Modules\Editor\Models\EditorDoc;
use Modules\Editor\Models\EditorDocMapper;
use phpOMS\Asset\AssetType;
use phpOMS\Contract\RenderableInterface;
use phpOMS\Message\RequestAbstract;
@ -132,6 +135,31 @@ class Controller extends ModuleAbstract implements WebInterface
$view->setTemplate('/Modules/Editor/Theme/Backend/editor-list');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1005301001, $request, $response));
$docs = EditorDocMapper::getNewest(50);
$view->addData('docs', $docs);
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 viewEditorSingle(RequestAbstract $request, ResponseAbstract $response, $data = null) : \Serializable
{
$view = new View($this->app, $request, $response);
$view->setTemplate('/Modules/Editor/Theme/Backend/editor');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1005301001, $request, $response));
$doc = EditorDocMapper::get((int) $request->getData('id'));
$view->addData('doc', $doc);
return $view;
}
@ -164,11 +192,16 @@ class Controller extends ModuleAbstract implements WebInterface
return;
}
$editorArticle = new Editor();
$doc = new EditorDoc();
$doc->setTitle($request->getData('title') ?? '');
$doc->setPlain($request->getData('plain') ?? '');
$doc->setContent($request->getData('plain') ?? '');
$doc->setCreatedAt(new \DateTime('now'));
$doc->setCreatedBy($request->getAccount());
EditorMapper::create($editorArticle);
EditorDocMapper::create($doc);
$response->set('editor', $editorArticle->jsonSerialize());
$response->set('editor', $doc->jsonSerialize());
}
}

275
Models/EditorDoc.php Normal file
View File

@ -0,0 +1,275 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @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\Editor\Models;
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 EditorDoc implements ArrayableInterface, \JsonSerializable
{
/**
* Article ID.
*
* @var int
* @since 1.0.0
*/
private $id = 0;
/**
* Title.
*
* @var string
* @since 1.0.0
*/
private $title = '';
/**
* Content.
*
* @var string
* @since 1.0.0
*/
private $content = '';
/**
* Unparsed.
*
* @var string
* @since 1.0.0
*/
private $plain = '';
/**
* Doc path for organizing.
*
* @var string
* @since 1.0.0
*/
private $path = '';
/**
* Created.
*
* @var \DateTime
* @since 1.0.0
*/
private $createdAt = null;
/**
* Creator.
*
* @var int
* @since 1.0.0
*/
private $createdBy = 0;
/**
* Constructor.
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function __construct()
{
$this->createdAt = new \DateTime('NOW');
}
/**
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getContent() : string
{
return $this->content;
}
/**
* @param string $content
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setContent(string $content)
{
$this->content = $content;
}
/**
* @param string $plain
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setPlain(string $plain)
{
$this->plain = $plain;
}
/**
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getPlain() : string
{
return $this->plain;
}
/**
* @return \DateTime
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getCreatedAt() : \DateTime
{
return $this->createdAt;
}
/**
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getId() : int
{
return $this->id;
}
/**
* @return int
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getCreatedBy() : int
{
return $this->createdBy;
}
/**
* @param int $id
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setCreatedBy(int $id)
{
$this->createdBy = $id;
}
/**
* @param \DateTime $createdAt
*
* @return void
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;
}
/**
* @return string
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function getTitle() : string
{
return $this->title;
}
/**
* @param string $title
*
* @return mixed
*
* @since 1.0.0
* @author Dennis Eichhorn <d.eichhorn@oms.com>
*/
public function setTitle(string $title)
{
$this->title = $title;
}
/**
* @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;
}
public function toArray() : array
{
return [
'id' => $this->id,
'title' => $this->title,
'plain' => $this->plain,
'content' => $this->content,
'createdAt' => $this->createdAt,
'createdBy' => $this->createdBy,
];
}
public function __toString()
{
return $this->jsonSerialize();
}
public function jsonSerialize()
{
return json_encode($this->toArray());
}
}

132
Models/EditorDocMapper.php Normal file
View File

@ -0,0 +1,132 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @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\Editor\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 EditorDocMapper extends DataMapperAbstract
{
/**
* Columns.
*
* @var array
* @since 1.0.0
*/
static protected $columns = [
'editor_doc_id' => ['name' => 'editor_doc_id', 'type' => 'int', 'internal' => 'id'],
'editor_doc_created_by' => ['name' => 'editor_doc_created_by', 'type' => 'string', 'internal' => 'createdBy'],
'editor_doc_title' => ['name' => 'editor_doc_title', 'type' => 'string', 'internal' => 'title'],
'editor_doc_plain' => ['name' => 'editor_doc_plain', 'type' => 'string', 'internal' => 'plain'],
'editor_doc_content' => ['name' => 'editor_doc_content', 'type' => 'string', 'internal' => 'content'],
'editor_doc_path' => ['name' => 'editor_doc_path', 'type' => 'string', 'internal' => 'path'],
'editor_doc_created_at' => ['name' => 'editor_doc_created_at', 'type' => 'DateTime', 'internal' => 'createdAt'],
];
static protected $belongsTo = [
'createdBy' => [
'mapper' => AccountMapper::class,
'src' => 'editor_doc_created_by',
],
];
/**
* Primary table.
*
* @var string
* @since 1.0.0
*/
protected static $table = 'editor_doc';
/**
* Primary field name.
*
* @var string
* @since 1.0.0
*/
protected static $primaryField = 'editor_doc_id';
/**
* Created at.
*
* @var string
* @since 1.0.0
*/
protected static $createdAt = 'editor_doc_created_at';
/**
* 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->getCreatedBy(), 'editor', 'editor', 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

@ -21,8 +21,9 @@ echo $this->getData('nav')->render(); ?>
<section class="box w-100">
<div class="inner">
<form>
<input type="text" class="wf-100">
<form id="fEditor" method="POST" action="<?= \phpOMS\Uri\UriFactory::build('/{/lang}/api/editor?csrf={$CSRF}'); ?>">
<input name="title" type="text" class="wf-100">
<input type="submit" value="<?= $this->getText('Save') ?>">
</form>
</div>
</section>
@ -95,7 +96,7 @@ echo $this->getData('nav')->render(); ?>
<div class="tab-content">
<input type="radio" id="c-tab2-1" name="tabular-2" checked>
<div class="tab">
<textarea class="wf-100"></textarea>
<textarea name="plain" class="wf-100" form="fEditor"></textarea>
</div>
<input type="radio" id="c-tab2-2" name="tabular-2">
<div class="tab">

View File

@ -22,20 +22,27 @@ $footerView->setTemplate('/Web/Templates/Lists/Footer/PaginationBig');
$footerView->setPages(20);
$footerView->setPage(1);
$docs = $this->getData('docs');
echo $this->getData('nav')->render(); ?>
<div class="box">
<table class="table">
<caption><?= $this->getText('Documents'); ?></caption>
<thead>
<tr>
<td class="wf-100"><?= $this->getText('Name'); ?>
<td class="wf-100"><?= $this->getText('Title'); ?>
<td><?= $this->getText('Creator'); ?>
<td><?= $this->getText('Created'); ?>
<tfoot>
<tr>
<td colspan="3"><?= $footerView->render(); ?>
<tbody>
<?php $count = 0; foreach([] as $key => $value) : $count++; ?>
<?php $count = 0; foreach($docs as $key => $value) : $count++;
$url = \phpOMS\Uri\UriFactory::build('/{/lang}/backend/editor/single?id=' . $value->getId()); ?>
<tr>
<td><a href="<?= $url; ?>"><?= $value->getTitle(); ?></a>
<td><a href="<?= $url; ?>"><?= $value->getCreatedBy(); ?></a>
<td><a href="<?= $url; ?>"><?= $value->getCreatedAt()->format('Y-m-d H:i:s'); ?></a>
<?php endforeach; ?>
<?php if($count === 0) : ?>
<tr><td colspan="5" class="empty"><?= $this->getText('Empty', 0, 0); ?>

View File

@ -1,3 +1,25 @@
<?php
/**
* Orange Management
*
* PHP Version 7.0
*
* @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
*/
/**
* @var \phpOMS\Views\View $this
*/
$doc = $this->getData('doc');
echo $this->getData('nav')->render(); ?>
<section class="box w-100">
<div class="inner">
<input type="text" name="title" placeholder="&#xf040; This is a news title" form="newsForm">
@ -32,11 +54,12 @@
<input type="radio" id="c-tab-1" name="tabular-1" checked>
<div class="tab">
<textarea style="height: 300px" placeholder="&#xf040;" name="plain" form="newsForm"></textarea><input type="hidden" id="iParsed" name="parsed">
<textarea style="height: 300px" placeholder="&#xf040;" name="plain" form="newsForm"><?= $doc->getPlain(); ?></textarea><input type="hidden" id="iParsed" name="parsed">
</div>
<input type="radio" id="c-tab-2" name="tabular-1">
<div class="tab">
<?= $doc->getContent(); ?>
</div>
</div>
</div>

View File

@ -21,8 +21,9 @@ echo $this->getData('nav')->render(); ?>
<section class="box w-100">
<div class="inner">
<form>
<input type="text" class="wf-100">
<form id="fEditor" method="POST" action="<?= \phpOMS\Uri\UriFactory::build('/{/lang}/api/editor?csrf={$CSRF}'); ?>">
<input name="title" type="text" class="wf-100">
<input type="submit" value="<?= $this->getText('Save') ?>">
</form>
</div>
</section>
@ -95,7 +96,7 @@ echo $this->getData('nav')->render(); ?>
<div class="tab-content">
<input type="radio" id="c-tab2-1" name="tabular-2" checked>
<div class="tab">
<textarea class="wf-100"></textarea>
<textarea name="plain" class="wf-100" form="fEditor"></textarea>
</div>
<input type="radio" id="c-tab2-2" name="tabular-2">
<div class="tab">

View File

@ -22,20 +22,27 @@ $footerView->setTemplate('/Web/Templates/Lists/Footer/PaginationBig');
$footerView->setPages(20);
$footerView->setPage(1);
$docs = $this->getData('docs');
echo $this->getData('nav')->render(); ?>
<div class="box">
<table class="table">
<caption><?= $this->getText('Documents'); ?></caption>
<thead>
<tr>
<td class="wf-100"><?= $this->getText('Name'); ?>
<td class="wf-100"><?= $this->getText('Title'); ?>
<td><?= $this->getText('Creator'); ?>
<td><?= $this->getText('Created'); ?>
<tfoot>
<tr>
<td colspan="3"><?= $footerView->render(); ?>
<tbody>
<?php $count = 0; foreach([] as $key => $value) : $count++; ?>
<?php $count = 0; foreach($docs as $key => $value) : $count++;
$url = \phpOMS\Uri\UriFactory::build('/{/lang}/backend/editor/single?id=' . $value->getId()); ?>
<tr>
<td><a href="<?= $url; ?>"><?= $value->getTitle(); ?></a>
<td><a href="<?= $url; ?>"><?= $value->getCreatedBy(); ?></a>
<td><a href="<?= $url; ?>"><?= $value->getCreatedAt()->format('Y-m-d H:i:s'); ?></a>
<?php endforeach; ?>
<?php if($count === 0) : ?>
<tr><td colspan="5" class="empty"><?= $this->getText('Empty', 0, 0); ?>