Kronolith::quickAdd PHP Method

quickAdd() public method

Imports an event parsed from a string.
public quickAdd ( string $text, string $calendar = null ) : array
$text string The text to parse into an event
$calendar string 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);
        if (strpos($text, "\n") !== false) {
            list($title, $description) = explode($text, "\n", 2);
        } else {
            $title = $text;
            $description = '';
        }
        $title = trim($title);
        $description = trim($description);
        $dateParser = Horde_Date_Parser::factory(array('locale' => $GLOBALS['language']));
        $r = $dateParser->parse($title, array('return' => 'result'));
        if (!($d = $r->guess())) {
            throw new Horde_Exception(sprintf(_("Cannot parse event description \"%s\""), Horde_String::truncate($text)));
        }
        $title = $r->untaggedText();
        $kronolith_driver = self::getDriver(null, $calendar);
        $event = $kronolith_driver->getEvent();
        $event->initialized = true;
        $event->title = $title;
        $event->description = $description;
        $event->start = $d;
        $event->end = $d->add(array('hour' => 1));
        $event->save();
        return $event;
    }

Usage Example

Example #1
0
 /**
  * TODO
  */
 public function quickSaveEvent()
 {
     $cal = explode('|', $this->vars->cal, 2);
     try {
         $event = Kronolith::quickAdd($this->vars->text, $cal[1]);
         return $this->_saveEvent($event);
     } catch (Horde_Exception $e) {
         $GLOBALS['notification']->push($e);
         $result = $this->_signedResponse($this->vars->cal);
         $result->error = true;
         return $result;
     }
 }
All Usage Examples Of Kronolith::quickAdd