From c4aee5b9a8cd45bd4973637436e377a1caff4043 Mon Sep 17 00:00:00 2001 From: Trevor Simonton Date: Tue, 5 Feb 2013 11:55:34 -0700 Subject: [PATCH] Issue #1908018 by tmsimont: Break up calendar_style_plugin object into smaller functions and objects so its easier to extend and override to get new child class plugins --- includes/calendar_plugin_style.inc | 789 ++++++++++++++++++++---------------- 1 files changed, 445 insertions(+), 344 deletions(-) diff --git a/includes/calendar_plugin_style.inc b/includes/calendar_plugin_style.inc index 50d1bbf..0b87197 100644 --- a/includes/calendar_plugin_style.inc +++ b/includes/calendar_plugin_style.inc @@ -314,27 +314,8 @@ class calendar_plugin_style extends views_plugin_style { $this->items = $items; // Retrieve the results array using a the right method for the granularity of the display. - switch ($this->options['calendar_type']) { - case 'year': - $rows = array(); - $this->view->date_info->mini = TRUE; - for ($i = 1; $i <= 12; $i++) { - $rows[$i] = $this->calendar_build_mini_month(); - } - $this->view->date_info->mini = FALSE; - break; - case 'month': - $rows = !empty($this->date_info->mini) ? $this->calendar_build_mini_month() : $this->calendar_build_month(); - break; - case 'day': - $rows = $this->calendar_build_day(); - break; - case 'week': - $rows = $this->calendar_build_week(); - // Merge the day names in as the first row. - $rows = array_merge(array(calendar_week_header($this->view)), $rows); - break; - } + $builder = $this->get_builder(); + $rows = $builder->build_rows(); // Send the sorted rows to the right theme for this type of calendar. $this->definition['theme'] = 'calendar_' . $this->options['calendar_type']; @@ -359,263 +340,443 @@ class calendar_plugin_style extends views_plugin_style { unset($this->view->row_index); return $output; } + + function get_builder() { + $builder_type = 'calendar_builder_' . $this->options['calendar_type']; + return new $builder_type($this); + } +} + + +class calendar_builder { + public $plugin; + + public function __construct($plugin) { + $this->plugin = $plugin; + } + + public function build_rows() { + return array(); + } + + /** + * helper function to identify dates out of the current month but in the + * current rows of weeks being displayed + */ + public function in_another_month($curday_date, $month) { + $plugin = $this->plugin; + return $curday_date < $plugin->date_info->min_date_date || $curday_date > $plugin->date_info->max_date_date || date_format($plugin->curday, 'n') != $month; + } +} + + + +class calendar_builder_year extends calendar_builder{ + public function build_rows() { + $rows = array(); + $this->plugin->view->date_info->mini = TRUE; + for ($i = 1; $i <= 12; $i++) { + $rows[$i] = $this->calendar_build_mini_month(); + } + $this->plugin->view->date_info->mini = FALSE; + return $rows; + } + + /** + * Build one mini month. + */ + function calendar_build_mini_month() { + $month = date_format($this->plugin->curday, 'n'); + date_modify($this->plugin->curday, '-' . strval(date_format($this->plugin->curday, 'j')-1) . ' days'); + $rows = array(); + do { + $rows = array_merge($rows, $this->calendar_build_mini_week()); + $curday_date = date_format($this->plugin->curday, DATE_FORMAT_DATE); + $curday_month = date_format($this->plugin->curday, 'n'); + } while ($curday_month == $month && $curday_date <= $this->plugin->date_info->max_date_date); + // Merge the day names in as the first row. + $rows = array_merge(array(calendar_week_header($this->plugin->view)), $rows); + return $rows; + } + + /** + * Build one week row. + */ + function calendar_build_mini_week($check_month = TRUE) { + $plugin = $this->plugin; + $curday_date = date_format($plugin->curday, DATE_FORMAT_DATE); + $weekdays = calendar_untranslated_days($plugin->items, $plugin->view); + $today = date_format(date_now(date_default_timezone()), DATE_FORMAT_DATE); + $month = date_format($plugin->curday, 'n'); + $week = date_week($curday_date); + $first_day = variable_get('date_first_day', 0); + // move backwards to the first day of the week + $day_wday = date_format($plugin->curday, 'w'); + date_modify($plugin->curday, '-' . strval((7 + $day_wday - $first_day) % 7) . ' days'); + $curday_date = date_format($plugin->curday, DATE_FORMAT_DATE); + + for ($i = 0; $i < 7; $i++) { + $curday_date = date_format($plugin->curday, DATE_FORMAT_DATE); + $class = strtolower($weekdays[$i] . ' mini'); + if ($check_month && ($this->in_another_month($curday_date, $month))) { + $class .= ' empty'; + $variables = array( + 'curday' => $curday_date, + 'view' => $plugin->view, + ); + + $content = array( + 'date' => '', + 'datebox' => '', + 'empty' => theme('calendar_empty_day', $variables), + 'link' => '', + 'all_day' => array(), + 'items' => array(), + ); + } + else { + //use a day builder + $builder = new calendar_builder_day($this->plugin); + $content = $builder->calendar_build_day(); + $class .= ($curday_date == $today ? ' today' : '') . + ($curday_date < $today ? ' past' : '') . + ($curday_date > $today ? ' future' : '') . + (empty($plugin->items[$curday_date]) ? ' has-no-events' : ' has-events'); + } + $rows[$week][] = array( + 'data' => $content, + 'class' => $class, + 'id' => $plugin->view->name . '-' . $curday_date, + ); + date_modify($plugin->curday, '+1 day'); + } + return $rows; + } + +} + + +class calendar_builder_month extends calendar_builder { + public function build_rows() { + $rows = array(); + if (!empty($this->plugin->date_info->mini)) { + //use a year-builder to get the mini month + $year_builder = new calendar_builder_year($this->plugin); + $rows = $year_builder->calendar_build_mini_month(); + } else { + $rows = $this->calendar_build_month(); + } + return $rows; + } + + /** * Build one month. */ function calendar_build_month() { - $translated_days = date_week_days_ordered(date_week_days(TRUE)); - $month = date_format($this->curday, 'n'); - $curday_date = date_format($this->curday, DATE_FORMAT_DATE); - $weekdays = calendar_untranslated_days($this->items, $this->view); - date_modify($this->curday, '-' . strval(date_format($this->curday, 'j')-1) . ' days'); + $plugin = $this->plugin; + $month = date_format($plugin->curday, 'n'); + $curday_date = date_format($plugin->curday, DATE_FORMAT_DATE); + date_modify($plugin->curday, '-' . strval(date_format($plugin->curday, 'j')-1) . ' days'); $rows = array(); do { - $init_day = clone($this->curday); + $init_day = clone($plugin->curday); $today = date_format(date_now(date_default_timezone()), DATE_FORMAT_DATE); - $month = date_format($this->curday, 'n'); + $month = date_format($plugin->curday, 'n'); $week = date_week($curday_date); - $first_day = variable_get('date_first_day', 0); - $week_rows = $this->calendar_build_week(TRUE); - $multiday_buckets = $week_rows['multiday_buckets']; - $singleday_buckets = $week_rows['singleday_buckets']; - $total_rows = $week_rows['total_rows']; - - // Theme each row - $output = ""; - $final_day = clone($this->curday); - - $iehint = 0; - $max_multirow_cnt = 0; - $max_singlerow_cnt = 0; - - for ($i = 0; $i < intval($total_rows + 1); $i++) { - $inner = ""; - - // If we're displaying the week number, add it as the - // first cell in the week. - if ($i == 0 && !empty($this->date_info->style_with_weekno) && !in_array($this->date_info->granularity, array('day', 'week'))) { - $path = calendar_granularity_path($this->view, 'week'); - if (!empty($path)) { - $url = $path . '/' . $this->date_info->year . '-W' . $week; - $weekno = l($week, $url, array('query' => !empty($this->date_info->append) ? $this->date_info->append : '')); - } - else { - // Do not link week numbers, if Week views are disabled. - $weekno = $week; - } - $item = array( - 'entry' => $weekno, - 'colspan' => 1, - 'rowspan' => $total_rows + 1, - 'id' => $this->view->name . '-weekno-' . $curday_date, - 'class' => 'week', - ); - $inner .= theme('calendar_month_col', array('item' => $item)); - } + + //use a week builder to grab week buckets and total rows count + $week_builder = new calendar_builder_week($this->plugin); + $week_rows = $week_builder->calendar_build_week(TRUE); + $final_day = clone($plugin->curday); - $this->curday = clone($init_day); - - // move backwards to the first day of the week - $day_wday = date_format($this->curday, 'w'); - date_modify($this->curday, '-' . strval((7 + $day_wday - $first_day) % 7) . ' days'); - - for ( $wday = 0; $wday < 7; $wday++) { - - $curday_date = date_format($this->curday, DATE_FORMAT_DATE); - $class = strtolower($weekdays[$wday]); - $item = NULL; - $in_month = !($curday_date < $this->date_info->min_date_date || $curday_date > $this->date_info->max_date_date || date_format($this->curday, 'n') != $month); - - // Add the datebox - if ($i == 0) { - $variables = array( - 'date' => $curday_date, - 'view' => $this->view, - 'items' => $this->items, - 'selected' => $in_month ? count($multiday_buckets[$wday]) + count($singleday_buckets[$wday]) : FALSE, - ); - $item = array( - 'entry' => theme('calendar_datebox', $variables), - 'colspan' => 1, - 'rowspan' => 1, - 'class' => 'date-box', - 'date' => $curday_date, - 'id' => $this->view->name . '-' . $curday_date . '-date-box', - 'header_id' => $translated_days[$wday], - 'day_of_month' => $this->curday->format('j'), - ); - $item['class'] .= ($curday_date == $today && $in_month ? ' today' : '') . - ($curday_date < $today ? ' past' : '') . - ($curday_date > $today ? ' future' : ''); - } - else { - $index = $i - 1; - $multi_count = count($multiday_buckets[$wday]); - - // Process multiday buckets first. If there is a multiday-bucket item in this row... - if ($index < $multi_count) { - // If this item is filled with either a blank or an entry... - if ($multiday_buckets[$wday][$index]['filled']) { - - // Add item and add class - $item = $multiday_buckets[$wday][$index]; - $item['class'] = 'multi-day'; - $item['date'] = $curday_date; - - // Is this an entry? - if (!$multiday_buckets[$wday][$index]['avail']) { - - // If the item either starts or ends on today, - // then add tags so we can style the borders - if ($curday_date == $today && $in_month) { - $item['class'] .= ' starts-today'; - } + $output = $this->calendar_month_build_weeks($today, $month, $curday_date, $week, $week_rows, $init_day); - // Calculate on which day of this week this item ends on.. - $end_day = clone($this->curday); - $span = $item['colspan'] - 1; - date_modify($end_day, '+' . $span . ' day'); - $endday_date = date_format($end_day, DATE_FORMAT_DATE); + $plugin->curday = $final_day; - // If it ends today, add class - if ($endday_date == $today && $in_month) { - $item['class'] .= ' ends-today'; - } - } - } + // Add the row into the row array.... + $rows[] = array('data' => $output); + $curday_date = date_format($plugin->curday, DATE_FORMAT_DATE); + $curday_month = date_format($plugin->curday, 'n'); + } while ($curday_month == $month && $curday_date <= $plugin->date_info->max_date_date); + // Merge the day names in as the first row. + $rows = array_merge(array(calendar_week_header($plugin->view)), $rows); + return $rows; + } + + /** + * Build the week rows that are in a month + */ + function calendar_month_build_weeks($today, $month, $curday_date, $week, $week_rows, $init_day) { + $plugin = $this->plugin; + $first_day = variable_get('date_first_day', 0); + $output = ""; + + $multiday_buckets = $week_rows['multiday_buckets']; + $singleday_buckets = $week_rows['singleday_buckets']; + $total_rows = $week_rows['total_rows']; + + $iehint = 0; + $max_multirow_cnt = 0; + $max_singlerow_cnt = 0; + + for ($week_idx = 0; $week_idx < intval($total_rows + 1); $week_idx++) { + $inner = ""; + + // If we're displaying the week number, add it as the + // first cell in the week. + if ($week_idx == 0 && !empty($plugin->date_info->style_with_weekno) && !in_array($plugin->date_info->granularity, array('day', 'week'))) { + $inner .= $this->calendar_month_show_week_number($week, $total_rows, $curday_date); + } - // If this is an actual entry, add classes regarding the state of the - // item - if ($multiday_buckets[$wday][$index]['avail']) { - $item['class'] .= ' ' . $wday . ' ' . $index . ' no-entry ' . ($curday_date == $today && $in_month ? ' today' : '') . - ($curday_date < $today ? ' past' : '') . - ($curday_date > $today ? ' future' : ''); - } + $plugin->curday = clone($init_day); - // Else, process the single day bucket - we only do this once per day - } - elseif ($index == $multi_count) { - $single_day_cnt = 0; - // If it's empty, add class - if (count($singleday_buckets[$wday]) == 0) { - $single_days = " "; - if ($max_multirow_cnt == 0 ) { - $class = ($multi_count > 0 ) ? 'single-day no-entry noentry-multi-day' : 'single-day no-entry'; - } - else { - $class = 'single-day'; - } - } - else { - $single_days = ""; - foreach ($singleday_buckets[$wday] as $day) { - foreach ($day as $event) { - $single_day_cnt++; - $single_days .= (isset($event['more_link'])) ? '
' . $event['entry'] . '
' : $event['entry']; - } - } - $class = 'single-day'; - } + // move backwards to the first day of the week + $day_wday = date_format($plugin->curday, 'w'); + date_modify($plugin->curday, '-' . strval((7 + $day_wday - $first_day) % 7) . ' days'); - $rowspan = $total_rows - $index; - // Add item... - $item = array( - 'entry' => $single_days, - 'colspan' => 1, - 'rowspan' => $rowspan, - 'class' => $class, - 'date' => $curday_date, - 'id' => $this->view->name . '-' . $curday_date . '-' . $index, - 'header_id' => $translated_days[$wday], - 'day_of_month' => $this->curday->format('j'), - ); - - // Hack for ie to help it properly space single day rows - if ($rowspan > 1 && $in_month && $single_day_cnt > 0) { - $max_multirow_cnt = max($max_multirow_cnt, $single_day_cnt); - } - else { - $max_singlerow_cnt = max($max_singlerow_cnt, $single_day_cnt); - } + $inner .= $this->calendar_month_build_week($week_idx, $week_rows, $max_singlerow_cnt, $max_multirow_cnt); + + if ($week_idx == 0) { + $output .= theme('calendar_month_row', array( + 'inner' => $inner, + 'class' => 'date-box', + 'iehint' => $iehint, + )); + } + elseif ($week_idx == $total_rows) { + $output .= theme('calendar_month_row', array( + 'inner' => $inner, + 'class' => 'single-day', + 'iehint' => $iehint, + )); + $iehint = 0; + $max_singlerow_cnt = 0; + $max_multirow_cnt = 0; + } + else { + // Style all the columns into a row + $output .= theme('calendar_month_row', array( + 'inner' => $inner, + 'class' => 'multi-day', + 'iehint' => 0, + )); + } - // If the singlerow is bigger than the multi-row, then null out - // ieheight - I'm estimating that a single row is twice the size of - // multi-row. This is really the best that can be done with ie - if ($max_singlerow_cnt >= $max_multirow_cnt || $max_multirow_cnt <= $multi_count / 2 ) { - $iehint = 0; - } - elseif ($rowspan > 1 && $in_month && $single_day_cnt > 0) { - $iehint = max($iehint, $rowspan - 1); // How many rows to adjust for? + } // End foreach + return $output; + } + + /** + * Build the week number column for a week in a month + */ + function calendar_month_show_week_number($week, $total_rows, $curday_date) { + $plugin = $this->plugin; + $path = calendar_granularity_path($plugin->view, 'week'); + if (!empty($path)) { + $url = $path . '/' . $plugin->date_info->year . '-W' . $week; + $weekno = l($week, $url, array('query' => !empty($plugin->date_info->append) ? $plugin->date_info->append : '')); + } + else { + // Do not link week numbers, if Week views are disabled. + $weekno = $week; + } + $item = array( + 'entry' => $weekno, + 'colspan' => 1, + 'rowspan' => $total_rows + 1, + 'id' => $plugin->view->name . '-weekno-' . $curday_date, + 'class' => 'week', + ); + return theme('calendar_month_col', array('item' => $item)); + } + + /** + * Build one of numerous weeks week in a month + */ + function calendar_month_build_week($week_idx, $week_rows, &$max_singlerow_cnt, &$max_multirow_cnt) { + $plugin = $this->plugin; + $inner = ""; + $translated_days = date_week_days_ordered(date_week_days(TRUE)); + $multiday_buckets = $week_rows['multiday_buckets']; + $singleday_buckets = $week_rows['singleday_buckets']; + $total_rows = $week_rows['total_rows']; + $weekdays = calendar_untranslated_days($plugin->items, $plugin->view); + + for ( $wday = 0; $wday < 7; $wday++) { + $today = date_format(date_now(date_default_timezone()), DATE_FORMAT_DATE); + $month = date_format($plugin->curday, 'n'); + $curday_date = date_format($plugin->curday, DATE_FORMAT_DATE); + $class = strtolower($weekdays[$wday]); + $item = NULL; + $in_month = !($this->in_another_month($curday_date, $month)); + + // Add the datebox + if ($week_idx == 0) { + $variables = array( + 'date' => $curday_date, + 'view' => $plugin->view, + 'items' => $plugin->items, + 'selected' => $in_month ? count($multiday_buckets[$wday]) + count($singleday_buckets[$wday]) : FALSE, + ); + $item = array( + 'entry' => theme('calendar_datebox', $variables), + 'colspan' => 1, + 'rowspan' => 1, + 'class' => 'date-box', + 'date' => $curday_date, + 'id' => $plugin->view->name . '-' . $curday_date . '-date-box', + 'header_id' => $translated_days[$wday], + 'day_of_month' => $plugin->curday->format('j'), + ); + $item['class'] .= ($curday_date == $today && $in_month ? ' today' : '') . + ($curday_date < $today ? ' past' : '') . + ($curday_date > $today ? ' future' : ''); + } + else { + $index = $week_idx - 1; + $multi_count = count($multiday_buckets[$wday]); + + // Process multiday buckets first. If there is a multiday-bucket item in this row... + if ($index < $multi_count) { + // If this item is filled with either a blank or an entry... + if ($multiday_buckets[$wday][$index]['filled']) { + + // Add item and add class + $item = $multiday_buckets[$wday][$index]; + $item['class'] = 'multi-day'; + $item['date'] = $curday_date; + + // Is this an entry? + if (!$multiday_buckets[$wday][$index]['avail']) { + + // If the item either starts or ends on today, + // then add tags so we can style the borders + if ($curday_date == $today && $in_month) { + $item['class'] .= ' starts-today'; } - // Set the class - $item['class'] .= ($curday_date == $today && $in_month ? ' today' : '') . - ($curday_date < $today ? ' past' : '') . - ($curday_date > $today ? ' future' : ''); + // Calculate on which day of this week this item ends on.. + $end_day = clone($plugin->curday); + $span = $item['colspan'] - 1; + date_modify($end_day, '+' . $span . ' day'); + $endday_date = date_format($end_day, DATE_FORMAT_DATE); + + // If it ends today, add class + if ($endday_date == $today && $in_month) { + $item['class'] .= ' ends-today'; + } } } - // If there isn't an item, then add empty class - if ($item != NULL) { - if (!$in_month) { - $item['class'] .= ' empty'; - } - // Style this entry - it will be a . - $inner .= theme('calendar_month_col', array('item' => $item)); + // If this is an actual entry, add classes regarding the state of the + // item + if ($multiday_buckets[$wday][$index]['avail']) { + $item['class'] .= ' ' . $wday . ' ' . $index . ' no-entry ' . ($curday_date == $today && $in_month ? ' today' : '') . + ($curday_date < $today ? ' past' : '') . + ($curday_date > $today ? ' future' : ''); } - date_modify($this->curday, '+1 day'); + // Else, process the single day bucket - we only do this once per day } + elseif ($index == $multi_count) { + $single_day_cnt = 0; + // If it's empty, add class + if (count($singleday_buckets[$wday]) == 0) { + $single_days = " "; + if ($max_multirow_cnt == 0 ) { + $class = ($multi_count > 0 ) ? 'single-day no-entry noentry-multi-day' : 'single-day no-entry'; + } + else { + $class = 'single-day'; + } + } + else { + $single_days = ""; + foreach ($singleday_buckets[$wday] as $day) { + foreach ($day as $event) { + $single_day_cnt++; + $single_days .= (isset($event['more_link'])) ? '
' . $event['entry'] . '
' : $event['entry']; + } + } + $class = 'single-day'; + } - if ($i == 0) { - $output .= theme('calendar_month_row', array( - 'inner' => $inner, - 'class' => 'date-box', - 'iehint' => $iehint, - )); - } - elseif ($i == $total_rows) { - $output .= theme('calendar_month_row', array( - 'inner' => $inner, - 'class' => 'single-day', - 'iehint' => $iehint, - )); - $iehint = 0; - $max_singlerow_cnt = 0; - $max_multirow_cnt = 0; - } - else { - // Style all the columns into a row - $output .= theme('calendar_month_row', array( - 'inner' => $inner, - 'class' => 'multi-day', - 'iehint' => 0, - )); + $rowspan = $total_rows - $index; + // Add item... + $item = array( + 'entry' => $single_days, + 'colspan' => 1, + 'rowspan' => $rowspan, + 'class' => $class, + 'date' => $curday_date, + 'id' => $plugin->view->name . '-' . $curday_date . '-' . $index, + 'header_id' => $translated_days[$wday], + 'day_of_month' => $plugin->curday->format('j'), + ); + + // Hack for ie to help it properly space single day rows + if ($rowspan > 1 && $in_month && $single_day_cnt > 0) { + $max_multirow_cnt = max($max_multirow_cnt, $single_day_cnt); + } + else { + $max_singlerow_cnt = max($max_singlerow_cnt, $single_day_cnt); + } + + // If the singlerow is bigger than the multi-row, then null out + // ieheight - I'm estimating that a single row is twice the size of + // multi-row. This is really the best that can be done with ie + if ($max_singlerow_cnt >= $max_multirow_cnt || $max_multirow_cnt <= $multi_count / 2 ) { + $iehint = 0; + } + elseif ($rowspan > 1 && $in_month && $single_day_cnt > 0) { + $iehint = max($iehint, $rowspan - 1); // How many rows to adjust for? + } + + // Set the class + $item['class'] .= ($curday_date == $today && $in_month ? ' today' : '') . + ($curday_date < $today ? ' past' : '') . + ($curday_date > $today ? ' future' : ''); } + } - } // End foreach + // If there isn't an item, then add empty class + if ($item != NULL) { + if (!$in_month) { + $item['class'] .= ' empty'; + } + // Style this entry - it will be a . + $inner .= theme('calendar_month_col', array('item' => $item)); + } + + date_modify($plugin->curday, '+1 day'); + } + + return $inner; + } +} - $this->curday = $final_day; - // Add the row into the row array.... - $rows[] = array('data' => $output); - $curday_date = date_format($this->curday, DATE_FORMAT_DATE); - $curday_month = date_format($this->curday, 'n'); - } while ($curday_month == $month && $curday_date <= $this->date_info->max_date_date); +class calendar_builder_week extends calendar_builder { + public function build_rows() { + $rows = array(); + $rows = $this->calendar_build_week(); // Merge the day names in as the first row. - $rows = array_merge(array(calendar_week_header($this->view)), $rows); + $rows = array_merge(array(calendar_week_header($this->plugin->view)), $rows); return $rows; } + /** * Build one week row. */ function calendar_build_week($check_month = FALSE) { - $curday_date = date_format($this->curday, DATE_FORMAT_DATE); - $weekdays = calendar_untranslated_days($this->items, $this->view); - $month = date_format($this->curday, 'n'); + $plugin = $this->plugin; + $curday_date = date_format($plugin->curday, DATE_FORMAT_DATE); + $weekdays = calendar_untranslated_days($plugin->items, $plugin->view); + $month = date_format($plugin->curday, 'n'); $first_day = variable_get('date_first_day', 0); // Set up buckets @@ -624,17 +785,17 @@ class calendar_plugin_style extends views_plugin_style { $singleday_buckets = array( array(), array(), array(), array(), array(), array(), array()); // move backwards to the first day of the week - $day_wday = date_format($this->curday, 'w'); - date_modify($this->curday, '-' . strval((7 + $day_wday - $first_day) % 7) . ' days'); - $curday_date = date_format($this->curday, DATE_FORMAT_DATE); + $day_wday = date_format($plugin->curday, 'w'); + date_modify($plugin->curday, '-' . strval((7 + $day_wday - $first_day) % 7) . ' days'); + $curday_date = date_format($plugin->curday, DATE_FORMAT_DATE); for ($i = 0; $i < 7; $i++) { - if ($check_month && ($curday_date < $this->date_info->min_date_date || $curday_date > $this->date_info->max_date_date || date_format($this->curday, 'n') != $month)) { + if ($check_month && ($this->in_another_month($curday_date, $month))) { $class = strtolower($weekdays[$i]) . ' empty'; $singleday_buckets[$i][][] = array( 'entry' => theme('calendar_empty_day', array( 'curday' => $curday_date, - 'view' => $this->view, + 'view' => $plugin->view, )), 'item' => NULL ); @@ -643,8 +804,8 @@ class calendar_plugin_style extends views_plugin_style { $this->calendar_build_week_day($i, $multiday_buckets, $singleday_buckets); } $total_rows = max(count($multiday_buckets[$i]) + 1, $total_rows); - date_modify($this->curday, '+1 day'); - $curday_date = date_format($this->curday, DATE_FORMAT_DATE); + date_modify($plugin->curday, '+1 day'); + $curday_date = date_format($plugin->curday, DATE_FORMAT_DATE); } $rows = array( @@ -658,10 +819,11 @@ class calendar_plugin_style extends views_plugin_style { * Build the contents of a single day for the $rows results. */ function calendar_build_week_day($wday, &$multiday_buckets, &$singleday_buckets) { - $curday_date = date_format($this->curday, DATE_FORMAT_DATE); - $max_events = $this->date_info->calendar_type == 'month' && !empty($this->date_info->style_max_items) ? $this->date_info->style_max_items : 0; - $hide = !empty($this->date_info->style_max_items_behavior) ? ($this->date_info->style_max_items_behavior == 'hide') : FALSE; - $multiday_theme = !empty($this->date_info->style_multiday_theme) && $this->date_info->style_multiday_theme == '1'; + $plugin = $this->plugin; + $curday_date = date_format($plugin->curday, DATE_FORMAT_DATE); + $max_events = $plugin->date_info->calendar_type == 'month' && !empty($plugin->date_info->style_max_items) ? $plugin->date_info->style_max_items : 0; + $hide = !empty($plugin->date_info->style_max_items_behavior) ? ($plugin->date_info->style_max_items_behavior == 'hide') : FALSE; + $multiday_theme = !empty($plugin->date_info->style_multiday_theme) && $plugin->date_info->style_multiday_theme == '1'; $first_day = variable_get('date_first_day', 0); $cur_cnt = 0; $total_cnt = 0; @@ -669,7 +831,7 @@ class calendar_plugin_style extends views_plugin_style { // If we are hiding, count before processing further if ($max_events != CALENDAR_SHOW_ALL) { - foreach ($this->items as $date => $day) { + foreach ($plugin->items as $date => $day) { if ($date == $curday_date) { foreach ($day as $time => $hour) { foreach ($hour as $key => $item) { @@ -689,7 +851,7 @@ class calendar_plugin_style extends views_plugin_style { $cur_cnt++; } } - foreach ($this->items as $date => $day) { + foreach ($plugin->items as $date => $day) { if ($date == $curday_date) { ksort($day); foreach ($day as $time => $hour) { @@ -699,7 +861,7 @@ class calendar_plugin_style extends views_plugin_style { // Parse out date part $start_ydate = date_format($item->date_start, DATE_FORMAT_DATE); $end_ydate = date_format($item->date_end, DATE_FORMAT_DATE); - $cur_ydate = date_format($this->curday, DATE_FORMAT_DATE); + $cur_ydate = date_format($plugin->curday, DATE_FORMAT_DATE); $is_multi_day = ($start_ydate < $cur_ydate || $end_ydate > $cur_ydate); @@ -711,16 +873,16 @@ class calendar_plugin_style extends views_plugin_style { // If this the first day of the week, or is the start date of the multi-day event, // then record this item, otherwise skip over - $day_no = date_format($this->curday, 'd'); - if ($wday == 0 || $start_ydate == $cur_ydate || ($this->date_info->granularity == 'month' && $day_no == 1) || ($all_day && !$is_multi_day)) { + $day_no = date_format($plugin->curday, 'd'); + if ($wday == 0 || $start_ydate == $cur_ydate || ($plugin->date_info->granularity == 'month' && $day_no == 1) || ($all_day && !$is_multi_day)) { // Calculate the colspan for this event // If the last day of this event exceeds the end of the current month or week, // truncate the remaining days - $diff = $this->curday->difference($this->date_info->max_date, 'days'); - $remaining_days = ($this->date_info->granularity == 'month') ? min(6 - $wday, $diff) : $diff - 1; + $diff = $plugin->curday->difference($plugin->date_info->max_date, 'days'); + $remaining_days = ($plugin->date_info->granularity == 'month') ? min(6 - $wday, $diff) : $diff - 1; // The bucket_cnt defines the colspan. colspan = bucket_cnt + 1 - $days = $this->curday->difference($item->date_end, 'days'); + $days = $plugin->curday->difference($item->date_end, 'days'); $bucket_cnt = max(0, min($days, $remaining_days)); // See if there is an available slot to add an event. This will allow @@ -735,7 +897,7 @@ class calendar_plugin_style extends views_plugin_style { } // Add continuation attributes - $item->continuation = ($item->date_start < $this->curday); + $item->continuation = ($item->date_start < $plugin->curday); $item->continues = ( $days > $bucket_cnt ); $item->is_multi_day = TRUE; @@ -748,7 +910,7 @@ class calendar_plugin_style extends views_plugin_style { 'all_day' => $all_day, 'item' => $item, 'wday' => $wday, - 'entry' => theme('calendar_item', array('view' => $this->view, 'rendered_fields' => $item->rendered_fields, 'item' => $item)), + 'entry' => theme('calendar_item', array('view' => $plugin->view, 'rendered_fields' => $item->rendered_fields, 'item' => $item)), ); // Block out empty buckets for the next days in this event for this week @@ -781,7 +943,7 @@ class calendar_plugin_style extends views_plugin_style { $cur_cnt++; // Assign to single day bucket $singleday_buckets[$wday][$time][] = array( - 'entry' => theme('calendar_item', array('view' => $this->view, 'rendered_fields' => $item->rendered_fields, 'item' => $item)), + 'entry' => theme('calendar_item', array('view' => $plugin->view, 'rendered_fields' => $item->rendered_fields, 'item' => $item)), 'item' => $item, 'colspan' => 1, 'rowspan' => 1, @@ -799,10 +961,10 @@ class calendar_plugin_style extends views_plugin_style { // Add a more link if necessary if ($max_events != CALENDAR_SHOW_ALL && $total_cnt > 0 && $cur_cnt < $total_cnt) { - $entry = theme('calendar_' . $this->date_info->calendar_type . '_multiple_entity', array( + $entry = theme('calendar_' . $plugin->date_info->calendar_type . '_multiple_entity', array( 'curday' => $curday_date, 'count' => $total_cnt, - 'view' => $this->view, + 'view' => $plugin->view, 'ids' => $ids, )); if (!empty($entry)) { @@ -814,21 +976,29 @@ class calendar_plugin_style extends views_plugin_style { } } } +} + + +class calendar_builder_day extends calendar_builder { + public function build_rows() { + return $this->calendar_build_day(); + } /** * Build the contents of a single day for the $rows results. */ function calendar_build_day() { - $curday_date = date_format($this->curday, DATE_FORMAT_DATE); + $plugin = $this->plugin; + $curday_date = date_format($plugin->curday, DATE_FORMAT_DATE); $selected = FALSE; - $max_events = !empty($this->date_info->style_max_items) ? $this->date_info->style_max_items : 0; + $max_events = !empty($plugin->date_info->style_max_items) ? $plugin->date_info->style_max_items : 0; $ids = array(); $inner = array(); $all_day = array(); $empty = ''; $link = ''; $count = 0; - foreach ($this->items as $date => $day) { + foreach ($plugin->items as $date => $day) { if ($date == $curday_date) { $count = 0; $selected = TRUE; @@ -839,7 +1009,7 @@ class calendar_plugin_style extends views_plugin_style { if (isset($item->type)) { $ids[$item->type] = $item; } - if (empty($this->date_info->mini) && ($max_events == CALENDAR_SHOW_ALL || $count <= $max_events || ($count > 0 && $max_events == CALENDAR_HIDE_ALL))) { + if (empty($plugin->date_info->mini) && ($max_events == CALENDAR_SHOW_ALL || $count <= $max_events || ($count > 0 && $max_events == CALENDAR_HIDE_ALL))) { if ($item->calendar_all_day) { $item->is_multi_day = TRUE; $all_day[] = $item; @@ -856,18 +1026,18 @@ class calendar_plugin_style extends views_plugin_style { ksort($inner); if (empty($inner) && empty($all_day)) { - $empty = theme('calendar_empty_day', array('curday' => $curday_date, 'view' => $this->view)); + $empty = theme('calendar_empty_day', array('curday' => $curday_date, 'view' => $plugin->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->date_info->calendar_type != 'day' && !$this->date_info->mini) { - if ($this->date_info->style_max_items_behavior == 'hide' || $max_events == CALENDAR_HIDE_ALL) { + if ($max_events != CALENDAR_SHOW_ALL && $count > 0 && $count > $max_events && $plugin->date_info->calendar_type != 'day' && !$plugin->date_info->mini) { + if ($plugin->date_info->style_max_items_behavior == 'hide' || $max_events == CALENDAR_HIDE_ALL) { $all_day = array(); $inner = array(); } - $link = theme('calendar_' . $this->date_info->calendar_type . '_multiple_node', array( + $link = theme('calendar_' . $plugin->date_info->calendar_type . '_multiple_node', array( 'curday' => $curday_date, 'count' => $count, - 'view' => $this->view, + 'view' => $plugin->view, 'ids' => $ids, )); } @@ -876,8 +1046,8 @@ class calendar_plugin_style extends views_plugin_style { 'date' => $curday_date, 'datebox' => theme('calendar_datebox', array( 'date' => $curday_date, - 'view' => $this->view, - 'items' => $this->items, + 'view' => $plugin->view, + 'items' => $plugin->items, 'selected' => $selected, )), 'empty' => $empty, @@ -887,73 +1057,4 @@ class calendar_plugin_style extends views_plugin_style { ); return $content; } - - /** - * Build one mini month. - */ - function calendar_build_mini_month() { - $month = date_format($this->curday, 'n'); - date_modify($this->curday, '-' . strval(date_format($this->curday, 'j')-1) . ' days'); - $rows = array(); - do { - $rows = array_merge($rows, $this->calendar_build_mini_week()); - $curday_date = date_format($this->curday, DATE_FORMAT_DATE); - $curday_month = date_format($this->curday, 'n'); - } while ($curday_month == $month && $curday_date <= $this->date_info->max_date_date); - // Merge the day names in as the first row. - $rows = array_merge(array(calendar_week_header($this->view)), $rows); - return $rows; - } - - /** - * Build one week row. - */ - function calendar_build_mini_week($check_month = TRUE) { - $curday_date = date_format($this->curday, DATE_FORMAT_DATE); - $weekdays = calendar_untranslated_days($this->items, $this->view); - $today = date_format(date_now(date_default_timezone()), DATE_FORMAT_DATE); - $month = date_format($this->curday, 'n'); - $week = date_week($curday_date); - $first_day = variable_get('date_first_day', 0); - // move backwards to the first day of the week - $day_wday = date_format($this->curday, 'w'); - date_modify($this->curday, '-' . strval((7 + $day_wday - $first_day) % 7) . ' days'); - $curday_date = date_format($this->curday, DATE_FORMAT_DATE); - - for ($i = 0; $i < 7; $i++) { - $curday_date = date_format($this->curday, DATE_FORMAT_DATE); - $class = strtolower($weekdays[$i] . ' mini'); - if ($check_month && ($curday_date < $this->date_info->min_date_date || $curday_date > $this->date_info->max_date_date || date_format($this->curday, 'n') != $month)) { - $class .= ' empty'; - $variables = array( - 'curday' => $curday_date, - 'view' => $this->view, - ); - - $content = array( - 'date' => '', - 'datebox' => '', - 'empty' => theme('calendar_empty_day', $variables), - 'link' => '', - 'all_day' => array(), - 'items' => array(), - ); - } - else { - $content = $this->calendar_build_day(); - $class .= ($curday_date == $today ? ' today' : '') . - ($curday_date < $today ? ' past' : '') . - ($curday_date > $today ? ' future' : '') . - (empty($this->items[$curday_date]) ? ' has-no-events' : ' has-events'); - } - $rows[$week][] = array( - 'data' => $content, - 'class' => $class, - 'id' => $this->view->name . '-' . $curday_date, - ); - date_modify($this->curday, '+1 day'); - } - return $rows; - } - } \ No newline at end of file -- 1.7.4.msysgit.0