Overview

Namespaces

  • intouch
    • ical

Classes

  • Duration
  • Factory
  • Freq
  • iCal
  • Line
  • Parser
  • Query
  • Recurrence
  • VCalendar
  • VEvent
  • VTimeZone
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php // BUILD: Remove line
 2: 
 3: namespace intouch\ical;
 4: 
 5: /**
 6:  *
 7:  * A collection of functions to query the events in a calendar.
 8:  *
 9:  * @author Morten Fangel (C) 2008
10:  * @author Michael Kahn (C) 2013
11:  * @license http://creativecommons.org/licenses/by-sa/2.5/dk/deed.en_GB CC-BY-SA-DK
12:  */
13: class Query {
14:     /**
15:      * Returns all events from the calendar between two timestamps
16:      *
17:      * Note that the events returned needs only slightly overlap.
18:      *
19:      * @param intouch\ical\iCal |array $ical The calendar to query
20:      * @param int $start
21:      * @param int $end
22:      * @return intouch\ical\VEvent[]
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:      * Returns all events from the calendar after a given timestamp
44:      *
45:      * @param intouch\ical\iCal|array $ical The calendar to query
46:      * @param int $start
47:      * @return intouch\ical\VEvent[]
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:      * Sorts the events from the calendar after the specified column.
68:      * Column can be all valid entires that getProperty can return.
69:      * So stuff like uid, start, end, summary etc.
70:      * @param intouch\ical\iCal|array $ical The calendar to query
71:      * @param string $column
72:      * @return intouch\ical\VEvent[]
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: 
intouch-iCalendar API documentation generated by ApiGen 2.8.0