linking clients to tickets
Bo Daley <[email protected]>
| Newsgroups | gmane.comp.horde.whups |
|---|---|
| Message-ID | <[email protected]> |
hi all, this patch extends the client/module links that were added last week so that tickets can also have clients. this achieves more or less the same thing as the 'Add Client' links at the bottom of the Ticket Details page, but brings it up into the ticket creation process and restricts the clients to only those that are already attached to the specified module. (in fact it might be worth removing the 'client' link stuff from registry.php if this is going to replace that code). In a couple of places I did make the assumption that tickets would only have one client -- does that make sense to people? (I don't imagine it would be too difficult to allow multiple clients if anyone thinks that's worth building in). thanks, bo. -- Whups mailing list Frequently Asked Questions: http://horde.org/faq/ To unsubscribe, mail: [email protected]
client_tickets.diff
(text/diff, 13.1 KB)
Index: create.php
===================================================================
RCS file: /repository/whups/create.php,v
retrieving revision 1.34
diff -u -r1.34 create.php
--- create.php 22 Jul 2003 02:15:44 -0000 1.34
+++ create.php 29 Jul 2003 04:55:31 -0000
@@ -147,11 +147,41 @@
header('Location: ' . Horde::applicationUrl('create.php', true));
exit;
}
-
$tid = $results[0];
$message = sprintf(_("Your ticket id is %s. "), $tid);
$message .= _("An appropriate person has been notified of this request.");
$notification->push($message, 'horde.success');
+ if (isset($conf['client']['driver'])) {
+ /* Add a link from this ticket to the selected client. */
+ switch ($conf['client']['driver']) {
+ case 'turba':
+ if (!empty($info['client'])) {
+ $clientsource = $conf['client']['params']['addressbook'];
+ require_once HORDE_BASE . '/lib/Links.php';
+ $links = &Horde_Links::singleton($registry->getApp());
+ $from_application = 'projects';
+ settype($tid, 'string'); // this needs to be a string to match properly
+ $from_parameters = array('ticket_id' => $tid);
+ $to_application = 'contacts';
+ $link_type = 'client';
+ /* Now add in the new client link. */
+ $client_id = $info['client'];
+ settype($client_id, 'string');
+ $to_parameters = array('source' => $clientsource, 'id' => $client_id);
+ $status = $links->addLink($from_application, $from_parameters, $to_application, $to_parameters, $link_type);
+ if (is_a($status, 'PEAR_Error')) {
+ $notification->push($status, 'horde.error');
+ } elseif ($registry->hasMethod($to_application . '/getLinkSummary')) {
+ $link_summary = $registry->call($to_application . '/getLinkSummary', $to_parameters);
+ $notification->push(sprintf(_("Added a %s link to %s."), $link_type, $link_summary), 'horde.success');
+ } else {
+ $notification->push(_("Link added."), 'horde.success');
+ }
+ }
+ break;
+ /* Any future client sources can be added here. */
+ }
+ }
$url = Horde::applicationUrl('details.php', true);
$url = Horde::addParameter($url, 'id', $tid);
Index: details.php
===================================================================
RCS file: /repository/whups/details.php,v
retrieving revision 1.49
diff -u -r1.49 details.php
--- details.php 27 Jun 2003 19:19:21 -0000 1.49
+++ details.php 29 Jul 2003 04:55:31 -0000
@@ -347,6 +347,9 @@
$form->addAttributes($attributes);
$details['user_id_requester'] = Whups::formatUser($details['user_id_requester']);
$details['user_id_owner'] = Whups::getOwners($ticket);
+ if (isset($conf['client']['driver']) && ($conf['client']['driver'] != 'none')) {
+ $details['client_name'] = Whups::getClients($details['module'], $ticket);
+ }
$RENDERER->beginInactive(sprintf(_("Ticket %s Details"), $ticket));
$RENDERER->renderFormInactive($form, new Horde_Form_Vars($details));
Index: lib/Create.php
===================================================================
RCS file: /repository/whups/lib/Create.php,v
retrieving revision 1.36
diff -u -r1.36 Create.php
--- lib/Create.php 22 Jul 2003 01:43:40 -0000 1.36
+++ lib/Create.php 29 Jul 2003 04:55:31 -0000
@@ -45,18 +45,30 @@
function CreateStep2Form(&$vars)
{
- global $whups;
+ global $whups, $conf;
parent::Horde_Form($vars, _("Create Ticket - Stage 2"));
$types = $whups->getTypes($vars->getVar('module'));
$info = $whups->getModule($vars->getVar('module'));
+ $clientlist = $whups->getClients($vars->getVar('module'));
if (count($types) == 0) {
$typetype = 'invalid';
$type_params = array(_("There are no ticket types associated with this module; until there are, you cannot create any tickets in this module."));
} else {
$typetype = 'enum';
$type_params = array($types);
+ }
+ if (isset($conf['client']['driver']) && ($conf['client']['driver'] != 'none')) {
+ /* Only list clients if a client driver has been configured. */
+ if (count($clientlist) == 0) {
+ $clienttype = 'invalid';
+ $client_params = array(_("There are no clients associated with this module; until there are, you cannot create any tickets in this module."));
+ } else {
+ $clienttype = 'enum';
+ $client_params = array($clientlist);
+ }
+ $this->addVariable(_("Client"), 'client', $clienttype, true, false, null, $client_params);
}
$this->addVariable(_("Ticket Type"), 'type', $typetype, true, false, null, $type_params);
Index: lib/Driver.php
===================================================================
RCS file: /repository/whups/lib/Driver.php,v
retrieving revision 1.52
diff -u -r1.52 Driver.php
--- lib/Driver.php 22 Jul 2003 02:58:31 -0000 1.52
+++ lib/Driver.php 29 Jul 2003 04:55:31 -0000
@@ -69,7 +69,7 @@
'resolved' => _("Resolved"));
}
- function getClients($module=null)
+ function getClients($module = null, $ticket = null)
{
/* Gets list of clients from the client source. */
$clients = array();
@@ -100,7 +100,10 @@
}
}
if (!empty($module)) {
- $clients = $this->filterClientsByModule($clients, $module);
+ $clients = $this->filterClientLinks('module', $clients, $module);
+ }
+ if (!empty($ticket)) {
+ $clients = $this->filterClientLinks('ticket', $clients, $ticket);
}
if (is_a('PEAR_Error', $clients)) {
$notification->push(_("Could not access client list from Turba."));
@@ -114,11 +117,11 @@
return $clients;
}
- function filterClientsByModule($clients, $module)
+ function filterClientLinks($type, $clients, $value)
{
/**
* Take a list of clients and return only those associated
- * with the specified module. Client/module associations come
+ * with the specified module or ticket. Client associations come
* from the Links API.
*/
global $registry;
@@ -129,7 +132,11 @@
/* TODO: add from/to_application to listLinks in Links API so it only
returns links for this application. */
- $from_parameters = array('module_id' => $module);
+ if ($type == 'module') {
+ $from_parameters = array('module_id' => $value);
+ } elseif ($type == 'ticket') {
+ $from_parameters = array('ticket_id' => $value);
+ }
$to_application = 'contacts';
$link_type = 'projects/client';
$client_links = $links->listLinks($link_type, $from_parameters);
@@ -143,12 +150,15 @@
return $clients_filtered;
}
- function notifyTicket($ticket_id, $summary, $module_name, $creator)
+ function notifyTicket($ticket_id, $summary, $module_name, $creator, $client_name=null)
{
$subject = sprintf(_("New ticket (%s): %s"), $ticket_id, $summary);
$message = sprintf(_("-Ticket %s\n"), $ticket_id);
$message .= sprintf(_("-Module: %s\n"), $module_name);
+ if (!empty($client_name)) {
+ $message .= sprintf(_("-Client: %s\n"), $client_name);
+ }
$message .= sprintf(_("-Created By: %s\n"), Whups::formatUser($creator));
$message .= "\n" . _("-Summary:") . "\n" . $this->_splitMessage($summary) . "\n";
$message .= '@@comment_placeholder@@';
@@ -164,6 +174,9 @@
$message = sprintf(_("-Ticket %s\n"), $info['id']);
$message .= sprintf(_("-Module: %s\n"), $info['_module_name']);
+ if (!empty($info['_client_name'])) {
+ $message .= sprintf(_("-Client: %s\n"), $info['_client_name']);
+ }
$message .= sprintf(_("-Added By: %s\n"), Whups::formatUser($creator));
$message .= "\n" . _("-Summary:") . "\n" . $this->_splitMessage($info['summary']) . "\n";
$message .= '@@comment_placeholder@@';
@@ -184,6 +197,9 @@
$message .= "-----------------------------------------------------------------------\n";
$message .= sprintf(_("Ticket : %s"), $ticket_id) . "\n";
$message .= sprintf(_("Module : %s"), $olddetails['_module_name']) . "\n";
+ if (!empty($olddetails['_client_name'])) {
+ $message .= sprintf(_("Client : %s"), $olddetails['_client_name']) . "\n";
+ }
$message .= sprintf(_("Assigned To : %s"), Whups::getOwners($ticket_id)) . "\n";
$message .= sprintf(_("Assigned By : %s"), Whups::formatUser(Auth::getAuth())) . "\n";
$message .= sprintf(_("State : %s"), $state_name) . "\n";
@@ -205,6 +221,9 @@
$message = sprintf(_("-Ticket %s"), $ticket_id) . "\n";
$message .= sprintf(_("-Module: %s"), $info['_module_name']) . "\n";
+ if (!empty($info['_client_name'])) {
+ $message .= sprintf(_("-Client: %s"), $info['_client_name']) . "\n";
+ }
$message .= sprintf(_("-New State: %s"), $state_name) . "\n";
$message .= "\n" . _("-Summary:") . "\n" . $this->_splitMessage($info['summary']) . "\n";
$message .= '@@comment_placeholder@@';
@@ -223,6 +242,9 @@
$message = sprintf(_("-Ticket %s"), $ticket_id) . "\n";
$message .= sprintf(_("-Module: %s"), $info['_module_name']) . "\n";
+ if (!empty($info['_client_name'])) {
+ $message .= sprintf(_("-Client: %s"), $info['_client_name']) . "\n";
+ }
$message .= sprintf(_("-New Priority: %s"), $priority_name) . "\n";
$message .= "\n" . _("-Summary:") . "\n" . $this->_splitMessage($info['summary']) . "\n";
$message .= '@@comment_placeholder@@';
@@ -241,6 +263,9 @@
$message = sprintf(_("-Ticket %s"), $ticket_id) . "\n";
$message .= sprintf(_("-Module: %s"), $info['_module_name']) . "\n";
+ if (!empty($info['_client_name'])) {
+ $message .= sprintf(_("-Client: %s"), $info['_client_name']) . "\n";
+ }
$message .= sprintf(_("-New Type: %s"), $type_name) . "\n";
$message .= "\n" . _("-Summary:") . "\n" . $this->_splitMessage($info['summary']) . "\n";
$message .= '@@comment_placeholder@@';
Index: lib/Search.php
===================================================================
RCS file: /repository/whups/lib/Search.php,v
retrieving revision 1.54
diff -u -r1.54 Search.php
--- lib/Search.php 27 Jun 2003 19:19:23 -0000 1.54
+++ lib/Search.php 29 Jul 2003 04:55:31 -0000
@@ -86,6 +86,8 @@
$version = &$this->addVariable(_("Module Version"), 'version', 'text', true, true);
$version->setDefault($vars->getVar('_version_name') . ': ' . $vars->getVar('_version_description'));
}
+
+ $this->addVariable(_("Client"), 'client_name', 'text', true, true);
$this->addVariable(_("Ticket Type"), '_type_name', 'text', true, true);
$this->addVariable(_("Ticket State"), '_state_name', 'text', true, true);
Index: lib/Whups.php
===================================================================
RCS file: /repository/whups/lib/Whups.php,v
retrieving revision 1.61
diff -u -r1.61 Whups.php
--- lib/Whups.php 19 Jul 2003 18:29:27 -0000 1.61
+++ lib/Whups.php 29 Jul 2003 04:55:31 -0000
@@ -384,4 +384,15 @@
return implode(', ', $results);
}
+ function getClients($module = null, $ticket = null)
+ {
+ global $whups;
+ $clients = $whups->getClients($module, $ticket);
+ if (is_a($clients, 'PEAR_Error')) {
+ Horde::logMessage($clients, __FILE__, __LINE__, PEAR_LOG_ERR);
+ return $clients->getMessage();
+ }
+ return implode(', ', $clients);
+ }
+
}
Index: lib/Driver/sql.php
===================================================================
RCS file: /repository/whups/lib/Driver/sql.php,v
retrieving revision 1.114
diff -u -r1.114 sql.php
--- lib/Driver/sql.php 11 Jul 2003 20:18:18 -0000 1.114
+++ lib/Driver/sql.php 29 Jul 2003 04:55:32 -0000
@@ -728,6 +728,7 @@
function getTicketDetails($ticket)
{
+ global $conf;
$info = array('id' => $ticket);
$result = $this->getTicketsByProperties($info);
@@ -740,6 +741,13 @@
array_flip(Whups::permissionsFilter($this->getModules(), 'module', _PERMS_READ)))) {
return PEAR::raiseError(sprintf(_("You do not have permission to access this ticket (%s)."), $ticket),
0);
+ }
+
+ /* Add the client name for this ticket (if available). */
+ if (isset($conf['client']['driver']) && ($conf['client']['driver'] != 'none')) {
+ $client_name = Whups::getClients($result[0]['module'], $result[0]['id']);
+ $result[0]['_client_name'] = !empty($client_name) ? $client_name : '';
+
}
return $result[0];