00001 <?php
00013 class SVEvent {
00014 const FREQ_NONE = 'NONE';
00015 const FREQ_YEAR = 'YEARLY';
00016 const FREQ_MONTH = 'MONTHLY';
00017 const FREQ_WEEK = 'WEEKLY';
00018 const FREQ_DAY = 'DAILY';
00019
00020 public $startDate = '00000000';
00021 public $startTime = '000000';
00022 public $endDate = '00000000';
00023 public $endTime = '000000';
00024
00025 public $allDay = false;
00026 public $frequency = '';
00027 public $endRepeat = '';
00028
00029 public $description;
00030 public $summary;
00031 public $uid;
00032 public $sequence;
00033
00039 public function setStartDate($date) {
00040 $date = str_replace('-', '', $date);
00041 $this->startDate = $date;
00042 }
00043
00049 public function setEndDate($date) {
00050 $date = str_replace('-', '', $date);
00051 $this->endDate = $date;
00052 }
00053
00059 public function setAllDay($allDay) {
00060 $this->allDay = $allDay;
00061 }
00062
00077 public function setRepeat($frequency, $endRepeat='') {
00078
00079
00080 if ($frequency != '' && $frequency != self::FREQ_NONE) {
00081 $this->frequency = $frequency;
00082 if ($endRepeat != '') {
00083 $this->endRepeat = "UNTIL=".str_replace('-', '', $endRepeat);
00084 }
00085 }
00086 }
00087
00096 public function render() {
00097 $description = ($this->description == '') ? '' : '
00098 DESCRIPTION: ' . $this->description;
00099 $dtstamp = date('Ymd').'T'.date('His');
00100 if (!$this->allDay) {
00101 $dtstart = 'TZID=US/Eastern:' . $this->startDate . 'T' . $this->startTime;
00102 $dtend = 'TZID=US/Eastern:' . $this->endDate . 'T' . $this->endTime;
00103 } else {
00104 $dtstart = 'VALUE=DATE:' . $this->startDate;
00105 $dtend = 'VALUE=DATE:' . $this->endDate;
00106 }
00107 $recurrence = '';
00108 if ($this->frequency != '') {
00109 $recurrence = "RRULE:FREQ=$this->frequency;";
00110 if ($this->frequency == self::FREQ_MONTH) {
00111 $recurrence.='BYMONTHDAY='.substr($this->startDate, 6, 2).';';
00112 }
00113 $recurrence.=$this->endRepeat;
00114 }
00115 $return = <<<END
00116
00117 BEGIN:VEVENT
00118 SEQUENCE:0
00119 DTSTART;$dtstart
00120 DTEND;$dtend
00121 SUMMARY:$this->summary$description
00122 UID:$this->uid
00123 DTSTAMP:$dtstamp
00124 $recurrence
00125 END:VEVENT
00126 END;
00127 return $return;
00128 }
00129 }
00130 ?>