<?php
namespace App\Controller;
use App\Repository\CourseOccurrenceRepository;
use App\Repository\CourseRepository;
use App\Repository\OrderRepository;
use App\Service\StatsService;
use Menke\UserBundle\Controller\AbstractClientableController;
use Symfony\Component\Routing\Annotation\Route;
class DashboardController extends AbstractClientableController
{
/**
* @Route("/", name="dashboard")
*/
public function index(
StatsService $statsService,
OrderRepository $orderRepo,
CourseOccurrenceRepository $courseOccurrenceRepo,
CourseRepository $courseRepo
)
{
$user = $this->getCurrentUser();
$roles = $user->getRoles();
if (in_array('ROLE_MANAGER', $roles) || in_array('ROLE_ADMIN', $roles) || in_array('ROLE_SUPER_USER', $roles)) {
$numberDays = 7;
$client = $this->getCurrentClient();
$statsData = [];
if ($client) {
$statsData['orderCoursesStats'] = $statsService->getCourseOrderStatsByRecentDays($numberDays, $client);
$statsData['orderStats'] = $statsService->getOrderStatsByRecentDays($numberDays, $client);
$statsData['peopleStats'] = $statsService->getCustomerStatsByRecentDays($numberDays, $client);
$statsData['courseStats'] = $statsService->getCourseStatsByRecentDays($numberDays, $client);
$statsData['salesStats'] = $statsService->getSaleStatsByRecentDays($numberDays, $client);
}
$openOrders = $orderRepo->getMappedCountOfOpenOrders($client);
$nextCourses = $courseOccurrenceRepo->getCoursesByClient($client, 5, 0, 'asc', 'start', new \DateTime());
return $this->render('dashboard/index.html.twig', [
'client' => $client,
'statsData' => $statsData,
'openOrders' => $openOrders,
'nextCourses' => $nextCourses,
]);
} elseif (in_array('ROLE_SPEAKER', $roles)) {
return $this->render('dashboard/speaker.html.twig', [
]);
} elseif (in_array('ROLE_EXTERNAL_AGENT', $roles)) {
// Fetch course templates
$courses = $courseRepo->findBy([
'courseNature' => 'CourseTemplate'
]);
return $this->render('dashboard/external-agent.html.twig', [
'courses' => $courses
]);
} elseif (in_array('ROLE_USER', $roles)) {
return $this->render('dashboard/customer.html.twig', [
]);
}
}
}