Skip to content

Instantly share code, notes, and snippets.

@bendalton
Created July 16, 2012 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bendalton/7f0794339728c8ebaf22 to your computer and use it in GitHub Desktop.
Save bendalton/7f0794339728c8ebaf22 to your computer and use it in GitHub Desktop.
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