Exemple #1
0
$e->setProperty('rrule', array('FREQ' => 'YEARLY'));
$c->setComponent($e);
$str = $c->createCalendar();
echo $str;
echo "<br />\n\n";
/*
 *   BEGIN:VTODO
 *   UID:19970901T130000Z-123404@host.com
 *   DTSTAMP:19970901T1300Z
 *   DTSTART:19970415T133000Z
 *   DUE:19970416T045959Z
 *   SUMMARY:1996 Income Tax Preparation
 *   CLASS:CONFIDENTIAL
 *   CATEGORIES:FAMILY,FINANCE
 *   PRIORITY:1
 *   STATUS:NEEDS-ACTION
 *   END:VTODO
 */
$c = new vcalendar();
$t = new vtodo();
$t->setProperty('dtstart', '19970415T133000 GMT');
$t->setProperty('due', '19970416T045959 GMT');
$t->setProperty('summary', '1996 Income Tax Preparation');
$t->setProperty('class', 'CONFIDENTIAL');
$t->setProperty('categories', 'FAMILY');
$t->setProperty('categories', 'FINANCE');
$t->setProperty('priority', 1);
$t->setProperty('status', 'NEEDS-ACTION');
$c->setComponent($t);
$str = $c->createCalendar();
echo $str;
/**
 * Render iCal data
 *
 * @param string $name iCalendar name
 * @param array $objects
 * @param boolean $include_project_name
 * @return void
 */
function render_icalendar($name, $objects, $include_project_name = false)
{
    require_once ANGIE_PATH . '/classes/icalendar/iCalCreator.class.php';
    $calendar = new vcalendar();
    //$calendar->setProperty('VERSION', '1.0');
    $calendar->setProperty('X-WR-CALNAME', $name);
    $calendar->setProperty('METHOD', 'PUBLISH');
    $projects = array();
    foreach ($objects as $object) {
        $summary = $object->getName();
        if ($include_project_name) {
            $project_id = $object->getProjectId();
            if (isset($projects[$project_id])) {
                $summary .= ' | ' . $projects[$project_id]->getName();
            } else {
                $project = $object->getProject();
                if (instance_of($project, 'Project')) {
                    $projects[$project_id] = $project;
                    $summary .= ' | ' . $projects[$project_id]->getName();
                }
                // if
            }
            // if
        }
        // if
        switch (strtolower($object->getType())) {
            case 'milestone':
                $start_on = $object->getStartOn();
                $due_on = $object->getDueOn();
                $due_on->advance(24 * 60 * 60, true);
                // One day shift because iCal and Windows Calendar don't include last day
                $start_on_year = $start_on->getYear();
                $start_on_month = $start_on->getMonth() < 10 ? '0' . $start_on->getMonth() : $start_on->getMonth();
                $start_on_day = $start_on->getDay() < 10 ? '0' . $start_on->getDay() : $start_on->getDay();
                $due_on_year = $due_on->getYear();
                $due_on_month = $due_on->getMonth() < 10 ? '0' . $due_on->getMonth() : $due_on->getMonth();
                $due_on_day = $due_on->getDay() < 10 ? '0' . $due_on->getDay() : $due_on->getDay();
                $event = new vevent();
                $event->setProperty('dtstart', array($start_on_year, $start_on_month, $start_on_day), array('VALUE' => 'DATE'));
                $event->setProperty('dtend', array($due_on_year, $due_on_month, $due_on_day), array('VALUE' => 'DATE'));
                $event->setProperty('dtstamp', date('Ymd'));
                $event->setProperty('summary', $summary);
                if ($object->getBody()) {
                    $event->setProperty('description', html_to_text($object->getFormattedBody()) . "\n\n" . lang('Details: ') . $object->getViewUrl());
                } else {
                    $event->setProperty('description', lang('Details') . ': ' . $object->getViewUrl());
                }
                // if
                switch ($object->getPriority()) {
                    case PRIORITY_HIGHEST:
                        $event->setProperty('priority', 1);
                        break;
                    case PRIORITY_HIGH:
                        $event->setProperty('priority', 3);
                        break;
                    case PRIORITY_LOW:
                        $event->setProperty('priority', 7);
                        break;
                    case PRIORITY_LOWEST:
                        $event->setProperty('priority', 9);
                        break;
                    case PRIORITY_ONGOING:
                        $event->setProperty('priority', 11);
                        break;
                    case PRIORITY_HOLD:
                        $event->setProperty('priority', 13);
                        break;
                    default:
                        $event->setProperty('priority', 5);
                }
                // switch
                $calendar->addComponent($event);
                break;
            case 'ticket':
            case 'task':
                $start_on = $object->getCreatedOn();
                $due_on = $object->getDueOn();
                $todo = new vtodo();
                $todo->setProperty('summary', $summary);
                $todo->setProperty('description', $object->getName() . "\n\n" . lang('Details') . ': ' . $object->getViewUrl());
                switch ($object->getPriority()) {
                    case PRIORITY_HIGHEST:
                        $todo->setProperty('priority', 1);
                        break;
                    case PRIORITY_HIGH:
                        $todo->setProperty('priority', 3);
                        break;
                    case PRIORITY_LOW:
                        $todo->setProperty('priority', 7);
                        break;
                    case PRIORITY_LOWEST:
                        $todo->setProperty('priority', 9);
                        break;
                    case PRIORITY_ONGOING:
                        $todo->setProperty('priority', 11);
                        break;
                    case PRIORITY_HOLD:
                        $todo->setProperty('priority', 13);
                        break;
                    default:
                        $todo->setProperty('priority', 5);
                }
                // switch
                if (instance_of($due_on, 'DateValue')) {
                    $due_on_year = $due_on->getYear();
                    $due_on_month = $due_on->getMonth() < 10 ? '0' . $due_on->getMonth() : $due_on->getMonth();
                    $due_on_day = $due_on->getDay() < 10 ? '0' . $due_on->getDay() : $due_on->getDay();
                    $todo->setProperty('due', $due_on_year, $due_on_month, $due_on_day);
                }
                // if
                $calendar->addComponent($todo);
                break;
            default:
                break;
        }
    }
    // foreach
    $cal = $calendar->createCalendar();
    header('Content-Type: text/calendar; charset=UTF-8');
    header('Content-Disposition: attachment; filename="' . $name . '.ics"');
    header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
    header('Pragma: no-cache');
    print $cal;
    die;
}