1: <?php
2:
3: namespace intouch\ical;
4:
5: 6: 7: 8: 9: 10: 11: 12:
13: class Query {
14: 15: 16: 17: 18: 19: 20: 21: 22: 23:
24: public static function Between(iCal $ical, $start, $end ) {
25: if( $ical instanceof iCal ) {
26: $ical = $ical->getEvents();
27: }
28: if( !is_array($ical) ) {
29: throw new Exception('intouch\ical\Query::Between called with invalid input!');
30: }
31:
32: $rtn = array();
33: foreach( $ical AS $e ) {
34: if( ($start <= $e->getStart() && $e->getStart() < $end)
35: || ($start < $e->getRangeEnd() && $e->getRangeEnd() <= $end) ) {
36: $rtn[] = $e;
37: }
38: }
39: return $rtn;
40: }
41:
42: 43: 44: 45: 46: 47: 48:
49: public static function After( $ical, $start ) {
50: if( $ical instanceof iCal ) {
51: $ical = $ical->getEvents();
52: }
53: if( !is_array($ical) ) {
54: throw new Exception('intouch\ical\Query::After called with invalid input!');
55: }
56:
57: $rtn = array();
58: foreach( $ical AS $e ) {
59: if($e->getStart() >= $start || $e->getRangeEnd() >= $start) {
60: $rtn[] = $e;
61: }
62: }
63: return $rtn;
64: }
65:
66: 67: 68: 69: 70: 71: 72: 73:
74: public static function Sort( $ical, $column ) {
75: if( $ical instanceof iCal ) {
76: $ical = $ical->getEvents();
77: }
78: if( !is_array($ical) ) {
79: throw new Exception('intouch\ical\Query::Sort called with invalid input!');
80: }
81:
82: $cmp = create_function('$a, $b', 'return strcmp($a->getProperty("' . $column . '"), $b->getProperty("' . $column . '"));');
83: usort($ical, $cmp);
84: return $ical;
85: }
86: }
87:
88: