No need to query tag storage 99% of the time we call listEvents. Do not retrieve tags
unless explicitly requested, and when we do, do it in a single batch query for all events
returned in listEvents. Also, lazy load the tags on events when accessing the tags property.
Still need to do something similar with the geoLocation stuff.
false, // Alarms only
false, // Show remote
true, // Hide exception events
- false); // Don't return multi-day events on *each* day
+ false, // Don't return multi-day events on *each* day
+ true); // Return Tags
} catch (Exception $e) {
return array();
}
*
* @param string $uid The calendar id
*
- * @return The iCalendar representation of the calendar
+ * @return Horde_ActiveSync_Message_Appointment
*/
public function calendar_export($uid)
{
}
$kronolith_driver = Kronolith::getDriver(null, $calendar);
- $events = $kronolith_driver->listEvents();
+ $events = $kronolith_driver->listEvents(null, null, null, true, false, true, false, true, true);
$version = '2.0';
switch ($contentType) {
public function listEvents($startstamp = null, $endstamp = null,
$calendars = null, $showRecurrence = true,
$alarmsOnly = false, $showRemote = true, $hideExceptions = false,
- $coverDates = true)
+ $coverDates = true, $fetchTags = false)
{
if (!isset($calendars)) {
$calendars = array($GLOBALS['prefs']->getValue('default_share'));
$alarmsOnly,
$showRemote,
$hideExceptions,
- $coverDates);
+ $coverDates,
+ $fetchTags);
}
/**
*/
public function listEvents($startDate = null, $endDate = null,
$showRecurrence = false, $hasAlarm = false,
- $json = false, $coverDates = true)
+ $json = false, $coverDates = true,
+ $fetchTags = false)
{
$result = $this->synchronize();
$result = $this->_store->save($attributes, $stored_uid);
/* Deal with tags */
- $tagger = Kronolith::getTagger();
if (!empty($edit)) {
- $tagger->replaceTags($event->uid, $event->tags, $event->creator, 'event');
+ Kronolith::getTagger()->replaceTags($event->uid, $event->tags, $event->creator, 'event');
} else {
- $tagger->tag($event->uid, $event->tags, $event->creator, 'event');
+ Kronolith::getTagger()->tag($event->uid, $event->tags, $event->creator, 'event');
}
$cal = $GLOBALS['kronolith_shares']->getShare($event->calendar);
* toJson() method?
* @param boolean $coverDates Whether to add the events to all days
* that they cover.
+ * @param boolean $fetchTags Whether to fetch tags for all events
*
* @return array Events in the given time range.
* @throws Kronolith_Exception
*/
public function listEvents($startDate = null, $endDate = null,
$showRecurrence = false, $hasAlarm = false,
- $json = false, $coverDates = true, $hideExceptions = false)
+ $json = false, $coverDates = true, $hideExceptions = false,
+ $fetchTags = false)
{
if (!is_null($startDate)) {
$startDate = clone $startDate;
$events = $this->_listEventsConditional($startDate, $endDate, $conditions, $values);
$results = array();
+ if ($fetchTags) {
+ $tags = Kronolith::getTagger()->getTags(array_keys($events));
+ }
foreach ($events as $id) {
- Kronolith::addEvents($results, $this->getEvent($id), $startDate,
- $endDate, $showRecurrence, $json, $coverDates);
+ $event = $this->getEvent($id);
+ if (isset($tags) && !empty($tags[$event->uid])) {
+ $event->setTags($tags[$event->uid]);
+ }
+ Kronolith::addEvents($results, $event, $startDate, $endDate,
+ $showRecurrence, $json, $coverDates);
}
return $results;
}
/* Update tags */
- $tagger = Kronolith::getTagger();
- $tagger->replaceTags($event->uid, $event->tags, $event->creator, 'event');
+ Kronolith::getTagger()->replaceTags($event->uid, $event->tags, $event->creator, 'event');
/* Add tags again, but as the share owner (replaceTags removes ALL tags). */
try {
} catch (Horde_Share_Exception $e) {
throw new Kronolith_Exception($e);
}
- $tagger->tag($event->uid, $event->tags, $cal->get('owner'), 'event');
+ Kronolith::getTagger()->tag($event->uid, $event->tags, $cal->get('owner'), 'event');
/* Update Geolocation */
if ($gDriver = Kronolith::getGeoDriver()) {
*
* @var array|string
*/
- public $tags = array();
+ protected $_tags = null;
/**
* Geolocation
if (!is_null($eventObject)) {
$this->fromDriver($eventObject);
- /* Get tags */
- $tagger = Kronolith::getTagger();
- $this->tags = $tagger->getTags($this->uid, 'event');
-
/* Get geolocation data */
if ($gDriver = Kronolith::getGeoDriver()) {
try {
case 'span':
case 'rowspan':
return $this->{'_' . $name};
+ case 'tags':
+ return $this->getTags();
}
$trace = debug_backtrace();
trigger_error('Undefined property via __set(): ' . $name
// Tags
$categories = $vEvent->getAttributeValues('CATEGORIES');
if (!($categories instanceof PEAR_Error)) {
- $this->tags = $categories;
+ $this->_tags = $categories;
}
// Description
}
// Tags.
- $this->tags = Horde_Util::getFormData('tags', $this->tags);
+ $this->_tags = Horde_Util::getFormData('tags', $this->tags);
// Geolocation
$this->geoLocation = array('lat' => Horde_Util::getFormData('lat'),
return 'kronolithEvent';
}
+ /**
+ * Setter for tags
+ *
+ * @param array $tags An array of tag_names
+ */
+ public function setTags($tags)
+ {
+ $this->_tags = $tags;
+ }
+
+ /**
+ * Getter for tags
+ *
+ * @return mixed An array of tag_names, or false if tags were never set.
+ */
+ public function getTags()
+ {
+ if (!isset($this->_tags)) {
+ $this->_tags = Kronolith::getTagger()->getTags($this->uid, 'event');
+ }
+
+ return $this->_tags;
+ }
+
private function _formIDEncode($id)
{
return str_replace(array('[', ']'),
$this->alarm = $alarm;
parent::__construct($driver, $eventObject);
+ $this->_tags = Kronolith::getTagger()->getTags($this->uid, 'event');
}
public function fromDriver($event)
* listTimeObjects as well?
* @param boolean $hideExceptions Hide events that represent exceptions to
* a recurring event?
+ * @param boolean $fetchTags Should we fetch each event's tags from
+ * storage?
*
* @return array The events happening in this time period.
* @throws Kronolith_Exception
public static function listEvents($startDate, $endDate, $calendars = null,
$showRecurrence = true,
$alarmsOnly = false, $showRemote = true,
- $hideExceptions = false, $coverDates = true)
+ $hideExceptions = false, $coverDates = true,
+ $fetchTags = false)
{
$results = array();
$driver->open($calendar);
$events = $driver->listEvents($startDate, $endDate, $showRecurrence,
$alarmsOnly, false, $coverDates,
- $hideExceptions);
+ $hideExceptions, $fetchTags);
self::mergeEvents($results, $events);
}
$to->status = $from->status;
$to->description = $from->description;
$to->url = $from->url;
- $to->tags = $from->tags;
+ $to->setTags($from->tags);
$to->geoLocation = $from->geoLocation;
$to->first = $from ->first;
$to->last = $from->last;
$this->_type_ids = array('calendar' => (int)$types[0],
'event' => (int)$types[1]);
- // Cache the tagger statically
+ // Cache the tagger
$this->_tagger = $GLOBALS['injector']->getInstance('Content_Tagger');
}
/**
* Retrieves the tags on given object(s).
*
- * @param string $localId The identifier of the kronolith object.
+ * @param mixed $localId Either the identifier of the kronolith object or
+ * an array of identifiers.
* @param string $type The type of object $localId represents.
*
- * @return a tag_id => tag_name hash.
+ * @return array A tag_id => tag_name hash, possibly wrapped in a localid hash.
*/
public function getTags($localId, $type = 'event')
{
- if (!is_array($localId)) {
- $localId = array($localId);
- }
- $tags = array();
- foreach ($localId as $id) {
- $tags = $tags + $this->_tagger->getTags(array('objectId' => array('object' => $id, 'type' => $this->_type_ids[$type])));
+ if (is_array($localId)) {
+ return $this->_tagger->getTagsByObjects($localId, $type);
}
- return $tags;
+ return $this->_tagger->getTags(array('objectId' => array('object' => $localId, 'type' => $this->_type_ids[$type])));
}
/**