From 7240938082d7c7e1b4df0699965bfac980f69336 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 22 Jul 2020 11:48:07 +0200 Subject: [PATCH] prepare for comment module --- Admin/Install/Comment.php | 55 ++++++++++++++++++++++++++++++++++++ Admin/Install/db.json | 6 ++++ Models/NewsArticle.php | 20 +++++++++++++ Models/NewsArticleMapper.php | 20 ++++++++++++- info.json | 3 +- 5 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 Admin/Install/Comment.php diff --git a/Admin/Install/Comment.php b/Admin/Install/Comment.php new file mode 100644 index 0000000..a326ae1 --- /dev/null +++ b/Admin/Install/Comment.php @@ -0,0 +1,55 @@ +get('schema')); + $builder->alterTable(NewsArticleMapper::getTable()) + ->addConstraint('news_comment_list', 'comment_list', 'comment_list_id'); + + $mapper = \file_get_contents(__DIR__ . '/../../Models/NewsArticleMapper.php'); + $mapper = \str_replace([ + '// @Module Comment ', + '/* @Module Comment ', + ' @Module Comment */' + ], '', $mapper); + \file_put_contents(__DIR__ . '/../../Models/NewsArticleMapper.php', $mapper); + } +} diff --git a/Admin/Install/db.json b/Admin/Install/db.json index 314c0bd..4df1b75 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -50,6 +50,12 @@ "type": "DATETIME", "null": false }, + "news_comment_list": { + "name": "news_comment_list", + "type": "int", + "null": true, + "default": null + }, "news_created_at": { "name": "news_created_at", "type": "DATETIME", diff --git a/Models/NewsArticle.php b/Models/NewsArticle.php index 9c0ea15..dab88f7 100755 --- a/Models/NewsArticle.php +++ b/Models/NewsArticle.php @@ -127,6 +127,14 @@ class NewsArticle implements ArrayableInterface, \JsonSerializable */ private array $tags = []; + /** + * Comments + * + * @var null|object|CommentList + * @since 1.0.0 + */ + private ?object $comments = null; + /** * Constructor. * @@ -191,6 +199,18 @@ class NewsArticle implements ArrayableInterface, \JsonSerializable return $this->plain; } + /** + * Get comments + * + * @return null|object|CommentList + * + * @since 1.0.0 + */ + public function getComments() : ?object + { + return $this->comments; + } + /** * Get date of creation * diff --git a/Models/NewsArticleMapper.php b/Models/NewsArticleMapper.php index 1467a01..9e87d16 100755 --- a/Models/NewsArticleMapper.php +++ b/Models/NewsArticleMapper.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace Modules\News\Models; use Modules\Admin\Models\AccountMapper; +// @Module Comment use Modules\Comments\Models\CommentListMapper; use Modules\Tag\Models\TagMapper; use phpOMS\DataStorage\Database\DataMapperAbstract; @@ -41,7 +42,6 @@ final class NewsArticleMapper extends DataMapperAbstract */ protected static array $columns = [ 'news_id' => ['name' => 'news_id', 'type' => 'int', 'internal' => 'id'], - 'news_created_by' => ['name' => 'news_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true], 'news_publish' => ['name' => 'news_publish', 'type' => 'DateTime', 'internal' => 'publish'], 'news_title' => ['name' => 'news_title', 'type' => 'string', 'internal' => 'title'], 'news_plain' => ['name' => 'news_plain', 'type' => 'string', 'internal' => 'plain'], @@ -50,9 +50,27 @@ final class NewsArticleMapper extends DataMapperAbstract 'news_status' => ['name' => 'news_status', 'type' => 'int', 'internal' => 'status'], 'news_type' => ['name' => 'news_type', 'type' => 'int', 'internal' => 'type'], 'news_featured' => ['name' => 'news_featured', 'type' => 'bool', 'internal' => 'featured'], + 'news_comment_list' => ['name' => 'news_comment_list', 'type' => 'int', 'internal' => 'comments'], 'news_created_at' => ['name' => 'news_created_at', 'type' => 'DateTime', 'internal' => 'createdAt', 'readonly' => true], + 'news_created_by' => ['name' => 'news_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true], ]; + /** + * Has one relation. + * + * @var array + * @since 1.0.0 + */ + /* @Module Comment protected static array $ownsOne = [ + 'news_comment_list' => [ + 'mapper' => CommentListMapper::class, + 'self' => 'accounting_costcenter_l11n_language', + 'by' => 'code2', + 'column' => 'code2', + 'conditional' => true, + ], + ]; @Module Comment */ + /** * Belongs to. * diff --git a/info.json b/info.json index 2cf2e09..ce9c998 100755 --- a/info.json +++ b/info.json @@ -22,7 +22,8 @@ "Tag": "1.0.0" }, "providing": { - "Navigation": "*" + "Navigation": "*", + "Comment": "*" }, "load": [ {