public function doUpcommingReservations()
 {
     $gameTypeId = $this->getParam('game');
     $date_from = DatetimeManager::format(strtotime('now'), DatetimeManager::DB_FULL);
     $date_to = DatetimeManager::format(strtotime('+ 1 month'), DatetimeManager::DB_FULL);
     $reservations = $this->reservations->fetchWithinByGame($date_from, $date_to, $gameTypeId);
     $subTemplate = ['reservations' => $reservations, 'urlgen' => $this->urlGen];
     $this->template['response'] = $this->twig->render('ajax/upcommingReservations.twig', $subTemplate);
 }
 public function prepareReservationWeek($week = 0, $user_id = null)
 {
     $weekBounds = DatetimeManager::getWeeksBounds($week);
     $dbTimePars = DatetimeManager::format($weekBounds, DatetimeManager::DB_FULL);
     $reservations = $this->reservations->fetchWithin($dbTimePars['time_from'], $dbTimePars['time_to'], $user_id);
     $events = $this->events->fetchWithinTimespan($dbTimePars['time_from'], $dbTimePars['time_to']);
     $weekEntityGroups = ['events' => $events, 'reservations' => $reservations];
     $return = [];
     $return['days'] = self::prepareReservationDays($weekBounds['time_from'], $weekEntityGroups);
     $return["pageTitle"] = self::makeVypisTitle($week);
     $return['timeSpan'] = DatetimeManager::format($weekBounds, DatetimeManager::HUMAN_DATE_ONLY);
     $return['currentWeekGames'] = $this->countGamesOnReservations($reservations);
     return $return;
 }
 public function doPridat()
 {
     $event = Tables\Event::fromPOST();
     $event->author_user_id = $this->user->user_id;
     $dateTime = DatetimeManager::reformat(['time_from' => strtotime($event->time_from), 'time_to' => strtotime($event->time_to)], DatetimeManager::DB_TIME_ONLY);
     $dateTime['date'] = DatetimeManager::reformat($event->event_date, DatetimeManager::DB_DATE_ONLY);
     $date_from = $dateTime['date'] . ' ' . $dateTime['time_from'];
     $date_to = $dateTime['date'] . ' ' . $dateTime['time_to'];
     $resrvations = $this->reservations->fetchWithin($date_from, $date_to);
     $total = count($resrvations);
     if ($total > 0) {
         $this->message->warning(sprintf('V den %s není možné vytvořit událost, vytvoření blokuje %d %s.', date(DatetimeManager::HUMAN_DATE_ONLY, strtotime($event->event_date)), $total, $total >= 5 ? 'rezervací' : 'rezervace'));
         $this->redirectPars('rezervace', 'vypis');
     }
     $id = Tables\Event::insert($this->pdo, $event);
     if ($id) {
         $this->message->success("Událost {$event->event_title} byla úspěšně vytvořena.");
         $this->redirectPars('udalost', 'zobrazit', ['id' => $id]);
     }
     $this->message->warning("Při vytváření události nastaly potíže.");
     $this->redirectPars("rezervace", "vypis");
 }
 private function reservationCreatedSendMail($reservation_id)
 {
     $reservation = $this->reservaions->fetchById($reservation_id);
     if (!$reservation) {
         $this->message->warning("Při pokusu o odeslání upozornění hráčům odebírajícím hru " . $reservation->game_name . " nastala chyba.");
         return;
     }
     $gameType = $this->gameTypes->fetchById($reservation->game_type_id);
     $users = Views\Subscription::fetchUsersByGame($this->pdo, $reservation->game_type_id);
     $dateTime = DatetimeManager::reformat($reservation->reservation_date, DatetimeManager::HUMAN_DATE_ONLY);
     $dateTime .= ' ' . DatetimeManager::reformat($reservation->time_from, DatetimeManager::HUMAN_TIME_ONLY);
     $pars = ['gameName' => $gameType->getFullName(), 'reservationDate' => $dateTime, 'reservationUrl' => $this->urlGen->url(['controller' => 'rezervace', 'action' => 'detail', 'id' => $reservation_id])];
     MailBuilder::openReservationCreated($users, $pars);
 }