render('reporting/report_by_user.html.twig', $this->getData($request)); } private function getData(Request $request): array { $currentUser = $this->getUser(); $dateTimeFactory = $this->getDateTimeFactory($currentUser); $canChangeUser = $this->canSelectUser(); $values = new MonthByUser(); $values->setUser($currentUser); $values->setDate($dateTimeFactory->getStartOfMonth()); $form = $this->createForm(MonthByUserForm::class, $values, [ 'include_user' => $canChangeUser, 'timezone' => $dateTimeFactory->getTimezone()->getName(), 'start_date' => $values->getDate(), ]); $form->submit($request->query->all(), false); if ($values->getUser() === null) { $values->setUser($currentUser); } if ($currentUser !== $values->getUser() && !$canChangeUser) { throw new AccessDeniedException('User is not allowed to see other users timesheet'); } if ($values->getDate() === null) { $values->setDate($dateTimeFactory->getStartOfMonth()); } $start = $values->getDate(); $start->modify('first day of 00:00:00'); $end = clone $start; $end->modify('last day of 23:59:59'); $selectedUser = $values->getUser(); $previousMonth = clone $start; $previousMonth->modify('-1 month'); $nextMonth = clone $start; $nextMonth->modify('+1 month'); $data = $this->prepareReport($start, $end, $selectedUser); return [ 'decimal' => $values->isDecimal(), 'dataType' => $values->getSumType(), 'report_title' => 'report_user_month', 'box_id' => 'user-month-reporting-box', 'form' => $form->createView(), 'rows' => $data, 'period' => new DailyStatistic($start, $end, $selectedUser), 'user' => $selectedUser, 'current' => $start, 'next' => $nextMonth, 'previous' => $previousMonth, ]; } }