diff --git a/src/CreepyCoder.php b/src/CreepyCoder.php index f13b0d6..ae36e07 100644 --- a/src/CreepyCoder.php +++ b/src/CreepyCoder.php @@ -40,3 +40,7 @@ require dirname(__FILE__).DIRECTORY_SEPARATOR.'WriteDayOfWeekData.php'; $dataManager->writeData(new WriteDayOfWeekData(array())); +require dirname(__FILE__).DIRECTORY_SEPARATOR.'WriteICalData.php'; +$dataManager->writeData(new WriteICalData(array('file'=>'out.ical'))); + + diff --git a/src/WriteICalData.php b/src/WriteICalData.php new file mode 100644 index 0000000..bbc4985 --- /dev/null +++ b/src/WriteICalData.php @@ -0,0 +1,55 @@ +. +**/ + + +class WriteICalData extends BaseWriteClass { + + public function write() { + + if (!$handle = fopen($this->configData['file'], 'w')) { + throw new Exception("Cannot open file"); + } + + $this->fwrite($handle,"BEGIN:VCALENDAR\r\n"); + $this->fwrite($handle,"VERSION:2.0\r\n"); + $this->fwrite($handle,"PRODID:-//hacksw/handcal//NONSGML v1.0//EN\r\n"); + + foreach($this->dataManager->getData() as $i=>$item) { + $this->fwrite($handle,"BEGIN:VEVENT\r\n"); + $this->fwrite($handle,"UID:uid".$i."@example.com\r\n"); + $this->fwrite($handle,"SUMMARY: Event\r\n"); + $this->fwrite($handle,"DTSTAMP:".$item->getDateTimeAs("Ymd\THis\Z")."\r\n"); + $this->fwrite($handle,"DTSTART:".$item->getDateTimeAs("Ymd\THis\Z")."\r\n"); + $this->fwrite($handle,"DTEND:".$item->getDateTimeAs("Ymd\THis\Z")."\r\n"); + $this->fwrite($handle,"END:VEVENT\r\n"); + } + + $this->fwrite($handle,"END:VCALENDAR\r\n"); + + fclose($handle); + + } + + private function fwrite($handle,$data) { + if (fwrite($handle, $data) === FALSE) { + throw new Exception("Cannot write to file"); + } + } + +} +