/** * @param $guid * @param $username * @param int $limit * @param int $offset * @return array * @throws InvalidParameterException */ function wire_get_comments($guid, $username, $limit = 20, $offset = 0) { if (!$username) { $user = elgg_get_logged_in_user_entity(); } else { $user = get_user_by_username($username); if (!$user) { throw new InvalidParameterException('registration:usernamenotvalid'); } } $options = array("metadata_name" => "wire_thread", "metadata_value" => $guid, "type" => "object", "subtype" => "thewire", "limit" => $limit, "offset" => $offset); $comments = get_elgg_comments($options, 'elgg_get_entities_from_metadata'); $return = array(); if ($comments) { foreach ($comments as $single) { $comment['guid'] = $single->guid; $comment['description'] = $single->description; $owner = get_entity($single->owner_guid); $comment['owner']['guid'] = $owner->guid; $comment['owner']['name'] = $owner->name; $comment['owner']['username'] = $owner->username; $comment['owner']['avatar_url'] = getProfileIcon($owner); //$owner->getIconURL('small'); $comment['time_created'] = time_ago($single->time_created); $comment['like_count'] = likes_count_number_of_likes($single->guid); $comment['like'] = checkLike($single->guid, $user->guid); $return[] = $comment; } } else { $msg = elgg_echo('generic_comment:none'); throw new InvalidParameterException($msg); } return $return; }
/** * @param $activity * @return int */ function getCommentCount($activity) { if ($activity->subtype == "thewire") { $options = array("metadata_name" => "wire_thread", "metadata_value" => $activity->object_guid, "type" => "object", "subtype" => "thewire", "limit" => 0); $comments = get_elgg_comments($options, 'elgg_get_entities_from_metadata'); } else { $comments = elgg_get_entities(array('type' => 'object', 'subtype' => 'comment', 'container_guid' => $activity->object_guid, "limit" => 0)); } $comment_count = sizeof($comments); if ($comment_count >= 1 && $activity->subtype == "thewire") { $comment_count = $comment_count - 1; } return $comment_count; }