Enhanced Calendar Navigation

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm

Enhanced Calendar Navigation

Post 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
nicmare
Power Poster
Power Poster
Posts: 1150
Joined: Sat Aug 25, 2007 9:55 am

Re: Enhanced Calendar Navigation

Post by nicmare »

hey,
thats very nice. i will use this. thanks dude
reidjazz

Re: Enhanced Calendar Navigation

Post by reidjazz »

This is great, Nullig...thank you very much!
hexdj
Power Poster
Power Poster
Posts: 415
Joined: Sat Mar 24, 2007 8:28 am

Re: Enhanced Calendar Navigation

Post by hexdj »

ok that's nice but what I'd really like to know is how you color coded events in your calendar?  ;D
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm

Re: Enhanced Calendar Navigation

Post 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
Post Reply

Return to “Tips and Tricks”