From 13907cbc8601e16836da9720f8c496b80d6a7091 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 2 May 2024 22:54:38 +0000 Subject: [PATCH] Went through todos --- Controller/ApiController.php | 71 +++++++++++++++++++++++++++++- Controller/BackendController.php | 3 -- Models/KanbanCard.php | 4 -- Theme/Backend/kanban-board.tpl.php | 3 ++ 4 files changed, 72 insertions(+), 9 deletions(-) diff --git a/Controller/ApiController.php b/Controller/ApiController.php index b0a1878..544ca2e 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -16,6 +16,7 @@ namespace Modules\Kanban\Controller; use Modules\Admin\Models\AccountMapper; use Modules\Admin\Models\NullAccount; +use Modules\Comments\Models\Comment; use Modules\Kanban\Models\BoardStatus; use Modules\Kanban\Models\CardStatus; use Modules\Kanban\Models\CardType; @@ -53,8 +54,7 @@ final class ApiController extends Controller * * @return void * - * @todo Create another notification whenever a comment is created for a card - * The card owner and all previous commentators should receive a notification + * @performance This should happen in the cli if possible? * * @since 1.0.0 */ @@ -82,6 +82,52 @@ final class ApiController extends Controller } } + /** + * Create a notification for a card + * + * @param Comment $comment Comment to create notification for + * @param RequestAbstract $request Request + * + * @return void + * + * @performance This should happen in the cli if possible? + * + * @since 1.0.0 + */ + private function createCommentNotifications(Comment $comment, RequestAbstract $request) : void + { + $card = KanbanCardMapper::get() + ->with('commentList') + ->with('commentList/comments') + ->where('commentList', $comment->list) + ->execute(); + + $accounts = []; + if ($card->createdBy->id !== $comment->createdBy->id) { + $accounts[] = $card->createdBy->id; + } + + foreach ($card->commentList->comments as $element) { + if ($element->createdBy->id !== $comment->createdBy->id) { + $accounts[] = $element->createdBy->id; + } + } + + foreach ($accounts as $account) { + $notification = new Notification(); + $notification->module = self::NAME; + $notification->title = $card->name; + $notification->createdBy = $card->createdBy; + $notification->createdFor = new NullAccount($account); + $notification->type = NotificationType::CREATE; + $notification->category = PermissionCategory::CARD; + $notification->element = $card->id; + $notification->redirect = '{/base}/kanban/card?{?}&id=' . $card->id; + + $this->createModel($request->header->account, $notification, NotificationMapper::class, 'notification', $request->getOrigin()); + } + } + /** * Routing end-point for application behavior. * @@ -389,4 +435,25 @@ final class ApiController extends Controller return []; } + + /** + * Api method to create comment + * + * @param RequestAbstract $request Request + * @param ResponseAbstract $response Response + * @param array $data Generic data + * + * @return void + * + * @api + * + * @since 1.0.0 + */ + public function apiCommentCreate(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void + { + $this->app->moduleManager->get('Comment', 'Api')->apiCommentCreate($request, $response, $data); + $comment = $response->getDataArray($request->uri->__toString())['response']; + + $this->createCommentNotifications($comment, $request); + } } diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 49591b5..832262c 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -34,9 +34,6 @@ use phpOMS\Views\View; * @link https://jingga.app * @since 1.0.0 * @codeCoverageIgnore - * - * @todo Implement unread cards/comments notification/highlight - * https://github.com/Karaka-Management/oms-Kanban/issues/5 */ final class BackendController extends Controller { diff --git a/Models/KanbanCard.php b/Models/KanbanCard.php index 238e848..d82d762 100755 --- a/Models/KanbanCard.php +++ b/Models/KanbanCard.php @@ -27,10 +27,6 @@ use Modules\Tasks\Models\Task; * @license OMS License 2.0 * @link https://jingga.app * @since 1.0.0 - * - * @todo Implement unread cards/comments notification/highlight - * See tasks for inspiration. However, here we also need to highlight the entire board for unread content - * https://github.com/Karaka-Management/oms-Kanban/issues/5 */ class KanbanCard implements \JsonSerializable { diff --git a/Theme/Backend/kanban-board.tpl.php b/Theme/Backend/kanban-board.tpl.php index 994f3f6..3c0d4ab 100755 --- a/Theme/Backend/kanban-board.tpl.php +++ b/Theme/Backend/kanban-board.tpl.php @@ -15,6 +15,9 @@ declare(strict_types=1); use Modules\Kanban\Models\NullKanbanBoard; use phpOMS\Uri\UriFactory; +// @todo Allow card templates? maybe at least colors? +// https://github.com/Karaka-Management/oms-Kanban/issues/10 + /** @var \Modules\Kanban\Models\KanbanBoard $board */ $board = $this->data['board'] ?? new NullKanbanBoard(); ?>