bomo/ical-bundle

为 Symfony 2, 3, 4 和 5 创建 ics URL 或文件

v2.0.2 2021-11-16 11:13 UTC

README

此包用于创建 ics 文件或 URL,以填充共享日历的事件。

注意

版本 2.0 引入了 kigkonsult 的新主要版本。

概述

<?php
public function getIcs()
{
    $provider = $this->get('bomo_ical.ics_provider');

    $tz = $provider->createTimezone();
    $tz
        ->setTzid('Europe/Paris')
        ->setXProp('X-LIC-LOCATION', $tz->getTzid())
        ;

    $cal = $provider->createCalendar($tz);

    $cal
        ->setName('My cal1')
        ->setDescription('Foo')
        ;

    $datetime = new \Datetime('now');
    $event = $cal->newEvent();
    $event
        ->setStartDate($datetime)
        ->setEndDate($datetime->modify('+5 hours'))
        ->setName('Event 1')
        ->setDescription('Desc for event')
        ->setAttendee('foo@bar.me')
        ->setAttendee('John Do')
        ;

    $alarm = $event->newAlarm();
    $alarm
        ->setAction('DISPLAY')
        ->setDescription($event->getDescription())
        ->setTrigger('-PT2H') //See Dateinterval string format
        ;

    // All Day event
    $event = $cal->newEvent();
    $event
        ->isAllDayEvent()
        ->setStartDate($datetime)
        ->setEndDate($datetime->modify('+10 days'))
        ->setName('All day event')
        ->setDescription('All day visualisation')
        ;

    $calStr = $cal->returnCalendar();

    return new Response(
        $calStr,
        200,
        array(
            'Content-Type' => 'text/calendar; charset=utf-8',
            'Content-Disposition' => 'attachment; filename="calendar.ics"',
        )
    );
}

版本

  • 版本 1.0: Kigkonsult 2.24
  • 版本 2.0: Kigkonsult >2.24,有重大更改

实际状态

此包在 1.0 版本中处于 稳定 状态;

安装

在您的 composer.json 中添加 BOMOIcalBundle

{
    "require": {
        "bomo/ical-bundle": "1.0.*"
    }
}

现在运行以下步骤让 composer 下载该包

$ php composer.phar update bomo/ical-bundle

AppKernel.php

$bundles = array(
    ...
    new BOMO\IcalBundle\BOMOIcalBundle(),
);

用户指南

所有对象都可以由提供者管理。但对象需要附加。

附加到日历的事件

附加到事件上的警报

为了简化使用,对象是创建子功能的代理方法。

$alarm = $event->newAlarm();
$alarm
    ->set[...]
    [...]
    ;

与以下严格相同

$alarm = $provider->createAlarm();
$alarm
    ->set[...]
    [...]
    ;
$event->attachAlarm($alarm);

Outlook 兼容性

Outlook 不支持参数 "x-wr-timezone"。为了防止将其添加到 ics 中,createCalendar 有一个新参数来定义是否在 ics 中包含时区。

$ical = $cal = $this->provider->createCalendar(null, true);

对象引用

提供者

Timezone function createTimezone();
Calendar function createCalendar();
Event function createEvent();
Alarm function createAlarm();

时区

Timezone function __construct(array $config=null);
string function getTzid();
this function setTzid($tz);
vtimezone function getTimezone();

日历

Calendar function __construct(array $config);
this function setName($name);
this function setDescription($desc);
Event function newEvent(); //Directly attached to this Calendar
this function attachEvent(Event $event)
string function returnCalendar();
vcalendar function getCalendar();

事件

Event function __construct(mixed $param);
this function setStartDate(Datetime $date);
this function setEndDate(Datetime $date);
this function isAllDayEvent();
this function setName($name);
this function setLocation($loc);
this function setDescription($desc);
this function setComment($comment);
this function setAttendee($attendee);
this function setOrganizer($org);
Alarm function newAlarm(); //Directly attached to this Event
this function attachAlarm(Alarm $alarm);
vevent function getEvent();

警报

Alarm function __construct(mixed $param);
this function setAction($action); //Currently, only 'DISPLAY' action is setted.
this function setDescription($desc);
this function setTrigger($trigger);
valarm function getAlarm();

配置示例

目前,此包不需要任何配置部分。