Page 1 of 1

[SOLVED] Help: Need 2 CGCalendars on one page

Posted: Thu Sep 19, 2013 2:24 am
by inyerface
Hello,

I have two CGCalendar's on one page... they work great if I sett hem to inline but I have a problem:

1) If inline, I hit next on one and I can go through the months but as soon as I hit next on the other one, the first one is reset to "today".

2) What I'd really like is to have both calendars displayed but when you hit next, both calendars change to the ame month. How can this be done?

http://66.48.72.81/~ruecater/index.php? ... ailability

The smarty code I use is:

Code: Select all

{cms_module module="CGCalendar" display="calendar" detailpage="calendar" calendartemplate="Calendar" category="No5"}

{cms_module module="CGCalendar" display="calendar" detailpage="calendar" calendartemplate="Calendar" category="No7"}
I love this module and wouldn't want to mofify it. Any help is appreciated.

Note: This is really just to show availability on two different properties that are next door to each other.

Thanks!!

Re: Help: Need 2 CGCalendars on one page

Posted: Thu Sep 19, 2013 5:23 am
by Rolf
You can put the content of two different templates in one new template, working example:
http://www.zeijen.nu/agenda

Re: Help: Need 2 CGCalendars on one page

Posted: Thu Sep 19, 2013 7:25 am
by inyerface
But can I display two calendars displaying different categories?

Re: Help: Need 2 CGCalendars on one page

Posted: Thu Sep 19, 2013 5:55 pm
by inyerface
Thanks Rolf.

I got the calendars changing together but how would I show the events from one category in the first one and the events in another category in the other?

My working example:

http://66.48.72.81/~ruecater/index.php?page=test

Re: Help: Need 2 CGCalendars on one page

Posted: Thu Sep 19, 2013 6:29 pm
by calguy1000
I would start looking at the use_session parameter. However, that may cause it's own complications.

If that doesn't work, then you'll prolly need some customizations.

Re: Help: Need 2 CGCalendars on one page

Posted: Thu Sep 19, 2013 9:50 pm
by inyerface
So close... thought I had a workaround.

I decided to hard code the colors in the template using {$event.categories.0.category_name} and {if} statements but noticed that when there are overlapping events, only one category is listed on that day when there should really be both.

<pre>{$event.categories.0|@print_r}</pre>

How can his be fixed to show the two category names associated with that day?

Re: Help: Need 2 CGCalendars on one page

Posted: Thu Sep 19, 2013 11:17 pm
by inyerface
So this is what I did:

http://66.48.72.81/~ruecater/index.php?page=test

I have two categories for each property... N05 and No7

I altered the table where the <td> colors are managed based on whether there's an event:

<td valign="top" align="right" {if isset($day.class)}class="{$day.class}"{/if}{foreach from=$day.events item=event}{if $event.categories.0.category_name == "No5"}style="background-color: #a0c084;"{else}style="background-color: #444;color:#f0f0f0;"{/if}{/foreach} style="background-color:#a0c084;">

So I'm essentially saying to ignore No7 category on the calendar... it works great UNTIL there's an overlapping event.

The other thing I though of doing was counting the number of events that appear:

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

How can I count how many {$event.event_title} there are per day? That'll resolve my issue

Re: Help: Need 2 CGCalendars on one page

Posted: Fri Sep 20, 2013 12:17 am
by calguy1000
try: {$nevents=count($day.events)}

Re: Help: Need 2 CGCalendars on one page

Posted: Fri Sep 20, 2013 3:21 am
by inyerface
Thank you Calguy!!

For those who can understand my logic here's my hack. Note, the two categories I have are No5 and No7:

<td valign="top" align="right" {if isset($day.class)}class="{$day.class}"{/if}{foreach from=$day.events item=event}{if count($day.events) == "2" || $event.categories.0.category_name == "No5"} style="background-color: #444;color:#f0f0f0;"{else} style="background-color:#a0c084;"{/if}{/foreach} style="background-color:#a0c084;">

The logic:

If there are 2 events in that day OR the event is tied to the category I mentioned, then run the style proposed, else just make the background the defaul color.

Works like magic. Thanks for the tip Calguy!!

The full Calendar Display template:

Code: Select all


{strip}
<div class="nextprev">
  <span class="calendar-prev"><a href="{$navigation.prev}"><img src="uploads/images/bg/arrow-left.png" alt="" /></a></span> 
  <span class="calendar-month">{$month_names[$month]} {$year} </span>
  <span class="calendar-next"><a href="{$navigation.next}"><img src="uploads/images/bg/arrow-right.png" alt="" /></a></span>
</div>


<table class="calendar-big" id="cal-calendar" cellpadding="0" cellspacing="2">
<tbody><tr>
{foreach from=$day_names item=day key=key}
<th abbr="{$day}">{$day_short_names[$key]}</th>
{/foreach}</tr>

<tr>
{* initial empty days *}
{if $first_of_month_weekday_number > 0}
<td colspan="{$first_of_month_weekday_number}"> </td>
{/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}
</tr>
<tr>
{/if}
<td valign="top" align="right" {if isset($day.class)}class="{$day.class}"{/if}{foreach from=$day.events item=event}{if count($day.events) == "2" || $event.categories.0.category_name == "No5"} style="background-color: #444;color:#f0f0f0;"{else} style="background-color:#a0c084;"{/if}{/foreach} style="background-color:#a0c084;">
{if isset($day.events.0)}{$key}


{else}{$key}{/if}
</td>
{math assign=weekday equation="x + 1" x=$weekday}
{/foreach}

{* remaining empty days *}
{if $weekday != 7}
<td colspan="{math equation="7-x" x=$weekday}"> </td>
{/if}


</tr>
</tbody></table>

{/strip}


<br />
<br />

{strip}

<table class="calendar-big" id="cal-calendar" cellpadding="0" cellspacing="2">
<tbody><tr>
{foreach from=$day_names item=day key=key}
<th abbr="{$day}">{$day_short_names[$key]}</th>
{/foreach}</tr>

<tr>
{* initial empty days *}
{if $first_of_month_weekday_number > 0}
<td colspan="{$first_of_month_weekday_number}"> </td>
{/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}
</tr>
<tr>
{/if}
<td valign="top" align="right" {if isset($day.class)}class="{$day.class}"{/if}{foreach from=$day.events item=event}{if count($day.events) == "2" || $event.categories.0.category_name == "No7"} style="background-color: #444;color:#f0f0f0;"{else} style="background-color:#a0c084;"{/if}{/foreach} style="background-color:#a0c084;">
{if isset($day.events.0)}{$key}

{else}{$key}{/if}
</td>
{math assign=weekday equation="x + 1" x=$weekday}
{/foreach}

{* remaining empty days *}
{if $weekday != 7}
<td colspan="{math equation="7-x" x=$weekday}"> </td>
{/if}


</tr>
</tbody></table>

{/strip}


Re: Help: Need 2 CGCalendars on one page

Posted: Fri Sep 20, 2013 3:22 am
by inyerface
calguy1000 wrote:try: {$nevents=count($day.events)}
{count($day.events)} DID THE TRICK :)))

Re: [SOLVED] Help: Need 2 CGCalendars on one page

Posted: Fri Sep 20, 2013 4:04 am
by inyerface
I'm more than thrilled about this!!! Using only 1 instance of CGCalendar and we can add more than one with both categories (properties) displaying avialability.

http://66.48.72.81/~ruecater/index.php? ... ailability