You are here

function file_download_counter_ranking in File Download 8

Implements hook_ranking().

File

modules/file_download_counter/file_download_counter.module, line 117
Logs and displays content file_download_counter for a site.

Code

function file_download_counter_ranking() {
  if (\Drupal::config('file_download_counter.settings')
    ->get('count_content_views')) {
    return [
      'views' => [
        'title' => t('Number of downloads'),
        'join' => [
          'type' => 'LEFT',
          'table' => 'file_download_counter',
          'alias' => 'file_download_counter',
          'on' => 'file_download_counter.fid = i.fid',
        ],
        // 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 :file_download_counter_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 + node_counter.totalcount * (ROUND(:file_download_counter_scale, 4)))',
        'arguments' => [
          ':file_download_counter_scale' => \Drupal::state()
            ->get('file_download_counter.node_counter_scale') ?: 0,
        ],
      ],
    ];
  }
}