diff --git a/Admin/Installer.php b/Admin/Installer.php index a727038..2e27fdc 100644 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -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(); diff --git a/Admin/Routes/Web/Backend.php b/Admin/Routes/Web/Backend.php index 444e390..2519faf 100644 --- a/Admin/Routes/Web/Backend.php +++ b/Admin/Routes/Web/Backend.php @@ -19,4 +19,10 @@ return [ 'verb' => RouteVerb::GET, ], ], + '^.*/backend/editor/single.*$' => [ + [ + 'dest' => '\Modules\Editor\Controller:viewEditorSingle', + 'verb' => RouteVerb::GET, + ], + ], ]; diff --git a/Controller.php b/Controller.php index dc8c824..e73947a 100644 --- a/Controller.php +++ b/Controller.php @@ -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 + */ + 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()); } } diff --git a/Models/EditorDoc.php b/Models/EditorDoc.php new file mode 100644 index 0000000..b6202fc --- /dev/null +++ b/Models/EditorDoc.php @@ -0,0 +1,275 @@ + + * @author Dennis Eichhorn + * @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 + * @author Dennis Eichhorn + * @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 + */ + public function __construct() + { + $this->createdAt = new \DateTime('NOW'); + } + + /** + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getContent() : string + { + return $this->content; + } + + /** + * @param string $content + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setContent(string $content) + { + $this->content = $content; + } + + /** + * @param string $plain + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setPlain(string $plain) + { + $this->plain = $plain; + } + + /** + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getPlain() : string + { + return $this->plain; + } + + /** + * @return \DateTime + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getCreatedAt() : \DateTime + { + return $this->createdAt; + } + + /** + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getId() : int + { + return $this->id; + } + + /** + * @return int + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getCreatedBy() : int + { + return $this->createdBy; + } + + /** + * @param int $id + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setCreatedBy(int $id) + { + $this->createdBy = $id; + } + + /** + * @param \DateTime $createdAt + * + * @return void + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setCreatedAt(\DateTime $createdAt) + { + $this->createdAt = $createdAt; + } + + /** + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getTitle() : string + { + return $this->title; + } + + /** + * @param string $title + * + * @return mixed + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setTitle(string $title) + { + $this->title = $title; + } + + /** + * @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; + } + + 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()); + } +} diff --git a/Models/EditorDocMapper.php b/Models/EditorDocMapper.php new file mode 100644 index 0000000..fb09be2 --- /dev/null +++ b/Models/EditorDocMapper.php @@ -0,0 +1,132 @@ + + * @author Dennis Eichhorn + * @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 + */ + 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 + */ + 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/Theme/Backend/editor-create.tpl.php b/Theme/Backend/editor-create.tpl.php index baa93e1..271b1b4 100644 --- a/Theme/Backend/editor-create.tpl.php +++ b/Theme/Backend/editor-create.tpl.php @@ -21,8 +21,9 @@ echo $this->getData('nav')->render(); ?>
-
- + + +
@@ -95,7 +96,7 @@ echo $this->getData('nav')->render(); ?>
- +
diff --git a/Theme/Backend/editor-list.tpl.php b/Theme/Backend/editor-list.tpl.php index 7be8e4f..f283e39 100644 --- a/Theme/Backend/editor-list.tpl.php +++ b/Theme/Backend/editor-list.tpl.php @@ -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(); ?>
- - $value) : $count++; ?> + $value) : $count++; + $url = \phpOMS\Uri\UriFactory::build('/{/lang}/backend/editor/single?id=' . $value->getId()); ?> + +
getText('Documents'); ?>
getText('Name'); ?> + getText('Title'); ?> getText('Creator'); ?> getText('Created'); ?>
render(); ?>
getTitle(); ?> + getCreatedBy(); ?> + getCreatedAt()->format('Y-m-d H:i:s'); ?>
getText('Empty', 0, 0); ?> diff --git a/Theme/Backend/editor.tpl.php b/Theme/Backend/editor.tpl.php index e1850b1..a303fa7 100644 --- a/Theme/Backend/editor.tpl.php +++ b/Theme/Backend/editor.tpl.php @@ -1,3 +1,25 @@ + + * @author Dennis Eichhorn + * @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(); ?>
@@ -32,11 +54,12 @@
- +
+ getContent(); ?>
diff --git a/Theme/backend/editor-create.tpl.php b/Theme/backend/editor-create.tpl.php index baa93e1..271b1b4 100644 --- a/Theme/backend/editor-create.tpl.php +++ b/Theme/backend/editor-create.tpl.php @@ -21,8 +21,9 @@ echo $this->getData('nav')->render(); ?>
-
- + + +
@@ -95,7 +96,7 @@ echo $this->getData('nav')->render(); ?>
- +
diff --git a/Theme/backend/editor-list.tpl.php b/Theme/backend/editor-list.tpl.php index 7be8e4f..f283e39 100644 --- a/Theme/backend/editor-list.tpl.php +++ b/Theme/backend/editor-list.tpl.php @@ -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(); ?>
- - $value) : $count++; ?> + $value) : $count++; + $url = \phpOMS\Uri\UriFactory::build('/{/lang}/backend/editor/single?id=' . $value->getId()); ?> + +
getText('Documents'); ?>
getText('Name'); ?> + getText('Title'); ?> getText('Creator'); ?> getText('Created'); ?>
render(); ?>
getTitle(); ?> + getCreatedBy(); ?> + getCreatedAt()->format('Y-m-d H:i:s'); ?>
getText('Empty', 0, 0); ?>