<?php
namespace AppBundle\Controller\Customer;
use AppBundle\Entity\Address;
use AppBundle\Entity\Booking;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
class DashboardController extends AbstractController
{
#[Route(path: '/dashboard', name: 'dashboard')]
public function indexAction()
{
$addresses = $this->addressBox();
$history = $this->historyBox();
return $this->render('Customer/Account/dashboard.html.twig', array_merge($addresses, $history));
}
private function addressBox(): array
{
$addresses = $this->getUser()->getAddresses();
$receivers = $addresses->filter(function ($entity) {
return Address::ADDRESS_TYPE_RECEIVER === $entity->getType();
});
$senders = $addresses->filter(function ($entity) {
return Address::ADDRESS_TYPE_SENDER === $entity->getType();
});
$neutralSenders = $addresses->filter(function ($entity) {
return Address::ADDRESS_TYPE_NEUTRAL_SENDER === $entity->getType();
});
return [
'countReceivers' => count($receivers),
'countSenders' => count($senders),
'countNeutralSenders' => count($neutralSenders),
];
}
private function historyBox()
{
$bookings = $this->getUser()->getBookings()->filter(function ($entity) {
return Booking::STATUS['booking.status.onhold'] === $entity->getStatus();
});
return [
'countBookings' => count($bookings),
];
}
}