Page 1 of 1

Enhanced Calendar Navigation

Posted: Tue Oct 07, 2008 10:29 pm
by Nullig
Here's a customization of the Calendar module that I use to enhance the prev and next links at the top of the large calendar display. This gives you a navigation display like:

  >

The arrows jump 3 months back or forward.

To achieve this, edit the function.displaycalendar.php file.

Replace:

Code: Select all

	$prev_month['timestamp'] = strtotime("-1 month", mktime(0,0,0,$month, 1, $year));
	$prev_month['year'] = date('Y', $prev_month['timestamp']);
	$prev_month['month'] = date('n', $prev_month['timestamp']);
	$next_month['timestamp'] = strtotime("+1 month", mktime(0,0,0,$month, 1, $year));
	$next_month['year'] = date('Y', $next_month['timestamp']);
	$next_month['month'] = date('n', $next_month['timestamp']);
with:

Code: Select all

	$prev_month['timestamp'] = strtotime("-1 month", mktime(0,0,0,$month, 1, $year));
	$prev_month['year'] = date('Y', $prev_month['timestamp']);
	$prev_month['month'] = date('n', $prev_month['timestamp']);

	$prev_month1['timestamp'] = strtotime("-2 month", mktime(0,0,0,$month, 1, $year));
	$prev_month1['year'] = date('Y', $prev_month1['timestamp']);
	$prev_month1['month'] = date('n', $prev_month1['timestamp']);

	$prev_month2['timestamp'] = strtotime("-3 month", mktime(0,0,0,$month, 1, $year));
	$prev_month2['year'] = date('Y', $prev_month2['timestamp']);
	$prev_month2['month'] = date('n', $prev_month2['timestamp']);

	$next_month['timestamp'] = strtotime("+1 month", mktime(0,0,0,$month, 1, $year));
	$next_month['year'] = date('Y', $next_month['timestamp']);
	$next_month['month'] = date('n', $next_month['timestamp']);

	$next_month1['timestamp'] = strtotime("+2 month", mktime(0,0,0,$month, 1, $year));
	$next_month1['year'] = date('Y', $next_month1['timestamp']);
	$next_month1['month'] = date('n', $next_month1['timestamp']);

	$next_month2['timestamp'] = strtotime("+3 month", mktime(0,0,0,$month, 1, $year));
	$next_month2['year'] = date('Y', $next_month2['timestamp']);
	$next_month2['month'] = date('n', $next_month2['timestamp']);
And replace:

Code: Select all

	$navigation['next'] = $module->CreateLink($id, 'default', $returnid, '', array('year'=>$next_month['year'], 'month'=>$next_month['month']), '', true,  true, '', false );
	$navigation['prev'] = $module->CreateLink($id, 'default', $returnid, '', array('year'=>$prev_month['year'], 'month'=>$prev_month['month']), '', true,  true, '', false );
with:

Code: Select all

	$navigation['prev'] = $module->CreateLink($id, 'default', $returnid, '', array('year'=>$prev_month['year'], 'month'=>$prev_month['month']), '', true,  true, '', false );

	$navigation['prev1'] = $module->CreateLink($id, 'default', $returnid, '', array('year'=>$prev_month1['year'], 'month'=>$prev_month1['month']), '', true,  true, '', false );

	$navigation['prev2'] = $module->CreateLink($id, 'default', $returnid, '', array('year'=>$prev_month2['year'], 'month'=>$prev_month2['month']), '', true,  true, '', false );

	$navigation['next'] = $module->CreateLink($id, 'default', $returnid, '', array('year'=>$next_month['year'], 'month'=>$next_month['month']), '', true,  true, '', false );

	$navigation['next1'] = $module->CreateLink($id, 'default', $returnid, '', array('year'=>$next_month1['year'], 'month'=>$next_month1['month']), '', true,  true, '', false );

	$navigation['next2'] = $module->CreateLink($id, 'default', $returnid, '', array('year'=>$next_month2['year'], 'month'=>$next_month2['month']), '', true,  true, '', false );
