You are here

function heartbeat_get_message_reactions in Heartbeat 7

Same name and namespace in other branches
  1. 6.4 modules/heartbeat_comments/heartbeat_comments.module \heartbeat_get_message_reactions()

Get heartbeat comments on a message

Parameters

$uid user_id of comment to load:

1 call to heartbeat_get_message_reactions()
heartbeat_get_reactions in modules/heartbeat_comments/heartbeat_comments.module
Function to fetch reactions on a heartbeat message.

File

modules/heartbeat_comments/heartbeat_comments.module, line 780
Heartbeat comments for activity.

Code

function heartbeat_get_message_reactions($uaid, $all = FALSE) {
  static $locale;
  if (!isset($locale)) {
    $locale = module_exists('locale');
  }
  $reactions = array();
  $query = "SELECT s.hcid, s.uid, s.message AS 'comment', s.cleared, s.time AS 'changed', u.uid\n    FROM {heartbeat_comments} s INNER JOIN {users} u ON s.uid = u.uid\n    WHERE s.uaid = :uaid ORDER BY changed DESC";
  if ($all) {
    $result = db_query($query, array(
      ':uaid' => $uaid,
    ));
  }
  else {
    $result = db_query_range($query, 0, heartbeat_plugins_get_plugin('activitycomments')
      ->getPlugin()->HEARTBEAT_REACTIONS_PER_PAGE, array(
      ':uaid' => $uaid,
    ));
  }
  $tags = heartbeat_allowed_html_tags();
  $uids = array();
  foreach ($result as $comment) {

    // Sanitize the comment messages.
    $comment->comment = filter_xss($comment->comment, $tags);
    $comment->uaid = $uaid;
    $reactions[] = $comment;
    $uids[$comment->uid] = $comment->uid;
  }
  $accounts = user_load_multiple($uids);

  // Merge the most used properties to the comment object.
  // E.g. Realname module can alter the name.
  foreach ($reactions as $key => $comment) {
    $account = $accounts[$comment->uid];
    $reactions[$key]->realname = isset($account->realname) ? $account->realname : $account->name;
    $reactions[$key]->name = $account->name;
    $reactions[$key]->picture = $account->picture;
    $reactions[$key]->data = $account->data;
    $reactions[$key]->signature = $account->signature;
  }
  return $reactions;
}