Exemplo n.º 1
0
 /**
  * @see ISchedulePageBuilder::GetScheduleDates()
  */
 public function GetScheduleDates(UserSession $user, ISchedule $schedule, ISchedulePage $page)
 {
     $userTimezone = $user->Timezone;
     $providedDate = $page->GetSelectedDate();
     $date = empty($providedDate) ? Date::Now() : new Date($providedDate, $userTimezone);
     $selectedDate = $date->ToTimezone($userTimezone)->GetDate();
     $selectedWeekday = $selectedDate->Weekday();
     $scheduleLength = $schedule->GetDaysVisible();
     if ($page->GetShowFullWeek()) {
         $scheduleLength = 7;
     }
     /**
      *  Examples
      *
      *  if we are on 3 and we need to start on 6, we need to go back 4 days
      *  if we are on 3 and we need to start on 5, we need to go back 5 days
      *  if we are on 3 and we need to start on 4, we need to go back 6 days
      *  if we are on 3 and we need to start on 3, we need to go back 0 days
      *  if we are on 3 and we need to start on 2, we need to go back 1 days
      *  if we are on 3 and we need to start on 1, we need to go back 2 days
      *  if we are on 3 and we need to start on 0, we need to go back 3 days
      */
     $startDay = $schedule->GetWeekdayStart();
     if ($startDay == Schedule::Today) {
         $startDate = $selectedDate;
     } else {
         $adjustedDays = $startDay - $selectedWeekday;
         if ($selectedWeekday < $startDay) {
             $adjustedDays = $adjustedDays - 7;
         }
         $startDate = $selectedDate->AddDays($adjustedDays);
     }
     $applicableDates = new DateRange($startDate, $startDate->AddDays($scheduleLength));
     return $applicableDates;
 }