src/Controller/Admin/DefaultController.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Admin;
  3. use App\DBAL\Types\CustomerCommentType;
  4. use App\DBAL\Types\NotificationSectionType;
  5. use App\Entity\Notification;
  6. use App\Entity\Notification\Customer\CommentNotification;
  7. use App\Repository\NotificationRepository;
  8. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  9. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. /**
  14.  * @Route("/admin")
  15.  */
  16. class DefaultController extends AbstractController
  17. {
  18.     /**
  19.      * @Route("/", name="admin_homepage")
  20.      *
  21.      * @return Response
  22.      */
  23.     public function index(): Response
  24.     {
  25.         return $this->render('admin/default/homepage.html.twig');
  26.     }
  27.     /**
  28.      * @Route("/notification/{id}", name="admin_notification")
  29.      * @ParamConverter("notification", class="App:Notification")
  30.      * @IsGranted("OBJECT_NOTIFICATION", subject="notification")
  31.      *
  32.      * @param NotificationRepository $notificationRepository
  33.      * @param Notification           $notification
  34.      *
  35.      * @return Response
  36.      */
  37.     public function notification(NotificationRepository $notificationRepositoryNotification $notification): Response
  38.     {
  39.         if (!$this->getUser()->hasNotification($notification)) {
  40.             return $this->redirectToRoute('admin_access_denied', ['rule' => 'object_notification']);
  41.         }
  42.         $notification->setUnread(false);
  43.         $notificationRepository->update($notification);
  44.         /** @var int|null */
  45.         $commentId $notification->getParams()['comment_id'] ?? null;
  46.         if (NotificationSectionType::CUSTOMER === $notification->getType()) {
  47.             return $this->redirectToRoute('admin_customers_view', [
  48.                 'id' => $notification->getCustomer()->getId(),
  49.             ]);
  50.         }
  51.         if (NotificationSectionType::CUSTOMER_COMMENT === $notification->getType()
  52.             || NotificationSectionType::CUSTOMER_FILE === $notification->getType()
  53.             || NotificationSectionType::CUSTOMER_MESSAGE === $notification->getType()
  54.             || NotificationSectionType::CUSTOMER_UPSELL_REQUEST === $notification->getType()
  55.             || NotificationSectionType::CUSTOMER_RATING_LOG === $notification->getType()
  56.         ) {
  57.             $object $notification->getObject();
  58.             $tab 'notes';
  59.             switch ($notification->getType()) {
  60.                 case NotificationSectionType::CUSTOMER_FILE:
  61.                     $tab 'files';
  62.                     break;
  63.                 case NotificationSectionType::CUSTOMER_MESSAGE:
  64.                     $tab 'messages';
  65.                     break;
  66.                 case NotificationSectionType::CUSTOMER_UPSELL_REQUEST:
  67.                     $tab 'upsells';
  68.                     break;
  69.                 case NotificationSectionType::CUSTOMER_COMMENT:
  70.                     switch ($object->getType()) {
  71.                         case CustomerCommentType::COMPLAINT:
  72.                             $tab 'complaints';
  73.                             break;
  74.                         case CustomerCommentType::TAX_RETURN:
  75.                             $tab 'returns';
  76.                             break;
  77.                         case CustomerCommentType::UPSELL_REQUEST:
  78.                             $tab 'upsells';
  79.                             break;
  80.                     }
  81.             }
  82.             if ($notification instanceof CommentNotification && $comment $notification->getComment()) {
  83.                 $commentId $comment->getId();
  84.             }
  85.             return $this->redirectToRoute('admin_customers_view', [
  86.                 'id' => $object->getCustomer()->getId(),
  87.                 'tab' => $tab,
  88.                 'commentId' => $commentId,
  89.             ]);
  90.         }
  91.         if (NotificationSectionType::EVENT === $notification->getType()) {
  92.             return $this->redirectToRoute('admin_events', [
  93.                 'filters' => json_encode(['id' => $notification->getEvent()->getId()]),
  94.                 'commentId' => $commentId,
  95.             ]);
  96.         }
  97.         if (NotificationSectionType::FEED === $notification->getType()) {
  98.             return $this->redirectToRoute('admin_feeds', [
  99.                 'filters' => json_encode(['id' => $notification->getFeed()->getId()]),
  100.                 'commentId' => $commentId,
  101.             ]);
  102.         }
  103.         if (NotificationSectionType::PROJECT === $notification->getType()) {
  104.             /** @var int|null */
  105.             $itemId $notification->getParams()['item_id'] ?? null;
  106.             if ($itemId) {
  107.                 return $this->redirectToRoute('admin_projects_view', [
  108.                     'id' => $notification->getProject()->getId(),
  109.                     'commentId' => $commentId,
  110.                     'type' => 'tasks',
  111.                 ]);
  112.             }
  113.             /** @var int|null */
  114.             $parentId $notification->getParams()['parent_id'] ?? null;
  115.             return $this->redirectToRoute('admin_projects_view', [
  116.                 'id' => $notification->getProject()->getId(),
  117.                 'parentId' => $parentId,
  118.                 'commentId' => $commentId,
  119.             ]);
  120.         }
  121.         if (NotificationSectionType::STREAM === $notification->getType()) {
  122.             /** @var int|null */
  123.             $parentId $notification->getParams()['parent_id'] ?? null;
  124.             return $this->redirectToRoute('admin_streams', [
  125.                 'filters' => json_encode(['id' => $notification->getStream()->getId()]),
  126.                 'parentId' => $parentId,
  127.                 'commentId' => $commentId,
  128.             ]);
  129.         }
  130.         if (NotificationSectionType::ISSUE === $notification->getType()) {
  131.             return $this->redirectToRoute('admin_issues', [
  132.                 'filters' => json_encode(['id' => $notification->getIssue()->getId()]),
  133.                 'commentId' => $commentId,
  134.             ]);
  135.         }
  136.         if (NotificationSectionType::LEAD === $notification->getType()) {
  137.             return $this->redirectToRoute('admin_leads', [
  138.                 'filters' => json_encode(['id' => $notification->getLead()->getId()]),
  139.             ]);
  140.         }
  141.         return $this->redirectToRoute('admin_homepage');
  142.     }
  143. }