Page 1 of 1
[SOLVED] CGCalendar - Browse by Category
Posted: Fri Oct 01, 2010 2:54 pm
by richardjkeys
Hi,
I'm using the CGCalendar module on my events section.
I'd like to create a dynamic category list (to use as sub nav) which filters the events; much like the Browse by Category option does in the news module.
Has anyone devised a simple solution for this?
If not, could anyone point me in the right direction to 'copy' the functionality of this from the news module into the CGCalendar module? I'm new to CMSMS plugins, but my PHP isn't too bad - I think this might be a useful solution for others too.
Any help is greatly appreciated.
Regards,
Rich
Re: CGCalendar - Browse by Category
Posted: Fri Oct 01, 2010 10:29 pm
by Peciura
Categories are saved on table `cms_module_cgcalendar_categories`.
Create list of categories,
add links with extra url parameter (e.g. "cgc_cat") to the same page where is CGCalendar tag
Code: Select all
cms_module module='CGCalendar' category=$smarty.get.cgc_cat}
It will display events of category stored in url, or all events if no category (url param) is set.
Re: CGCalendar - Browse by Category
Posted: Mon Oct 04, 2010 8:29 am
by richardjkeys
Hi,
Thanks for the advice.
Could you point me in the right direction for creating this list? As I said, I'm new to CMSMS plugins & modules - am I right in thinking I could create a tag for this event 'sub-navigation'?
Rich
Re: CGCalendar - Browse by Category
Posted: Mon Oct 04, 2010 6:57 pm
by Peciura
a. Create UDT 'get_cgcalendar_categories'
Code: Select all
/**
* Get list of CGCalendar categories and assign to Smarty variable.
*
* @params string $params['assign'] Mandatory. Name of variable to assign result
*/
$assign = trim($params['assign']);
if (!empty($assign)){
$gCms = cmsms(); // global $gCms;
$db = $gCms->GetDB(); // cms_utils :: get_db();
$smarty = $gCms->GetSmarty(); // cms_utils :: get_smarty();
$dbresult = FALSE;
$query = 'SELECT * FROM `'.cms_db_prefix().'module_cgcalendar_categories` ORDER BY `category_order`, `category_name`, `category_id`';
$dbresult = $db->GetArray($query);
if(!empty($dbresult)){
$smarty->assign($assign, $dbresult);
}
}
b. Create list of links to
calendar page for each category. For pretty url use '
?' instead of '&'
{get_cgcalendar_categories assign='cgc_cats'}
{if !empty($cgc_cats)}
{foreach from=$cgc_cats item='cgc_cat'}
{cms_selflink page=$page_alias urlparam="&cgc_cat=`$cgc_cat.category_name`" title="`$cgc_cat.category_name`" text="`$cgc_cat.category_name`"}
{/foreach}
{/if}
c. And finally, add tag you already know on
calendar page.
Code: Select all
{cms_module module='CGCalendar' category=$smarty.get.cgc_cat}
Re: CGCalendar - Browse by Category
Posted: Wed Oct 06, 2010 7:31 am
by richardjkeys
Excellent!
That works a treat, thank you Peciura
