Improved SG_iCal_Query and added run-time inclusion of it.

master
fangel 2008-03-25 18:26:52 +00:00
rodzic 9a6ac5a6fa
commit 3129a15965
2 zmienionych plików z 52 dodań i 6 usunięć

Wyświetl plik

@ -40,6 +40,7 @@ class SG_iCalReader {
require_once dirname(__FILE__) . '/helpers/SG_iCal_Factory.php'; // BUILD: Remove line
require_once dirname(__FILE__) . '/helpers/SG_iCal_Line.php'; // BUILD: Remove line
require_once dirname(__FILE__) . '/helpers/SG_iCal_Query.php'; // BUILD: Remove line
}
/**

Wyświetl plik

@ -10,22 +10,67 @@
class SG_iCal_Query {
/**
* Returns all events from the calendar between two timestamps
*
* @param SG_iCalReader $ical The calendar to query
*
* Note that the events returned needs only slightly overlap.
*
* @param SG_iCalReader|array $ical The calendar to query
* @param int $start
* @param int $end
* @return SG_iCal_VEvent[]
*/
public static function Between( SG_iCalReader $ical, $start, $end ) {
$evs = $ical->getEvents();
public static function Between( $ical, $start, $end ) {
if( $ical instanceof SG_iCalReader ) {
$evs = $ical->getEvents();
}
if( !is_array($evs) ) {
throw new Exception('SG_iCal_Query::Between called with invalid input!');
}
$rtn = array();
foreach( $evs AS $e ) {
if( ($start < $e->getStart() && $e->getStart() < $end)
|| ($start < $e->getEnd() && $e->getEnd() < $end) ) {
if( ($start <= $e->getStart() && $e->getStart() < $end)
|| ($start < $e->getEnd() && $e->getEnd() <= $end) ) {
$rtn[] = $e;
}
}
return $rtn;
}
/**
* Returns all events from the calendar after a given timestamp
*
* @param SG_iCalReader|array $ical The calendar to query
* @param int $start
* @return SG_iCal_VEvent[]
*/
public static function After( $ical, $start ) {
if( $ical instanceof SG_iCalReader ) {
$evs = $ical->getEvents();
}
if( !is_array($ical) ) {
throw new Exception('SG_iCal_Query::After called with invalid input!');
}
$rtn = array();
foreach( $ical AS $e ) {
if( $start <= $e->getStart() ) {
$rtn[] = $e;
}
}
return $rtn;
}
public static function Sort( $ical, $column ) {
if( $ical instanceof SG_iCalReader ) {
$evs = $ical->getEvents();
}
if( !is_array($ical) ) {
throw new Exception('SG_iCal_Query::Sort called with invalid input!');
}
$cmp = create_function('$a, $b', 'return strcmp($a->getProperty("' . $column . '"), $b->getProperty("' . $column . '"));');
usort($ical, $cmp);
return $ical;
}
}