Search for tags too, when searching for events.
authorJan Schneider <jan@horde.org>
Thu, 15 Apr 2010 12:56:35 +0000 (14:56 +0200)
committerJan Schneider <jan@horde.org>
Thu, 15 Apr 2010 12:56:35 +0000 (14:56 +0200)
kronolith/lib/Ajax/Application.php
kronolith/lib/Driver/Sql.php
kronolith/lib/Kronolith.php

index 71d16ad..89406c6 100644 (file)
@@ -265,6 +265,7 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base
             break;
         }
 
+        $tagger = new Kronolith_Tagger();
         $cals = Horde_Serialize::unserialize($this->_vars->cals, Horde_Serialize::JSON);
         $events = array();
         foreach ($cals as $cal) {
@@ -279,6 +280,13 @@ class Kronolith_Ajax_Application extends Horde_Ajax_Application_Base
             } catch (Exception $e) {
                 $GLOBALS['notification']->push($e, 'horde.error');
             }
+            $split = explode('|', $cal);
+            if ($split[0] == 'internal') {
+                $result = $tagger->search($query->title, array('type' => 'event', 'calendar' => $split[1]));
+                foreach ($result['events'] as $uid) {
+                    Kronolith::addSearchEvents($events[$cal], $kronolith_driver->getByUID($uid), $query, true);
+                }
+            }
         }
 
         $result = new stdClass;
index eb25a98..7f98651 100644 (file)
@@ -186,36 +186,9 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
                                                   $query->end,
                                                   $cond,
                                                   $values);
-        $now = new Horde_Date($_SERVER['REQUEST_TIME']);
         $events = array();
         foreach ($eventIds as $eventId) {
-            $event = $this->getEvent($eventId);
-            $showRecurrence = true;
-            if ($event->recurs()) {
-                if (empty($query->start) && empty($query->end)) {
-                    $eventStart = $event->start;
-                    $eventEnd = $event->end;
-                } else {
-                    if (empty($query->end)) {
-                        $eventEnd = $event->recurrence->nextRecurrence($now);
-                        if (!$eventEnd) {
-                            continue;
-                        }
-                    } else {
-                        $eventEnd = $query->end;
-                    }
-                    if (empty($query->start)) {
-                        $eventStart = $event->start;
-                        $showRecurrence = false;
-                    } else {
-                        $eventStart = $query->start;
-                    }
-                }
-            } else {
-                $eventStart = $event->start;
-                $eventEnd = $event->end;
-            }
-            Kronolith::addEvents($events, $event, $eventStart, $eventEnd, $showRecurrence, $json, false);
+            Kronolith::addSearchEvents($events, $this->getEvent($eventId), $query, $json);
         }
 
         return $events;
index b6f5242..cbb0a66 100644 (file)
@@ -801,6 +801,50 @@ class Kronolith
     }
 
     /**
+     * Adds an event to set of search results.
+     *
+     * @param array $events           The list of events to update with the new
+     *                                event.
+     * @param Kronolith_Event $event  An event from a search result.
+     * @param stdClass $query         A search query.
+     * @param boolean $json           Store the results of the events' toJson()
+     *                                method?
+     */
+    public static function addSearchEvents(&$events, $event, $query, $json)
+    {
+        static $now;
+        if (!isset($now)) {
+            $now = new Horde_Date($_SERVER['REQUEST_TIME']);
+        }
+        $showRecurrence = true;
+        if ($event->recurs()) {
+            if (empty($query->start) && empty($query->end)) {
+                $eventStart = $event->start;
+                $eventEnd = $event->end;
+            } else {
+                if (empty($query->end)) {
+                    $eventEnd = $event->recurrence->nextRecurrence($now);
+                    if (!$eventEnd) {
+                        continue;
+                    }
+                } else {
+                    $eventEnd = $query->end;
+                }
+                if (empty($query->start)) {
+                    $eventStart = $event->start;
+                    $showRecurrence = false;
+                } else {
+                    $eventStart = $query->start;
+                }
+            }
+        } else {
+            $eventStart = $event->start;
+            $eventEnd = $event->end;
+        }
+        Kronolith::addEvents($events, $event, $eventStart, $eventEnd, $showRecurrence, $json, false);
+    }
+
+    /**
      * Returns the number of events in calendars that the current user owns.
      *
      * @return integer  The number of events.