Returns formatted owner names of a ticket.
public static getOwners ( integer $ticket, $showemail = true, boolean $showname = true, array $owners = null ) : string | ||
$ticket | integer | A ticket id. Only used if $owners is null. |
$showname | boolean | Should we include the name in the output? |
$owners | array | An array of owners as returned from Whups_Driver::getOwners() to be formatted. If this is provided, they are used instead of the owners from $ticket. |
return | string | The formatted owner string. |
/** * @throws Whups_Exception */ public function download(Horde_Variables $vars) { global $injector, $whups_driver; switch ($vars->actionID) { case 'download_file': // Get the ticket details first. if (empty($vars->ticket)) { exit; } $details = $whups_driver->getTicketDetails($vars->ticket); // Check permissions on this ticket. if (!count(Whups::permissionsFilter($whups_driver->getHistory($vars->ticket), 'comment', Horde_Perms::READ))) { throw new Whups_Exception(sprintf(_("You are not allowed to view ticket %d."), $vars->ticket)); } try { $vfs = $injector->getInstance('Horde_Core_Factory_Vfs')->create(); } catch (Horde_Exception $e) { throw new Whups_Exception(_("The VFS backend needs to be configured to enable attachment uploads.")); } try { return array('data' => $vfs->read(Whups::VFS_ATTACH_PATH . '/' . $vars->ticket, $vars->file), 'name' => $vars->file); } catch (Horde_Vfs_Exception $e) { throw new Whups_Exception(sprintf(_("Access denied to %s"), $vars->file)); } break; case 'report': $_templates = Horde::loadConfiguration('templates.php', '_templates', 'whups'); $tpl = $vars->template; if (empty($_templates[$tpl])) { throw new Whups_Exception(_("The requested template does not exist.")); } if ($_templates[$tpl]['type'] != 'searchresults') { throw new Whups_Exception(_("This is not a search results template.")); } // Fetch all unresolved tickets assigned to the current user. $info = array('id' => explode(',', $vars->ids)); $tickets = $whups_driver->getTicketsByProperties($info); foreach ($tickets as $id => $info) { $tickets[$id]['#'] = $id + 1; $tickets[$id]['link'] = Whups::urlFor('ticket', $info['id'], true, -1); $tickets[$id]['date_created'] = strftime('%x', $info['timestamp']); $tickets[$id]['owners'] = Whups::getOwners($info['id']); $tickets[$id]['owner_name'] = Whups::getOwners($info['id'], false, true); $tickets[$id]['owner_email'] = Whups::getOwners($info['id'], true, false); if (!empty($info['date_assigned'])) { $tickets[$id]['date_assigned'] = strftime('%x', $info['date_assigned']); } if (!empty($info['date_resolved'])) { $tickets[$id]['date_resolved'] = strftime('%x', $info['date_resolved']); } // If the template has a callback function defined for data // filtering, call it now. if (!empty($_templates[$tpl]['callback'])) { array_walk($tickets[$id], $_templates[$tpl]['callback']); } } Whups::sortTickets($tickets, isset($_templates[$tpl]['sortby']) ? $_templates[$tpl]['sortby'] : null, isset($_templates[$tpl]['sortdir']) ? $_templates[$tpl]['sortdir'] : null); $template = $injector->createInstance('Horde_Template'); $template->set('tickets', $tickets); $template->set('now', strftime('%x')); $template->set('values', Whups::getSearchResultColumns(null, true)); return array('data' => $template->parse($_templates[$tpl]['template']), 'name' => isset($_templates[$tpl]['filename']) ? $_templates[$tpl]['filename'] : 'report.html'); } }
/** * Returns a plain text representation of a ticket. */ public function toString() { $fields = array('queue' => _("Queue"), 'version' => _("Version"), 'type' => _("Type"), 'state' => _("State"), 'priority' => _("Priority"), 'due' => _("Due")); /* Find longest translated field name. */ $length = 0; foreach (array_merge($fields, array(_("Summary"), _("Owners"))) as $field) { $length = max($length, Horde_String::length($field)); } $wrap_break = "\n" . str_repeat(' ', $length + 2) . '| '; $wrap_width = 73 - $length; /* Ticket properties. */ $message = ' ' . Horde_String::pad(_("Ticket"), $length) . ' | ' . $this->_id . "\n" . ' ' . Horde_String::pad(_("Summary"), $length) . ' | ' . Horde_String::wrap($this->get('summary'), $wrap_width, $wrap_break) . "\n"; foreach ($fields as $field => $label) { if ($name = $this->get($field . '_name')) { $message .= ' ' . Horde_String::pad($label, $length) . ' | ' . Horde_String::wrap($name, $wrap_width, $wrap_break) . "\n"; } } $message .= ' ' . Horde_String::pad(_("Owners"), $length) . ' | ' . Horde_String::wrap(Whups::getOwners($this->_id, false, true), $wrap_width, $wrap_break) . "\n"; return $message; }