src/AppBundle/Controller/Customer/DashboardController.php line 13

Open in your IDE?
  1. <?php
  2. namespace AppBundle\Controller\Customer;
  3. use AppBundle\Entity\Address;
  4. use AppBundle\Entity\Booking;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. class DashboardController extends AbstractController
  8. {
  9.     #[Route(path'/dashboard'name'dashboard')]
  10.     public function indexAction()
  11.     {
  12.         $addresses $this->addressBox();
  13.         $history $this->historyBox();
  14.         return $this->render('Customer/Account/dashboard.html.twig'array_merge($addresses$history));
  15.     }
  16.     private function addressBox(): array
  17.     {
  18.         $addresses $this->getUser()->getAddresses();
  19.         $receivers $addresses->filter(function ($entity) {
  20.             return Address::ADDRESS_TYPE_RECEIVER === $entity->getType();
  21.         });
  22.         $senders $addresses->filter(function ($entity) {
  23.             return Address::ADDRESS_TYPE_SENDER === $entity->getType();
  24.         });
  25.         $neutralSenders $addresses->filter(function ($entity) {
  26.             return Address::ADDRESS_TYPE_NEUTRAL_SENDER === $entity->getType();
  27.         });
  28.         return [
  29.             'countReceivers' => count($receivers),
  30.             'countSenders' => count($senders),
  31.             'countNeutralSenders' => count($neutralSenders),
  32.         ];
  33.     }
  34.     private function historyBox()
  35.     {
  36.         $bookings $this->getUser()->getBookings()->filter(function ($entity) {
  37.             return Booking::STATUS['booking.status.onhold'] === $entity->getStatus();
  38.         });
  39.         return [
  40.             'countBookings' => count($bookings),
  41.         ];
  42.     }
  43. }