acpRepository = $accompanyingPeriodRepository; $this->security = $security; $this->notificationRepository = $notificationRepository; } public function supports(array $config, array $context = []): bool { return $config['alias'] === 'number'; } public function getDataForWidget(array $config, array $context = []): array { $user = $this->security->getUser(); $dataForWidget = []; if (!$user instanceof User) { throw new AccessDeniedException(); } if ($context !== []) { switch ($context['what']) { /*case 'accompanying_period_history' : //Send back a data that need to be serialize in order to see $since = (new DateTimeImmutable('now'))->sub(new DateInterval('P1Y')); $data = $this->acpRepository->countByRecentUserHistory($user, $since); $what = $this->acpRepository->findConfirmedByUser($user); break;*/ case 'notification_sender': //Count the number of notification the sender send $countSend = $this->notificationRepository->countAllForSender($user); $dataForWidget = [ 'labels' => ['Notification Send'], 'datasets' => [ [ 'backgroundColor' => ['#41B883'], 'data' => [$countSend] ] ] ]; break; case 'notification_unread': //Count the number of unread notification by the current User $countUnread = $this->notificationRepository->countUnreadByUser($user); $dataForWidget = [ 'labels' => ['Notification Unread'], 'datasets' => [ [ 'backgroundColor' => ['#41B883'], 'data' => [$countUnread] ] ] ]; break; default : throw new \InvalidArgumentException('Invalid Context.'); } } return [ 'data' => $dataForWidget, 'type' => 'number', ]; } }