From c2dcc1ac735e2b38e6289a729661e53ec45756e3 Mon Sep 17 00:00:00 2001 From: Marco Villegas Date: Sat, 7 Aug 2010 02:41:26 -0500 Subject: [PATCH] display project name on the project issue to link filter --- project_issue.module | 54 ++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 44 insertions(+), 10 deletions(-) diff --git project_issue.module project_issue.module index 32c2428..cc43803 100644 --- project_issue.module +++ project_issue.module @@ -398,6 +398,7 @@ function project_issue_theme() { 'comment_id' => NULL, 'comment_number' => NULL, 'include_assigned' => FALSE, + 'include_project_name' => FALSE, ), ), 'project_issue_issue_cockpit' => array( @@ -1127,9 +1128,15 @@ function project_issue_link_alter(&$links, $node) { * The comment's number, as visible to users, optional. * @param $include_assigned * Optional boolean to include the user the issue is assigned to. + * @param $include_project_name + * Optional boolean to include the name of the project the issue belongs to. */ -function theme_project_issue_issue_link($node, $comment_id = NULL, $comment_number = NULL, $include_assigned = FALSE) { +function theme_project_issue_issue_link($node, $comment_id = NULL, $comment_number = NULL, $include_assigned = FALSE, $include_project_name = FALSE) { $path = "node/$node->nid"; + if ($include_project_name) { + $project_node = node_load($node->project_issue['pid']); + $project_name = $project_node->project['uri']; + } // See if the issue is assigned to anyone. If so, we'll include it either // in the title attribute on hover, or next to the issue link if there was @@ -1145,19 +1152,41 @@ function theme_project_issue_issue_link($node, $comment_id = NULL, $comment_numb // We have an assigned user, but we're not going to print it next to the // issue link, so include it in title. l() runs $attributes through // drupal_attributes() which escapes the value. - $attributes = array('title' => t('Status: !status, Assigned to: !username', array('!status' => project_issue_state($node->project_issue['sid']), '!username' => $username))); + + // avoid the project name when not needed since it needs extra queries + if ($include_project_name) { + $attributes = array('title' => t('Project: !project_name, Status: !status, Assigned to: !username', array('!project_name' => $project_name, '!status' => project_issue_state($node->project_issue['sid']), '!username' => $username))); + } + else { + $attributes = array('title' => t('Status: !status, Assigned to: !username', array('!status' => project_issue_state($node->project_issue['sid']), '!username' => $username))); + } } else { // Just the status. - $attributes = array('title' => t('Status: !status', array('!status' => project_issue_state($node->project_issue['sid'])))); + if ($include_project_name) { + $attributes = array('title' => t('Project: !project_name, Status: !status', array('!project_name' => $project_name, '!status' => project_issue_state($node->project_issue['sid'])))); + } + else { + $attributes = array('title' => t('Status: !status', array('!status' => project_issue_state($node->project_issue['sid'])))); + } } if (isset($comment_id)) { - $title = "#$node->nid-$comment_number: $node->title"; + if ($include_project_name) { + $title = "#$node->nid-$comment_number [$project_name]: $node->title"; + } + else { + $title = "#$node->nid-$comment_number: $node->title"; + } $link = l($title, $path, array('attributes' => $attributes, 'fragment' => "comment-$comment_id")); } else { - $title = "#$node->nid: $node->title"; + if ($include_project_name) { + $title = "#$node->nid [$project_name]: $node->title"; + } + else { + $title = "#$node->nid: $node->title"; + } $link = l($title, $path, array('attributes' => $attributes)); } $output = ''. $link; @@ -1196,7 +1225,7 @@ function project_issue_filter($op, $delta = 0, $format = -1, $text = '') { case 'prepare': return $text; case 'process': - $regex = '(?:(?.*?<\/pre>|.*?<\/code>|"\']|"[^"]*"|\'[^\']*\')*>.*?<\/a>'; + $regex = '(?:(?.*?<\/pre>|.*?<\/code>|"\']|"[^"]*"|\'[^\']*\')*>.*?<\/a>'; $text = preg_replace_callback("/$regex/", 'project_issue_link_filter_callback', $text); return $text; @@ -1205,21 +1234,26 @@ function project_issue_filter($op, $delta = 0, $format = -1, $text = '') { function project_issue_link_filter_callback($matches) { $parts = array(); - if (preg_match('/^\[#(\d+)(?:-(\d+))?(@)?\]$/', $matches[0], $parts)) { + if (preg_match('/^\[#(\d+)(?:-(\d+))?([@P]{1,2})?\]$/', $matches[0], $parts)) { $nid = $parts[1]; $node = node_load($nid); - $include_assigned = isset($parts[3]); + $include_assigned = FALSE; + $include_project_name = FALSE; + if (isset($parts[3])) { + $include_assigned = strpos($parts[3], '@') !== FALSE; + $include_project_name = strpos($parts[3], 'P') !== FALSE; + } if (is_object($node) && node_access('view', $node) && $node->type == 'project_issue') { if (isset($parts[2])) { // Pull comment id based on the comment number if we have one. $comment_number = $parts[2]; if ($comment_id = db_result(db_query("SELECT pic.cid FROM {project_issue_comments} pic INNER JOIN {comments} c ON pic.cid = c.cid WHERE pic.nid = %d AND pic.comment_number = %d AND c.status = %d", $nid, $comment_number, COMMENT_PUBLISHED))) { - return theme('project_issue_issue_link', $node, $comment_id, $comment_number, $include_assigned); + return theme('project_issue_issue_link', $node, $comment_id, $comment_number, $include_assigned, $include_project_name); } } // If we got this far there wasn't a valid comment number, so just link // to the node instead. - return theme('project_issue_issue_link', $node, NULL, NULL, $include_assigned); + return theme('project_issue_issue_link', $node, NULL, NULL, $include_assigned, $include_project_name); } } // If we haven't already returned a replacement, return the original text. -- 1.7.1