eventDispatcher = $dispatcher; $this->repository = $repository; $this->dashboard = $dashboard; } /** * @Route(path="/", defaults={}, name="dashboard", methods={"GET"}) */ public function indexAction() { $event = new DashboardEvent($this->getUser()); foreach ($this->dashboard as $widgetRow) { if (empty($widgetRow['widgets'])) { continue; } if (!$this->isGranted($widgetRow['permission'])) { continue; } $row = new DashboardSection($widgetRow['title'] ?? null); $row ->setOrder($widgetRow['order']) ->setType($widgetRow['type']) ; foreach ($widgetRow['widgets'] as $widgetName) { if (!$this->repository->has($widgetName)) { throw new \Exception('Unknwon widget: ' . $widgetName); } $row->addWidget($this->repository->get($widgetName, $event->getUser())); } $event->addSection($row); } $this->eventDispatcher->dispatch( DashboardEvent::DASHBOARD, $event ); $sections = $event->getSections(); uasort( $sections, function (DashboardSection $a, DashboardSection $b) { if ($a->getOrder() == $b->getOrder()) { return 0; } return ($a->getOrder() < $b->getOrder()) ? -1 : 1; } ); return $this->render('dashboard/index.html.twig', [ 'widget_rows' => $sections ]); } }