From d12eba903dbcd0dbb9f8b992e378b0922e56411f Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Wed, 26 Jul 2017 20:03:36 +0200 Subject: [PATCH] Using last version available in -dev --- sites/all/modules/calendar/theme/theme.inc | 135 +++++++++++---------- 1 file changed, 72 insertions(+), 63 deletions(-) diff --git a/sites/all/modules/calendar/theme/theme.inc b/sites/all/modules/calendar/theme/theme.inc index c89a0c0..3bcd94f 100644 --- a/sites/all/modules/calendar/theme/theme.inc +++ b/sites/all/modules/calendar/theme/theme.inc @@ -15,12 +15,12 @@ function template_preprocess_calendar_main(&$vars) { $vars['min_date_formatted'] = !empty($view->date_info->min_date) ? date_format($view->date_info->min_date, DATE_FORMAT_DATETIME) : ''; $vars['max_date_formatted'] = !empty($view->date_info->end_date) ? date_format($view->date_info->max_date, DATE_FORMAT_DATETIME) : ''; $view->date_info->mini = isset($view->date_info->mini) ? $view->date_info->mini : $view->date_info->granularity == 'year'; - + $url = $view->get_url(); $view->date_info->url = $url; $arg = $view->date_info->date_arg; $displays = $view->date_info->display_types; - + // Set up the links to other calendar views. $current_date = $view->date_info->min_date; if (!empty($date->info->day)) { @@ -36,6 +36,9 @@ function template_preprocess_calendar_main(&$vars) { else { $current_date = date_make_date($view->date_info->year .'-01-01 00:00:00'); } + $ww = date_day_of_week($vars['min_date_formatted'], DATE_ISO); + $ww = variable_get('date_first_day', 1) ? ($ww == 0 ? 6 : $ww - 1) : $ww; + $week_date = date('Y-m-d', strtotime("-$ww days", strtotime($vars['min_date_formatted']))); if (empty($view->date_info->month) || $view->date_info->month == $view->argument['date_argument']->options['wildcard']) { $view->date_info->month = date_format($current_date, 'm'); } @@ -43,9 +46,10 @@ function template_preprocess_calendar_main(&$vars) { $view->date_info->day = date_format($current_date, 'd'); } if (empty($view->date_info->week) || $view->date_info->week == $view->argument['date_argument']->options['wildcard']) { - $view->date_info->week = date_week($view->date_info->year .'-'. date_pad($view->date_info->month) .'-'. date_pad($view->date_info->day)); + $view->date_info->week = date_week(date_pad(date_part_extract($week_date, 'year'), 4) .'-'. date_part_extract($week_date, 'month') .'-'. date_part_extract($week_date, 'day')); +# $view->date_info->week = date_week($view->date_info->year .'-'. date_pad($view->date_info->month) .'-'. date_pad($view->date_info->day)); } - + $calendar_links = array(); $base = array('attributes' => array('rel' => 'nofollow')); if (!empty($displays['year'])) { @@ -55,18 +59,21 @@ function template_preprocess_calendar_main(&$vars) { $calendar_links['calendar calendar-month'] = $base + array('title' => date_t('Month', 'datetime'), 'href' => date_real_url($view, 'month')); } if (!empty($displays['week'])) { + $wy = $view->date_info->year; + $view->date_info->year = date_pad(date_part_extract($week_date, 'year'), 4); $calendar_links['calendar calendar-week'] = $base + array('title' => date_t('Week', 'datetime'), 'href' => date_real_url($view, 'week')); + $view->date_info->year = $wy; } if (!empty($displays['day'])) { $calendar_links['calendar calendar-day'] = $base + array('title' => date_t('Day', 'datetime'), 'href' => date_real_url($view, 'day')); } $vars['calendar_links'] = $calendar_links; - + // If the Date Popup module is enabled, add a popup date selector. if (!empty($view->date_info->calendar_popup)) { $vars['calendar_popup'] = '
'. calendar_date_select($view) .'
'; } - + // If an 'Add new ... link is provided, add it here. // the query will bring the user back here after adding the node. if (!empty($view->date_info->calendar_date_link) @@ -80,12 +87,12 @@ function template_preprocess_calendar_main(&$vars) { 'query' => $query, ); } - + $vars['view'] = $view; $vars['mini'] = !empty($view->date_info->mini); $vars['block'] = !empty($view->date_info->block); $vars['block_identifier'] = date_block_identifier($view); - + } /** @@ -102,26 +109,26 @@ function template_preprocess_calendar(&$vars) { if (!empty($view->date_info->calendar_processed)) { return; } - + $result = (array) $view->result; $options = $view->style_plugin->options; $handler = $view->style_plugin; $fields = $view->field; - + // Render each field into an output array. We have to do the rendering // here because we don't apppear to have full access to the view // handlers in the theme functions. $items = array(); $calendar_fields = date_api_fields($view->base_table); $calendar_fields = array_keys($calendar_fields['alias']); - + foreach ($result as $num => $row) { $copy = drupal_clone($row); $items[$num] = $row; $items[$num]->raw = $copy; $items[$num]->calendar_fields = new stdClass(); - + foreach ($row as $key => $value) { if (in_array($key, $calendar_fields)) { $items[$num]->calendar_fields->$key = $value; @@ -140,14 +147,14 @@ function template_preprocess_calendar(&$vars) { } } } - + $vars['display_type'] = $view->date_info->granularity; $vars['min_date_formatted'] = date_format($view->date_info->min_date, DATE_FORMAT_DATETIME); $vars['max_date_formatted'] = date_format($view->date_info->max_date, DATE_FORMAT_DATETIME); - + // Massage the resulting items into formatted calendar items. $items = calendar_build_nodes($view, $items); - + // Merge in items from other sources. foreach (module_implements('calendar_add_items') as $module) { $function = $module .'_calendar_add_items'; @@ -161,13 +168,13 @@ function template_preprocess_calendar(&$vars) { } $view->date_info->mini = isset($view->date_info->mini) ? $view->date_info->mini : $view->date_info->granularity == 'year'; - + // Create the calendar day names and rows. $rows = calendar_build_calendar($view, $items); - + $vars['items'] = $items; $vars['rows'] = $rows; - + $view->date_info->calendar_processed = TRUE; $vars['view'] = $view; $vars['mini'] = !empty($view->date_info->mini); @@ -181,9 +188,9 @@ function template_preprocess_calendar_month(&$vars) { // Add in all the $vars added by the main calendar preprocessor. template_preprocess_calendar($vars); $view = $vars['view']; - + $rows = $vars['rows']; - + if (sizeof($rows) > 1) { $day_names = array_shift($rows); } @@ -191,12 +198,12 @@ function template_preprocess_calendar_month(&$vars) { $day_names = $rows; $rows = array(); } - + $month_rows = $rows; foreach ($rows as $weekno => $row) { foreach ($row as $day => $data) { $cell = $data['data']; - + // If this cell is already rendered, like the weekno column, // move to the next item. if (!is_array($cell)) { @@ -222,10 +229,10 @@ function template_preprocess_calendar_month(&$vars) { } } } - + $vars['rows'] = $month_rows; $vars['day_names'] = $day_names; - + $vars['display_type'] = $view->date_info->granularity; $vars['min_date_formatted'] = date_format($view->date_info->min_date, DATE_FORMAT_DATETIME); $vars['max_date_formatted'] = date_format($view->date_info->max_date, DATE_FORMAT_DATETIME); @@ -237,7 +244,7 @@ function template_preprocess_calendar_month(&$vars) { function template_preprocess_calendar_mini(&$vars) { // Add in all the $vars added by the main calendar preprocessor. template_preprocess_calendar_month($vars); - + $view = $vars['view']; $view->date_info->show_title = !empty($view->date_info->show_title) ? $view->date_info->show_title : FALSE; $vars['show_title'] = $view->date_info->show_title; @@ -251,13 +258,13 @@ function template_preprocess_calendar_year(&$vars) { // Add in all the $vars added by the main calendar preprocessor. $vars['view']->date_info->style_with_weekno = FALSE; template_preprocess_calendar($vars); - + // Get the url of the year view and remove the year argument from it. // TODO clean this up in case there is another arg that looks like // the year to make sure only the year gets removed. $view = $vars['view']; $year = date_format($view->date_info->min_date, 'Y'); - + // Construct a calendar for each month, adjusting the $view passed // to the theme so it will produce the right results. $view = drupal_clone($vars['view']); @@ -279,25 +286,25 @@ function template_preprocess_calendar_year(&$vars) { $vars['months'] = $months; $vars['view']->date_info->hide_nav = FALSE; $vars['view']->date_info->granularity = 'year'; - + } /** * Display a day view. */ function template_preprocess_calendar_day(&$vars) { - + // Add in all the $vars added by the main calendar preprocessor. $vars['view']->style_with_weekno = FALSE; template_preprocess_calendar($vars); - + $view = $vars['view']; $rows = $vars['rows']; - + $item_count = 0; $by_hour_count = 0; $grouping_field = $view->date_info->style_groupby_field; - + // If we're not grouping by time, move all items into the 'all day' array. if (empty($view->date_info->style_groupby_times)) { // Items are already grouped into times, so we need to process each time-group. @@ -308,9 +315,9 @@ function template_preprocess_calendar_day(&$vars) { } $rows['items'] = array(); } - + $columns = array(); - + // Move all_day items into the right columns and render them. $grouped_items = array(); foreach ($rows['all_day'] as $item) { @@ -329,14 +336,14 @@ function template_preprocess_calendar_day(&$vars) { $item_count++; } $vars['rows']['all_day'] = $grouped_items; - + // Moved timed items into the right columns and render them. $start_times = $view->date_info->style_groupby_times; $show_empty_times = $view->date_info->style_show_empty_times; $end_start_time = '23:59:59'; $start_time = array_shift($start_times); $next_start_time = count($start_times) ? array_shift($start_times) : $end_start_time; - + $grouped_items = array(); foreach ($rows['items'] as $time => $items) { foreach ($items as $item) { @@ -365,7 +372,7 @@ function template_preprocess_calendar_day(&$vars) { $by_hour_count++; } } - + // Finish out the day's time values if we want to see empty times. if (!empty($show_empty_times)) { while ($start_time < $end_start_time) { @@ -376,7 +383,7 @@ function template_preprocess_calendar_day(&$vars) { $next_start_time = count($start_times) ? array_shift($start_times) : $end_start_time; } } - + // Do the headers last, once we know what the actual values are. $i = 0; $start_times = array_keys($grouped_items); @@ -389,20 +396,20 @@ function template_preprocess_calendar_day(&$vars) { } ksort($grouped_items); $vars['rows']['items'] = $grouped_items; - + if (empty($columns)) { $columns = array(t('Items')); } $vars['columns'] = $columns; - + $vars['agenda_hour_class'] = 'calendar-agenda-hour'; $first_column_width = 10; - + if (empty($view->date_info->style_groupby_times)) { $vars['agenda_hour_class'] .= ' calendar-agenda-no-hours'; $first_column_width = 1; } - + $vars['first_column_width'] = $first_column_width; if (count($columns)) { $vars['column_width'] = round((100 - $first_column_width)/count($columns)); @@ -422,12 +429,12 @@ function template_preprocess_calendar_week(&$vars) { // Add in all the $vars added by the main calendar preprocessor. $vars['view']->style_with_weekno = FALSE; template_preprocess_calendar($vars); - + $view = $vars['view']; $rows = $vars['rows']; $item_count = 0; $by_hour_count = 0; - + if (sizeof($rows) > 1) { $day_names = array_shift($rows); } @@ -435,24 +442,26 @@ function template_preprocess_calendar_week(&$vars) { $day_names = $rows; $rows = array(); } - + // Moved timed items into the right columns and render them. $show_empty_times = $view->date_info->style_show_empty_times; $end_start_time = '23:59:59'; - + $grouped_items = array(); $vars['rows'] = $rows[0]; foreach ($rows[0] as $weekno => $row) { $vars['rows'][$weekno] = $row['data']; - + // If we're not grouping by time, move all items into the 'all day' array. if (empty($view->date_info->style_groupby_times)) { - foreach ($row['data']['items'] as $item) { - $row['data']['all_day'] = array_merge($row['data']['all_date'], $item); + foreach ($row['data']['items'] as $items) { + foreach($items as $item) { + $rows['all_day'][] = $item; + } } $row['data']['items'] = array(); } - + $columns[] = $weekno; $start_times = $view->date_info->style_groupby_times; $start_time = array_shift($start_times); @@ -479,7 +488,7 @@ function template_preprocess_calendar_week(&$vars) { $by_hour_count++; } } - + // Finish out the day's time values if we want to see empty times. if ($show_empty_times) { while ($start_time < $end_start_time) { @@ -492,7 +501,7 @@ function template_preprocess_calendar_week(&$vars) { } } ksort($grouped_items); - + // Do the headers last, once we know what the actual values are. $i = 0; $start_times = array_keys($grouped_items); @@ -504,14 +513,14 @@ function template_preprocess_calendar_week(&$vars) { } $vars['items'] = $grouped_items; - + $vars['day_names'] = $day_names; $vars['columns'] = $columns; $vars['start_times'] = $view->date_info->style_groupby_times; - + $vars['agenda_hour_class'] = 'calendar-agenda-hour'; $first_column_width = 10; - + if (empty($view->date_info->style_groupby_times)) { $vars['agenda_hour_class'] .= ' calendar-agenda-no-hours'; $first_column_width = 1; @@ -527,14 +536,14 @@ function template_preprocess_calendar_week(&$vars) { function template_preprocess_calendar_datebox(&$vars) { $date = $vars['date']; $view = $vars['view']; - + $vars['day'] = intval(substr($date, 8, 2)); $force_view_url = !empty($view->date_info->block) ? TRUE : FALSE; $vars['url'] = date_real_url($view, NULL, $date, $force_view_url); $vars['link'] = !empty($view->date_info->display_types['day']) ? l($vars['day'], $vars['url']) : $vars['day']; $vars['granularity'] = $view->date_info->granularity; $vars['mini'] = $view->date_info->mini; - + if ($view->date_info->mini) { if (!empty($vars['selected'])) { $vars['class'] = 'mini-day-on'; @@ -561,7 +570,7 @@ function template_preprocess_calendar_node(&$vars) { if (!empty($node->$field_alias)) { $data = $node->$field_alias; $label = $field->options['label']; - + // CCK has some special label options. if (!empty($field->content_field)) { switch ($field->options['label_type']) { @@ -585,7 +594,7 @@ function template_preprocess_calendar_node(&$vars) { $vars['calendar_end'] = $node->calendar_end; $vars['calendar_start_date'] = $node->calendar_start_date; $vars['calendar_end_date'] = $node->calendar_end_date; - + // We added the node type to the results in the query, // but it will show up as $node->node_type instead of // $node->type. Rename it to match the normal way it @@ -612,7 +621,7 @@ function template_preprocess_calendar_month_multiple_node(&$vars) { $year = $parts[0]; $month = intval($parts[1]); $day = intval($parts[2]); - + // create the link to the day $vars['link'] = date_real_url($view, NULL, date_pad($year, 4) .'-'. date_pad($month) .'-'. date_pad($day)); } @@ -642,13 +651,13 @@ function template_preprocess_calendar_week_node(&$vars) { function template_preprocess_calendar_week_multiple_node(&$vars) { $view = $vars['view']; $curday = $vars['curday']; - + // get the year month and date $parts = explode('-', substr($curday, 0, 10)); $year = $parts[0]; $month = intval($parts[1]); $day = intval($parts[2]); - + // create the link to the day $vars['link'] = date_real_url($view, NULL, date_pad($year, 4) .'-'. date_pad($month) .'-'. date_pad($day)); } @@ -733,7 +742,7 @@ function theme_calendar_stripe_stripe($node) { * The day to display. */ function theme_calendar_empty_day($curday, $view) { - + if ($view->date_info->calendar_type != 'day') { return '
 
'."\n"; }