src/Controller/DashboardController.php line 63
<?phpnamespace App\Controller;use App\Helper\DashBoardHelper;use App\Entity\User;use App\ValueObject\UserPermission;use App\ValueObject\UserTypes;use Doctrine\ORM\EntityManagerInterface;use Ecommerce121\UtilBundle\Controller\ControllerBase;use Ecommerce121\UtilBundle\Controller\ControllerUtil;use Ecommerce121\UtilBundle\Repository\QueryOptions;use Exception;use Psr\Cache\InvalidArgumentException;use Symfony\Component\Cache\Adapter\DoctrineDbalAdapter;use Symfony\Component\Routing\Attribute\Route;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response;class DashboardController extends ControllerBase{const int YEAR_PERIOD = 11;const int SIX_MONTH_PERIOD = 5;const int SEVEN_MONTH_PERIOD = 6;const int YEAR_AND_MONTH_PERIOD = 12;const int DAYS_PERIOD = 30;const int ITEMS_PER_PAGE = 10;const int ITEM_PER_PAGE_PENDING_REGISTRATION = 5;const int ITEMS_PER_PAGE_CANDIDATE = 10;public function __construct(ControllerUtil $controllerUtil,private readonly DashBoardHelper $dashBoardHelper,private readonly EntityManagerInterface $entityManager) {parent::__construct($controllerUtil);}/*** @throws Exception* @throws InvalidArgumentException*/#[Route('/', name: 'app_home')]public function indexAction(Request $request): array|Response{$this->denyAccessUnlessGranted(UserPermission::VIEW_DASHBOARD);/** @var User $user */$user = $this->getUser();$entityId = null;$options = [];$totalInvoiced = 0;$barRegistration = null;$candidates = null;$candidatesPaginator = null;$propertiesPaginator = null;$dueInvoices = null;$dueInvoicesPaginator = null;$properties = null;$invoicesPaginator = null;$pendingRegistrationRequest = null;$pendingRegistrationRequestPaginator = null;$registrationAndRenewalPaginator = null;$userEmail = null;$cache = new DoctrineDbalAdapter($this->entityManager->getConnection(),'chartData',);$page = $request->query->get('page', 1);if ($user->getType() === UserTypes::MUNICIPALITY) {$entityId = $user->getMunicipality()->getId();}if ($user->getRegisterAsIndividual()) {$userEmail = $user->getEmail();}if ($user->getType() === UserTypes::REGISTER_PARTY) {if ($user->getOrganization())$entityId = $user->getOrganization()->getId();}if ($user->getType() === UserTypes::MUNIREG) {// $barInvoice = $this->dashBoardHelper->getInvoiceValues(self::YEAR_AND_MONTH_PERIOD);// $barRegistration = $this->dashBoardHelper->getRegistrationValues(self::SIX_MONTH_PERIOD, $user->getType());$barInvoiceCacheItem = $cache->getItem('barInvoice');$barRegistrationCacheItem = $cache->getItem('barRegistration_'. $user->getType().'_');$barInvoice = $barInvoiceCacheItem->get();$barRegistration = $barRegistrationCacheItem->get();$options = ['barInvoice' => $barInvoice,'barRegistration' => $barRegistration];}if ($user->getType() === UserTypes::MUNICIPALITY) {// $barRegistration = $this->dashBoardHelper->getRegistrationValues(self::YEAR_PERIOD, $user->getType(), $entityId);// $pieRegistration = $this->dashBoardHelper->getRegistrationPieValues(self::YEAR_PERIOD, $user->getType(), $entityId);$barRegistrationCacheItem = $cache->getItem('barRegistration_'. $user->getType() .'_' .$entityId);$pieRegistrationCacheItem = $cache->getItem('pieRegistration_'. $user->getType() .'_' .$entityId);$barRegistration = $barRegistrationCacheItem->get();$pieRegistration = $pieRegistrationCacheItem->get();$lastForms = $this->dashBoardHelper->getRegistrationAndRenewal(self::DAYS_PERIOD,$user->getMunicipality(),new QueryOptions($page, self::ITEMS_PER_PAGE, 'createdDate', 'DESC'));$registrationAndRenewalPaginator = $this->dashBoardHelper->getRegistrationAndRenewalPaginator(self::DAYS_PERIOD,$user->getMunicipality(),$page,self::ITEMS_PER_PAGE);$options = ['barRegistration' => $barRegistration,'pieRegistration' => $pieRegistration,'registrationAndRenewalPaginator' => $registrationAndRenewalPaginator,'lastForms' => $lastForms];}if ($user->getType() === UserTypes::REGISTER_PARTY) {$organization = $user->getOrganization();if ($organization) {$properties = $this->dashBoardHelper->getRequiredRenewalFormsByOrganization($organization,new QueryOptions($page, self::ITEMS_PER_PAGE, 'createdDate', 'DESC'));$propertiesPaginator = $this->dashBoardHelper->getRequiredRenewalFormsByOrganizationPaginator($organization, $page, self::ITEMS_PER_PAGE);$dueInvoices = $this->dashBoardHelper->getDueRenewalsByOrganization($organization,new QueryOptions($page, 5, 'createdDate', 'DESC'));$invoicesPaginator = $this->dashBoardHelper->getDueRenewalsByOrganizationPaginator($organization, $page, self::ITEMS_PER_PAGE);$candidates = $this->dashBoardHelper->getCandidateProperties($organization,new QueryOptions($page, self::ITEMS_PER_PAGE_CANDIDATE, 'createdDate', 'DESC'));$candidatesPaginator = $this->dashBoardHelper->getCandidatePropertiesPaginator($organization,$page,self::ITEMS_PER_PAGE_CANDIDATE);$pendingRegistrationRequest = $this->dashBoardHelper->getPendingRegistrationRequestOfUser($user,new QueryOptions($page, self::ITEM_PER_PAGE_PENDING_REGISTRATION,'createdDate', 'DESC'),);$pendingRegistrationRequestPaginator = $this->dashBoardHelper->getPendingRegistrationRequestOfUser($user,new QueryOptions($page, self::ITEM_PER_PAGE_PENDING_REGISTRATION,'createdDate', 'DESC'),true,$page,self::ITEM_PER_PAGE_PENDING_REGISTRATION);$totalInvoiced = $this->dashBoardHelper->getAccountBalance($organization, $userEmail);}if ($entityId) {// $barRegistration = $this->dashBoardHelper->getRegistrationValues(self::SEVEN_MONTH_PERIOD, $user->getType(), $entityId, $userEmail);$sanitizedEmail = '';if (!empty($userEmail)) {$sanitizedEmail = str_replace(['{', '}', '(', ')', '/', '\\', '@', ':'],'_',$userEmail);}$barRegistrationCacheItem = $cache->getItem('barRegistration_'. $user->getType() .'_' . $entityId . '_' . $sanitizedEmail);$barRegistration = $barRegistrationCacheItem->get();}$options = ['totalInvoiced' => $totalInvoiced,'barRegistration' => $barRegistration,'candidates' => $candidates,'candidatesPaginator' => $candidatesPaginator,'dueInvoices' => $dueInvoices,'properties' => $properties,'propertiesPaginator' => $propertiesPaginator,'invoicePaginator' => $invoicesPaginator,'pendingRegistrationRequests' => $pendingRegistrationRequest,'pendingRegistrationRequestPaginator' => $pendingRegistrationRequestPaginator,];}if ($user->getType() === UserTypes::REGISTER_PARTY) {if ($request->isXmlHttpRequest()) {$loadCandidates = $request->query->get('type');if ($loadCandidates == 'candidates') {return $this->jsonView('Dashboard/Register/list_candidates.html.twig', $options);}if ($loadCandidates == 'require-renewal') {return $this->jsonView('Dashboard/Register/list_invoices.html.twig', $options);}if ($loadCandidates == 'pending-request') {return $this->jsonView('Dashboard/Register/list_pending_registration_request.html.twig', $options);}if ($loadCandidates == 'properties') {return $this->jsonView('Dashboard/Register/list_required_renewal_property.html.twig', $options);}}return $this->render('Dashboard/Register/index.html.twig', $options);} elseif ($user->getType() === UserTypes::MUNICIPALITY) {if ($request->isXmlHttpRequest()) {return $this->jsonView('Dashboard/Municipal/list.html.twig', $options);}return $this->render('Dashboard/Municipal/index.html.twig', $options);}return $this->render('Dashboard/munireg.html.twig', $options);}}