You are here

function theme_patch_manager_formatter_issuelink in Patch manager 6

Theme an issue link.

File

./patch_manager.module, line 434
patch_manager.module Patch manager provides developers with tools for managing patches.

Code

function theme_patch_manager_formatter_issuelink($element) {
  $nid = $value = $element['#item']['value'];
  if (!$nid) {
    return NULL;
  }

  // Parse out the comment ID.
  if (strpos($nid, '/') !== FALSE) {
    list($nid, $comment) = explode('/', $nid);
  }

  // Get the issue status from drupal.org.
  static $issue_statuses = array();
  if (empty($issue_statuses[$nid])) {

    // Check cache.
    $cached = cache_get("patch_manager:issue_status:{$nid}");
    if (!$cached || !($issue_status = $cached->data)) {

      // Request to drupal.org to get the status.
      $response_json = drupal_http_request("http://drupal.org/node/{$nid}/project-issue/json");

      // Parse JSON-response to get item we need.
      $response = json_decode($response_json->data);
      $issue_status = $response->status;

      // Set cache for future requests.
      cache_set("patch_manager:issue_status:{$nid}", $issue_status);
    }

    // Set static value.
    $issue_statuses[$nid] = $issue_status;
  }

  // Set the status.
  $status = $issue_statuses[$nid];

  // URL options.
  $options = array();
  $options['attributes']['title'] = 'Issue status at drupal.org: ' . $status;

  // Map issue status with class.
  $map = array(
    'active' => 'state-1',
    'fixed' => 'state-2',
    'closed (duplicate)' => 'state-3',
    'postponed' => 'state-4',
    "closed (won't fix)" => 'state-5',
    'closed (works as designed)' => 'state-6',
    'closed (fixed)' => 'state-7',
    'needs review' => 'state-8',
    'needs work' => 'state-13',
    'reviewed & tested by the communty' => 'state-14',
    'patch (to be ported)' => 'state-15',
    'postponed (maintainer needs more info)' => 'state-16',
    'closed (cannot reproduce)' => 'state-18',
  );
  $class = $map[$status];

  // Add class for coloring depending on issue status.
  $options['attributes']['class'] = $class;

  // Add CSS.
  drupal_add_css(drupal_get_path('module', 'patch_manager') . '/patch_manager.css');

  // Display.
  return l($nid, 'http://drupal.org/node/' . $nid, $options);
}