Here are the mods to get week view with Calendar.
I was working with Calendar 0.7 stable, which just has one file, later versions I understand have been broken down into more files. Also, I haven't done it properly with a template tab in the admin panel etc.
First thing is to add the following case to the switch inside function UserDisplay:
This is the main DisplayWeekList function. I've left in the code which grabs the external feed information.
Code: Select all
function DisplayWeekList($id, $parameters, $returnid)
{
$category = get_parameter_value($parameters, 'category', '');
$summaries = get_parameter_value($parameters, 'summaries', 1);
$detail = get_parameter_value($parameters, 'detail', 0);
$categories_table_name = $this->categories_table_name;
$events_to_categories_table_name = $this->events_to_categories_table_name;
$events_table_name = $this->events_table_name;
$first_day_of_week = get_parameter_value($parameters, 'first_day_of_week', 1);
$table_id = get_parameter_value($parameters, 'table_id', 'calendar-'.$id.$returnid);
$return_link = get_parameter_value($parameters, 'return_link', 0);
$limit = get_parameter_value($parameters, 'limit', -1);
$compact_view = get_parameter_value($parameters, 'compact_view', 0);
$moretext = get_parameter_value($parameters, 'moretext', $this->Lang('cal_more'));
$reverse = get_parameter_value($parameters, 'reverse', 'false');
$sorting = ($reverse == 'true' ? 'DESC' : 'ASC');
// basic information about dates
$yesterday=strtotime("-1 day");
$next_week=strtotime("+1 week");
$start_month = date('n', $yesterday);
$start_year = date('Y', $yesterday);
$start_day = date('d',$yesterday);
$start = sprintf('%04d-%02d-%02d 00:00:00', date('Y', $yesterday), date('m', $yesterday), date('d', $yesterday));
$end = sprintf('%04d-%02d-%02d 23:59:59', date('Y', $next_week), date('m', $next_week), date('d', $next_week));
$first_day = date('w', $yesterday);
$last_day_of_month = mktime(0, 0, 0, date('m',$next_month), 0, $year);
$days_in_month=date('d',$last_day_of_month);
$db = $this->cms->db;
$where = 'WHERE';
$sql = "SELECT DISTINCT $events_table_name.*, $categories_table_name.category_name
FROM $events_table_name\n";
// this bit can be left out, but I need the category information in there. NB may cause duplicate entries
// if an event has more than one cat.
$sql .= "LEFT JOIN $events_to_categories_table_name
ON $events_table_name.event_id = $events_to_categories_table_name.event_id
LEFT JOIN $categories_table_name
ON $events_to_categories_table_name.category_id = $categories_table_name.category_id
";
$sql .= "$where ($events_table_name.event_date_start >= '$start' \n\tOR $events_table_name.event_date_end >= '$start')\n";
$sql .= "AND ($events_table_name.event_date_start <= '$end' \n\tOR $events_table_name.event_date_end <= '$end')\n";
$where = ' AND ';
if($category)
{
$cats = explode(',', $category);
$sql .= $where . ' (';
$count = 0;
foreach($cats as $cat)
{
$cat = trim($cat);
if($count != 0)
{
$sql .= ' OR ';
}
$count++;
$sql .= "$categories_table_name.category_name LIKE '$cat' ";
}
$sql .= ') ';
$where = ' AND ';
}
$sql .= " ORDER BY $events_table_name.event_date_start $sorting";
if($limit > 0)
{
$rs = $db->SelectLimit($sql, $limit);
}
else
{
$rs = $db->Execute($sql); /* @var $rs ADOConnection */
}
$days = array();
$day_names = $this->GetDayNames();
// This is the bit that grabs the rss data: can be left out. You need the rss_fetch.inc file.
require_once 'rss_fetch.inc';
$rss = fetch_rss('http://www.universalis.com/England/atomweek.xml');
$item=$rss->items;
# Usually the Universalis feed begins with yesterday, but it can be the day before.
# this loop finds the first occurance of yesterday's day name in the feed titles
# It should never be possible for the first day in the feed to be later than today. If the first day
# in the feed is today (an exceptional case) then the first occurance of yesterday's day name would be
# that same day next week, in the 7th entry (array key 6), so by stopping the loop at 5 we ensure that if that is the
# case the offset is -1 - yesterday in our table will not have universalis data, but every other day will.
# If yesterday is the first day in the feed, the offset will be 0 (usual case). If yesterday is the second day, the
# offset will be 1. Worst case, universalis is broken and the feed begins with tomorrow, then we will end up with an offset of 5
# and the labels will be a week out, but this should never happen
$universalis_offset=-1;
for($j = 0; $j <=5 && $universalis_offset==-1; $j++)
{
if(strncasecmp($item[$j]['title'],$day_names[$first_day],2)==0)
{
$universalis_offset=$j;
}
}
// end of optional RSS-handling section
for($i = 0; $i <= 7; $i++)
{
$dmonth=$start_month;
$dyear=$start_year;
$dday=$start_day+$i;
if($dday>$days_in_month)
{
$dday=$dday-$days_in_month;
$dmonth=$start_month+1;
if($start_month==12)
{
$dyear=$start_year+1;
$dmonth=1;
}
}
$days[$i]['day']=$dday;
$days[$i]['month']=$dmonth;
$days[$i]['year']=$dyear;
if($dday==date('d')||$dday==date('j'))
{
$days[$i]['class']="today";
}
$day_of_week = ($first_day + $i) % 7;
$days[$i]['name']=$day_names[$day_of_week];
$days[$i]['dow']=$day_of_week;
$days[$i]['url'] = $this->CreateLink($id, 'default', $returnid, $contents='',
$params=array('year'=>$dyear, 'month'=>$dmonth, 'day'=>$dday, 'display'=>'list','return_link'=>1,'detail'=>1, 'lang'=>$this->curlang), '', true);
$days[$i]['events'] = array();
// this bit is just for the rss handling feature
if($i+$universalis_offset>=0 && $item[$i+$universalis_offset])
{
$days[$i]['title'] = $item[$i+$universalis_offset]['summary'];
}else{
$days[$i]['title'] = '';
}
}
if($rs->RowCount() > 0)
{
while($row = $rs->FetchRow())
{
//debug_display($row, '$row');
$start_date = strtotime($row['event_date_start']);
if(empty($row['event_date_end']))
{
$end_date = $start_date;
}
else
{
$end_date = strtotime($row['event_date_end']);
}
$url = $this->CreateLink($id, 'default', $returnid, $contents='', $params=array('year'=>$year, 'month'=>$month, 'event_id'=>$row['event_id'], 'display'=>'event', 'lang'=>$this->curlang), '', true);
$row['url'] = $url;
$row['details_nohtml']=strip_tags($row['event_details']);
for($i=0; $i<=7; $i++)
{
if(date('Y',$start_date)==$days[$i]['year'] && date('m',$start_date)==$days[$i]['month'] && date('d',$start_date)==$days[$i]['day'])
{
$days[$i]['events'][] = $row;
}
}
}
}
$navigation['next'] = $this->CreateReturnLink($id, $returnid, '', array('year'=>$next_month['year'], 'month'=>$next_month['month']), true);
$navigation['prev'] = $this->CreateReturnLink($id, $returnid, '', array('year'=>$prev_month['year'], 'month'=>$prev_month['month']), true);
$day_short_names = $this->GetDayShortNames();
$month_names = $this->GetMonthNames();
if($first_day_of_week != 0)
{
for($i = 0; $i < $first_day_of_week; $i++)
{
$first = array_shift($day_names);
$day_names[] = $first;
$first = array_shift($day_short_names);
$day_short_names[] = $first;
}
}
$return_url = '';
if($return_link == 1)
{
$return_url = $this->CreateReturnLink($id, $returnid, $this->lang('cal_return'));
}
// other language fields
$lang = $this->GetLabels();
// assign to Smarty
$this->smarty->assign_by_ref('start_month', $start_month);
$this->smarty->assign_by_ref('month_names', $month_names);
$this->smarty->assign_by_ref('day_names', $day_names);
$this->smarty->assign_by_ref('day_short_names', $day_short_names);
$this->smarty->assign_by_ref('table_id', $table_id);
$this->smarty->assign_by_ref('days', $days);
$this->smarty->assign_by_ref('day', $day);
$this->smarty->assign_by_ref('start_year', $start_year);
$this->smarty->assign_by_ref('summaries', $summaries);
$this->smarty->assign_by_ref('detail', $detail);
$this->smarty->assign_by_ref('return_url', $return_url);
$this->smarty->assign_by_ref('lang', $lang);
$this->smarty->assign_by_ref('navigation', $navigation);
$this->smarty->assign_by_ref('compact_view', $compact_view);
// Display template
// if (isset($params['listtemplate']))
// {
// echo $this->ProcessTemplate($params['listtemplate']);
// }
// else
// {
// $t = $this->GetTemplate('weeklist');
// if(empty($t))
// {
$this->SetTemplate('weeklist', $this->GetDefaultTemplate('weeklist'));
// }
echo $this->ProcessTemplateFromDatabase('weeklist');
// }
}
We also need a template: I just added another case to the switch inside function GetDefaultTemplate. Just to complicate things further I have added a feature that shows weekly service times automatically without needed an event in the database, but they can be cancelled on any given day by adding an event with category 'cancellation'
I hope all this is of some use, but there is an awful lot of hard-coded customisation in there which may distract you from the essential stuff (especially in the template section).