ICSGenerator - The module can generate basic ICS calendar strings and files

Overview

ICSGenerator

The module can generate basic ICS calendar strings and files.

The module simply extends WireData. It has these properties and default values:

$this->set('date', 'now');
$this->set('dateEnd', 'now + 60 minutes');
$this->set('summary', 'ICS Calendar File');
$this->set('description', '');
$this->set('location', '');
$this->set('url', '');
$this->set('timezone', new \DateTimeZone(date_default_timezone_get()));
  • date / dateEnd should be a PHP DateTime object or a string.
  • Date strings will be passed to DateTime constructor.
  • Date strings will use the set timezone.
  • Final output will be converted to UTC (Z timestamp)
// get the module
$icsgen = wire()->modules->IcsGenerator;

// set single properties (date strings)
$icsgen->set('date',    '2033-12-24 12:00');
$icsgen->set('dateEnd', '2033-12-24 14:00');

// set single properties (DateTime)
$icsgen->set('date',    new \DateTime('2033-12-24 12:00'));
$icsgen->set('dateEnd', new \DateTime('2033-12-24 14:00'));

// the set timezone will only impact time strings!
$icsgen->set('timezone', new \DateTimeZone('Europe/Berlin'));
$icsgen->set('date',    'now');
$icsgen->set('dateEnd', 'now + 60 minutes');

// set timezone will be ignored when string is a unix timestamp or contains a timezone
$icsgen->set('date',    '@946684800');
$icsgen->set('date',    '2010-01-28T15:00:00+02:00');

// set timezone will not impact DateTime!
// construct your DateTime with DateTimeZone instead
$icsgen->set('date',    new \DateTime('2033-12-24 12:00', new \DateTimeZone('Asia/Dubai')));
$icsgen->set('dateEnd', new \DateTime('2033-12-24 12:00', new \DateTimeZone('Europe/Paris')));

// set multiple properties at once
$icsgen->setArray(array(
    'date' => '2033-12-24 12:00',
    'dateEnd' => '2033-12-24 14:00',
    'summary' => 'Event Title',
    'description' => 'Event Description',
));

// get ICS string
$str = $icsgen->getString();

// get ICS object
$ics = $icsgen->getICS();

// get path to a temporary .ics file
// using wire()->files->tempDir
$path = $icsgen->getFile();

// get path to a temporary .ics file by ID
// this is useful if you need the same ICS multiple times in one request
// (same file id will only be created once)
$path = $icsgen->getFileByID('christmas-2033');

// example: send email with ics file
$mail = wireMail();
$mail->attachment($path, 'calendar.ics');
$mail->to($user->email);
$mail->subject('ICS Demo');
$mail->body('This is a ICS demo.');
$numSent = $mail->send();

Code is heavily based on https://gist.github.com/jakebellacera/635416 with some improvements.

PRs are open.

You might also like...
Create executable strings using a fluent API.

command-builder A PHP class to build executable with using fluent API. Summary About Features Installation Examples Compatibility table Tests About I

A comprehensive library for generating differences between two strings in multiple formats (unified, side by side HTML etc). Based on the difflib implementation in Python

PHP Diff Class Introduction A comprehensive library for generating differences between two hashable objects (strings or arrays). Generated differences

Shortest Path - have a function ShortestPath (strArr) take strArr which will be an array of strings which models a non-looping Graph.

Have the function ShortestPath(strArr) take strArr which will be an array of strings which models a non-looping Graph

Laminas\Text is a component to work on text strings

laminas-text This package is considered feature-complete, and is now in security-only maintenance mode, following a decision by the Technical Steering

PHP Class Encoding featuring popular Encoding::toUTF8() function --formerly known as forceUTF8()-- that fixes mixed encoded strings.
PHP Class Encoding featuring popular Encoding::toUTF8() function --formerly known as forceUTF8()-- that fixes mixed encoded strings.

forceutf8 PHP Class Encoding featuring popular \ForceUTF8\Encoding::toUTF8() function --formerly known as forceUTF8()-- that fixes mixed encoded strin

Zend\Text is a component to work on text strings from Zend Framework

zend-text Repository abandoned 2019-12-31 This repository has moved to laminas/laminas-text. Zend\Text is a component to work on text strings. It cont

Strings Package provide a fluent, object-oriented interface for working with multibyte string

Strings Package provide a fluent, object-oriented interface for working with multibyte string, allowing you to chain multiple string operations together using a more readable syntax compared to traditional PHP strings functions.

Replace, concat strings or change number fields permanently using Grid Options
Replace, concat strings or change number fields permanently using Grid Options

It's Pimcore Bundle to replace ,concat strings or change number fields permanently using Grid Options. It will save replaced strings directly in object.

PHP class for parsing user agent strings (HTTP_USER_AGENT).

PHP class for parsing user agent strings (HTTP_USER_AGENT). Includes mobile checks, bots and banned bots checks, browser types/versions and more. Based on browscap (via phpbrowscap), Mobile_Detect and ua-parser. Created for high traffic websites and fast batch processing.

Owner
Timo Hausmann
Timo Hausmann
Basic class library to read, write and view files using PHP.

File Basic class library to read, write and view files using PHP. Supported PHP Versions Build Status (dev) Main Aim of The Library The main aim of th

WebFiori 2 May 13, 2022
Connect Nios4 with Google Calendar via PHP

Nios4_Google_Calendar Connect Nios4 with Google Calendar via PHP ISTRUZIONI INTEGRAZIONE GOOGLE CALENDAR CON NIOS4. Guida per l'integrazione del calen

null 2 Sep 23, 2021
TeamCal Pro is a legacy web application of a day-based calendar

TeamCal Pro is a legacy web application of a day-based calendar. It's generic purpose is the absence management of project teams, more precisely of their members.

George Lewe 1 Jan 7, 2022
Dobren Dragojević 6 Jun 11, 2023
This module adds a command to easily generate "modules" in Laravel and install them using composer.

Laravel Module Create This module adds a command to easily generate "modules" in Laravel and install them using composer Installation Simply install t

null 2 Feb 18, 2022
PHP Japanese string helper functions for converting Japanese strings from full-width to half-width and reverse. Laravel Rule for validation Japanese string only full-width or only half-width.

Japanese String Helpers PHP Japanese string helper functions for converting Japanese strings from full-width to half-width and reverse. Laravel Rule f

Deha 54 Mar 22, 2022
Parse DSN strings into value objects to make them easier to use, pass around and manipulate

DSN parser Parse DSN strings into value objects to make them easier to use, pass around and manipulate. Install Via Composer composer require nyholm/d

Tobias Nyholm 77 Dec 13, 2022
Allows generate class files parse from json and map json to php object, including multi-level and complex objects;

nixihz/php-object Allows generate class files parse from json and map json to php object, including multi-level and complex objects; Installation You

zhixin 2 Sep 9, 2022
Decimal handling as value object instead of plain strings.

Decimal Object Decimal value object for PHP. Background When working with monetary values, normal data types like int or float are not suitable for ex

Spryker 16 Oct 24, 2022