jsvrcek/ics-bundle

This bundle provides a dependency injection wrapper for the JsvrcekICS iCal library

Installs: 111 873

Dependents: 0

Suggesters: 0

Security: 0

Stars: 11

Watchers: 3

Forks: 4

Open Issues: 5

Type:symfony-bundle

1.1 2022-11-28 17:54 UTC

This package is auto-updated.

Last update: 2024-12-30 15:17:24 UTC


README

Symfony Bundle providing dependency injection for the Jsvrcek\ICS library, which is for creating iCal .ics files.

Installation

composer req jsvrcek/ics-bundle

Usage

    namespace App\Services;

    use Jsvrcek\ICS\CalendarExport;
    use Jsvrcek\ICS\Model\Calendar;
    use Jsvrcek\ICS\Model\CalendarEvent;
    use Jsvrcek\ICS\Model\Relationship\Attendee;
    use Jsvrcek\ICS\Utility\Formatter;

    private Formatter $formatter;
    private CalendarExport $calendarExport;

    class MyService
    {

    public function __construct(Formatter $formatter, CalendarExport $calendarExport) {

        $this->formatter = $formatter;
        $this->calendarExport = $calendarExport;
    }
// or inject them into the controller
        public function calendarAction(Formatter $formatter, CalendarExport $calendarExport)
        {
            $eventOne = new CalendarEvent();
            $eventOne->setStart(new \DateTime())
                ->setSummary('Family reunion')
                ->setUid('event-uid');

            //add an Attendee
            $attendee = new Attendee($formatter);
            $attendee->setValue('moe@example.com')
                ->setName('Moe Smith');
            $eventOne->addAttendee($attendee);

            // Add event to CalendarExport
            $calendarExport->setCalendars( [
                (new Calendar)->setTimezone( new DateTimeZone(date_default_timezone_get()) )
                    ->addEvent( $eventOne )
            ] );
            
            $response = new Response($calendarExport->getStream());
            $response->headers->set('Content-Type', 'text/calendar');
            
            return $response;
        }
    }