diff --git a/src/JMBTechnologyLimited/ICalDissect/ICalEvent.php b/src/JMBTechnologyLimited/ICalDissect/ICalEvent.php index 26f92e9..de84ff5 100644 --- a/src/JMBTechnologyLimited/ICalDissect/ICalEvent.php +++ b/src/JMBTechnologyLimited/ICalDissect/ICalEvent.php @@ -37,6 +37,10 @@ class ICalEvent protected $exdates = array(); + protected $geoLat; + + protected $geoLng; + protected $raw = array(); public function __construct(\DateTimeZone $timeZone = null) { @@ -72,7 +76,14 @@ public function processLine($keyword, $value, $keywordProperties = "") { $this->ical_rrule = $rrule; } else if ($keyword == "EXDATE") { $this->exdates[] = new ICalExDate($value, $keywordProperties); - } + } else if ($keyword == "GEO") { + $bits = explode(";", $value); + if (count($bits) == 2) { + $this->geoLat = $bits[0]; + $this->geoLng = $bits[1]; + } + } + if (!isset($this->raw[strtoupper($keyword)])) { $this->raw[strtoupper($keyword)] = array(); } @@ -221,6 +232,18 @@ public function getRaw($keyword = null) } } + public function hasGeo() { + return (boolean)($this->geoLat && $this->geoLng); + } + + public function getGeoLat() { + return $this->geoLat; + } + + public function getGeoLng() { + return $this->geoLng; + } + diff --git a/tests/JMBTechnologyLimited/ICalDissect/GeoTest.php b/tests/JMBTechnologyLimited/ICalDissect/GeoTest.php new file mode 100644 index 0000000..4a4e432 --- /dev/null +++ b/tests/JMBTechnologyLimited/ICalDissect/GeoTest.php @@ -0,0 +1,62 @@ + + */ +class GeoTest extends \PHPUnit_Framework_TestCase { + + function dataForTestGeo1() { + return array( + array('GeoExample.ics',37.5739497,-85.7399606), + ); + } + + /** + * @dataProvider dataForTestGeo1 + */ + function testGeo1 ($filename, $lat, $lng) { + $parser = new ICalParser(); + $this->assertTrue($parser->parseFromFile(dirname(__FILE__)."/data/".$filename)); + + $events = $parser->getEvents(); + $this->assertEquals(1, count($events)); + + /** @var $event ICalEvent */ + $event = $events[0]; + + $this->assertTrue($event->hasGeo()); + $this->assertEquals($lat, $event->getGeoLat()); + $this->assertEquals($lng, $event->getGeoLng()); + + } + + function dataForTestNoGeo1() { + return array( + array('exdate1.ics'), + ); + } + + /** + * @dataProvider dataForTestNoGeo1 + */ + function testNoGeo1 ($filename, $lat, $lng) { + $parser = new ICalParser(); + $this->assertTrue($parser->parseFromFile(dirname(__FILE__)."/data/".$filename)); + + $events = $parser->getEvents(); + $this->assertEquals(1, count($events)); + + /** @var $event ICalEvent */ + $event = $events[0]; + + $this->assertFalse($event->hasGeo()); + } + +} + diff --git a/tests/JMBTechnologyLimited/ICalDissect/data/GeoExample.ics b/tests/JMBTechnologyLimited/ICalDissect/data/GeoExample.ics new file mode 100644 index 0000000..a03f1cd --- /dev/null +++ b/tests/JMBTechnologyLimited/ICalDissect/data/GeoExample.ics @@ -0,0 +1,24 @@ +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//ZContent.net//Zap Calendar 1.0//EN +CALSCALE:GREGORIAN +METHOD:PUBLISH +BEGIN:VEVENT +SUMMARY:Abraham Lincoln +UID:2008-04-28-04-15-56-62-@americanhistorycalendar.com +SEQUENCE:0 +STATUS:CONFIRMED +TRANSP:TRANSPARENT +RRULE:FREQ=YEARLY;INTERVAL=1;BYMONTH=2;BYMONTHDAY=12 +DTSTART:20080212 +DTEND:20080213 +DTSTAMP:20150421T141403 +CATEGORIES:U.S. Presidents,Civil War People +LOCATION:Hodgenville\, Kentucky +GEO:37.5739497;-85.7399606 +DESCRIPTION:Born February 12\, 1809\nSixteenth President (1861-1865)\n\n\n + \nhttp://AmericanHistoryCalendar.com +URL:http://americanhistorycalendar.com/peoplecalendar/1,328-abraham-lincol + n +END:VEVENT +END:VCALENDAR