From f4302ddb6ba1c4f5839f1e40f8daa9eca9685acb Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 5 Mar 2020 20:35:58 +0100 Subject: [PATCH] fixes Orange-Management/phpOMS#224 and fixes Orange-Management/phpOMS#212 --- Controller/ApiController.php | 5 +++-- Models/EditorDoc.php | 19 +++++++++++-------- Models/EditorDocMapper.php | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Controller/ApiController.php b/Controller/ApiController.php index d3affd8..70ec032 100644 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -14,9 +14,10 @@ declare(strict_types=1); namespace Modules\Editor\Controller; +use Modules\Admin\Models\NullAccount; use Modules\Editor\Models\EditorDoc; -use Modules\Editor\Models\EditorDocMapper; +use Modules\Editor\Models\EditorDocMapper; use phpOMS\Message\NotificationLevel; use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; @@ -103,7 +104,7 @@ final class ApiController extends Controller $doc->setTitle((string) ($request->getData('title') ?? '')); $doc->setPlain((string) ($request->getData('plain') ?? '')); $doc->setContent(Markdown::parse((string) ($request->getData('plain') ?? ''))); - $doc->setCreatedBy($request->getHeader()->getAccount()); + $doc->setCreatedBy(new NullAccount($request->getHeader()->getAccount())); return $doc; } diff --git a/Models/EditorDoc.php b/Models/EditorDoc.php index f002142..c795e56 100644 --- a/Models/EditorDoc.php +++ b/Models/EditorDoc.php @@ -14,6 +14,8 @@ declare(strict_types=1); namespace Modules\Editor\Models; +use Modules\Admin\Models\Account; +use Modules\Admin\Models\NullAccount; use phpOMS\Contract\ArrayableInterface; /** @@ -77,10 +79,10 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable /** * Creator. * - * @var int|\Modules\Admin\Models\Account + * @var Account * @since 1.0.0 */ - private $createdBy = 0; + private Account $createdBy; /** * Constructor. @@ -89,7 +91,8 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable */ public function __construct() { - $this->createdAt = new \DateTime('NOW'); + $this->createdBy = new NullAccount(); + $this->createdAt = new \DateTime('now'); } /** @@ -171,11 +174,11 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable /** * Get created by * - * @return int|\Modules\Admin\Models\Account + * @return Account * * @since 1.0.0 */ - public function getCreatedBy() + public function getCreatedBy() : Account { return $this->createdBy; } @@ -183,13 +186,13 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable /** * Set created by * - * @param int $id Creator + * @param Account $account Creator * * @since 1.0.0 */ - public function setCreatedBy($id) : void + public function setCreatedBy(Account $account) : void { - $this->createdBy = $id; + $this->createdBy = $account; } /** diff --git a/Models/EditorDocMapper.php b/Models/EditorDocMapper.php index 156ab35..e65708e 100644 --- a/Models/EditorDocMapper.php +++ b/Models/EditorDocMapper.php @@ -35,7 +35,7 @@ final class EditorDocMapper extends DataMapperAbstract */ protected static array $columns = [ 'editor_doc_id' => ['name' => 'editor_doc_id', 'type' => 'int', 'internal' => 'id'], - 'editor_doc_created_by' => ['name' => 'editor_doc_created_by', 'type' => 'int', 'internal' => 'createdBy'], + 'editor_doc_created_by' => ['name' => 'editor_doc_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true], 'editor_doc_title' => ['name' => 'editor_doc_title', 'type' => 'string', 'internal' => 'title'], 'editor_doc_plain' => ['name' => 'editor_doc_plain', 'type' => 'string', 'internal' => 'plain'], 'editor_doc_content' => ['name' => 'editor_doc_content', 'type' => 'string', 'internal' => 'content'],