-
-
Save bendalton/7f0794339728c8ebaf22 to your computer and use it in GitHub Desktop.
This file contains 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
component persistent="true"{ | |
property name="id" fieldtype="id" generator="uuid"; | |
//Query Properties | |
property name="startDate" type="date" ormtype="date"; | |
property name="endDate" type="date" ormtype="date"; | |
property name="modes" default="bike"; | |
property name="siteID"; | |
//Properties to be set via Query | |
property name="label"; | |
property name="points" type="numeric" default="0"; | |
property name="miles" type="numeric" default="0"; | |
property name="trips" type="numeric" default="0"; | |
function init(){ | |
startDate = createDate(2010,1,1); | |
endDate = now(); | |
return this; | |
} | |
function updateStats(group){ | |
label = group.getLabel(); | |
var c = new coldbox.system.orm.hibernate.CriteriaBuilder('Group'); | |
c.createAlias('users','u'); | |
c.createAlias('u.pointAwards','p'); | |
c.createAlias('p.log','l'); | |
c.add(c.restrictions.eq('id',group.getGroupID())); | |
if(!isNull(modes)) | |
c.add(c.restrictions.isIn('l.mode',modes)); | |
if(!isNull(startDate)) | |
c.add(c.restrictions.isGE('l.date',startDate)); | |
if(!isNull(endDate)) | |
c.add(c.restrictions.isLE('l.date',endDate)); | |
if(!isNull(siteID)) | |
c.add(c.restrictions.eq('u.siteID',siteID)); | |
points = c.withProjections(sum="p.pointValue").get(); | |
if(isNull(points)) | |
points = 0; | |
var c = new coldbox.system.orm.hibernate.CriteriaBuilder('Group'); | |
c.createAlias('users','u'); | |
c.createAlias('u.logs','l'); | |
c.add(c.restrictions.eq('id',group.getGroupID())); | |
if(!isNull(modes)) | |
c.add(c.restrictions.isIn('l.mode',modes)); | |
if(!isNull(startDate)) | |
c.add(c.restrictions.isGE('l.date',startDate)); | |
if(!isNull(endDate)) | |
c.add(c.restrictions.isLE('l.date',endDate)); | |
if(!isNull(siteID)) | |
c.add(c.restrictions.eq('u.siteID',siteID)); | |
miles = c.withProjections(sum="l.miles").get(); | |
if(isNull(miles)) | |
miles = 0; | |
var c = new coldbox.system.orm.hibernate.CriteriaBuilder('Group'); | |
c.createAlias('users','u'); | |
c.createAlias('u.logs','l'); | |
c.add(c.restrictions.eq('id',group.getGroupID())); | |
if(!isNull(modes)) | |
c.add(c.restrictions.isIn('l.mode',modes)); | |
if(!isNull(startDate)) | |
c.add(c.restrictions.isGE('l.date',startDate)); | |
if(!isNull(endDate)) | |
c.add(c.restrictions.isLE('l.date',endDate)); | |
if(!isNull(siteID)) | |
c.add(c.restrictions.eq('u.siteID',siteID)); | |
trips = c.withProjections(rowcount=1).get(); | |
if(isNull(trips)) | |
trips = 0; | |
return this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment