From 7d228df57387fcb1d65ffb896390b6f9af6736e1 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Mon, 31 Aug 2009 16:33:16 +0200 Subject: [PATCH] Move most of quickAdd() to Kronolith:: so that we can call it directly. --- kronolith/lib/Api.php | 27 +-------------------------- kronolith/lib/Kronolith.php | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 26 deletions(-) diff --git a/kronolith/lib/Api.php b/kronolith/lib/Api.php index efbfeb88c..8afafcdaf 100644 --- a/kronolith/lib/Api.php +++ b/kronolith/lib/Api.php @@ -690,32 +690,7 @@ class Kronolith_Api extends Horde_Registry_Api return PEAR::raiseError(_("Permission Denied")); } - $text = trim($text); - list($title, $description) = explode($text, "\n", 2); - $title = trim($title); - $description = trim($description); - - $dateParser = Horde_Date_Parser::factory(); - $r = $dateParser->parse($title, array('return' => 'result')); - if (! ($d = $r->guess())) { - throw new Horde_Exception(json_encode(array('name' => $title, 'description' => $description))); - } - - $title = $r->untaggedText(); - $start = $d->timestamp(); - - $kronolith_driver = Kronolith::getDriver(null, $calendar); - $event = $kronolith_driver->getEvent(); - $event->setTitle($title); - $event->setDescription($description); - $event->start = $d; - $event->end = $d->add(array('hour' => 1)); - - $eventId = $event->save(); - if (is_a($eventId, 'PEAR_Error')) { - return $eventId; - } - return $event->getUID(); + return Kronolith::quickAdd($text, $calendar); } /** diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index 674b17c3f..83c97bbc8 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -618,6 +618,46 @@ class Kronolith } /** + * Imports an event parsed from a string. + * + * @param string $text The text to parse into an event + * @param string $calendar The calendar into which the event will be + * imported. If 'null', the user's default + * calendar will be used. + * + * @return array The UID of all events that were added. + */ + public function quickAdd($text, $calendar = null) + { + $text = trim($text); + list($title, $description) = explode($text, "\n", 2); + $title = trim($title); + $description = trim($description); + + $dateParser = Horde_Date_Parser::factory(); + $r = $dateParser->parse($title, array('return' => 'result')); + if (!($d = $r->guess())) { + throw new Horde_Exception(_("Cannot parse event description.")); + } + + $title = $r->untaggedText(); + $start = $d->timestamp(); + + $kronolith_driver = Kronolith::getDriver(null, $calendar); + $event = $kronolith_driver->getEvent(); + $event->setTitle($title); + $event->setDescription($description); + $event->start = $d; + $event->end = $d->add(array('hour' => 1)); + + $eventId = $event->save(); + if (is_a($eventId, 'PEAR_Error')) { + return $eventId; + } + return $event->getUID(); + } + + /** * Initial app setup code. */ public static function initialize() -- 2.11.0