src/Controller/Api/NotificationController.php line 84

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Api;
  3. use App\Entity\Customer;
  4. use App\Entity\Notification;
  5. use App\Entity\NotificationAutomatic;
  6. use App\Repository\NotificationAutomaticRepository;
  7. use App\Repository\NotificationRepository;
  8. use App\Services\Api\NotificationManager;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  11. use Symfony\Component\HttpFoundation\JsonResponse;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. use Symfony\Contracts\Translation\TranslatorInterface;
  16. class NotificationController extends ApiController
  17. {
  18.     /** @var NotificationManager $notificationManager */
  19.     protected $notificationManager;
  20.     public function __construct(EntityManagerInterface $emParameterBagInterface $parameterBagNotificationManager $notificationManager)
  21.     {
  22.         parent::__construct($em$parameterBag);
  23.         $this->notificationManager $notificationManager;
  24.     }
  25.     /**
  26.      * @param Request $request
  27.      * @return JsonResponse
  28.      *
  29.      * @Route("/notification/list", name="api_notification_list", methods={"POST"})
  30.      */
  31.     public function list(Request $request)
  32.     {
  33.         $baseurl $request->getScheme() . '://' $request->getHttpHost() . $request->getBasePath();
  34.         $prefixFile $this->getParameter("app.path.type_notification_images");
  35.         $prefixFileAutomatic $this->getParameter("app.path.notification_automatic_message_images");
  36.         $prefixFileGame $this->getParameter("app.path.game_images");
  37.         $folderImageNotification $baseurl $prefixFile "/";
  38.         $folderImageGame $baseurl $prefixFileGame "/";
  39.         $folderImageNotificationAutomatic $baseurl $prefixFileAutomatic "/";
  40.         /** @var Customer $notification */
  41.         $customer $this->getUser();
  42.         /** @var NotificationRepository $notificationRepository */
  43.         $notificationRepository $this->em->getRepository(Notification::class);
  44.         $locale $request->getLocale();
  45.         $generals $notificationRepository->getNotificationCustomer($customer$locale$folderImageNotification$folderImageGame$folderImageNotificationAutomatic);
  46.         return $this->response([
  47.             'list' => $generals,
  48.             'code' => 200
  49.         ]);
  50.     }
  51.     /**
  52.      * @param Request $request
  53.      * @return JsonResponse
  54.      *
  55.      * @Route("/notification/remove/{notificationId}", name="api_notification_remove", methods={"POST"})
  56.      */
  57.     public function remove($notificationIdRequest $request)
  58.     {
  59.         /** @var Customer $notification */
  60.         $customer $this->getUser();
  61.         $customerId $customer->getId();
  62.         $results $this->notificationManager->remove($notificationId$customerId);
  63.         return $this->response($results);
  64.     }
  65.     /**
  66.      * @param Request $request
  67.      * @return JsonResponse
  68.      *
  69.      * @Route("/notification/read/{notificationId}", name="api_notification_read", methods={"POST"})
  70.      */
  71.     public function read($notificationIdRequest $request)
  72.     {
  73.         /** @var Customer $notification */
  74.         $customer $this->getUser();
  75.         $customerId $customer->getId();
  76.         $results $this->notificationManager->read($notificationId$customerId);
  77.         return $this->response($results);
  78.     }
  79. }