function CommentStatistics::getRankingInfo

Same name and namespace in other branches
  1. 9 core/modules/comment/src/CommentStatistics.php \Drupal\comment\CommentStatistics::getRankingInfo()
  2. 8.9.x core/modules/comment/src/CommentStatistics.php \Drupal\comment\CommentStatistics::getRankingInfo()
  3. 10 core/modules/comment/src/CommentStatistics.php \Drupal\comment\CommentStatistics::getRankingInfo()

File

core/modules/comment/src/CommentStatistics.php, line 173

Class

CommentStatistics

Namespace

Drupal\comment

Code

public function getRankingInfo() {
    return [
        'comments' => [
            'title' => t('Number of comments'),
            'join' => [
                'type' => 'LEFT',
                'table' => 'comment_entity_statistics',
                'alias' => 'ces',
                // Default to comment field as this is the most common use case for
                // nodes.
'on' => "ces.entity_id = i.sid AND ces.entity_type = 'node' AND ces.field_name = 'comment'",
            ],
            // Inverse law that maps the highest view count on the site to 1 and 0
            // to 0. Note that the ROUND here is necessary for PostgreSQL and SQLite
            // in order to ensure that the :comment_scale argument is treated as
            // a numeric type, because the PostgreSQL PDO driver sometimes puts
            // values in as strings instead of numbers in complex expressions like
            // this.
'score' => '2.0 - 2.0 / (1.0 + ces.comment_count * (ROUND(:comment_scale, 4)))',
            'arguments' => [
                ':comment_scale' => \Drupal::state()->get('comment.node_comment_statistics_scale', 0),
            ],
        ],
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.