<?php
namespace App\Controller\Admin;
use App\DBAL\Types\CustomerCommentType;
use App\DBAL\Types\NotificationSectionType;
use App\Entity\Notification;
use App\Entity\Notification\Customer\CommentNotification;
use App\Repository\NotificationRepository;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/admin")
*/
class DefaultController extends AbstractController
{
/**
* @Route("/", name="admin_homepage")
*
* @return Response
*/
public function index(): Response
{
return $this->render('admin/default/homepage.html.twig');
}
/**
* @Route("/notification/{id}", name="admin_notification")
* @ParamConverter("notification", class="App:Notification")
* @IsGranted("OBJECT_NOTIFICATION", subject="notification")
*
* @param NotificationRepository $notificationRepository
* @param Notification $notification
*
* @return Response
*/
public function notification(NotificationRepository $notificationRepository, Notification $notification): Response
{
if (!$this->getUser()->hasNotification($notification)) {
return $this->redirectToRoute('admin_access_denied', ['rule' => 'object_notification']);
}
$notification->setUnread(false);
$notificationRepository->update($notification);
/** @var int|null */
$commentId = $notification->getParams()['comment_id'] ?? null;
if (NotificationSectionType::CUSTOMER === $notification->getType()) {
return $this->redirectToRoute('admin_customers_view', [
'id' => $notification->getCustomer()->getId(),
]);
}
if (NotificationSectionType::CUSTOMER_COMMENT === $notification->getType()
|| NotificationSectionType::CUSTOMER_FILE === $notification->getType()
|| NotificationSectionType::CUSTOMER_MESSAGE === $notification->getType()
|| NotificationSectionType::CUSTOMER_UPSELL_REQUEST === $notification->getType()
|| NotificationSectionType::CUSTOMER_RATING_LOG === $notification->getType()
) {
$object = $notification->getObject();
$tab = 'notes';
switch ($notification->getType()) {
case NotificationSectionType::CUSTOMER_FILE:
$tab = 'files';
break;
case NotificationSectionType::CUSTOMER_MESSAGE:
$tab = 'messages';
break;
case NotificationSectionType::CUSTOMER_UPSELL_REQUEST:
$tab = 'upsells';
break;
case NotificationSectionType::CUSTOMER_COMMENT:
switch ($object->getType()) {
case CustomerCommentType::COMPLAINT:
$tab = 'complaints';
break;
case CustomerCommentType::TAX_RETURN:
$tab = 'returns';
break;
case CustomerCommentType::UPSELL_REQUEST:
$tab = 'upsells';
break;
}
}
if ($notification instanceof CommentNotification && $comment = $notification->getComment()) {
$commentId = $comment->getId();
}
return $this->redirectToRoute('admin_customers_view', [
'id' => $object->getCustomer()->getId(),
'tab' => $tab,
'commentId' => $commentId,
]);
}
if (NotificationSectionType::EVENT === $notification->getType()) {
return $this->redirectToRoute('admin_events', [
'filters' => json_encode(['id' => $notification->getEvent()->getId()]),
'commentId' => $commentId,
]);
}
if (NotificationSectionType::FEED === $notification->getType()) {
return $this->redirectToRoute('admin_feeds', [
'filters' => json_encode(['id' => $notification->getFeed()->getId()]),
'commentId' => $commentId,
]);
}
if (NotificationSectionType::PROJECT === $notification->getType()) {
/** @var int|null */
$itemId = $notification->getParams()['item_id'] ?? null;
if ($itemId) {
return $this->redirectToRoute('admin_projects_view', [
'id' => $notification->getProject()->getId(),
'commentId' => $commentId,
'type' => 'tasks',
]);
}
/** @var int|null */
$parentId = $notification->getParams()['parent_id'] ?? null;
return $this->redirectToRoute('admin_projects_view', [
'id' => $notification->getProject()->getId(),
'parentId' => $parentId,
'commentId' => $commentId,
]);
}
if (NotificationSectionType::STREAM === $notification->getType()) {
/** @var int|null */
$parentId = $notification->getParams()['parent_id'] ?? null;
return $this->redirectToRoute('admin_streams', [
'filters' => json_encode(['id' => $notification->getStream()->getId()]),
'parentId' => $parentId,
'commentId' => $commentId,
]);
}
if (NotificationSectionType::ISSUE === $notification->getType()) {
return $this->redirectToRoute('admin_issues', [
'filters' => json_encode(['id' => $notification->getIssue()->getId()]),
'commentId' => $commentId,
]);
}
if (NotificationSectionType::LEAD === $notification->getType()) {
return $this->redirectToRoute('admin_leads', [
'filters' => json_encode(['id' => $notification->getLead()->getId()]),
]);
}
return $this->redirectToRoute('admin_homepage');
}
}