You are here

public function Calendar::calendarBuildWeek in Calendar 8

Build one week row.

Parameters

bool $check_month: TRUE to check the rest of the month, FALSE otherwise.

Return value

array An assosiative array containing the multiday buckets, the singleday buckets and the total row count.

2 calls to Calendar::calendarBuildWeek()
Calendar::calendarBuildMonth in src/Plugin/views/style/Calendar.php
Build one month.
Calendar::render in src/Plugin/views/style/Calendar.php
Render the display in this style.

File

src/Plugin/views/style/Calendar.php, line 989

Class

Calendar
Views style plugin for the Calendar module.

Namespace

Drupal\calendar\Plugin\views\style

Code

public function calendarBuildWeek($check_month = FALSE) {
  $week_days = CalendarHelper::weekDays(TRUE);
  $week_days = CalendarHelper::weekDaysOrdered($week_days);
  $current_day_date = $this->currentDay
    ->format(DateTimeItemInterface::DATE_STORAGE_FORMAT);
  $month = $this->currentDay
    ->format('n');
  $first_day = \Drupal::config('system.date')
    ->get('first_day');

  // Set up buckets.
  $total_rows = 0;

  // Move backwards to the first day of the week.
  $day_week_day = $this->currentDay
    ->format('w');
  $this->currentDay
    ->modify('-' . (7 + $day_week_day - $first_day) % 7 . ' days');
  foreach ($week_days as $i => $day_object) {

    // Create each bucket on the fly so it goes with the correct key order.
    $multiday_buckets[$i] = [];
    $singleday_buckets[$i] = [];
    if ($check_month && ($current_day_date < $this->dateInfo
      ->getMinDate()
      ->format(DateTimeItemInterface::DATE_STORAGE_FORMAT) || $current_day_date > $this->dateInfo
      ->getMaxDate()
      ->format(DateTimeItemInterface::DATE_STORAGE_FORMAT) || $this->currentDay
      ->format('n') != $month)) {
      $singleday_buckets[$i][][] = [
        'entry' => [
          '#theme' => 'calendar_empty_day',
          '#curday' => $current_day_date,
          '#view' => $this->view,
        ],
        'item' => NULL,
      ];
    }
    else {
      $this
        ->calendarBuildWeekDay($i, $multiday_buckets, $singleday_buckets);
    }
    $total_rows = max(count($multiday_buckets[$i]) + 1, $total_rows);
    $this->currentDay
      ->modify('+1 day');
    $current_day_date = $this->currentDay
      ->format(DateTimeItemInterface::DATE_STORAGE_FORMAT);
  }
  return [
    'multiday_buckets' => $multiday_buckets,
    'singleday_buckets' => $singleday_buckets,
    'total_rows' => $total_rows,
  ];
}