You are here

public function Calendar::calendarBuildMiniWeek in Calendar 8

Build one mini week row.

Parameters

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

Return value

array An array of rows with render info.

1 call to Calendar::calendarBuildMiniWeek()
Calendar::calendarBuildMiniMonth in src/Plugin/views/style/Calendar.php
Build one mini month.

File

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

Class

Calendar
Views style plugin for the Calendar module.

Namespace

Drupal\calendar\Plugin\views\style

Code

public function calendarBuildMiniWeek($check_month = FALSE) {
  $current_day_date = $this->currentDay
    ->format(DateTimeItemInterface::DATE_STORAGE_FORMAT);
  $weekdays = CalendarHelper::untranslatedDays();
  $today = $this->dateFormatter
    ->format($this->time
    ->getRequestTime(), 'custom', DateTimeItemInterface::DATE_STORAGE_FORMAT);
  $month = $this->currentDay
    ->format('n');
  $week = CalendarHelper::dateWeek($current_day_date);
  $first_day = \Drupal::config('system.date')
    ->get('first_day');

  // 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');
  $current_day_date = $this->currentDay
    ->format(DateTimeItemInterface::DATE_STORAGE_FORMAT);
  if (!empty($this->styleInfo
    ->isShowWeekNumbers())) {
    $url = CalendarHelper::getURLForGranularity($this->view, 'week', [
      $this->dateInfo
        ->getMinYear() . sprintf('%02s', $week),
    ]);
    if (!empty($url)) {
      $week_number = [
        '#type' => 'link',
        '#url' => $url,
        '#title' => $week,
      ];
    }
    else {

      // Do not link week numbers, if Week views are disabled.
      $week_number = $week;
    }
    $rows[$week][] = [
      'data' => $week_number,
      'class' => 'mini week',
      'id' => $this->view
        ->id() . '-weekno-' . $current_day_date,
    ];
  }
  for ($i = 0; $i < 7; $i++) {
    $current_day_date = $this->currentDay
      ->format(DateTimeItemInterface::DATE_STORAGE_FORMAT);
    $class = strtolower($weekdays[$this->currentDay
      ->format('w')] . ' mini');
    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)) {
      $class .= ' empty';
      $content = [
        'date' => '',
        'datebox' => '',
        'empty' => [
          '#theme' => 'calendar_empty_day',
          '#curday' => $current_day_date,
          '#view' => $this->view,
        ],
        'link' => '',
        'all_day' => [],
        'items' => [],
      ];
    }
    else {
      $content = $this
        ->calendarBuildDay();
      $class .= ($current_day_date == $today ? ' today' : '') . ($current_day_date < $today ? ' past' : '') . ($current_day_date > $today ? ' future' : '') . ($this
        ->isPastMonth($this->currentDay
        ->format('n'), $month) ? ' past-month' : '') . ($this
        ->isFutureMonth($this->currentDay
        ->format('n'), $month) ? ' future-month' : '') . (empty($this->items[$current_day_date]) ? ' has-no-events' : ' has-events');
    }
    $rows[$week][] = [
      'data' => $content,
      'class' => $class,
      'id' => $this->view
        ->id() . '-' . $current_day_date,
    ];
    $this->currentDay
      ->modify('+1 day');
  }
  return $rows;
}