Esempio n. 1
0
 /**
  * @todo rename and document
  *
  * @param \Drupal\calendar\CalendarEvent $event
  * @return array
  */
 function explode_values($event)
 {
     $rows = [];
     $dateInfo = $this->dateArgument->view->dateInfo;
     //    $item_start_date = $event->date_start;
     //    $item_end_date = $event->date_end;
     //    $to_zone = $event->to_zone;
     //    $db_tz = $event->db_tz;
     //    $granularity = $event->granularity;
     //    $increment = $event->increment;
     // Now that we have an 'entity' for each view result, we need to remove
     // anything outside the view date range, and possibly create additional
     // nodes so that we have a 'node' for each day that this item occupies in
     // this view.
     // @TODO make this work with the CalendarDateInfo object
     //    $now = max($dateInfo->min_zone_string, $this->dateFormatter->format($event->getStartDate()->getTimestamp(), 'Y-m-d'));
     //    $to = min($dateInfo->max_zone_string, $this->dateFormatter->format($event->getEndDate()->getTimestamp(), 'Y-m-d'));
     $now = $event->getStartDate()->format('Y-m-d');
     $to = $event->getEndDate()->format('Y-m-d');
     $next = new \DateTime();
     $next->setTimestamp($event->getStartDate()->getTimestamp());
     if (timezone_name_get($this->dateArgument->view->dateInfo->getTimezone()) != $event->getTimezone()->getName()) {
         // Make $start and $end (derived from $node) use the timezone $to_zone,
         // just as the original dates do.
         $next->setTimezone($event->getTimezone());
     }
     if (empty($to) || $now > $to) {
         $to = $now;
     }
     // $now and $next are midnight (in display timezone) on the first day where node will occur.
     // $to is midnight on the last day where node will occur.
     // All three were limited by the min-max date range of the view.
     $position = 0;
     while (!empty($now) && $now <= $to) {
         /** @var $entity \Drupal\calendar\CalendarEvent */
         $entity = clone $event;
         // Get start and end of current day.
         $start = $this->dateFormatter->format($next->getTimestamp(), 'custom', 'Y-m-d H:i:s');
         $next->setTimestamp(strtotime(' +1 day -1 second', $next->getTimestamp()));
         $end = $this->dateFormatter->format($next->getTimestamp(), 'custom', 'Y-m-d H:i:s');
         // Get start and end of item, formatted the same way.
         $item_start = $this->dateFormatter->format($event->getStartDate()->getTimestamp(), 'custom', 'Y-m-d H:i:s');
         $item_end = $this->dateFormatter->format($event->getEndDate()->getTimestamp(), 'custom', 'Y-m-d H:i:s');
         // Get intersection of current day and the node value's duration (as
         // strings in $to_zone timezone).
         $start_string = $item_start < $start ? $start : $item_start;
         $entity->setStartDate(new \DateTime($start_string));
         $end_string = !empty($item_end) ? $item_end > $end ? $end : $item_end : NULL;
         $entity->setEndDate(new \DateTime($end_string));
         // @TODO don't hardcode granularity and increment
         $granularity = 'hour';
         $increment = 1;
         $entity->setAllDay(CalendarHelper::dateIsAllDay($entity->getStartDate()->format('Y-m-d H:i:s'), $entity->getEndDate()->format('Y-m-d H:i:s'), $granularity, $increment));
         $calendar_start = new \DateTime();
         $calendar_start->setTimestamp($entity->getStartDate()->getTimestamp());
         //      unset($entity->calendar_fields);
         if (isset($entity) && empty($calendar_start)) {
             // if no date for the node and no date in the item
             // there is no way to display it on the calendar
             unset($entity);
         } else {
             //        $entity->date_id .= '.' . $position;
             $rows[] = $entity;
             unset($entity);
         }
         $next->setTimestamp(strtotime('+1 second', $next->getTimestamp()));
         $now = $this->dateFormatter->format($next->getTimestamp(), 'Y-m-d');
         $position++;
     }
     return $rows;
 }