acpRepository = $accompanyingPeriodRepository; $this->security = $security; // $this->notificationRepository = $notificationRepository; // $this->em = $em; $this->dataFetcher = $dataFetcher; } public function supports(array $config, array $context = []): bool { // Check if the context is "bar" return $config['alias'] === 'bar'; } /** * @throws \Exception */ public function getDataForWidget(array $config, array $context = []): array { $user = $this->security->getUser(); //$userId = $user->getId(); //Hardcoder pour résultat $userId = 19; $dataForWidget = []; if (!$user instanceof User) { throw new AccessDeniedException(); } if ($context !== []) { switch ($context['what']) { case 'accompanying_period_by_month': $data = $this->dataFetcher->fetchDataForWidget($userId); $dataForWidget = [ 'labels' => $data['months'], 'datasets' => [ [ 'label' => 'Number of accompanying periods opened', 'backgroundColor' => ['#41B883'], 'data' => $data['counts'] ] ] ]; break; default: throw new \InvalidArgumentException('Invalid Context.'); } } return [ 'data' => $dataForWidget, 'options' => [ 'responsive' => 'true', 'maintainAspectRatio' => 'false', 'position' => 'relative' ], 'type' => 'bar', ]; } }