eluceo/ical 如何删除事件

问题描述 投票:0回答:0

我正在使用 eluceo/ical 将应用程序中的事件添加到我的日历中。这很好用,我已经成功地将多个事件添加到我的日历中,但是如果我从应用程序中删除一个事件,它就会被日历保留。我怎样才能删除事件?

考虑以下创建日历的函数。

    public function createUserCalendar(): Component
    {
        // Get the shortname of the user
        $boom = explode( ' ', $this->name );
        $shortName = $boom[0];

        $events = [];
        $pending = $this->calendarPending()->get();

        foreach ( $pending as $day ) {
            $eventUid = 'ecl-' . $day->user_id . '-' . $day->id;
            $uniqueIdentifier = new UniqueIdentifier($eventUid);

            if ( $day->half_days === 1 ) {
                $summary = $shortName . ' Half day ' . $day->period;
            } else {
                $summary = $shortName . ' Full day';
            }
            $event = new Event( $uniqueIdentifier );

            $firstDay = new Date(\DateTimeImmutable::createFromFormat( 'Y-m-d', $day->date ));
            $lastDay = new Date(\DateTimeImmutable::createFromFormat( 'Y-m-d', $day->date));

            $occurrence = new MultiDay($firstDay, $lastDay);

            $event->setSummary( $summary )
                ->setStatus( EventStatus::CONFIRMED())
                ->setDescription( $day->description )
                ->setOccurrence( $occurrence );

            $events[] = $event;
        }

        $cancelled = $this->calendarCancelled()->get();

        foreach ( $cancelled as $day ) {
            $eventUid = 'ecl-' . $day->user_id . '-' . $day->id;
            $uniqueIdentifier = new UniqueIdentifier($eventUid);

            $event = new Event( $uniqueIdentifier );
            $firstDay = new Date(\DateTimeImmutable::createFromFormat( 'Y-m-d', $day->date ));
            $lastDay = new Date(\DateTimeImmutable::createFromFormat( 'Y-m-d', $day->date));

            $occurrence = new MultiDay($firstDay, $lastDay);

            $event->setOccurrence( $occurrence )->setStatus( EventStatus::CANCELLED());

            $events[] = $event;
        }

        // 2. Create Calendar domain entity
        $calendar = new Calendar( $events );

        // 3. Transform domain entity into an iCalendar component
        return (new CalendarFactory())->createCalendar( $calendar );
    }

如果我运行它并添加到日历中,我会看到所有日期都按预期正确添加。如果我随后取消活动并重新提交日历,它仍会显示该活动。那么如何将其从我的日历中删除和/或取消此活动?

谢谢

*** 编辑 ***

这是我生成的 ics 文件中包含取消事件的示例。正如下面评论中提到的,如果有帮助,我正在使用 Laravel9 和 php8.1,eluceo/ical 的文档可以在 https://ical.poerschke.nrw/docs

上找到
BEGIN:VCALENDAR
PRODID:-//eluceo/ical//2.0/EN
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VEVENT
UID:ecl-77-25
DTSTAMP:20230222T153729Z
SUMMARY:Room 8 booking
DESCRIPTION:Booking room 8
DTSTART:20230224
DTEND:20230225
STATUS:CONFIRMED
END:VEVENT
BEGIN:VEVENT
UID:ecl-77-7
DTSTAMP:20230222T153729Z
DTSTART:20230315
DTEND:20230316
STATUS:CANCELLED
END:VEVENT
END:VCALENDAR
php icalendar
© www.soinside.com 2019 - 2024. All rights reserved.