/** * Searches for locations that begin with the text in $search. * * @param string $search The text to search. * * @return array An array of stdClass objects with 'name' and 'code' * properties. * @throws Horde_Service_Weather_Exception */ public function autocompleteLocation($search) { if (empty($this->_db)) { return array(); } $sql = 'SELECT icao, name, state, municipality, country FROM ' . $this->_tableName . ' WHERE ' . 'name LIKE ? OR icao LIKE ? OR state LIKE ? OR municipality LIKE ?'; try { $rows = $this->_db->select($sql, array_fill(0, 4, $search . '%')); } catch (Horde_Db_Exception $e) { throw new Horde_Service_Weather_Exception($e); } $results = array(); foreach ($rows as $row) { $obj = new stdClass(); $obj->name = sprintf('%s (%s, %s, %s)', $row['name'], $row['municipality'], $row['state'], $row['country']); $obj->code = $row['icao']; $results[] = $obj; } return $results; }