security = $security; $this->user = $user; $this->activity = $activity; $this->project = $project; $this->customer = $customer; } /** * @return array */ public static function getSubscribedEvents(): array { return [ DashboardEvent::DASHBOARD => ['onDashboardEvent', 100], ]; } /** * @param DashboardEvent $event * @throws \Doctrine\ORM\NonUniqueResultException */ public function onDashboardEvent(DashboardEvent $event) { if (!$this->security->isGranted(User::ROLE_ADMIN)) { return; } $this->addAdminWidgets($event); } /** * @param DashboardEvent $event * @throws \Doctrine\ORM\NonUniqueResultException */ protected function addAdminWidgets(DashboardEvent $event) { $section = new DashboardSection('dashboard.admin'); $section->setOrder(100); $widget = new Widget('stats.userTotal', $this->user->countUser()); $widget ->setRoute('admin_user') ->setIcon('user') ->setType(Widget::TYPE_MORE) ; $section->addWidget($widget); $widget = new Widget('stats.customerTotal', $this->customer->countCustomer()); $widget ->setRoute('admin_customer') ->setIcon('customer') ->setColor('blue') ->setType(Widget::TYPE_MORE) ; $section->addWidget($widget); $widget = new Widget('stats.projectTotal', $this->project->countProject()); $widget ->setRoute('admin_project') ->setIcon('project') ->setColor('yellow') ->setType(Widget::TYPE_MORE) ; $section->addWidget($widget); $widget = new Widget('stats.activityTotal', $this->activity->countActivity()); $widget ->setRoute('admin_activity') ->setIcon('activity') ->setColor('purple') ->setType(Widget::TYPE_MORE) ; $section->addWidget($widget); $event->addSection($section); } }