eventDispatcher = $dispatcher; $this->widgets = $service; $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 (null !== $widgetRow['permission'] && !$this->isGranted($widgetRow['permission'])) { continue; } // TODO this should be dynamic if ($widgetRow['type'] === 'compoundChart') { $row = new CompoundChart(); } else { $row = new CompoundRow(); } $row->setTitle($widgetRow['title'] ?? ''); $row->setOrder($widgetRow['order']); foreach ($widgetRow['widgets'] as $widgetName) { if (!$this->widgets->hasWidget($widgetName)) { throw new \Exception(sprintf('Unknown widget "%s"', $widgetName)); } $row->addWidget($this->widgets->getWidget($widgetName)); } $event->addSection($row); } $this->eventDispatcher->dispatch($event); $sections = $event->getSections(); uasort( $sections, function (WidgetContainerInterface $a, WidgetContainerInterface $b) { if ($a->getOrder() == $b->getOrder()) { return 0; } return ($a->getOrder() < $b->getOrder()) ? -1 : 1; } ); return $this->render('dashboard/index.html.twig', [ 'widgets' => $sections ]); } }