Skip to content

Commit

Permalink
updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jasvrcek committed Jun 8, 2016
1 parent 5fb1969 commit 4dca5c6
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Object-oriented php library for creating (and eventually reading) .ics iCal file

* This project does not yet support all functionality of the .ics format.

## Usage
## 1. Basic Usage

use Jsvrcek\ICS\Model\Calendar;
use Jsvrcek\ICS\Model\CalendarEvent;
Expand Down Expand Up @@ -56,6 +56,57 @@ Object-oriented php library for creating (and eventually reading) .ics iCal file
//output .ics formatted text
echo $calendarExport->getStream();

## 2. Batch Event Provider

The basic usage example will build the complete .ics string in memory and then echo it all
at once. This will use a lot of memory for a large calendar. The following example shows
how to make CalendarExport::getStream() output each line of the ics file as it is generated, as well as how to set a provider
for building the event list of a calendar in batches during export.

(Thank you to Thijs Wijnmaalen at [thijsw](https://github.com/thijsw/ics-large) for inspiration on the batch provider code.)

use Jsvrcek\ICS\Model\Calendar;
use Jsvrcek\ICS\Model\CalendarEvent;

use Jsvrcek\ICS\Utility\Formatter;
use Jsvrcek\ICS\CalendarStream;
use Jsvrcek\ICS\CalendarExport;

//setup calendar
$calendar = new Calendar();
$calendar->setProdId('-//My Company//Cool Calendar App//EN');

//setup event provider to add events in batches during event iteration in $calendarExport->getStream()
$calendar->setEventsProvider(function ($startKey) use ($myDatabase) {

//pseudo-code to get a batch of events from database
$eventDataArray = $myDatabase->getEventsBatch($startKey);
$events = array();
foreach ($eventDataArray as $row)
{
$event = new CalendarEvent();
$event->setStart($row['start_date'])
->setSummary($row['summary'])
->setUid($row['event_uid']);
$events[] = $event;
}
return $events;
});

//setup exporter
$calendarExport = new CalendarExport(new CalendarStream, new Formatter());
$calendarExport->addCalendar($calendar);

//set exporter to send items directly to output instead of storing in memory
$calendarExport->getStreamObject()->setDoImmediateOutput(true);

//output .ics formatted text
echo $calendarExport->getStream();

## Todos

* Jsvrcek\ICS\Model\CalendarAlarm
Expand Down

2 comments on commit 4dca5c6

@resing
Copy link

@resing resing commented on 4dca5c6 Jul 27, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have bug about ->setLocations because when l'was setting this parametres with array they generating error about Call to a member function getUri() on string.
In CalenderExport.php at line 162 you have this :
foreach ($event->getLocations() as $location)
{
$this->stream
->addItem('LOCATION'.$location->getUri().$location->getLanguage().':'.$location->getName());
}

@jasvrcek
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@resing how are you adding locations to your events? Can you post some example code?

Please sign in to comment.