Adds an event to set of search results.
public static addSearchEvents ( array &$events, Kronolith_Event $event, stdClass $query, boolean $json ) | ||
$events | array | The list of events to update with the new event. |
$event | Kronolith_Event | An event from a search result. |
$query | stdClass | A search query. |
$json | boolean | Store the results of the events' toJson() method? |
/** * TODO */ public function searchEvents() { $query = Horde_Serialize::unserialize($this->vars->query, Horde_Serialize::JSON); if (!isset($query->start)) { $query->start = new Horde_Date($_SERVER['REQUEST_TIME']); } if (!isset($query->end)) { $query->end = null; } switch ($this->vars->time) { case 'all': $query->start = null; $query->end = null; break; case 'future': $query->start = new Horde_Date($_SERVER['REQUEST_TIME']); $query->end = null; break; case 'past': $query->start = null; $query->end = new Horde_Date($_SERVER['REQUEST_TIME']); break; } $tagger = new Kronolith_Tagger(); $cals = Horde_Serialize::unserialize($this->vars->cals, Horde_Serialize::JSON); $events = array(); foreach ($cals as $cal) { if (!($kronolith_driver = $this->_getDriver($cal))) { continue; } try { $result = $kronolith_driver->search($query, true); if ($result) { $events[$cal] = $result; } } 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(); $result->view = 'search'; $result->query = $this->vars->query; if ($events) { $result->events = $events; } return $result; }
/** * Searches a calendar. * * @param object $query An object with the criteria to search for. * @param boolean $json Store the results of the events' toJson() method? * * @return mixed An array of Kronolith_Events. * @throws Kronolith_Exception */ public function search($query, $json = false) { /* Build SQL conditions based on the query string. */ $cond = '(('; $values = array(); foreach (array('title', 'location', 'url', 'description') as $field) { if (!empty($query->{$field})) { $binds = $this->_db->buildClause('event_' . $field, 'LIKE', $this->convertToDriver($query->{$field}), true); if (is_array($binds)) { $cond .= $binds[0] . ' AND '; $values = array_merge($values, $binds[1]); } else { $cond .= $binds; } } } if (!empty($query->baseid)) { $binds = $this->_db->buildClause('event_baseid', '=', $query->baseid, true); if (is_array($binds)) { $cond .= $binds[0] . ' AND '; $values = array_merge($values, $binds[1]); } else { $cond .= $binds; } } if (isset($query->status)) { $binds = $this->_db->buildClause('event_status', '=', $query->status, true); if (is_array($binds)) { $cond .= $binds[0] . ' AND '; $values = array_merge($values, $binds[1]); } else { $cond .= $binds; } } if (!empty($query->creator)) { $binds = $this->_db->buildClause('event_creator_id', '=', $query->creator, true); if (is_array($binds)) { $cond .= $binds[0] . ' AND '; $values = array_merge($values, $binds[1]); } else { $cond .= $binds; } } if ($cond == '((') { $cond = ''; } else { $cond = substr($cond, 0, strlen($cond) - 5) . '))'; } $eventIds = $this->_listEventsConditional(empty($query->start) ? null : $query->start, empty($query->end) ? null : $query->end, $cond, $values); $events = array(); foreach ($eventIds as $eventId) { Kronolith::addSearchEvents($events, $this->getEvent($eventId), $query, $json); } return $events; }