Last active
October 4, 2017 22:03
-
-
Save stevewithington/5201eab8f7e83681a98b to your computer and use it in GitHub Desktop.
Mura CMS : Get Calendar Events by Date
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
// Drop this in your THEME or SITE contentRenderer.cfc | |
public any function getEventsByDate( | |
calendarContentID='#variables.$.content('contentid')#' | |
, theDate = '#CreateDate(Year(Now()), Month(Now()), Day(Now()))#' | |
, returnFormat = 'query' | |
) { | |
var local = {}; | |
local.contentBean = variables.$.getBean('content').loadBy(contentid=arguments.calendarContentID); | |
if ( local.contentBean.getIsNew() || local.contentBean.getType() != 'Calendar' || !IsValid('date', arguments.theDate) ) { | |
return QueryNew(''); | |
} | |
// start and end dates (1 day) | |
local.displaystart = CreateDateTime(Year(arguments.theDate), Month(arguments.theDate), Day(arguments.theDate), 0, 0, 0); | |
local.displaystop = DateAdd('l', -1, DateAdd('d', 1, local.displaystart)); | |
// the calendar feed | |
local.rs = variables.$.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='LT' | |
,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 | |
.getQuery( | |
from=local.displaystart | |
, to=local.displaystop | |
); | |
// add a 'timestart' column, so we can sort the days events by time | |
QueryAddColumn(local.rs, 'timestart', []); | |
for ( i=1; i<=local.rs.recordcount; i++) { | |
local.rs['timestart'][i] = TimeFormat(local.rs.displaystart[i], 'HH:MM:SS'); | |
} | |
// Query of Queries for sorting by the event time | |
var qoq = new Query(); | |
qoq.setDBType('query'); | |
qoq.setAttributes(rs=local.rs); | |
qoq.setSQL(' | |
SELECT * | |
FROM rs | |
ORDER BY timestart | |
'); | |
local.rsQoQ = qoq.execute().getResult(); | |
return arguments.returnFormat == 'iterator' | |
? variables.$.getBean('contentIterator').setQuery(local.rsQoQ) | |
: local.rsQoQ; | |
} | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment