src/Controller/DashboardController.php line 63

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Helper\DashBoardHelper;
  4. use App\Repository\PropertyRepository;
  5. use App\Repository\RegistrationFormRepository;
  6. use App\Entity\User;
  7. use App\ValueObject\UserPermission;
  8. use App\ValueObject\UserTypes;
  9. use Ecommerce121\UtilBundle\Controller\ControllerBase;
  10. use Ecommerce121\UtilBundle\Controller\ControllerUtil;
  11. use Ecommerce121\UtilBundle\Repository\QueryOptions;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\Response;
  16. /**
  17.  * Class with default actions.
  18.  */
  19. class DashboardController extends ControllerBase
  20. {
  21.     const YEAR_PERIOD 11;
  22.     const SIX_MONTH_PERIOD 5;
  23.     const SEVEN_MONTH_PERIOD 6;
  24.     const YEAR_AND_MONTH_PERIOD 12;
  25.     const DAYS_PERIOD 30;
  26.     const ITEMS_PER_PAGE 10;
  27.     const ITEM_PER_PAGE_PENDING_REGISTRATION 5;
  28.     const ITEMS_PER_PAGE_CANDIDATE 10;
  29.     /**
  30.      * @var DashBoardHelper
  31.      */
  32.     protected $dashBoardHelper;
  33.     /**
  34.      * DashboardController constructor.
  35.      *
  36.      * @param ControllerUtil  $controllerUtil
  37.      * @param DashBoardHelper $dashBoardHelper
  38.      */
  39.     public function __construct(
  40.         ControllerUtil $controllerUtil,
  41.         DashBoardHelper $dashBoardHelper
  42.     ) {
  43.         parent::__construct($controllerUtil);
  44.         $this->dashBoardHelper $dashBoardHelper;
  45.     }
  46.     /**
  47.      * Show default home.
  48.      *
  49.      * @Route("/", name="app_home")
  50.      *
  51.      * @param Request $request HTTP request.
  52.      *
  53.      * @return array|Response
  54.      */
  55.     public function indexAction(Request $request)
  56.     {
  57.         $this->denyAccessUnlessGranted(UserPermission::VIEW_DASHBOARD);
  58.         /** @var User $user */
  59.         $user $this->getUser();
  60.         $entityId null;
  61.         $options = [];
  62.         $totalInvoiced 0;
  63.         $barRegistration null;
  64.         $candidates null;
  65.         $candidatesPaginator null;
  66.         $propertiesPaginator null;
  67.         $dueInvoices null;
  68.         $dueInvoicesPaginator null;
  69.         $properties null;
  70.         $invoicesPaginator null;
  71.         $pendingRegistrationRequest null;
  72.         $pendingRegistrationRequestPaginator null;
  73.         $registrationAndRenewalPaginator null;
  74.         $userEmail null;
  75.         $page $request->query->get('page'1);
  76.         if ($user->getType() === UserTypes::MUNICIPALITY) {
  77.             $entityId $user->getMunicipality()->getId();
  78.         }
  79.         if ($user->getRegisterAsIndividual()) {
  80.             $userEmail $user->getEmail();
  81.         }
  82.         if ($user->getType() === UserTypes::REGISTER_PARTY) {
  83.             if ($user->getOrganization())
  84.                 $entityId $user->getOrganization()->getId();
  85.         }
  86.         if ($user->getType() === UserTypes::MUNIREG) {
  87.             $barInvoice $this->dashBoardHelper->getInvoiceValues(self::YEAR_AND_MONTH_PERIOD);
  88.             $barRegistration $this->dashBoardHelper->getRegistrationValues(self::SIX_MONTH_PERIOD$user->getType());
  89.             $options = [
  90.                 'barInvoice' => $barInvoice,
  91.                 'barRegistration' => $barRegistration
  92.             ];
  93.         }
  94.         if ($user->getType() === UserTypes::MUNICIPALITY) {
  95.             $barRegistration $this->dashBoardHelper->getRegistrationValues(self::YEAR_PERIOD$user->getType(), $entityId);
  96.             $pieRegistration $this->dashBoardHelper->getRegistrationPieValues(self::YEAR_PERIOD$user->getType(), $entityId);
  97.             $lastForms $this->dashBoardHelper->getRegistrationAndRenewal(
  98.                 self::DAYS_PERIOD,
  99.                 $user->getMunicipality(),
  100.                 new QueryOptions($pageself::ITEMS_PER_PAGE'createdDate''DESC')
  101.             );
  102.             $registrationAndRenewalPaginator $this->dashBoardHelper->getRegistrationAndRenewalPaginator(
  103.                 self::DAYS_PERIOD,
  104.                 $user->getMunicipality(),
  105.                 $page,
  106.                 self::ITEMS_PER_PAGE
  107.             );
  108.             $options = [
  109.                 'barRegistration' => $barRegistration,
  110.                 'pieRegistration' => $pieRegistration,
  111.                 'registrationAndRenewalPaginator' => $registrationAndRenewalPaginator,
  112.                 'lastForms' => $lastForms
  113.             ];
  114.         }
  115.         if ($user->getType() === UserTypes::REGISTER_PARTY) {
  116.             $organization $user->getOrganization();
  117.             if ($organization) {
  118.                 $properties $this->dashBoardHelper->getRequiredRenewalFormsByOrganization($organization,
  119.                     new QueryOptions($pageself::ITEMS_PER_PAGE'createdDate''DESC')
  120.                 );
  121.                 $propertiesPaginator $this->dashBoardHelper->getRequiredRenewalFormsByOrganizationPaginator($organization$pageself::ITEMS_PER_PAGE);
  122.                 $dueInvoices $this->dashBoardHelper->getDueRenewalsByOrganization(
  123.                     $organization,
  124.                     new QueryOptions($page5'createdDate''DESC')
  125.                 );
  126.                 $invoicesPaginator $this->dashBoardHelper->getDueRenewalsByOrganizationPaginator($organization$pageself::ITEMS_PER_PAGE);
  127.                 $candidates $this->dashBoardHelper->getCandidateProperties(
  128.                     $organization,
  129.                     new QueryOptions($pageself::ITEMS_PER_PAGE_CANDIDATE'createdDate''DESC')
  130.                 );
  131.                 $candidatesPaginator $this->dashBoardHelper->getCandidatePropertiesPaginator(
  132.                     $organization,
  133.                     $page,
  134.                     self::ITEMS_PER_PAGE_CANDIDATE
  135.                 );
  136.                 $pendingRegistrationRequest $this->dashBoardHelper->getPendingRegistrationRequestOfUser(
  137.                     $user,
  138.                     new QueryOptions($pageself::ITEM_PER_PAGE_PENDING_REGISTRATION,'createdDate''DESC'),
  139.                 );
  140.                 $pendingRegistrationRequestPaginator $this->dashBoardHelper->getPendingRegistrationRequestOfUser(
  141.                     $user,
  142.                     new QueryOptions($pageself::ITEM_PER_PAGE_PENDING_REGISTRATION,'createdDate''DESC'),
  143.                     true,
  144.                     $page,
  145.                     self::ITEM_PER_PAGE_PENDING_REGISTRATION
  146.                 );
  147.                 $totalInvoiced $this->dashBoardHelper->getAccountBalance($organization$userEmail);
  148.             }
  149.             if ($entityId) {
  150.                 $barRegistration $this->dashBoardHelper->getRegistrationValues(self::SEVEN_MONTH_PERIOD$user->getType(), $entityId$userEmail);
  151.             }
  152.             $options = [
  153.                 'totalInvoiced' => $totalInvoiced,
  154.                 'barRegistration' => $barRegistration,
  155.                 'candidates' => $candidates,
  156.                 'candidatesPaginator' => $candidatesPaginator,
  157.                 'dueInvoices' => $dueInvoices,
  158.                 'properties' => $properties,
  159.                 'propertiesPaginator' => $propertiesPaginator,
  160.                 'invoicePaginator' => $invoicesPaginator,
  161.                 'pendingRegistrationRequests' => $pendingRegistrationRequest,
  162.                 'pendingRegistrationRequestPaginator' => $pendingRegistrationRequestPaginator,
  163.             ];
  164.         }
  165.         if ($user->getType() === UserTypes::REGISTER_PARTY) {
  166.             if ($request->isXmlHttpRequest()) {
  167.                 $loadCandidates $request->query->get('type');
  168.                 if ($loadCandidates == 'candidates') {
  169.                     return $this->jsonView('Dashboard/Register/list_candidates.html.twig'$options);
  170.                 }
  171.                 if ($loadCandidates == 'require-renewal') {
  172.                     return $this->jsonView('Dashboard/Register/list_invoices.html.twig'$options);
  173.                 }
  174.                 if ($loadCandidates == 'pending-request') {
  175.                     return $this->jsonView('Dashboard/Register/list_pending_registration_request.html.twig'$options);
  176.                 }
  177.                 if ($loadCandidates == 'properties') {
  178.                     return $this->jsonView('Dashboard/Register/list_required_renewal_property.html.twig'$options);
  179.                 }
  180.             }
  181.             return $this->render('Dashboard/Register/index.html.twig'$options);
  182.         } elseif ($user->getType() === UserTypes::MUNICIPALITY) {
  183.             if ($request->isXmlHttpRequest()) {
  184.                 return $this->jsonView('Dashboard/Municipal/list.html.twig'$options);
  185.             }
  186.             return $this->render('Dashboard/Municipal/index.html.twig'$options);
  187.         }
  188.         return $this->render('Dashboard/munireg.html.twig'$options);
  189.     }
  190. }