Skip to content

Instantly share code, notes, and snippets.

@stevewithington
Last active September 18, 2018 12:48
Show Gist options
  • Save stevewithington/18a6ef38e7234f1e1fc3 to your computer and use it in GitHub Desktop.
Save stevewithington/18a6ef38e7234f1e1fc3 to your computer and use it in GitHub Desktop.
Mura CMS : Example of how to get upcoming calendar events by Feed name
<!---
https://gist.github.com/stevewithington/18a6ef38e7234f1e1fc3
1) Drop this in your Site or Theme contentRenderer.cfc
2) To use, drop the following line of code in your layout template, and modify as you wish:
#$.getUpcomingEventsByFeedname(feedname='Your Feed Name', maxMonths=2, groupDailyEvents=true)#
--->
<cffunction name="getUpcomingEventsByFeedname">
<cfargument name="feedName" type="string" required="true" />
<cfargument name="maxMonths" type="numeric" default="3" />
<cfargument name="groupDailyEvents" default="true" />
<cfscript>
var rs = '';
var subRS = '';
var local = {};
local.feed = variables.$.getBean('feed').loadBy(name=arguments.feedName).setMaxItems(0).setNextN(0);
local.listIDs = '';
if ( feed.getIsNew() ) {
return '<div class="alert alert-info"><strong>Ooops!</strong> The Content Collection/Feed &quot;<strong>#HTMLEditFormat(arguments.feedName)#</strong>&quot; does not exist.</div>';
}
local.it = feed.getIterator(
from=Now()
, to=DateAdd('m', Val(arguments.maxMonths), Now())
);
rs = local.it.getQuery();
</cfscript>
<cfsavecontent variable="str">
<cfoutput>
<div class="mura-index">
<div>
<cfloop condition="local.it.hasNext()">
<cfset local.item = local.it.next() />
<cfif not ListFind(local.listIDs, local.item.getValue('contentid'))>
<dl>
<!--- date --->
<dt class="date releaseDate">
#LSDateFormat(local.item.getValue('displayStart'))#
<!--- end date (if 'daily' event, and grouping is requested) --->
<cfif YesNoFormat(arguments.groupDailyEvents)>
<cfquery dbtype="query" name="subRS">
select *
from rs
where rs.contentid = <cfqueryparam value="#local.item.getValue('contentid')#" />
</cfquery>
<cfif subRS.recordcount gt 1>
<cfset enddate = ListLast(ValueList(subRS.displaystop)) />
<cfif IsValid('date', enddate)>
- #LSDateFormat(enddate)#
</cfif>
</cfif>
<cfset local.listIDs = ListAppend(local.listIDs, local.item.getValue('contentid')) />
</cfif>
</dt>
<!--- Title --->
<dt>
<a href="#local.item.getURL()#">
#HTMLEditFormat(local.item.getValue('title'))#
</a>
</dt>
<!--- Summary --->
<cfif Len(local.item.getValue('summary'))>
<dd class="summary">
#local.item.getValue('summary')#
</dd>
</cfif>
</dl>
</cfif>
</cfloop>
</div>
</div>
</cfoutput>
</cfsavecontent>
<cfreturn str />
</cffunction>
@stevewithington
Copy link
Author

If you don't want to group your calendar events, then you will need to use this Gist:
https://gist.github.com/stevewithington/ba402e81c2c0e79f94e5

@boyzoid
Copy link

boyzoid commented Dec 8, 2015

Is there some way to add this type of functionality as a 'Content Object' so that it can be used as such?

@kucits
Copy link

kucits commented Sep 25, 2017

Having an issue with the display behaviour. If I were to list all of the events, the events will display as expected in chronological order; however, if I reduce the display number, then some events are omitted. If I remove all repeating events, then things appear to display correctly (but I can't really have 100 events displayed on the home page).

It's appears that If I set the display to say 10, it will grab the first 10 events, but if one (or more) of those events spans multiple days, then it still displays 10 events, but some of the events that fall within the events are not listed. If I look at the RSS Feed of the collection, all of the events are there.

@kucits
Copy link

kucits commented Nov 23, 2017

Any thoughts on this...

@kucits
Copy link

kucits commented Sep 18, 2018

Giving this another bump...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment