/**
* Executes a query.
*
* @param Whups_Query $query A query object.
* @param Horde_Variables $vars Request variables.
* @param boolean $get_details Whether to return all ticket details.
* @param boolean $munge @TODO (?)
*
* @return array List of ticket IDs or ticket details that match the query
* criteria.
* @throws Whups_Exception
*/
public function executeQuery(Whups_Query $query, Horde_Variables $vars, $get_details = true, $munge = true)
{
$this->jtables = array();
$this->joins = array();
$where = $query->reduce(array($this, 'clauseFromQuery'), $vars);
if (!$where) {
$GLOBALS['notification']->push(_("No query to run"), 'horde.message');
return array();
}
if ($this->joins) {
$joins = implode(' ', $this->joins);
} else {
$joins = '';
}
try {
$ids = $this->_db->selectValues("SELECT whups_tickets.ticket_id FROM whups_tickets {$joins} " . "WHERE {$where}");
} catch (Horde_Db_Exception $e) {
$GLOBALS['notification']->push($e->getMessage(), 'horde.error');
return array();
}
if (!count($ids)) {
return array();
}
if ($get_details) {
$ids = $this->getTicketsByProperties(array('id' => $ids), $munge);
}
return $ids;
}