diff --git a/Models/Comment.php b/Models/Comment.php index f36ed3d..a103e4e 100644 --- a/Models/Comment.php +++ b/Models/Comment.php @@ -14,6 +14,9 @@ declare(strict_types=1); namespace Modules\Comments\Models; +use Modules\Admin\Models\Account; +use Modules\Admin\Models\NullAccount; + /** * Task class. * @@ -32,7 +35,13 @@ class Comment */ protected int $id = 0; - private $createdBy = 0; + /** + * Account. + * + * @var Account + * @since 1.0.0 + */ + private Account $createdBy; /** * Created at @@ -85,6 +94,7 @@ class Comment */ public function __construct() { + $this->createdBy = new NullAccount(); $this->createdAt = new \DateTime(); } @@ -233,11 +243,11 @@ class Comment /** * Get created by * - * @return int|\phpOMS\Account\Account + * @return Account * * @since 1.0.0 */ - public function getCreatedBy() + public function getCreatedBy() : Account { return $this->createdBy; } @@ -245,13 +255,13 @@ class Comment /** * Set the creator * - * @param mixed $createdBy Creator + * @param Account $createdBy Creator * * @return void * * @since 1.0.0 */ - public function setCreatedBy($createdBy) : void + public function setCreatedBy(Account $createdBy) : void { $this->createdBy = $createdBy; } diff --git a/Models/CommentMapper.php b/Models/CommentMapper.php index 4b71dbe..a9075ef 100644 --- a/Models/CommentMapper.php +++ b/Models/CommentMapper.php @@ -14,6 +14,7 @@ declare(strict_types=1); namespace Modules\Comments\Models; +use Modules\Admin\Models\AccountMapper; 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_list' => ['name' => 'comments_comment_list', 'type' => 'int', 'internal' => 'list'], '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], ]; + /** + * Belongs to. + * + * @var array + * @since 1.0.0 + */ + protected static array $belongsTo = [ + 'createdBy' => [ + 'mapper' => AccountMapper::class, + 'self' => 'comments_comment_created_by', + ], + ]; + /** * Primary table. *