From dc5b332b718a014f62e6f9a9cc5c54db212c9ad9 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 | 9 +++++---- Models/KanbanBoard.php | 20 ++++++++++++-------- Models/KanbanBoardMapper.php | 2 +- Models/KanbanCard.php | 23 +++++++++++++---------- Models/KanbanCardComment.php | 20 ++++++++++++-------- Models/KanbanCardCommentMapper.php | 16 +++++++++++++++- Models/KanbanCardMapper.php | 2 +- 7 files changed, 59 insertions(+), 33 deletions(-) diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 39c3141..c6e2f14 100644 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -14,17 +14,18 @@ declare(strict_types=1); namespace Modules\Kanban\Controller; +use Modules\Admin\Models\NullAccount; use Modules\Kanban\Models\BoardStatus; use Modules\Kanban\Models\CardStatus; use Modules\Kanban\Models\CardType; use Modules\Kanban\Models\KanbanBoard; use Modules\Kanban\Models\KanbanBoardMapper; -use Modules\Kanban\Models\KanbanCard; +use Modules\Kanban\Models\KanbanCard; use Modules\Kanban\Models\KanbanCardMapper; use Modules\Kanban\Models\KanbanColumn; -use Modules\Kanban\Models\KanbanColumnMapper; +use Modules\Kanban\Models\KanbanColumnMapper; use phpOMS\Message\NotificationLevel; use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; @@ -89,7 +90,7 @@ final class ApiController extends Controller $card->setRef((int) ($request->getData('ref') ?? 0)); $card->setStatus((int) ($request->getData('status') ?? CardStatus::ACTIVE)); $card->setType((int) ($request->getData('type') ?? CardType::TEXT)); - $card->setCreatedBy($request->getHeader()->getAccount()); + $card->setCreatedBy(new NullAccount($request->getHeader()->getAccount())); return $card; } @@ -165,7 +166,7 @@ final class ApiController extends Controller $board->setDescription((string) ($request->getData('plain') ?? '')); $board->setOrder((int) ($request->getData('order') ?? 1)); $board->setStatus((int) ($request->getData('status') ?? BoardStatus::ACTIVE)); - $board->setCreatedBy($request->getHeader()->getAccount()); + $board->setCreatedBy(new NullAccount($request->getHeader()->getAccount())); return $board; } diff --git a/Models/KanbanBoard.php b/Models/KanbanBoard.php index 90f4b25..6a3da66 100644 --- a/Models/KanbanBoard.php +++ b/Models/KanbanBoard.php @@ -14,6 +14,9 @@ declare(strict_types=1); namespace Modules\Kanban\Models; +use Modules\Admin\Models\Account; +use Modules\Admin\Models\NullAccount; + /** * Task class. * @@ -51,11 +54,11 @@ class KanbanBoard implements \JsonSerializable */ private string $description = ''; - private $createdBy = 0; + private Account $createdBy; - private $createdAt = null; + private \DateTime $createdAt; - private $columns = []; + private array $columns = []; /** * Constructor. @@ -65,6 +68,7 @@ class KanbanBoard implements \JsonSerializable public function __construct() { $this->createdAt = new \DateTime('now'); + $this->createdBy = new NullAccount(); } /** @@ -186,11 +190,11 @@ class KanbanBoard implements \JsonSerializable /** * Get created by * - * @return int|\phpOMS\Account\Account + * @return Account * * @since 1.0.0 */ - public function getCreatedBy() + public function getCreatedBy() : Account { return $this->createdBy; } @@ -198,15 +202,15 @@ class KanbanBoard implements \JsonSerializable /** * Set created by * - * @param mixed $id Created by + * @param Account $account Created by * * @return void * * @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/KanbanBoardMapper.php b/Models/KanbanBoardMapper.php index 07325ab..ead1566 100644 --- a/Models/KanbanBoardMapper.php +++ b/Models/KanbanBoardMapper.php @@ -39,7 +39,7 @@ final class KanbanBoardMapper extends DataMapperAbstract 'kanban_board_desc' => ['name' => 'kanban_board_desc', 'type' => 'string', 'internal' => 'description'], 'kanban_board_status' => ['name' => 'kanban_board_status', 'type' => 'int', 'internal' => 'status'], 'kanban_board_order' => ['name' => 'kanban_board_order', 'type' => 'int', 'internal' => 'order'], - 'kanban_board_created_by' => ['name' => 'kanban_board_created_by', 'type' => 'int', 'internal' => 'createdBy'], + 'kanban_board_created_by' => ['name' => 'kanban_board_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true], 'kanban_board_created_at' => ['name' => 'kanban_board_created_at', 'type' => 'DateTime', 'internal' => 'createdAt', 'readonly' => true], ]; diff --git a/Models/KanbanCard.php b/Models/KanbanCard.php index 7994989..e561bec 100644 --- a/Models/KanbanCard.php +++ b/Models/KanbanCard.php @@ -14,6 +14,8 @@ declare(strict_types=1); namespace Modules\Kanban\Models; +use Modules\Admin\Models\Account; +use Modules\Admin\Models\NullAccount; use Modules\Tasks\Models\Task; /** @@ -59,15 +61,15 @@ class KanbanCard implements \JsonSerializable private $ref = 0; - private $createdBy = 0; + private Account $createdBy; - private $createdAt = null; + private \DateTime $createdAt; - private $comments = []; + private array $comments = []; - private $labels = []; + private array $labels = []; - private $media = []; + private array $media = []; /** * Constructor. @@ -77,6 +79,7 @@ class KanbanCard implements \JsonSerializable public function __construct() { $this->createdAt = new \DateTime('now'); + $this->createdBy = new NullAccount(); } /** @@ -276,11 +279,11 @@ class KanbanCard implements \JsonSerializable /** * Get created by * - * @return int|\phpOMS\Account\Account + * @return Account * * @since 1.0.0 */ - public function getCreatedBy() + public function getCreatedBy() : Account { return $this->createdBy; } @@ -288,15 +291,15 @@ class KanbanCard implements \JsonSerializable /** * Set created by * - * @param mixed $id Created by + * @param Account $account Created by * * @return void * * @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/KanbanCardComment.php b/Models/KanbanCardComment.php index 408beb1..55c4836 100644 --- a/Models/KanbanCardComment.php +++ b/Models/KanbanCardComment.php @@ -14,6 +14,9 @@ declare(strict_types=1); namespace Modules\Kanban\Models; +use Modules\Admin\Models\Account; +use Modules\Admin\Models\NullAccount; + /** * Task class. * @@ -41,11 +44,11 @@ class KanbanCardComment implements \JsonSerializable private $card = 0; - private $createdBy = 0; + private Account $createdBy; - private $createdAt = null; + private \DateTime $createdAt; - private $media = []; + private array $media = []; /** * Constructor. @@ -55,6 +58,7 @@ class KanbanCardComment implements \JsonSerializable public function __construct() { $this->createdAt = new \DateTime('now'); + $this->createdBy = new NullAccount(); } /** @@ -124,11 +128,11 @@ class KanbanCardComment implements \JsonSerializable /** * Get created by * - * @return int|\phpOMS\Account\Account + * @return Account * * @since 1.0.0 */ - public function getCreatedBy() : int + public function getCreatedBy() : Account { return $this->createdBy; } @@ -136,15 +140,15 @@ class KanbanCardComment implements \JsonSerializable /** * Set created by * - * @param mixed $id Created by + * @param Account $account Created by * * @return void * * @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/KanbanCardCommentMapper.php b/Models/KanbanCardCommentMapper.php index 0d33cee..5e32cf9 100644 --- a/Models/KanbanCardCommentMapper.php +++ b/Models/KanbanCardCommentMapper.php @@ -14,6 +14,7 @@ declare(strict_types=1); namespace Modules\Kanban\Models; +use Modules\Admin\Models\AccountMapper; use Modules\Media\Models\MediaMapper; use phpOMS\DataStorage\Database\DataMapperAbstract; @@ -38,7 +39,7 @@ final class KanbanCardCommentMapper extends DataMapperAbstract 'kanban_card_comment_description' => ['name' => 'kanban_card_comment_description', 'type' => 'string', 'internal' => 'description'], 'kanban_card_comment_card' => ['name' => 'kanban_card_comment_card', 'type' => 'int', 'internal' => 'card'], 'kanban_card_comment_created_at' => ['name' => 'kanban_card_comment_created_at', 'type' => 'DateTime', 'internal' => 'createdAt', 'readonly' => true], - 'kanban_card_comment_created_by' => ['name' => 'kanban_card_comment_created_by', 'type' => 'int', 'internal' => 'createdBy'], + 'kanban_card_comment_created_by' => ['name' => 'kanban_card_comment_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true], ]; /** @@ -56,6 +57,19 @@ final class KanbanCardCommentMapper extends DataMapperAbstract ], ]; + /** + * Belongs to. + * + * @var array + * @since 1.0.0 + */ + protected static array $belongsTo = [ + 'createdBy' => [ + 'mapper' => AccountMapper::class, + 'self' => 'kanban_card_comment_created_by', + ], + ]; + /** * Primary table. * diff --git a/Models/KanbanCardMapper.php b/Models/KanbanCardMapper.php index 8afdfc7..6ff8744 100644 --- a/Models/KanbanCardMapper.php +++ b/Models/KanbanCardMapper.php @@ -44,7 +44,7 @@ final class KanbanCardMapper extends DataMapperAbstract 'kanban_card_ref' => ['name' => 'kanban_card_ref', 'type' => 'int', 'internal' => 'ref'], 'kanban_card_column' => ['name' => 'kanban_card_column', 'type' => 'int', 'internal' => 'column'], 'kanban_card_created_at' => ['name' => 'kanban_card_created_at', 'type' => 'DateTime', 'internal' => 'createdAt', 'readonly' => true], - 'kanban_card_created_by' => ['name' => 'kanban_card_created_by', 'type' => 'int', 'internal' => 'createdBy'], + 'kanban_card_created_by' => ['name' => 'kanban_card_created_by', 'type' => 'int', 'internal' => 'createdBy', 'readonly' => true], ]; /**