mirror of
https://github.com/Karaka-Management/oms-News.git
synced 2026-02-12 14:58:41 +00:00
prepare for comment module
This commit is contained in:
parent
83c99580ea
commit
7240938082
55
Admin/Install/Comment.php
Normal file
55
Admin/Install/Comment.php
Normal 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user