dawulli/ical-bundle

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

v2.0.2 2023-08-18 07:03 UTC

This package is auto-updated.

Last update: 2024-09-18 09:41:19 UTC


README

此bundle用于创建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,有重大更改

当前状态

此bundle在版本1.0下处于稳定状态;

安装

在您的composer.json中添加BOMOIcalBundle

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

现在运行以下步骤让composer下载bundle:

$ 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();

配置示例

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