You are here

public function Calendar::calendarBuildDay in Calendar 8

Build the datebox information for the current day.

@todo expand documentation If a day has no events, the empty day theme info is added to the return array.

Return value

array An array with information on the current day for use in a datebox.

2 calls to Calendar::calendarBuildDay()
Calendar::calendarBuildMiniWeek in src/Plugin/views/style/Calendar.php
Build one mini week row.
Calendar::render in src/Plugin/views/style/Calendar.php
Render the display in this style.

File

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

Class

Calendar
Views style plugin for the Calendar module.

Namespace

Drupal\calendar\Plugin\views\style

Code

public function calendarBuildDay() {
  $current_day_date = $this->currentDay
    ->format(DateTimeItemInterface::DATE_STORAGE_FORMAT);
  $selected = FALSE;
  $max_events = !empty($this->styleInfo
    ->getMaxItems()) ? $this->styleInfo
    ->getMaxItems() : 0;
  $ids = [];
  $inner = [];
  $all_day = [];
  $empty = '';
  $link = '';
  $count = 0;
  foreach ($this->items as $date => $day) {
    if ($date == $current_day_date) {
      $count = 0;
      $selected = TRUE;
      ksort($day);
      foreach ($day as $time => $hour) {

        /** @var \Drupal\calendar\CalendarEvent $item */
        foreach ($hour as $key => $item) {
          $count++;
          $ids[$item
            ->getType()] = $item;
          if (empty($this->styleInfo
            ->isMini()) && ($max_events == CALENDAR_SHOW_ALL || $count <= $max_events || $count > 0 && $max_events == CALENDAR_HIDE_ALL)) {
            if ($item
              ->isAllDay()) {
              $item
                ->setIsMultiDay(TRUE);
              $all_day[] = $item;
            }
            else {
              $this->dateFormatter
                ->format($item
                ->getStartDate()
                ->getTimestamp(), 'custom', 'H:i:s');
              $inner[$key][] = $item;
            }
          }
        }
      }
    }
  }
  ksort($inner);
  if (empty($inner) && empty($all_day)) {
    $empty = [
      '#theme' => 'calendar_empty_day',
      '#curday' => $current_day_date,
      '#view' => $this->view,
    ];
  }

  // We have hidden events on this day, use the theme('calendar_multiple_')
  // to show a link.
  if ($max_events != CALENDAR_SHOW_ALL && $count > 0 && $count > $max_events && $this->dateInfo
    ->getCalendarType() != 'day' && !$this->styleInfo
    ->isMini()) {
    if ($this->styleInfo
      ->getMaxItemsStyle() == 'hide' || $max_events == CALENDAR_HIDE_ALL) {
      $all_day = [];
      $inner = [];
    }
    $link = [
      '#theme' => 'calendar_' . $this->dateInfo
        ->getCalendarType() . '_multiple_entity',
      '#curday' => $current_day_date,
      '#count' => $count,
      '#view' => $this->view,
      '#ids' => $ids,
    ];
  }
  $content = [
    '#date' => $current_day_date,
    'datebox' => [
      '#theme' => 'calendar_datebox',
      '#date' => $current_day_date,
      '#view' => $this->view,
      '#items' => $this->items,
      '#selected' => $selected,
    ],
    'empty' => $empty,
    'link' => $link,
    'all_day' => $all_day,
    'items' => $inner,
  ];
  return $content;
}