From ac67da39a17f0baaf115074da3ac91a93e0c1f94 Mon Sep 17 00:00:00 2001
From: Moshe Weitzman <weitzman@tejasa.com>
Date: Fri, 15 Jul 2011 13:22:02 -0400
Subject: [PATCH] Feature #112805 by moshe weitzman. JSON callback for an issue.

---
 includes/project_issue.json.inc |   33 +++++++++++++++++++++++++++++++++
 project_issue.module            |   14 ++++++++++++++
 2 files changed, 47 insertions(+), 0 deletions(-)
 create mode 100644 includes/project_issue.json.inc

diff --git a/includes/project_issue.json.inc b/includes/project_issue.json.inc
new file mode 100644
index 0000000..fbbfde2
--- /dev/null
+++ b/includes/project_issue.json.inc
@@ -0,0 +1,33 @@
+<?php
+
+/**
+ * Menu callback. Returns JSON for an issue node.
+ *
+ * @param $node_issue
+ *   A node of type project_issue.
+ * @return void
+ */
+function project_issue_json($node_issue) {
+  if ($node_project = node_load($node_issue->project_issue['pid'])) {
+    $options = array('absolute' => TRUE);
+    $return = array(
+      // Bump minor version when you add items. Bump major version when breaking backwards compatibility.
+      'json-version' => '1.0',
+      'title' => $node_issue->title,
+      'description' => $node_issue->body,
+      'id' => $node_issue->nid,
+      'url' => url('node/' . $node_issue->nid, $options),
+      'component' => $node_issue->project_issue['component'],
+      'priority' => $node_issue->project_issue['priority'],
+      'version' => $node_issue->project_issue['rid'],
+      'assigned' => $node_issue->project_issue['assigned'],
+      'status' => $node_issue->project_issue['sid'],
+      'project-id' => $node_project->nid,
+      'project-title' => $node_project->title,
+      'project-url' => url('node/' . $node_project->nid, $options),
+      'project-project' => $node_project->project['uri'],
+    );
+    drupal_alter('project_issue_json', $return);
+    drupal_json($return);
+  }
+}
\ No newline at end of file
diff --git a/project_issue.module b/project_issue.module
index 7c57e27..aa910fa 100644
--- a/project_issue.module
+++ b/project_issue.module
@@ -193,6 +193,16 @@ function project_issue_menu() {
     'type' => MENU_CALLBACK,
   );
 
+  $items['node/%node/json'] = array(
+    'title' => 'JSON',
+    'page callback' => 'project_issue_json',
+    'page arguments' => array(1),
+    'access callback' => 'project_issue_menu_access_task',
+    'access arguments' => array(1),
+    'type' => MENU_LOCAL_TASK,
+    'file' => 'includes/project_issue.json.inc',
+    'weight' => 10,
+  );
   // Autocomplete paths.
 
   // Autocomplete a comma-separated list of projects that have issues enabled.
@@ -259,6 +269,10 @@ function project_issue_menu_access($type) {
   return user_access('access project issues') || user_access('access own project issues');
 }
 
+function project_issue_menu_access_task($node) {
+  return $node->type == 'project_issue' && node_access('view', $node);
+}
+
 function project_issue_help($path, $arg) {
   switch ($path) {
     case 'admin/help#project_issue':
-- 
1.7.4.1

