prepare for comment module

This commit is contained in:
Dennis Eichhorn 2020-07-22 11:48:07 +02:00
parent 83c99580ea
commit 7240938082
5 changed files with 102 additions and 2 deletions

55
Admin/Install/Comment.php Normal file
View File

@ -0,0 +1,55 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package Modules\News\Admin\Install
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace Modules\News\Admin\Install;
use Modules\News\Models\NewsArticleMapper;
use phpOMS\DataStorage\Database\DatabasePool;
use phpOMS\DataStorage\Database\Schema\Builder;
/**
* Comment class.
*
* @package Modules\News\Admin\Install
* @license OMS License 1.0
* @link https://orange-management.org
* @since 1.0.0
*/
class Comment
{
/**
* Install comment relation
*
* @param string $path Module path
* @param DatabasePool $dbPool Database pool for database interaction
*
* @return void
*
* @since 1.0.0
*/
public static function install(string $path, DatabasePool $dbPool) : void
{
$builder = new Builder($dbPool->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);
}
}

View File

@ -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",

View File

@ -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
*

View File

@ -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<string, array{mapper:string, self:string, by?:string, column?:string}>
* @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.
*

View File

@ -22,7 +22,8 @@
"Tag": "1.0.0"
},
"providing": {
"Navigation": "*"
"Navigation": "*",
"Comment": "*"
},
"load": [
{