/** * Adds an event to the backend. * * @param Kronolith_Event $event The event to save. * * @return string The event id. * @throws Horde_Mime_Exception * @throws Kronolith_Exception */ protected function _addEvent(Kronolith_Event $event) { if (!$event->id) { $event->id = (string) new Horde_Support_Randomid(); } if (!$event->uid) { $event->uid = (string) new Horde_Support_Guid(); } $query = 'INSERT INTO kronolith_events'; $cols_name = ' (event_id, event_uid,'; $cols_values = ' VALUES (?, ?,'; $values = array($event->id, $event->uid); foreach ($event->toProperties() as $key => $val) { $cols_name .= " {$key},"; $cols_values .= ' ?,'; $values[] = $val; } $cols_name .= ' calendar_id)'; $cols_values .= ' ?)'; $values[] = $this->calendar; $query .= $cols_name . $cols_values; try { $this->_db->insert($query, $values); } catch (Horde_Db_Exception $e) { throw new Kronolith_Exception($e); } /* Log the creation of this item in the history log. */ try { $GLOBALS['injector']->getInstance('Horde_History')->log('kronolith:' . $this->calendar . ':' . $event->uid, array('action' => 'add'), true); } catch (Exception $e) { Horde::log($e, 'ERR'); } $this->_addTags($event); /* Update Geolocation */ if ($event->geoLocation) { try { $GLOBALS['injector']->getInstance('Kronolith_Geo')->setLocation($event->id, $event->geoLocation); } catch (Kronolith_Exception $e) { } } /* Notify users about the new event. */ $this->_handleNotifications($event, 'add'); return $event->id; }