Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
36 / 36 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
Referer | |
100.00% |
36 / 36 |
|
100.00% |
4 / 4 |
4 | |
100.00% |
1 / 1 |
create | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
__construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
display | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
getHeader | |
100.00% |
15 / 15 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace Drupal\visitors\Controller\Report; |
4 | |
5 | use Drupal\Core\Controller\ControllerBase; |
6 | use Drupal\Core\Datetime\DateFormatterInterface; |
7 | use Drupal\Core\Form\FormBuilderInterface; |
8 | use Drupal\Core\StringTranslation\TranslationInterface; |
9 | use Drupal\visitors\VisitorsReportInterface; |
10 | use Symfony\Component\DependencyInjection\ContainerInterface; |
11 | |
12 | /** |
13 | * Referer Report controller. |
14 | */ |
15 | final class Referer extends ControllerBase { |
16 | /** |
17 | * The date service. |
18 | * |
19 | * @var \Drupal\Core\Datetime\DateFormatterInterface |
20 | */ |
21 | protected $date; |
22 | |
23 | /** |
24 | * The form builder service. |
25 | * |
26 | * @var \Drupal\Core\Form\FormBuilderInterface |
27 | */ |
28 | protected $formBuilder; |
29 | |
30 | /** |
31 | * The report service. |
32 | * |
33 | * @var \Drupal\visitors\VisitorsReportInterface |
34 | */ |
35 | protected $report; |
36 | |
37 | /** |
38 | * {@inheritdoc} |
39 | */ |
40 | public static function create(ContainerInterface $container): Referer { |
41 | return new self( |
42 | $container->get('date.formatter'), |
43 | $container->get('form_builder'), |
44 | $container->get('visitors.report'), |
45 | $container->get('string_translation') |
46 | ); |
47 | } |
48 | |
49 | /** |
50 | * Constructs a Referer object. |
51 | * |
52 | * @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter |
53 | * The date service. |
54 | * @param \Drupal\Core\Form\FormBuilderInterface $form_builder |
55 | * The form builder service. |
56 | * @param \Drupal\visitors\VisitorsReportInterface $report_service |
57 | * The report service. |
58 | * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation |
59 | * The string translation service. |
60 | */ |
61 | public function __construct(DateFormatterInterface $date_formatter, FormBuilderInterface $form_builder, VisitorsReportInterface $report_service, TranslationInterface $string_translation) { |
62 | |
63 | $this->date = $date_formatter; |
64 | $this->formBuilder = $form_builder; |
65 | $this->report = $report_service; |
66 | $this->setStringTranslation($string_translation); |
67 | } |
68 | |
69 | /** |
70 | * Returns a referer page. |
71 | * |
72 | * @return array |
73 | * A render array representing the referrers page content. |
74 | */ |
75 | public function display(): array { |
76 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\Referer'); |
77 | $header = $this->getHeader(); |
78 | |
79 | return [ |
80 | 'visitors_date_filter_form' => $form, |
81 | 'visitors_table' => [ |
82 | '#type' => 'table', |
83 | '#header' => $header, |
84 | '#rows' => $this->report->referer($header), |
85 | ], |
86 | 'visitors_pager' => ['#type' => 'pager'], |
87 | ]; |
88 | } |
89 | |
90 | /** |
91 | * Returns a table header configuration. |
92 | * |
93 | * @return array |
94 | * A render array representing the table header info. |
95 | */ |
96 | protected function getHeader(): array { |
97 | return [ |
98 | 'visitors_referer' => [ |
99 | 'data' => $this->t('Referer'), |
100 | 'field' => 'visitors_referer', |
101 | 'specifier' => 'visitors_referer', |
102 | 'class' => [RESPONSIVE_PRIORITY_LOW], |
103 | ], |
104 | 'count' => [ |
105 | 'data' => $this->t('Count'), |
106 | 'field' => 'count', |
107 | 'specifier' => 'count', |
108 | 'class' => [RESPONSIVE_PRIORITY_LOW], |
109 | 'sort' => 'desc', |
110 | ], |
111 | ]; |
112 | } |
113 | |
114 | } |