And add the following to the "// assign to Smarty" section near the bottom:

Code: Select all

	$module->smarty->assign_by_ref('prev_month', $prev_month['month']);
	$module->smarty->assign_by_ref('prev_month1', $prev_month1['month']);
	$module->smarty->assign_by_ref('next_month', $next_month['month']);
	$module->smarty->assign_by_ref('next_month1', $next_month1['month']);

Then, in your "Calendar Template", change:

Code: Select all

<caption class="calendar-month"><span class="calendar-prev"><a href="{$navigation.prev}">«</a></span> {$month_names[$month]} {$year} <span class="calendar-next"><a href="{$navigation.next}">»</a></span></caption>
to:

Code: Select all

{if $table_id eq "big"}
<caption class="calendar-month">
<span class="calendar-prev">
<a href="{$navigation.prev2}">«</a>  
<a href="{$navigation.prev1}">{$month_names[$prev_month1]|truncate:3:""}</a>  
<a href="{$navigation.prev}">{$month_names[$prev_month]|truncate:3:""}</a>
</span>
    {$month_names[$month]} {$year}    
<span class="calendar-next">
<a href="{$navigation.next}">{$month_names[$next_month]|truncate:3:""}</a>  
<a href="{$navigation.next1}">{$month_names[$next_month1]|truncate:3:""}</a>  
<a href="{$navigation.next2}">»</a>
</span>
</caption>
{else}
<caption class="calendar-month"><span class="calendar-prev"><a href="{$navigation.prev}">«</a></span> {$month_names[$month]} {$year} <span class="calendar-next"><a href="{$navigation.next}">»</a></span></caption>
{/if}
And of course, style it to your liking. Here is a site that uses this navigation.

http://www.petgranny.com/index.php?page ... g-calendar

Nullig

Re: Enhanced Calendar Navigation

Posted: Wed Oct 08, 2008 3:47 pm
by nicmare
hey,
thats very nice. i will use this. thanks dude

Re: Enhanced Calendar Navigation

Posted: Mon Oct 13, 2008 10:39 pm
by reidjazz
This is great, Nullig...thank you very much!

Re: Enhanced Calendar Navigation

Posted: Tue Nov 04, 2008 5:27 pm
by hexdj
ok that's nice but what I'd really like to know is how you color coded events in your calendar?  ;D

Re: Enhanced Calendar Navigation

Posted: Tue Nov 04, 2008 5:38 pm
by Nullig
Here is the full template, with the section you're interested in highlighted in red:

{strip}

{if $compact_view neq 1}
{if $table_id eq "big"}


«  
{$month_names[$prev_month1]|truncate:3:""}  
{$month_names[$prev_month]|truncate:3:""}

    {$month_names[$month]} {$year}    

{$month_names[$next_month]|truncate:3:""}  
{$month_names[$next_month1]|truncate:3:""}  
»


{else}
« {$month_names[$month]} {$year} »
{/if}
{/if}

{foreach from=$day_names item=day key=key}
{$day_short_names[$key]}
{/foreach}


{* initial empty days *}
{if $first_of_month_weekday_number > 0}
 
{/if}

{* iterate over the days of this month *}
{assign var=weekday value=$first_of_month_weekday_number}
{foreach from=$days item=day key=key}
{if $weekday == 7}
{assign var=weekday value=0}


{/if}

{if isset($day.events.0)}{$key}
{if $summaries == true}

{foreach from=$day.events item=event}
{$event.event_title}
{/foreach}


{/if}
{else}{$key}{/if}

{math assign=weekday equation="x + 1" x=$weekday}
{/foreach}

{* remaining empty days *}
{if $weekday != 7}
 
{/if}





{/strip}

So, basically, all events use specific words like "Tentative" and "Confirmed" at the beginning of their title. I look for these strings and set the class for the to the appropriate one.

Nullig