This commit is contained in:
Dennis Eichhorn 2020-03-05 20:35:58 +01:00
parent 851eab7fa5
commit 17beb7bb3b
2 changed files with 30 additions and 6 deletions

View File

@ -14,6 +14,9 @@ declare(strict_types=1);
namespace Modules\Comments\Models; namespace Modules\Comments\Models;
use Modules\Admin\Models\Account;
use Modules\Admin\Models\NullAccount;
/** /**
* Task class. * Task class.
* *
@ -32,7 +35,13 @@ class Comment
*/ */
protected int $id = 0; protected int $id = 0;
private $createdBy = 0; /**
* Account.
*
* @var Account
* @since 1.0.0
*/
private Account $createdBy;
/** /**
* Created at * Created at
@ -85,6 +94,7 @@ class Comment
*/ */
public function __construct() public function __construct()
{ {
$this->createdBy = new NullAccount();
$this->createdAt = new \DateTime(); $this->createdAt = new \DateTime();
} }
@ -233,11 +243,11 @@ class Comment
/** /**
* Get created by * Get created by
* *
* @return int|\phpOMS\Account\Account * @return Account
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function getCreatedBy() public function getCreatedBy() : Account
{ {
return $this->createdBy; return $this->createdBy;
} }
@ -245,13 +255,13 @@ class Comment
/** /**
* Set the creator * Set the creator
* *
* @param mixed $createdBy Creator * @param Account $createdBy Creator
* *
* @return void * @return void
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function setCreatedBy($createdBy) : void public function setCreatedBy(Account $createdBy) : void
{ {
$this->createdBy = $createdBy; $this->createdBy = $createdBy;
} }

View File

@ -14,6 +14,7 @@ declare(strict_types=1);
namespace Modules\Comments\Models; namespace Modules\Comments\Models;
use Modules\Admin\Models\AccountMapper;
use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\DataStorage\Database\DataMapperAbstract;
/** /**
@ -40,10 +41,23 @@ final class CommentMapper extends DataMapperAbstract
'comments_comment_content_raw' => ['name' => 'comments_comment_content_raw', 'type' => 'string', 'internal' => 'contentRaw'], 'comments_comment_content_raw' => ['name' => 'comments_comment_content_raw', 'type' => 'string', 'internal' => 'contentRaw'],
'comments_comment_list' => ['name' => 'comments_comment_list', 'type' => 'int', 'internal' => 'list'], 'comments_comment_list' => ['name' => 'comments_comment_list', 'type' => 'int', 'internal' => 'list'],
'comments_comment_ref' => ['name' => 'comments_comment_ref', 'type' => 'int', 'internal' => 'ref'], 'comments_comment_ref' => ['name' => 'comments_comment_ref', 'type' => 'int', 'internal' => 'ref'],
'comments_comment_created_by' => ['name' => 'comments_comment_created_by', 'type' => 'int', 'internal' => 'createdBy'], 'comments_comment_created_by' => ['name' => 'comments_comment_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true],
'comments_comment_created_at' => ['name' => 'comments_comment_created_at', 'type' => 'DateTime', 'internal' => 'createdAt', 'readonly' => true], 'comments_comment_created_at' => ['name' => 'comments_comment_created_at', 'type' => 'DateTime', 'internal' => 'createdAt', 'readonly' => true],
]; ];
/**
* Belongs to.
*
* @var array<string, array{mapper:string, self:string}>
* @since 1.0.0
*/
protected static array $belongsTo = [
'createdBy' => [
'mapper' => AccountMapper::class,
'self' => 'comments_comment_created_by',
],
];
/** /**
* Primary table. * Primary table.
* *