src/Controller/DashboardController.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\CourseOccurrenceRepository;
  4. use App\Repository\CourseRepository;
  5. use App\Repository\OrderRepository;
  6. use App\Service\StatsService;
  7. use Menke\UserBundle\Controller\AbstractClientableController;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. class DashboardController extends AbstractClientableController
  10. {
  11.     /**
  12.      * @Route("/", name="dashboard")
  13.      */
  14.     public function index(
  15.         StatsService $statsService,
  16.         OrderRepository $orderRepo,
  17.         CourseOccurrenceRepository $courseOccurrenceRepo,
  18.         CourseRepository $courseRepo
  19.     )
  20.     {
  21.         $user $this->getCurrentUser();
  22.         $roles $user->getRoles();
  23.         if (in_array('ROLE_MANAGER'$roles) || in_array('ROLE_ADMIN'$roles) || in_array('ROLE_SUPER_USER'$roles)) {
  24.             $numberDays 7;
  25.             $client $this->getCurrentClient();
  26.             $statsData = [];
  27.             if ($client) {
  28.                 $statsData['orderCoursesStats'] = $statsService->getCourseOrderStatsByRecentDays($numberDays$client);
  29.                 $statsData['orderStats'] = $statsService->getOrderStatsByRecentDays($numberDays$client);
  30.                 $statsData['peopleStats'] = $statsService->getCustomerStatsByRecentDays($numberDays$client);
  31.                 $statsData['courseStats'] = $statsService->getCourseStatsByRecentDays($numberDays$client);
  32.                 $statsData['salesStats'] = $statsService->getSaleStatsByRecentDays($numberDays$client);
  33.             }
  34.             $openOrders $orderRepo->getMappedCountOfOpenOrders($client);
  35.             $nextCourses $courseOccurrenceRepo->getCoursesByClient($client50'asc''start', new \DateTime());
  36.             return $this->render('dashboard/index.html.twig', [
  37.                 'client' => $client,
  38.                 'statsData' => $statsData,
  39.                 'openOrders' => $openOrders,
  40.                 'nextCourses' => $nextCourses,
  41.             ]);
  42.         } elseif (in_array('ROLE_SPEAKER'$roles)) {
  43.          return $this->render('dashboard/speaker.html.twig', [
  44.         ]);
  45.         } elseif (in_array('ROLE_EXTERNAL_AGENT'$roles)) {
  46.         // Fetch course templates
  47.             $courses $courseRepo->findBy([
  48.                 'courseNature' => 'CourseTemplate'
  49.             ]);
  50.             return $this->render('dashboard/external-agent.html.twig', [
  51.                 'courses' => $courses
  52.             ]);
  53.         } elseif (in_array('ROLE_USER'$roles)) {
  54.             return $this->render('dashboard/customer.html.twig', [
  55.             ]);
  56.         }
  57.     }
  58. }