mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-21 14:14:58 +00:00
feat: add task notification handler
- WIP Implement `TaskNotificationHandler` for generating task-related notifications - Created `showInNotification.html.twig` for rendering task notification view - Added logic to fetch and display task data in notifications
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\TaskBundle\Notification;
|
||||
|
||||
use Chill\MainBundle\Entity\Notification;
|
||||
use Chill\MainBundle\Notification\NotificationHandlerInterface;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
|
||||
use Chill\TaskBundle\Entity\SingleTask;
|
||||
use Chill\TaskBundle\Repository\SingleTaskAclAwareRepository;
|
||||
use Chill\TaskBundle\Repository\SingleTaskRepository;
|
||||
use Symfony\Component\Translation\TranslatableMessage;
|
||||
use Symfony\Contracts\Translation\TranslatableInterface;
|
||||
|
||||
final readonly class TaskNotificationHandler implements NotificationHandlerInterface
|
||||
{
|
||||
public function __construct(private SingleTaskRepository $repository) {}
|
||||
|
||||
public function getTemplate(Notification $notification, array $options = []): string
|
||||
{
|
||||
return '@ChillTask/SingleTask/showInNotification.html.twig';
|
||||
}
|
||||
|
||||
public function getTemplateData(Notification $notification, array $options = []): array
|
||||
{
|
||||
return [
|
||||
'notification' => $notification,
|
||||
'task' => $this->repository->find($notification->getRelatedEntityId()),
|
||||
];
|
||||
}
|
||||
|
||||
public function supports(Notification $notification, array $options = []): bool
|
||||
{
|
||||
return SingleTask::class === $notification->getRelatedEntityClass();
|
||||
}
|
||||
|
||||
public function getTitle(Notification $notification, array $options = []): TranslatableInterface
|
||||
{
|
||||
if (null === $task = $this->getRelatedEntity($notification)) {
|
||||
return new TranslatableMessage('task.deleted');
|
||||
}
|
||||
|
||||
return new TranslatableMessage('task.title', ['id' => $task->getId()]);
|
||||
}
|
||||
|
||||
public function getAssociatedPersons(Notification $notification, array $options = []): array
|
||||
{
|
||||
if (null === $task = $this->getRelatedEntity($notification)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $task->get;
|
||||
}
|
||||
|
||||
public function getRelatedEntity(Notification $notification): ?AccompanyingPeriod
|
||||
{
|
||||
return $this->accompanyingPeriodRepository->find($notification->getRelatedEntityId());
|
||||
}
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
{% macro recordAction(task) %}
|
||||
<li>
|
||||
<a href="{{ path('chill_person_accompanying_course_index', { 'task_id': task }) }}"
|
||||
class="btn btn-show" title="{{ 'See task'|trans }}"></a>
|
||||
</li>
|
||||
{% endmacro %}
|
||||
|
||||
{% if task is not null %}
|
||||
<div class="flex-table">
|
||||
{# TODO task item #}
|
||||
<p>Some task</p>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="alert alert-warning border-warning border-1">
|
||||
{{ 'You are getting a notification for a task which does not exist any more'|trans }}
|
||||
</div>
|
||||
{% endif %}
|
Reference in New Issue
Block a user