Skip to content

Commit

Permalink
Add GEO field
Browse files Browse the repository at this point in the history
  • Loading branch information
jarofgreen committed Aug 5, 2016
1 parent a3fd2c6 commit 9788388
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/JMBTechnologyLimited/ICalDissect/ICalEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class ICalEvent

protected $exdates = array();

protected $geoLat;

protected $geoLng;

protected $raw = array();

public function __construct(\DateTimeZone $timeZone = null) {
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;
}




Expand Down
62 changes: 62 additions & 0 deletions tests/JMBTechnologyLimited/ICalDissect/GeoTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace JMBTechnologyLimited\ICalDissect;

/**
*
* @link https://github.com/JMB-Technology-Limited/ICalDissect
* @license https://raw.github.com/JMB-Technology-Limited/ICalDissect/master/LICENSE.txt 3-clause BSD
* @copyright (c) 2014, JMB Technology Limited, http://jmbtechnology.co.uk/
* @author James Baster <[email protected]>
*/
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());
}

}

24 changes: 24 additions & 0 deletions tests/JMBTechnologyLimited/ICalDissect/data/GeoExample.ics
Original file line number Diff line number Diff line change
@@ -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:[email protected]
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

0 comments on commit 9788388

Please sign in to comment.