src/Controller/Common/CounterController.php line 27

Open in your IDE?
  1. <?php
  2. //----------------------------------------------------------------------
  3. // src/Controller/Common/CounterController.php
  4. //----------------------------------------------------------------------
  5. namespace App\Controller\Common;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpKernel\Exception\HttpException;
  10. use Symfony\Contracts\Translation\TranslatorInterface;
  11. use Symfony\Component\HttpFoundation\JsonResponse;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use App\Services\Common\CounterTools;
  15. use App\Services\LogTools;
  16. // NOTE: Controller was simplify during migration, if needed old code is available on GitLab
  17. class CounterController extends AbstractController
  18. {
  19.     public function __construct(ManagerRegistry $doctrineTranslatorInterface $translatorLogTools $logToolsCounterTools $counterTools)
  20.     {
  21.         $this->em $doctrine->getManager();
  22.         $this->translator $translator;
  23.         $this->logTools $logTools;
  24.         $this->counterTools $counterTools;
  25.     }
  26.     public function countStuffMission(Request $request): JsonResponse
  27.     {
  28.         if (!$request->isXmlHttpRequest())
  29.             return new JsonResponse(array('status' => 'Error'), 400);
  30.         if (!isset($request->request))
  31.             return new JsonResponse(array('status' => 'Error'), 400);
  32.         if (!$this->isGranted('list_missions_any'))
  33.             return new JsonResponse(array('status' => 'Error'), 403);
  34.         // All seems fine
  35.         // Plan.io Task #3710 : Get current user and group
  36.         $access $this->getUser();
  37.         $currentGroup $this->getUser()->getSocietyGroup();
  38.         $totalCount $this->counterTools->countMissions($currentGroup$access);
  39.         return new JsonResponse(array(
  40.             'status'    =>    'Done',
  41.             'response'    =>    $totalCount,
  42.         ), 200);
  43.     }
  44.     public function countStuffDemand(Request $request): JsonResponse
  45.     {
  46.         if (!$request->isXmlHttpRequest())
  47.             return new JsonResponse(array('status' => 'Error'), 400);
  48.         if (!isset($request->request))
  49.             return new JsonResponse(array('status' => 'Error'), 400);
  50.         // Plan.io Task #4619 : Added list_external_messages_any
  51.         if (!$this->isGranted('list_demands_any') && !$this->isGranted('list_ikea_service_orders_any') && !$this->isGranted('list_external_messages_any'))
  52.             return new JsonResponse(array('status' => 'Error'), 403);
  53.         // All seems fine
  54.         // Plan.io Task #3710 : Get current user and group
  55.         $access $this->getUser();
  56.         $currentGroup $this->getUser()->getSocietyGroup();
  57.         $totalCount 0;
  58.         $demands $this->counterTools->countDemands($currentGroup$access);
  59.         $ikeaServiceOrders $this->counterTools->countIkeaServiceOrders($currentGroup$access);
  60.         // Plan.io Task #4619
  61.         $sms $this->counterTools->countExternalMessagesSms($currentGroup$access);
  62.         // $this->logTools->ploopLog("sms = ".$sms);
  63.         // $this->logTools->ploopLog("ikeaServiceOrders = ".$ikeaServiceOrders);
  64.         // $this->logTools->ploopLog("demands = ".$demands);
  65.         $totalCount $demands $ikeaServiceOrders $sms;
  66.         return new JsonResponse(array(
  67.             'status'    =>    'Done',
  68.             'response'    =>    $totalCount,
  69.         ), 200);
  70.     }
  71.     public function countStuffNotification(Request $request): JsonResponse
  72.     {
  73.         if (!$request->isXmlHttpRequest())
  74.             return new JsonResponse(array('status' => 'Error'), 400);
  75.         if (!isset($request->request))
  76.             return new JsonResponse(array('status' => 'Error'), 400);
  77.         if (!$this->isGranted('IS_AUTHENTICATED_FULLY'))
  78.             return new JsonResponse(array('status' => 'Error'), 200);
  79.         // All seems fine
  80.         $access $this->getUser();
  81.         $notifications $this->counterTools->countNotifications($access);
  82.         // Plan.io Task #3865
  83.         $advancedNotifications $this->counterTools->countAdvancedNotifications($access);
  84.         $totalCount $notifications $advancedNotifications;
  85.         if ($totalCount 99)
  86.         {
  87.             $totalCount "99+";
  88.         }
  89.         return new JsonResponse(array(
  90.             'status'    =>    'Done',
  91.             'response'    =>    $totalCount,
  92.         ), 200);
  93.     }
  94.     public function countStuffApplication(Request $request): JsonResponse
  95.     {
  96.         if (!$request->isXmlHttpRequest())
  97.             return new JsonResponse(array('status' => 'Error'), 400);
  98.         if (!isset($request->request))
  99.             return new JsonResponse(array('status' => 'Error'), 400);
  100.         if (!$this->isGranted('list_applications_any'))
  101.             return new JsonResponse(array('status' => 'Error'), 403);
  102.         // All seems fine
  103.         // Plan.io Task #3710 : Get current user and group
  104.         $access $this->getUser();
  105.         $currentGroup $this->getUser()->getSocietyGroup();
  106.         $totalCount $this->counterTools->countApplications($currentGroup$access);
  107.         return new JsonResponse(array(
  108.             'status'    =>    'Done',
  109.             'response'    =>    $totalCount,
  110.         ), 200);
  111.     }
  112.     // Task plan.io #3847
  113.     public function countStuffCost(Request $request): JsonResponse
  114.     {
  115.         if (!$request->isXmlHttpRequest())
  116.             return new JsonResponse(array('status' => 'Error'), 400);
  117.         if (!isset($request->request))
  118.             return new JsonResponse(array('status' => 'Error'), 400);
  119.         if (!$this->isGranted('IS_AUTHENTICATED_FULLY'))
  120.             return new JsonResponse(array(), 400);
  121.         // All seems fine
  122.         // Plan.io Task #3710 : Get current user and group
  123.         $access $this->getUser();
  124.         $currentGroup $access->getSocietyGroup();
  125.         return new JsonResponse(array(
  126.             'status'    =>    'Done',
  127.             'response'    =>    $this->counterTools->countCosts($currentGroup$access),
  128.         ), 200);
  129.     }
  130. }