From d93b4c75b6ce66720c28896cba0eb91aa6770428 Mon Sep 17 00:00:00 2001
From: Moshe Weitzman <weitzman@tejasa.com>
Date: Fri, 15 Jul 2011 13:22:23 -0400
Subject: [PATCH] Feature [#112805] by Moshe Weitzman. Add information about attachments, contributors, and comments to the JSON for an issue.

---
 comment_upload.module |   36 +++++++++++++++++++++++++++++++++++-
 1 files changed, 35 insertions(+), 1 deletions(-)

diff --git a/comment_upload.module b/comment_upload.module
index 4cb9ca0..a0131e2 100644
--- a/comment_upload.module
+++ b/comment_upload.module
@@ -194,6 +194,40 @@ function comment_upload_file_download($filepath) {
   }
 }
 
+function comment_upload_project_issue_json_alter(&$issue) {
+  $result = comment_upload_fetch_all($issue['id']);
+  while ($row = db_fetch_object($result)) {
+    $issue['attachments'][$row->cid][$row->fid] = array(
+      'contributor' => $row->uid,
+      'url' => file_create_url($row->filepath),
+      'comment-id' => $row->cid,
+    );
+    $issue['contributors'][$row->uid] = array(
+      'name' => $row->name,
+      'uid' => $row->uid,
+      'url' => url('user/' . $row->uid, array('absolute' => TRUE)),
+    );
+    $issue['comments'][$row->cid] = array(
+      'contributor' => $row->uid,
+      'url' => url('node/' . $issue['id'], array('absolute' => TRUE, 'fragment' => 'comment-' . $row->cid)),
+      'status' => $row->status,
+      'thread' => $row->thread,
+    );
+  }
+}
+
+/**
+ * Retrieve all files attached to a given node.
+ *
+ * @param $nid
+ *   A node ID.
+ * @return resource
+ *   A database result resource or FALSE if the query fails.
+ */
+function comment_upload_fetch_all($nid) {
+  return db_query("SELECT cu.fid, cu.nid, cu.cid, f.filepath, c.status, c.thread, u.uid, u.name  FROM {comment_upload} cu INNER JOIN {files} f ON cu.fid = f.fid INNER JOIN {comments} c ON cu.cid = c.cid INNER JOIN {users} u ON c.uid = u.uid WHERE cu.nid = %d ORDER BY cu.cid ASC, fid ASC", $nid);
+}
+
 /*
  * Listen to node deletion and delete files from comments on that node.
  *
@@ -203,7 +237,7 @@ function comment_upload_file_download($filepath) {
  */
 function comment_upload_nodeapi(&$node, $op, $arg = 0) {
   if ($op == 'delete') {
-    $result = db_query("SELECT cu.fid, cu.nid, f.filepath FROM {comment_upload} cu INNER JOIN {files} f ON cu.fid = f.fid WHERE cu.nid = %d", $node->nid);
+    $result = comment_upload_fetch_all($node->nid);
     while ($row = db_fetch_array($result)) {
       // comment_upload_delete_file just needs a filepath and a fid.
       comment_upload_delete_file($row);
-- 
1.7.4.1

