<?php
//----------------------------------------------------------------------
// src/Controller/Common/CounterController.php
//----------------------------------------------------------------------
namespace App\Controller\Common;
use Doctrine\Persistence\ManagerRegistry;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use App\Services\Common\CounterTools;
use App\Services\LogTools;
// NOTE: Controller was simplify during migration, if needed old code is available on GitLab
class CounterController extends AbstractController
{
public function __construct(ManagerRegistry $doctrine, TranslatorInterface $translator, LogTools $logTools, CounterTools $counterTools)
{
$this->em = $doctrine->getManager();
$this->translator = $translator;
$this->logTools = $logTools;
$this->counterTools = $counterTools;
}
public function countStuffMission(Request $request): JsonResponse
{
if (!$request->isXmlHttpRequest())
return new JsonResponse(array('status' => 'Error'), 400);
if (!isset($request->request))
return new JsonResponse(array('status' => 'Error'), 400);
if (!$this->isGranted('list_missions_any'))
return new JsonResponse(array('status' => 'Error'), 403);
// All seems fine
// Plan.io Task #3710 : Get current user and group
$access = $this->getUser();
$currentGroup = $this->getUser()->getSocietyGroup();
$totalCount = $this->counterTools->countMissions($currentGroup, $access);
return new JsonResponse(array(
'status' => 'Done',
'response' => $totalCount,
), 200);
}
public function countStuffDemand(Request $request): JsonResponse
{
if (!$request->isXmlHttpRequest())
return new JsonResponse(array('status' => 'Error'), 400);
if (!isset($request->request))
return new JsonResponse(array('status' => 'Error'), 400);
// Plan.io Task #4619 : Added list_external_messages_any
if (!$this->isGranted('list_demands_any') && !$this->isGranted('list_ikea_service_orders_any') && !$this->isGranted('list_external_messages_any'))
return new JsonResponse(array('status' => 'Error'), 403);
// All seems fine
// Plan.io Task #3710 : Get current user and group
$access = $this->getUser();
$currentGroup = $this->getUser()->getSocietyGroup();
$totalCount = 0;
$demands = $this->counterTools->countDemands($currentGroup, $access);
$ikeaServiceOrders = $this->counterTools->countIkeaServiceOrders($currentGroup, $access);
// Plan.io Task #4619
$sms = $this->counterTools->countExternalMessagesSms($currentGroup, $access);
// $this->logTools->ploopLog("sms = ".$sms);
// $this->logTools->ploopLog("ikeaServiceOrders = ".$ikeaServiceOrders);
// $this->logTools->ploopLog("demands = ".$demands);
$totalCount = $demands + $ikeaServiceOrders + $sms;
return new JsonResponse(array(
'status' => 'Done',
'response' => $totalCount,
), 200);
}
public function countStuffNotification(Request $request): JsonResponse
{
if (!$request->isXmlHttpRequest())
return new JsonResponse(array('status' => 'Error'), 400);
if (!isset($request->request))
return new JsonResponse(array('status' => 'Error'), 400);
if (!$this->isGranted('IS_AUTHENTICATED_FULLY'))
return new JsonResponse(array('status' => 'Error'), 200);
// All seems fine
$access = $this->getUser();
$notifications = $this->counterTools->countNotifications($access);
// Plan.io Task #3865
$advancedNotifications = $this->counterTools->countAdvancedNotifications($access);
$totalCount = $notifications + $advancedNotifications;
if ($totalCount > 99)
{
$totalCount = "99+";
}
return new JsonResponse(array(
'status' => 'Done',
'response' => $totalCount,
), 200);
}
public function countStuffApplication(Request $request): JsonResponse
{
if (!$request->isXmlHttpRequest())
return new JsonResponse(array('status' => 'Error'), 400);
if (!isset($request->request))
return new JsonResponse(array('status' => 'Error'), 400);
if (!$this->isGranted('list_applications_any'))
return new JsonResponse(array('status' => 'Error'), 403);
// All seems fine
// Plan.io Task #3710 : Get current user and group
$access = $this->getUser();
$currentGroup = $this->getUser()->getSocietyGroup();
$totalCount = $this->counterTools->countApplications($currentGroup, $access);
return new JsonResponse(array(
'status' => 'Done',
'response' => $totalCount,
), 200);
}
// Task plan.io #3847
public function countStuffCost(Request $request): JsonResponse
{
if (!$request->isXmlHttpRequest())
return new JsonResponse(array('status' => 'Error'), 400);
if (!isset($request->request))
return new JsonResponse(array('status' => 'Error'), 400);
if (!$this->isGranted('IS_AUTHENTICATED_FULLY'))
return new JsonResponse(array(), 400);
// All seems fine
// Plan.io Task #3710 : Get current user and group
$access = $this->getUser();
$currentGroup = $access->getSocietyGroup();
return new JsonResponse(array(
'status' => 'Done',
'response' => $this->counterTools->countCosts($currentGroup, $access),
), 200);
}
}