0

I'm writing a module that uses flag to handle notifications, and one of the options is to be notified of replies to a given comment.

I can implement without problem hook_comment_publish($comment), but I want to get all of its parent comments so that I can pick up the users that flagged them.

So, how can I retrieve all the parent comments of a given comment (if any)? I noticed that in taxonomy there is a taxonomy_get_parents($tid) but I can't find anything similar for threatened comments.

0

This code does the trick:

  $threads = explode('.', $comment->thread);
  $thread = "";
  $pnids = array();
  for($i=0;$i<(count($threads)-1);$i++){
        $thread .= $threads[$i];
        $local_thread = $thread."/";
        $result = db_query('SELECT c.cid FROM {comment} c WHERE c.nid = :nid AND c.thread = :thread AND c.status = :status',
        array(':nid' => $comment->nid, ':thread' => $local_thread, ':status'=>'1'));
        foreach ($result as $record) {
            $pnids[] = $record->cid;
        }
        $thread .= ".";
  }

However this code produces 1 DB query for each parent. I don't know if it is feasible/better to include all the :thread in a single query with OR.

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.