ElggEntity::countComments PHP Method

countComments() public method

Count the number of comments attached to this entity.
Since: 1.8.0
public countComments ( ) : integer
return integer Number of comments
    public function countComments()
    {
        $params = array('entity' => $this);
        $num = _elgg_services()->hooks->trigger('comments:count', $this->getType(), $params);
        if (is_int($num)) {
            return $num;
        } else {
            return elgg_get_entities(array('type' => 'object', 'subtype' => 'comment', 'container_guid' => $this->getGUID(), 'count' => true, 'distinct' => false));
        }
    }

Usage Example

Example #1
0
/**
 * Count the number of comments attached to an entity
 *
 * @param ElggEntity $entity
 * @return int Number of comments
 * @deprecated 1.8 Use ElggEntity->countComments()
 */
function elgg_count_comments($entity)
{
    elgg_deprecated_notice('elgg_count_comments() is deprecated by ElggEntity->countComments()', 1.8);
    if ($entity instanceof ElggEntity) {
        return $entity->countComments();
    }
    return 0;
}