ical renderer
authorChristian Weiske <cweiske@cweiske.de>
Fri, 21 Mar 2014 05:52:42 +0000 (06:52 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Fri, 21 Mar 2014 05:52:42 +0000 (06:52 +0100)
src/bdrem/Renderer/Ical.php [new file with mode: 0644]
src/bdrem/UserInterface.php

diff --git a/src/bdrem/Renderer/Ical.php b/src/bdrem/Renderer/Ical.php
new file mode 100644 (file)
index 0000000..019e218
--- /dev/null
@@ -0,0 +1,71 @@
+<?php
+/**
+ * Part of bdrem
+ *
+ * PHP version 5
+ *
+ * @category  Tools
+ * @package   Bdrem
+ * @author    Christian Weiske <cweiske@cweiske.de>
+ * @copyright 2014 Christian Weiske
+ * @license   http://www.gnu.org/licenses/agpl.html GNU AGPL v3
+ * @link      http://cweiske.de/bdrem.htm
+ */
+namespace bdrem;
+
+/**
+ * Renders events in an iCalendar file
+ *
+ * @category  Tools
+ * @package   Bdrem
+ * @author    Christian Weiske <cweiske@cweiske.de>
+ * @copyright 2014 Christian Weiske
+ * @license   http://www.gnu.org/licenses/agpl.html GNU AGPL v3
+ * @version   Release: @package_version@
+ * @link      http://cweiske.de/bdrem.htm
+ */
+class Renderer_Ical extends Renderer
+{
+    /**
+     * HTTP content type
+     * @var string
+     */
+    protected $httpContentType = 'text/calendar; charset=utf-8';
+
+    /**
+     * Render the events in an iCalendar file
+     *
+     * @param array $arEvents Event objects to render
+     *
+     * @return string iCal file
+     */
+    public function render($arEvents)
+    {
+        $s = "BEGIN:VCALENDAR\n"
+            . "VERSION:2.0\n"
+            . "PRODID:-//bdrem\n";
+        foreach ($arEvents as $event) {
+            $props = array('BEGIN' => 'VEVENT');
+            
+            $props['UID'] = str_replace(
+                array('-', '????'), array('', '0000'), $event->date
+            )
+                . '.' . $event->age
+                . '.' . md5($event->title . '/' . $event->type)
+                . '@bdrem';
+            $props['DTSTART']  = str_replace('-', '', $event->date);
+            $props['DURATION'] = 'P1D';
+            $props['SUMMARY']  = sprintf(
+                '%s - %s. %s', $event->title, $event->age, $event->type
+            );
+            $props['END'] = 'VEVENT';
+
+            foreach ($props as $key => $value) {
+                $s .= $key . ':' . $value . "\n";
+            }
+        }
+        $s .= "END:VCALENDAR\n";
+        return $s;
+    }
+}
+?>
index 66b72e2..ea0e142 100644 (file)
@@ -113,6 +113,7 @@ abstract class UserInterface
                     'console',
                     'html',
                     'htmltable',
+                    'ical',
                     'mail',
                 ),
                 'default'     => 'console',