dispatcher = $dispatcher; } /** * @Route(path="/", name="calendar", methods={"GET"}) */ public function userCalendar(SystemConfiguration $configuration, TrackingModeService $service, TimesheetRepository $repository) { $mode = $service->getActiveMode(); $factory = $this->getDateTimeFactory(); $defaultStart = $factory->createDateTime($configuration->getTimesheetDefaultBeginTime()); $config = [ 'dayLimit' => $configuration->getCalendarDayLimit(), 'showWeekNumbers' => $configuration->isCalendarShowWeekNumbers(), 'showWeekends' => $configuration->isCalendarShowWeekends(), 'businessDays' => $configuration->getCalendarBusinessDays(), 'businessTimeBegin' => $configuration->getCalendarBusinessTimeBegin(), 'businessTimeEnd' => $configuration->getCalendarBusinessTimeEnd(), 'slotDuration' => $configuration->getCalendarSlotDuration(), 'timeframeBegin' => $configuration->getCalendarTimeframeBegin(), 'timeframeEnd' => $configuration->getCalendarTimeframeEnd(), ]; $isPunchMode = !$mode->canEditDuration() && !$mode->canEditBegin() && !$mode->canEditEnd(); $dragAndDrop = []; if ($mode->canEditBegin()) { $dragAndDrop = $this->getDragAndDropResources($repository); } return $this->render('calendar/user.html.twig', [ 'config' => $config, 'dragAndDrop' => $dragAndDrop, 'google' => $this->getGoogleSources($configuration), 'now' => $factory->createDateTime(), 'defaultStartTime' => $defaultStart->format('h:i:s'), 'is_punch_mode' => $isPunchMode, 'can_edit_begin' => $mode->canEditBegin(), 'can_edit_end' => $mode->canEditBegin(), 'can_edit_duration' => $mode->canEditDuration(), ]); } /** * @return DragAndDropSource[] */ private function getDragAndDropResources(TimesheetRepository $repository): array { $event = new CalendarDragAndDropSourceEvent($this->getUser()); try { $data = $repository->getRecentActivities( $this->getUser(), $this->getDateTimeFactory()->createDateTime('-1 year'), 10 ); $recentActivity = new RecentActivityEvent($this->getUser(), $data); $this->dispatcher->dispatch($recentActivity); $entries = []; $colorHelper = new Color(); foreach ($recentActivity->getRecentActivities() as $timesheet) { $entries[] = new TimesheetEntry($timesheet, $colorHelper->getTimesheetColor($timesheet)); } $event->addSource(new RecentActivitiesSource($entries)); } catch (\Exception $ex) { $this->logException($ex); } $this->dispatcher->dispatch($event); return $event->getSources(); } private function getGoogleSources(SystemConfiguration $configuration): ?Google { $apiKey = $configuration->getCalendarGoogleApiKey(); if ($apiKey === null) { return null; } $sources = []; foreach ($configuration->getCalendarGoogleSources() as $name => $config) { $sources[] = new GoogleSource($name, $config['id'], $config['color']); } $event = new CalendarGoogleSourceEvent($this->getUser()); $this->dispatcher->dispatch($event); foreach ($event->getSources() as $source) { $sources[] = $source; } return new Google($apiKey, $sources); } }