Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stevewithington/d2d900e2493dc70d7c21 to your computer and use it in GitHub Desktop.
Save stevewithington/d2d900e2493dc70d7c21 to your computer and use it in GitHub Desktop.
Mura CMS : Filter Calendar Items by Extended Attribute
<cfscript>
// Drop this in your THEME or SITE contentRenderer.cfc
public any function getThisMonthEventsByExtendedAttribute(
calendarContentID='#variables.$.content('contentid')#'
, extendedAttributeName=''
, extendedAttributeValue=''
, returnFormat='query'
) {
var local = {};
local.contentBean = $.getBean('content').loadBy(contentid=arguments.calendarContentID);
if ( local.contentBean.getIsNew() || local.contentBean.getType() != 'Calendar' ) {
return QueryNew('');
}
if ( !IsNumeric(variables.$.event('year')) ) {
variables.$.event('year', Year(Now()));
}
if ( !IsNumeric(variables.$.event('month')) || ( IsNumeric(variables.$.event('month')) && variables.$.event('month') > 12) ) {
variables.$.event('month', Month(Now()));
}
// start and end dates (1 month)
local.displaystart = CreateDate(variables.$.event('year'), variables.$.event('month'), 1);
local.displaystop = DateAdd('d', -1, DateAdd('m', 1, local.displaystart));
// the calendar feed
local.feed = $.getBean('feed')
.setMaxItems(0) // get all records
.setNextN(0) // no pagination
.addParam(
relationship='AND'
,field='tcontent.parentid'
,condition='EQ'
,criteria=local.contentBean.getContentID()
)
// filter records with a displayStart date that is before the displayStop date
.addParam(
relationship='AND'
,field='tcontent.displaystart'
,condition='LTE'
,criteria=local.displaystop
)
// OPEN GROUPING
// filter records with a displayStop date that occurs after the displayStart date OR doesn't have one at all
.addParam(relationship='andOpenGrouping')
.addParam(
field='tcontent.displaystop'
,condition='GTE'
,criteria=local.displaystart
)
.addParam(
relationship='OR'
,field='tcontent.displaystop'
,criteria='null'
)
.addParam(relationship='closeGrouping');
// CLOSE GROUPING
// Filter on Extended Attribute
if ( Len(arguments.extendedAttributeName) && Len(arguments.extendedAttributeValue) ) {
local.feed.addParam(
relationship='AND'
,field=arguments.extendedAttributeName
,condition='EQ'
,criteria=arguments.extendedAttributeValue
);
}
local.rs = feed.getQuery(
from=local.displaystart
, to=local.displaystop
);
return local.rs;
}
</cfscript>
<!---
2) Then, copy the entire directory located under /{SiteID}/inclues/display_objects/calendar/
and paste it under either the /custom directory, or under your theme at:
/{SiteID}/includes/themes/{ThemeName}/display_objects/
3) You will need a way to dynamically pass in the extended attribute name and value. The easiest would be to
create some links, and add them to the index.cfm file.
For example, let's say you have an extended attribute called 'department' ... you could then have a listing of
departments to filter on. However, for each link, you will want to pass in the currently selected date. Such as:
--->
<!--- Extended Attribute Filter --->
<cfset exAtts = 'Marketing,Human Resources,IT' />
<div class="btn-group">
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown">Filter <span class="caret"></span></button>
<ul class="dropdown-menu" role="menu">
<cfloop list="#exAtts#" index="a">
<cfset class = URLDecode($.event('department')) eq a ? 'active' : '' />
<li class="#class#">
<a href="./?department=#URLEncodedFormat(a)#&amp;year=#$.event('year')#&amp;month=#$.event('month')#">#HTMLEditFormat(a)#</a>
</li>
</cfloop>
</ul>
</div>
<!---
4) Finally, in the index.cfm file, comment out the variable setting for 'variables.rsSection' (around line 54)
and replace it with the following code:
--->
<cfset variables.rsSection = variables.$.getThisMonthEventsByExtendedAttribute(extendedAttributeName='department', extendedAttributeValue=variables.$.event('department')) />
<!---
The main point here is that you would replace 'department' with your actual extendedAttributeName,
and then the extendedAttributeValue should be whatever the key is that you're using in your filter/link.
--->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment