Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 public function blockForm($form, FormStateInterface $form_state)
 {
     $options = CalendarHelper::listCalendarViews();
     $config = $this->getConfiguration();
     $form['calendar_legend_view'] = ['#type' => 'select', '#title' => $this->t('Legend View'), '#description' => $this->t('Choose the view display that contains the settings for the stripes that should be displayed in a legend in this block. Note that if you change the stripe values in that view you will need to clear the cache to pick up the new values in this block.'), '#default_value' => isset($config['calendar_legend_view_settings_view']) ? $config['calendar_legend_view_settings_view'] : '', '#options' => $options];
     return $form;
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 public function render($empty = FALSE)
 {
     if (!$empty || !empty($this->options['empty'])) {
         $argument = CalendarHelper::getDateArgumentHandler($this->view);
         $render = [];
         $header_text = $this->renderTextField($this->options['content']);
         if (!$this->options['pager_embed']) {
             $render = array('#theme' => 'calendar_header', '#title' => $header_text, '#empty' => $empty, '#granularity' => $argument->getGranularity());
         } else {
             if ($this->view->display_handler->renderPager()) {
                 $exposed_input = isset($this->view->exposed_raw_input) ? $this->view->exposed_raw_input : NULL;
                 $render = $this->view->renderPager($exposed_input);
                 // Override the exclude option of the pager.
                 $render['#exclude'] = FALSE;
                 $render['#items']['current'] = $header_text;
             }
         }
         return $render;
     }
     return array();
 }
Esempio n. 3
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;
 }
Esempio n. 4
0
 /**
  * Get select options for Views displays that support Calendar with set granularity.
  *
  * @param $granularity
  *
  * @return array
  */
 protected function viewOptionsForGranularity($granularity)
 {
     $options = [];
     $view_displays = Views::getApplicableViews('uses_route');
     foreach ($view_displays as $view_display) {
         list($view_id, $display_id) = $view_display;
         $view = View::load($view_id);
         $view_exec = $view->getExecutable();
         if ($argument = CalendarHelper::getDateArgumentHandler($view_exec, $display_id)) {
             if ($argument->getGranularity() == $granularity) {
                 $route_name = CalendarHelper::getDisplayRouteName($view_id, $display_id);
                 $options[$route_name] = $view->label() . ' : ' . $view_exec->displayHandlers->get($display_id)->display['display_title'];
             }
         }
     }
     return $options;
 }
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL)
 {
     parent::init($view, $display, $options);
     $this->argument = CalendarHelper::getDateArgumentHandler($this->view);
 }