Created
August 2, 2011 23:39
-
-
Save retrofox/1121517 to your computer and use it in GitHub Desktop.
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
| var limitsByDate = [ | |
| // event starts into current period | |
| { | |
| start: { | |
| $gt: start | |
| , $lt: end | |
| } | |
| } | |
| // event ends into current period | |
| , { | |
| end: { | |
| $gt: start | |
| , $lt: end | |
| } | |
| } | |
| // event not starts and not ends into current period | |
| , { | |
| start: { | |
| $lt: start | |
| } | |
| , end: { | |
| $gt: end | |
| } | |
| } | |
| ] | |
| , belongTo = [ | |
| // events belongs to classroom calendar | |
| { | |
| _classroom: { | |
| $in: this.allowedClassrooms | |
| } | |
| } | |
| // eventos belongs to current user | |
| , { | |
| _user: this.id | |
| } | |
| ] | |
| , ors = []; | |
| // mixing OR conditions | |
| for (var k = 0; k < belongTo.length; k++) | |
| for (var l = 0; l < limitsByDate.length; l++) { | |
| // cloning belongTo[k] object | |
| var belong = {}; | |
| for (var m in belongTo[k]) | |
| belong[m] = belongTo[k][m]; | |
| ors.push (object.merge(belong, limitsByDate[l])); | |
| } | |
| console.log("-- ors ----------------------------------------------------"); | |
| console.log(ors); | |
| console.log("---------------------------------------------------- ors --"); | |
| return this.model('Calevent').find({ $or: ors }, fn); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment