This commit is contained in:
Dennis Eichhorn 2020-03-05 20:35:58 +01:00
parent ba2aca4491
commit f4302ddb6b
3 changed files with 15 additions and 11 deletions

View File

@ -14,9 +14,10 @@ declare(strict_types=1);
namespace Modules\Editor\Controller; namespace Modules\Editor\Controller;
use Modules\Admin\Models\NullAccount;
use Modules\Editor\Models\EditorDoc; use Modules\Editor\Models\EditorDoc;
use Modules\Editor\Models\EditorDocMapper;
use Modules\Editor\Models\EditorDocMapper;
use phpOMS\Message\NotificationLevel; use phpOMS\Message\NotificationLevel;
use phpOMS\Message\RequestAbstract; use phpOMS\Message\RequestAbstract;
use phpOMS\Message\ResponseAbstract; use phpOMS\Message\ResponseAbstract;
@ -103,7 +104,7 @@ final class ApiController extends Controller
$doc->setTitle((string) ($request->getData('title') ?? '')); $doc->setTitle((string) ($request->getData('title') ?? ''));
$doc->setPlain((string) ($request->getData('plain') ?? '')); $doc->setPlain((string) ($request->getData('plain') ?? ''));
$doc->setContent(Markdown::parse((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; return $doc;
} }

View File

@ -14,6 +14,8 @@ declare(strict_types=1);
namespace Modules\Editor\Models; namespace Modules\Editor\Models;
use Modules\Admin\Models\Account;
use Modules\Admin\Models\NullAccount;
use phpOMS\Contract\ArrayableInterface; use phpOMS\Contract\ArrayableInterface;
/** /**
@ -77,10 +79,10 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable
/** /**
* Creator. * Creator.
* *
* @var int|\Modules\Admin\Models\Account * @var Account
* @since 1.0.0 * @since 1.0.0
*/ */
private $createdBy = 0; private Account $createdBy;
/** /**
* Constructor. * Constructor.
@ -89,7 +91,8 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable
*/ */
public function __construct() 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 * Get created by
* *
* @return int|\Modules\Admin\Models\Account * @return Account
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function getCreatedBy() public function getCreatedBy() : Account
{ {
return $this->createdBy; return $this->createdBy;
} }
@ -183,13 +186,13 @@ class EditorDoc implements ArrayableInterface, \JsonSerializable
/** /**
* Set created by * Set created by
* *
* @param int $id Creator * @param Account $account Creator
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function setCreatedBy($id) : void public function setCreatedBy(Account $account) : void
{ {
$this->createdBy = $id; $this->createdBy = $account;
} }
/** /**

View File

@ -35,7 +35,7 @@ final class EditorDocMapper extends DataMapperAbstract
*/ */
protected static array $columns = [ protected static array $columns = [
'editor_doc_id' => ['name' => 'editor_doc_id', 'type' => 'int', 'internal' => 'id'], '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_title' => ['name' => 'editor_doc_title', 'type' => 'string', 'internal' => 'title'],
'editor_doc_plain' => ['name' => 'editor_doc_plain', 'type' => 'string', 'internal' => 'plain'], 'editor_doc_plain' => ['name' => 'editor_doc_plain', 'type' => 'string', 'internal' => 'plain'],
'editor_doc_content' => ['name' => 'editor_doc_content', 'type' => 'string', 'internal' => 'content'], 'editor_doc_content' => ['name' => 'editor_doc_content', 'type' => 'string', 'internal' => 'content'],