You are here

protected function VisitorsBlock::_showUniqueVisitors in Visitors 8.2

Display unique visitors count to visitors block.

1 call to VisitorsBlock::_showUniqueVisitors()
VisitorsBlock::build in src/Plugin/Block/VisitorsBlock.php
Builds and returns the renderable array for this block plugin.

File

src/Plugin/Block/VisitorsBlock.php, line 68
Contains \Drupal\visitors\Plugin\Block\VisitorsBlock.

Class

VisitorsBlock
Provides a 'Visitors' block.

Namespace

Drupal\visitors\Plugin\Block

Code

protected function _showUniqueVisitors() {
  if ($this->config
    ->get('show_unique_visitor')) {
    $query = \Drupal::database()
      ->select('visitors');
    $query
      ->addExpression('COUNT(DISTINCT visitors_ip)');
    $unique_visitors = $query
      ->execute()
      ->fetchField();
    $this->items[] = t('Unique Visitors: %unique_visitors', array(
      '%unique_visitors' => $unique_visitors,
    ));
  }
}