Lines
100.00%
14 / 14
Methods
100.00%
1 / 1
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __invoke | 100.00% | 14 / 14 | 100.00% | 1 / 1 | 5 | ||
| 31 | final class Timeline extends BaseController | |
| 32 | { | |
| 33 | public function __invoke( | |
| 34 | string $agentName, | |
| 35 | Request $request, | |
| 36 | UserRepository $userRepository, | |
| 37 | AgentStatRepository $agentStatRepository, | |
| 38 | TimelineEventRepository $timelineEventRepository, | |
| 39 | TimelineBuilder $timelineBuilder, | |
| 40 | DoneBannerRepository $doneBannerRepository, | |
| 41 | #[MapQueryParameter(filter: \FILTER_VALIDATE_REGEXP, options: ['regexp' => TimelineChart::DAY])] | |
| 42 | ?string $from = null, | |
| 43 | #[MapQueryParameter(filter: \FILTER_VALIDATE_REGEXP, options: ['regexp' => TimelineChart::DAY])] | |
| 44 | ?string $to = null, | |
| 45 | #[MapQueryParameter] | |
| 46 | bool $chart = false, | |
| 47 | ): Response { | |
| 48 | $agent = $userRepository->findOneByAgentName($agentName); | |
| 49 | if (!$agent instanceof User || !$agent->isVisible(ProfilePart::STATS_HISTORY)) { | |
| 50 | throw $this->createNotFoundException('No timeline of '.$agentName.' to show.'); | |
| 51 | } | |
| 52 | ||
| 53 | $stats = $agentStatRepository->findByOwner($agent); | |
| 54 | $events = $timelineEventRepository->findByOwner($agent); | |
| 55 | $timelineChart = TimelineChart::build($stats, $events, $request->getLocale(), TimelineChart::date($from), TimelineChart::date($to)); | |
| 56 | ||
| 57 | if ($chart) { | |
| 58 | return $this->render('agent_stat/_timeline_chart_frame.html.twig', ['chart' => $timelineChart]); | |
| 59 | } | |
| 60 | ||
| 61 | // Banners only with the Bannergress part | |
| 62 | $banners = $agent->isVisible(ProfilePart::BANNERGRESS) ? $doneBannerRepository->findDatedByOwner($agent) : []; | |
| 63 | ||
| 64 | return $this->render('agent/timeline.html.twig', [ | |
| 65 | 'agent' => $agent, | |
| 66 | 'timeline' => $timelineBuilder->build($stats, $events, $banners), | |
| 67 | 'chart' => $timelineChart, | |
| 68 | ]); | |
| 69 | } | |
| 70 | } |