1

I'd like to be able to let a user know that their comment has been submitted and is awaiting approval on every view of that particular node, not just a notification printed in the message region immediately after a submission. I assume there's a way to cross-check the current node's unpublished comments and print something in the comment area if the user shows up as an author of an unpublished comment. I have a feeling I can write a simple function, something like below, but I'm missing something and I'm not sure where to run it (ie, in the .tpl or in an .inc):

function find_unpublished_comments_of_current_user(&$comment, &$user) {
    if ($comment->status == 0 && $user->id == $comment->uid){
      //something here 
      }
}

Thanks for any help.

  • After exploring what's available in node.tpl.php and comment.tpl.php it appears that I can access all comments from the $content['comments'] array and $comment array respectively, but neither hold unpublished comments. So I'm thinking that this does indeed need to be a preprocessor – cdmo Oct 16 '12 at 2:51
0

You can achieve this in either of the following way,

1) If you are writing custom function as described in question, a) Write your function in a block by selecting text format as PHP code, and display the block in desired region. b) Otherwise define the function in your module and call it in your node template file node--type.tpl.php

2) Through view: Create a view to show un published comments of a node as follows,

View

Create a view: Settings: Show: Comments Create block: select Click save & continue

Filter criteria Comment: Approved (No) Advanced->Add Contextual filters

  1. Content: Nid

    Under When the filter value is NOT available

    Provide default value : Content ID from URL

  2. Comment: Author uid Provide default value ->choose user id from logged in user

Now assign your block to a region on the node display page, you will get unpublished comments of the particular user for that node,

  • Thanks for the ideas. I tried option 2, but couldn't seem to get it to work. Passed the nid and uid as contextual filters and placed a block for the view in the content area of nodes and nothing showed up. Tried adding a filter of "Current user logged in" and that didn't work either. – cdmo Oct 16 '12 at 2:48
  • I edited answer for view part, i tried this and got work so please check your views settings with answer – Anoop Joseph Oct 16 '12 at 4:21
0

I got around to doing this finally:

function comment_detection_node_view($node, $view_mode, $langcode) {

  $current_user_id = $GLOBALS['user']->uid;
  $node_id = $node->vid;

  $query = "SELECT COUNT(c.cid) FROM {comment} c WHERE c.uid = $current_user_id AND c.status = 0 AND c.nid = $node_id";
  $result = db_query($query);

  if ($result) {
    while ($row = $result->fetchAssoc()) {
      $comment_detector = $row['COUNT(c.cid)'];
    }
  }
  // $comment_detector is the number of comments on the current node by the user  
  // logged in that are unpublished, i.e. 0 or 1.  

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.