Skip to content

Commit

Permalink
Merge pull request #95 from sekjal/Issue58
Browse files Browse the repository at this point in the history
Replace ICSReader with ICS-Parser
  • Loading branch information
unclecheese committed Mar 4, 2016
2 parents 5e8eb7c + b1d71b6 commit c1b5a84
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 218 deletions.
27 changes: 11 additions & 16 deletions code/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,31 +347,30 @@ public function newRecursionDateTime($recurring_event_datetime, $start_date) {


public function getFeedEvents($start_date, $end_date) {
$start = sfDate::getInstance($start_date);
$start = new DateTime($start_date);
// single day views don't pass end dates
if ($end_date) {
$end = sfDate::getInstance($end_date);
$end = new DateTime($end_date);
} else {
$end = $start;
}

$feeds = $this->Feeds();
$feedevents = new ArrayList();
foreach( $feeds as $feed ) {
$feedreader = new ICSReader( $feed->URL );
$events = $feedreader->getEvents();
$feedreader = new ICal( $feed->URL );
$events = $feedreader->events();
foreach ( $events as $event ) {
// translate iCal schema into CalendarAnnouncement schema (datetime + title/content)
$feedevent = new CalendarAnnouncement;
$feedevent->Title = $event['SUMMARY'];
if ( isset($event['DESCRIPTION']) ) {
$feedevent->Content = $event['DESCRIPTION'];
}

$startdatetime = $this->iCalDateToDateTime($event['DTSTART']);
$enddatetime = $this->iCalDateToDateTime($event['DTEND']);
if ( ($startdatetime->get() < $start->get() && $enddatetime->get() < $start->get())
|| $startdatetime->get() > $end->get() && $enddatetime->get() > $end->get()) {
$startdatetime = $this->iCalDateToDateTime($event['DTSTART']);//->setTimezone(new DateTimeZone($this->stat('timezone')));
$enddatetime = $this->iCalDateToDateTime($event['DTEND']);//->setTimezone(new DateTimeZone($this->stat('timezone')));
if ( ($startdatetime < $start && $enddatetime < $start)
|| $startdatetime > $end && $enddatetime > $end) {
// do nothing; dates outside range
} else {
$feedevent->StartDate = $startdatetime->format('Y-m-d');
Expand All @@ -388,16 +387,12 @@ public function getFeedEvents($start_date, $end_date) {
}

public function iCalDateToDateTime($date) {
date_default_timezone_set($this->stat('timezone'));
$date = str_replace('T', '', $date);//remove T
$date = str_replace('Z', '', $date);//remove Z
$date = strtotime($date);
$date = $date + date('Z');
return sfDate::getInstance($date);
$dt = new DateTime($date);
$dt->setTimeZone( new DateTimezone($this->stat('timezone')) );
return $dt;
}



public function getAllCalendars() {
$calendars = new ArrayList();
$calendars->push($this);
Expand Down
201 changes: 0 additions & 201 deletions code/ICSReader.php

This file was deleted.

3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"require": {
"php": ">=5.3.2",
"silverstripe/framework": ">=3.1",
"silverstripe/cms": ">=3.1"
"silverstripe/cms": ">=3.1",
"johngrogg/ics-parser" : "*"
},
"support": {
"issues": "https://github.com/unclecheese/silverstripe-event-calendar/issues"
Expand Down

0 comments on commit c1b5a84

Please sign in to comment.