Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
VisitorsLocalHour
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 query
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace Drupal\visitors\Plugin\views\field;
4
5use Drupal\views\Plugin\views\field\FieldPluginBase;
6
7/**
8 * Field handler to display the hour (server) of the visit.
9 *
10 * @ingroup views_field_handlers
11 *
12 * @ViewsField("visitors_local_hour")
13 */
14final class VisitorsLocalHour extends FieldPluginBase {
15
16  /**
17   * {@inheritdoc}
18   */
19  public function query() {
20    $this->ensureMyTable();
21    // Add the field.
22    $params = $this->options['group_type'] != 'group' ? ['function' => $this->options['group_type']] : [];
23    /** @var \Drupal\views\Plugin\views\query\Sql $query */
24    $query = $this->query;
25    $field = $this->configuration['field'];
26    $alias = 'visitors_visitor_localtime';
27    $this->field_alias = $query->addField(NULL, "FLOOR($field/3600)", $alias, $params);
28
29    $this->addAdditionalFields();
30  }
31
32}