Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
94.39% |
589 / 624 |
|
96.97% |
32 / 33 |
CRAP | |
0.00% |
0 / 1 |
ReportController | |
94.39% |
589 / 624 |
|
96.97% |
32 / 33 |
65.75 | |
0.00% |
0 / 1 |
create | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
__construct | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
renderViews | |
100.00% |
22 / 22 |
|
100.00% |
1 / 1 |
8 | |||
software | |
100.00% |
38 / 38 |
|
100.00% |
1 / 1 |
1 | |||
time | |
100.00% |
63 / 63 |
|
100.00% |
1 / 1 |
1 | |||
path | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
1 | |||
entryPath | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
1 | |||
exitPath | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
1 | |||
topHost | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
1 | |||
recentHost | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
1 | |||
getHostTitle | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
topRoute | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
1 | |||
entryRoute | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
1 | |||
exitRoute | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
1 | |||
recentRoute | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
1 | |||
getRouteTitle | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
recentViews | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
1 | |||
nodeViews | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
1 | |||
device | |
100.00% |
35 / 35 |
|
100.00% |
1 / 1 |
1 | |||
location | |
100.00% |
45 / 45 |
|
100.00% |
1 / 1 |
1 | |||
getContinentTitle | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
continent | |
100.00% |
27 / 27 |
|
100.00% |
1 / 1 |
2 | |||
getCountryTitle | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
country | |
100.00% |
31 / 31 |
|
100.00% |
1 / 1 |
3 | |||
performance | |
100.00% |
19 / 19 |
|
100.00% |
1 / 1 |
5 | |||
getRegionTitle | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
4 | |||
region | |
100.00% |
30 / 30 |
|
100.00% |
1 / 1 |
4 | |||
getCityTitle | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
6 | |||
city | |
100.00% |
36 / 36 |
|
100.00% |
1 / 1 |
6 | |||
user | |
100.00% |
18 / 18 |
|
100.00% |
1 / 1 |
1 | |||
social | |
100.00% |
18 / 18 |
|
100.00% |
1 / 1 |
1 | |||
ai | |
100.00% |
18 / 18 |
|
100.00% |
1 / 1 |
1 | |||
engagement | |
0.00% |
0 / 35 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Drupal\visitors\Controller; |
4 | |
5 | use Drupal\Core\Config\ConfigFactoryInterface; |
6 | use Drupal\Core\Controller\ControllerBase; |
7 | use Drupal\Core\Extension\ModuleHandlerInterface; |
8 | use Drupal\Core\Form\FormBuilderInterface; |
9 | use Drupal\Core\Messenger\MessengerInterface; |
10 | use Drupal\Core\Session\AccountProxyInterface; |
11 | use Drupal\Core\StringTranslation\TranslationInterface; |
12 | use Drupal\visitors\VisitorsLocationInterface; |
13 | use Symfony\Component\DependencyInjection\ContainerInterface; |
14 | |
15 | /** |
16 | * Generic Report controller. |
17 | */ |
18 | class ReportController extends ControllerBase { |
19 | |
20 | |
21 | /** |
22 | * The date service. |
23 | * |
24 | * @var \Drupal\Core\Datetime\DateFormatterInterface |
25 | */ |
26 | protected $date; |
27 | |
28 | /** |
29 | * The form builder service. |
30 | * |
31 | * @var \Drupal\Core\Form\FormBuilderInterface |
32 | */ |
33 | protected $formBuilder; |
34 | |
35 | /** |
36 | * The settings. |
37 | * |
38 | * @var \Drupal\Core\Config\Config |
39 | */ |
40 | protected $settings; |
41 | |
42 | /** |
43 | * The current user. |
44 | * |
45 | * @var \Drupal\Core\Session\AccountProxyInterface |
46 | */ |
47 | protected $account; |
48 | |
49 | /** |
50 | * The location service. |
51 | * |
52 | * @var \Drupal\visitors\VisitorsLocationInterface |
53 | */ |
54 | protected $location; |
55 | |
56 | /** |
57 | * The module handler. |
58 | * |
59 | * @var \Drupal\Core\Extension\ModuleHandlerInterface |
60 | */ |
61 | protected $moduleHandler; |
62 | |
63 | /** |
64 | * {@inheritdoc} |
65 | */ |
66 | public static function create(ContainerInterface $container) { |
67 | return new self( |
68 | $container->get('form_builder'), |
69 | $container->get('string_translation'), |
70 | $container->get('config.factory'), |
71 | $container->get('messenger'), |
72 | $container->get('current_user'), |
73 | $container->get('visitors.location'), |
74 | $container->get('module_handler') |
75 | ); |
76 | } |
77 | |
78 | /** |
79 | * Constructs the report controller. |
80 | * |
81 | * @param \Drupal\Core\Form\FormBuilderInterface $form_builder |
82 | * The form builder service. |
83 | * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation |
84 | * The string translation service. |
85 | * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory |
86 | * The config factory. |
87 | * @param \Drupal\Core\Messenger\MessengerInterface $messenger |
88 | * The messenger service. |
89 | * @param \Drupal\Core\Session\AccountProxyInterface $current_user |
90 | * The current user. |
91 | * @param \Drupal\visitors\VisitorsLocationInterface $location |
92 | * The location service. |
93 | * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler |
94 | * The module handler. |
95 | */ |
96 | public function __construct(FormBuilderInterface $form_builder, TranslationInterface $string_translation, ConfigFactoryInterface $config_factory, MessengerInterface $messenger, AccountProxyInterface $current_user, VisitorsLocationInterface $location, ModuleHandlerInterface $module_handler) { |
97 | |
98 | $this->formBuilder = $form_builder; |
99 | $this->account = $current_user; |
100 | $this->location = $location; |
101 | $this->moduleHandler = $module_handler; |
102 | |
103 | $this->settings = $config_factory->get('visitors.settings'); |
104 | |
105 | $this->setStringTranslation($string_translation); |
106 | $this->setMessenger($messenger); |
107 | } |
108 | |
109 | /** |
110 | * Render the registered blocks as output. |
111 | * |
112 | * @param array $blocks |
113 | * An array of block items formatted for rendering a view. |
114 | * @param string|null $class |
115 | * An optional class to add to the wrapper div. |
116 | * @param array|null $args |
117 | * An optional array of arguments to pass to the view. |
118 | */ |
119 | public function renderViews(array $blocks, $class = NULL, $args = NULL) { |
120 | $output = []; |
121 | // Render each block element. |
122 | foreach ($blocks as $block) { |
123 | if (empty($block['#view_id'])) { |
124 | |
125 | $build = $block; |
126 | } |
127 | else { |
128 | $view_id = $block['#view_id']; |
129 | $display_id = $block['#view_display']; |
130 | |
131 | if (is_null($args)) { |
132 | // Create a view embed for this content. |
133 | $build = \views_embed_view($view_id, $display_id); |
134 | } |
135 | else { |
136 | if (!is_array($args)) { |
137 | $args = [$args]; |
138 | } |
139 | // Create a view embed for this content. |
140 | $build = \views_embed_view($view_id, $display_id, ...$args); |
141 | } |
142 | |
143 | } |
144 | if (!isset($build['#attributes']) && isset($block['#attributes'])) { |
145 | $build['#attributes'] = $block['#attributes']; |
146 | } |
147 | |
148 | $output[] = $build; |
149 | } |
150 | $prefix = '<div>'; |
151 | if (!empty($class)) { |
152 | $prefix = '<div class="' . $class . '">'; |
153 | } |
154 | return [ |
155 | '#prefix' => $prefix, |
156 | 'blocks' => $output, |
157 | '#suffix' => '</div>', |
158 | ]; |
159 | } |
160 | |
161 | /** |
162 | * Returns software report. |
163 | * |
164 | * @return array |
165 | * A render array representing the days of month page content. |
166 | */ |
167 | public function software(): array { |
168 | |
169 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
170 | $first_row = []; |
171 | $second_row = []; |
172 | |
173 | $first_row['os_version_table'] = [ |
174 | '#view_id' => 'visitors', |
175 | '#view_display' => 'os_version_table', |
176 | '#attributes' => [ |
177 | 'class' => ['layout-column--half'], |
178 | ], |
179 | ]; |
180 | $first_row['browser_version_table'] = [ |
181 | '#view_id' => 'visitors', |
182 | '#view_display' => 'browser_version_table', |
183 | '#attributes' => [ |
184 | 'class' => ['layout-column--half'], |
185 | ], |
186 | ]; |
187 | |
188 | $second_row['device_config_table'] = [ |
189 | '#view_id' => 'visitors', |
190 | '#view_display' => 'device_config_table', |
191 | '#attributes' => [ |
192 | 'class' => ['layout-column--half'], |
193 | ], |
194 | ]; |
195 | $second_row['browser_engine_pie'] = [ |
196 | '#view_id' => 'visitors', |
197 | '#view_display' => 'browser_engine_pie', |
198 | '#attributes' => [ |
199 | 'class' => ['layout-column--half'], |
200 | ], |
201 | ]; |
202 | |
203 | $third_row['browser_plugin_list'] = [ |
204 | '#view_id' => 'visitors', |
205 | '#view_display' => 'browser_plugin_list', |
206 | '#attributes' => [ |
207 | 'class' => ['layout-column--half'], |
208 | ], |
209 | ]; |
210 | |
211 | return [ |
212 | 'visitors_date_filter_form' => $form, |
213 | 'main' => [ |
214 | '#type' => 'container', |
215 | '#attributes' => [ |
216 | 'class' => ['visitors-main'], |
217 | ], |
218 | '1' => [ |
219 | $this->renderViews($first_row, 'layout-row'), |
220 | ], |
221 | '2' => [ |
222 | $this->renderViews($second_row, 'layout-row'), |
223 | ], |
224 | '3' => [ |
225 | $this->renderViews($third_row, 'layout-row'), |
226 | ], |
227 | ], |
228 | '#attached' => [ |
229 | 'library' => [ |
230 | 'visitors/visitors.report', |
231 | ], |
232 | ], |
233 | ]; |
234 | } |
235 | |
236 | /** |
237 | * Returns a time report. |
238 | * |
239 | * @return array |
240 | * A render array representing the hours page content. |
241 | */ |
242 | public function time($scope = 'visit'): array { |
243 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
244 | |
245 | $first_row['daily_column'] = [ |
246 | '#view_id' => 'visitors', |
247 | '#view_display' => "daily_{$scope}_column", |
248 | ]; |
249 | |
250 | $second_row['local_hour_column'] = [ |
251 | '#view_id' => 'visitors', |
252 | '#view_display' => "local_hour_{$scope}_column", |
253 | '#attributes' => [ |
254 | 'class' => ['layout-column--half'], |
255 | ], |
256 | ]; |
257 | $second_row['hour_column'] = [ |
258 | '#view_id' => 'visitors', |
259 | '#view_display' => "hour_{$scope}_column", |
260 | '#attributes' => [ |
261 | 'class' => ['layout-column--half'], |
262 | ], |
263 | ]; |
264 | |
265 | $third_row['day_of_week_column'] = [ |
266 | '#view_id' => 'visitors', |
267 | '#view_display' => "day_of_week_{$scope}_column", |
268 | '#attributes' => [ |
269 | 'class' => ['layout-column--half'], |
270 | ], |
271 | ]; |
272 | $third_row['day_of_month_column'] = [ |
273 | '#view_id' => 'visitors', |
274 | '#view_display' => "day_of_month_{$scope}_column", |
275 | '#attributes' => [ |
276 | 'class' => ['layout-column--half'], |
277 | ], |
278 | ]; |
279 | |
280 | $fourth_row['monthly_column'] = [ |
281 | '#view_id' => 'visitors', |
282 | '#view_display' => "monthly_{$scope}_column", |
283 | ]; |
284 | |
285 | return [ |
286 | 'visitors_date_filter_form' => $form, |
287 | |
288 | 'main' => [ |
289 | '#type' => 'container', |
290 | '#attributes' => [ |
291 | 'class' => ['visitors-main'], |
292 | ], |
293 | '1' => [ |
294 | $this->renderViews($first_row), |
295 | ], |
296 | '2' => [ |
297 | $this->renderViews($second_row, 'layout-row'), |
298 | ], |
299 | '3' => [ |
300 | $this->renderViews($third_row, 'layout-row'), |
301 | ], |
302 | '4' => [ |
303 | $this->renderViews($fourth_row), |
304 | ], |
305 | ], |
306 | '#attached' => [ |
307 | 'library' => [ |
308 | 'visitors/visitors.report', |
309 | ], |
310 | ], |
311 | ]; |
312 | } |
313 | |
314 | /** |
315 | * Returns a path report. |
316 | * |
317 | * @return array |
318 | * A render array representing the paths page content. |
319 | */ |
320 | public function path(): array { |
321 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
322 | $blocks['path_table'] = [ |
323 | '#view_id' => 'visitors', |
324 | '#view_display' => 'path_table', |
325 | ]; |
326 | |
327 | return [ |
328 | 'visitors_date_filter_form' => $form, |
329 | 'main' => [ |
330 | '#type' => 'container', |
331 | '#attributes' => [ |
332 | 'class' => ['visitors-main'], |
333 | ], |
334 | '1' => [ |
335 | $this->renderViews($blocks), |
336 | ], |
337 | ], |
338 | ]; |
339 | } |
340 | |
341 | /** |
342 | * Returns a path report. |
343 | * |
344 | * @return array |
345 | * A render array representing the paths page content. |
346 | */ |
347 | public function entryPath(): array { |
348 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
349 | $blocks['entry_path_table'] = [ |
350 | '#view_id' => 'visitors', |
351 | '#view_display' => 'entry_path_table', |
352 | ]; |
353 | |
354 | return [ |
355 | 'visitors_date_filter_form' => $form, |
356 | 'main' => [ |
357 | '#type' => 'container', |
358 | '#attributes' => [ |
359 | 'class' => ['visitors-main'], |
360 | ], |
361 | '1' => [ |
362 | $this->renderViews($blocks), |
363 | ], |
364 | ], |
365 | ]; |
366 | } |
367 | |
368 | /** |
369 | * Returns a path report. |
370 | * |
371 | * @return array |
372 | * A render array representing the paths page content. |
373 | */ |
374 | public function exitPath(): array { |
375 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
376 | $blocks['exit_path_table'] = [ |
377 | '#view_id' => 'visitors', |
378 | '#view_display' => 'exit_path_table', |
379 | ]; |
380 | |
381 | return [ |
382 | 'visitors_date_filter_form' => $form, |
383 | 'main' => [ |
384 | '#type' => 'container', |
385 | '#attributes' => [ |
386 | 'class' => ['visitors-main'], |
387 | ], |
388 | '1' => [ |
389 | $this->renderViews($blocks), |
390 | ], |
391 | ], |
392 | ]; |
393 | } |
394 | |
395 | /** |
396 | * Returns a hosts page. |
397 | * |
398 | * @return array |
399 | * A render array representing the hosts page content. |
400 | */ |
401 | public function topHost(): array { |
402 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
403 | $blocks['path'] = [ |
404 | '#view_id' => 'visitors', |
405 | '#view_display' => 'top_host_table', |
406 | ]; |
407 | |
408 | return [ |
409 | 'visitors_date_filter_form' => $form, |
410 | 'main' => [ |
411 | '#type' => 'container', |
412 | '#attributes' => [ |
413 | 'class' => ['visitors-main'], |
414 | ], |
415 | '1' => [ |
416 | $this->renderViews($blocks), |
417 | ], |
418 | ], |
419 | ]; |
420 | } |
421 | |
422 | /** |
423 | * Returns a hosts report. |
424 | * |
425 | * @return array |
426 | * A render array representing the hosts page content. |
427 | */ |
428 | public function recentHost($host): array { |
429 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
430 | $blocks['path'] = [ |
431 | '#view_id' => 'visitors', |
432 | '#view_display' => 'recent_view_table', |
433 | ]; |
434 | |
435 | return [ |
436 | 'visitors_date_filter_form' => $form, |
437 | 'main' => [ |
438 | '#type' => 'container', |
439 | '#attributes' => [ |
440 | 'class' => ['visitors-main'], |
441 | ], |
442 | '1' => [ |
443 | $this->renderViews($blocks, NULL, [NULL, $host]), |
444 | ], |
445 | ], |
446 | ]; |
447 | } |
448 | |
449 | /** |
450 | * Returns a title for the page. |
451 | */ |
452 | public function getHostTitle(string $host) { |
453 | $title = $this->stringTranslation |
454 | ->translate('Visits from @host', ['@host' => $host]); |
455 | |
456 | return $title; |
457 | } |
458 | |
459 | /** |
460 | * Returns a top route page. |
461 | * |
462 | * @return array |
463 | * A render array representing the top pages page content. |
464 | */ |
465 | public function topRoute(): array { |
466 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
467 | $blocks['route'] = [ |
468 | '#view_id' => 'visitors', |
469 | '#view_display' => 'route_table', |
470 | ]; |
471 | |
472 | return [ |
473 | 'visitors_date_filter_form' => $form, |
474 | 'main' => [ |
475 | '#type' => 'container', |
476 | '#attributes' => [ |
477 | 'class' => ['visitors-main'], |
478 | ], |
479 | '1' => [ |
480 | $this->renderViews($blocks), |
481 | ], |
482 | ], |
483 | ]; |
484 | } |
485 | |
486 | /** |
487 | * Returns a path report. |
488 | * |
489 | * @return array |
490 | * A render array representing the paths page content. |
491 | */ |
492 | public function entryRoute(): array { |
493 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
494 | $blocks['entry_route_table'] = [ |
495 | '#view_id' => 'visitors', |
496 | '#view_display' => 'entry_route_table', |
497 | ]; |
498 | |
499 | return [ |
500 | 'visitors_date_filter_form' => $form, |
501 | 'main' => [ |
502 | '#type' => 'container', |
503 | '#attributes' => [ |
504 | 'class' => ['visitors-main'], |
505 | ], |
506 | '1' => [ |
507 | $this->renderViews($blocks), |
508 | ], |
509 | ], |
510 | ]; |
511 | } |
512 | |
513 | /** |
514 | * Returns a exit route report. |
515 | * |
516 | * @return array |
517 | * A render array representing the exit route page content. |
518 | */ |
519 | public function exitRoute(): array { |
520 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
521 | $blocks['exit_route_table'] = [ |
522 | '#view_id' => 'visitors', |
523 | '#view_display' => 'exit_route_table', |
524 | ]; |
525 | |
526 | return [ |
527 | 'visitors_date_filter_form' => $form, |
528 | 'main' => [ |
529 | '#type' => 'container', |
530 | '#attributes' => [ |
531 | 'class' => ['visitors-main'], |
532 | ], |
533 | '1' => [ |
534 | $this->renderViews($blocks), |
535 | ], |
536 | ], |
537 | ]; |
538 | } |
539 | |
540 | /** |
541 | * Returns recent visitors filtered by route. |
542 | * |
543 | * @return array |
544 | * A render array representing page views. |
545 | */ |
546 | public function recentRoute(string $route) { |
547 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
548 | $blocks['route'] = [ |
549 | '#view_id' => 'visitors', |
550 | '#view_display' => 'recent_view_table', |
551 | ]; |
552 | |
553 | return [ |
554 | 'visitors_date_filter_form' => $form, |
555 | 'main' => [ |
556 | '#type' => 'container', |
557 | '#attributes' => [ |
558 | 'class' => ['visitors-main'], |
559 | ], |
560 | '1' => [ |
561 | $this->renderViews($blocks, NULL, [$route]), |
562 | ], |
563 | ], |
564 | ]; |
565 | } |
566 | |
567 | /** |
568 | * Returns a title for the page. |
569 | */ |
570 | public function getRouteTitle(string $route) { |
571 | $title = $this->stringTranslation |
572 | ->translate('Route @route', ['@route' => $route]); |
573 | |
574 | return $title; |
575 | } |
576 | |
577 | /** |
578 | * Returns a recent hits page. |
579 | * |
580 | * @return array |
581 | * A render array representing the recent hits page content. |
582 | */ |
583 | public function recentViews(): array { |
584 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
585 | $blocks['path'] = [ |
586 | '#view_id' => 'visitors', |
587 | '#view_display' => 'recent_view_table', |
588 | ]; |
589 | |
590 | return [ |
591 | 'visitors_date_filter_form' => $form, |
592 | 'main' => [ |
593 | '#type' => 'container', |
594 | '#attributes' => [ |
595 | 'class' => ['visitors-main'], |
596 | ], |
597 | '1' => [ |
598 | $this->renderViews($blocks), |
599 | ], |
600 | ], |
601 | ]; |
602 | } |
603 | |
604 | /** |
605 | * Returns referrer report. |
606 | */ |
607 | public function nodeViews(int $node): array { |
608 | |
609 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
610 | $blocks['path'] = [ |
611 | '#view_id' => 'visitors', |
612 | '#view_display' => 'referrer_table', |
613 | ]; |
614 | |
615 | return [ |
616 | 'visitors_date_filter_form' => $form, |
617 | 'main' => [ |
618 | '#type' => 'container', |
619 | '#attributes' => [ |
620 | 'class' => ['visitors-main'], |
621 | ], |
622 | '1' => [ |
623 | $this->renderViews($blocks), |
624 | ], |
625 | ], |
626 | ]; |
627 | } |
628 | |
629 | /** |
630 | * Shows report related to devices. |
631 | * |
632 | * @return array |
633 | * A render array representing the days of month page content. |
634 | */ |
635 | public function device(): array { |
636 | |
637 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
638 | $first_blocks = []; |
639 | $second_blocks = []; |
640 | |
641 | $first_blocks['device_type_table'] = [ |
642 | '#view_id' => 'visitors', |
643 | '#view_display' => 'device_type_table', |
644 | '#attributes' => [ |
645 | 'class' => ['layout-column--half'], |
646 | ], |
647 | ]; |
648 | $first_blocks['device_model_table'] = [ |
649 | '#view_id' => 'visitors', |
650 | '#view_display' => 'device_model_table', |
651 | '#attributes' => [ |
652 | 'class' => ['layout-column--half'], |
653 | ], |
654 | ]; |
655 | |
656 | $second_blocks['device_brand_table'] = [ |
657 | '#view_id' => 'visitors', |
658 | '#view_display' => 'device_brand_table', |
659 | '#attributes' => [ |
660 | 'class' => ['layout-column--half'], |
661 | ], |
662 | ]; |
663 | $second_blocks['device_resolution_table'] = [ |
664 | '#view_id' => 'visitors', |
665 | '#view_display' => 'device_resolution_table', |
666 | '#attributes' => [ |
667 | 'class' => ['layout-column--half'], |
668 | ], |
669 | ]; |
670 | |
671 | return [ |
672 | 'visitors_date_filter_form' => $form, |
673 | 'main' => [ |
674 | '#type' => 'container', |
675 | '#attributes' => [ |
676 | 'class' => ['visitors-main'], |
677 | ], |
678 | '1' => [ |
679 | $this->renderViews($first_blocks, 'layout-row'), |
680 | ], |
681 | '2' => [ |
682 | $this->renderViews($second_blocks, 'layout-row'), |
683 | ], |
684 | ], |
685 | '#attached' => [ |
686 | 'library' => [ |
687 | 'visitors/visitors.report', |
688 | ], |
689 | ], |
690 | ]; |
691 | } |
692 | |
693 | /** |
694 | * Returns a hours page. |
695 | * |
696 | * @return array |
697 | * A render array representing the hours page content. |
698 | */ |
699 | public function location(): array { |
700 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
701 | |
702 | $first_row['continent_table'] = [ |
703 | '#view_id' => 'visitors', |
704 | '#view_display' => 'continent_table', |
705 | '#attributes' => [ |
706 | 'class' => ['layout-column--half'], |
707 | ], |
708 | ]; |
709 | |
710 | $first_row['country_table'] = [ |
711 | '#view_id' => 'visitors', |
712 | '#view_display' => 'country_table', |
713 | '#attributes' => [ |
714 | 'class' => ['layout-column--half'], |
715 | ], |
716 | ]; |
717 | |
718 | $second_row['distinct_countries_list'] = [ |
719 | '#view_id' => 'visitors', |
720 | '#view_display' => 'distinct_countries_list', |
721 | '#attributes' => [ |
722 | 'class' => ['layout-column--half'], |
723 | ], |
724 | ]; |
725 | $second_row['region_table'] = [ |
726 | '#view_id' => 'visitors', |
727 | '#view_display' => 'region_table', |
728 | '#attributes' => [ |
729 | 'class' => ['layout-column--half'], |
730 | ], |
731 | ]; |
732 | |
733 | $third_row['language_table'] = [ |
734 | '#view_id' => 'visitors', |
735 | '#view_display' => 'language_table', |
736 | '#attributes' => [ |
737 | 'class' => ['layout-column--half'], |
738 | ], |
739 | ]; |
740 | $third_row['city_table'] = [ |
741 | '#view_id' => 'visitors', |
742 | '#view_display' => 'city_table', |
743 | '#attributes' => [ |
744 | 'class' => ['layout-column--half'], |
745 | ], |
746 | ]; |
747 | |
748 | return [ |
749 | 'visitors_date_filter_form' => $form, |
750 | |
751 | 'main' => [ |
752 | '#type' => 'container', |
753 | '#attributes' => [ |
754 | 'class' => ['visitors-main'], |
755 | ], |
756 | '1' => [ |
757 | $this->renderViews($first_row, 'layout-row'), |
758 | ], |
759 | '2' => [ |
760 | $this->renderViews($second_row, 'layout-row'), |
761 | ], |
762 | '3' => [ |
763 | $this->renderViews($third_row, 'layout-row'), |
764 | ], |
765 | ], |
766 | '#attached' => [ |
767 | 'library' => [ |
768 | 'visitors/visitors.report', |
769 | ], |
770 | ], |
771 | ]; |
772 | } |
773 | |
774 | /** |
775 | * Returns the Continent as the title for the page. |
776 | */ |
777 | public function getContinentTitle($continent) { |
778 | $title = $this->t('Continent'); |
779 | if ($continent) { |
780 | $title = $this->location->getContinentLabel($continent); |
781 | } |
782 | |
783 | return $title; |
784 | } |
785 | |
786 | /** |
787 | * Returns a continent page. |
788 | * |
789 | * @return array |
790 | * A render array representing the continent page content. |
791 | */ |
792 | public function continent($continent): array { |
793 | $args = []; |
794 | $view_display = 'continent_table'; |
795 | if ($continent) { |
796 | $args[] = $continent; |
797 | $view_display = 'country_table'; |
798 | } |
799 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
800 | |
801 | $first_row['continent_table'] = [ |
802 | '#view_id' => 'visitors', |
803 | '#view_display' => $view_display, |
804 | ]; |
805 | |
806 | return [ |
807 | 'visitors_date_filter_form' => $form, |
808 | |
809 | 'main' => [ |
810 | '#type' => 'container', |
811 | '#attributes' => [ |
812 | 'class' => ['visitors-main'], |
813 | ], |
814 | '1' => [ |
815 | $this->renderViews($first_row, NULL, $args), |
816 | ], |
817 | ], |
818 | '#attached' => [ |
819 | 'library' => [ |
820 | 'visitors/visitors.report', |
821 | ], |
822 | ], |
823 | ]; |
824 | } |
825 | |
826 | /** |
827 | * Returns the Country as the title for the page. |
828 | */ |
829 | public function getCountryTitle($country) { |
830 | $title = $this->t('Country'); |
831 | if ($country) { |
832 | $title = $this->location->getCountryLabel($country); |
833 | } |
834 | |
835 | return $title; |
836 | } |
837 | |
838 | /** |
839 | * Returns a country page. |
840 | * |
841 | * @return array |
842 | * A render array representing the country page content. |
843 | */ |
844 | public function country($country): array { |
845 | $args = []; |
846 | $view_id = 'visitors'; |
847 | $view_display = 'country_table'; |
848 | if ($country) { |
849 | $args[] = NULL; |
850 | $args[] = NULL; |
851 | $args[] = $country; |
852 | $view_display = 'recent_view_table'; |
853 | } |
854 | if ($this->moduleHandler->moduleExists('visitors_geoip')) { |
855 | $args = [$country]; |
856 | $view_id = 'visitors'; |
857 | $view_display = 'region_table'; |
858 | } |
859 | |
860 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
861 | $first_row['country_table'] = [ |
862 | '#view_id' => $view_id, |
863 | '#view_display' => $view_display, |
864 | ]; |
865 | |
866 | return [ |
867 | 'visitors_date_filter_form' => $form, |
868 | |
869 | 'main' => [ |
870 | '#type' => 'container', |
871 | '#attributes' => [ |
872 | 'class' => ['visitors-main'], |
873 | ], |
874 | '1' => [ |
875 | $this->renderViews($first_row, NULL, $args), |
876 | ], |
877 | ], |
878 | '#attached' => [ |
879 | 'library' => [ |
880 | 'visitors/visitors.report', |
881 | ], |
882 | ], |
883 | ]; |
884 | } |
885 | |
886 | /** |
887 | * Display the performance report. |
888 | */ |
889 | public function performance($sequence = NULL): array { |
890 | $view_display = NULL; |
891 | switch ($sequence) { |
892 | case 'hour': |
893 | $view_display = 'performance_hourly_column'; |
894 | break; |
895 | |
896 | case 'day': |
897 | $view_display = 'performance_daily_column'; |
898 | break; |
899 | |
900 | case 'week': |
901 | default: |
902 | $view_display = 'performance_weekly_column'; |
903 | break; |
904 | } |
905 | |
906 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
907 | |
908 | $first_row['performance_column'] = [ |
909 | '#view_id' => 'visitors', |
910 | '#view_display' => $view_display, |
911 | ]; |
912 | |
913 | return [ |
914 | 'visitors_date_filter_form' => $form, |
915 | 'visitors_performance' => [ |
916 | '1' => $this->renderViews($first_row, 'layout-row'), |
917 | ], |
918 | ]; |
919 | } |
920 | |
921 | /** |
922 | * The region page title. |
923 | */ |
924 | public function getRegionTitle($country, $region) { |
925 | $title = 'Region'; |
926 | if ($country) { |
927 | $title = $this->location->getCountryLabel($country); |
928 | } |
929 | if ($region) { |
930 | if ($region == '_none') { |
931 | $region = 'Unknown'; |
932 | } |
933 | $title = "$region, $title"; |
934 | } |
935 | return $title; |
936 | } |
937 | |
938 | /** |
939 | * Country report. |
940 | * |
941 | * @param string $country |
942 | * The country code. |
943 | * @param string|null $region |
944 | * The region code. |
945 | */ |
946 | public function region($country, $region): array { |
947 | $args = []; |
948 | $view_display = 'region_table'; |
949 | if ($country) { |
950 | $args[] = $country; |
951 | } |
952 | if ($region) { |
953 | if ($region != '_none') { |
954 | $args[] = $region; |
955 | } |
956 | $view_display = 'city_table'; |
957 | } |
958 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
959 | $first_row['region_table'] = [ |
960 | '#view_id' => 'visitors', |
961 | '#view_display' => $view_display, |
962 | ]; |
963 | |
964 | return [ |
965 | 'visitors_date_filter_form' => $form, |
966 | |
967 | 'main' => [ |
968 | '#type' => 'container', |
969 | '#attributes' => [ |
970 | 'class' => ['visitors-main'], |
971 | ], |
972 | '1' => [ |
973 | $this->renderViews($first_row, NULL, $args), |
974 | ], |
975 | ], |
976 | '#attached' => [ |
977 | 'library' => [ |
978 | 'visitors/visitors.report', |
979 | ], |
980 | ], |
981 | ]; |
982 | } |
983 | |
984 | /** |
985 | * The city page title. |
986 | */ |
987 | public function getCityTitle($country, $region, $city) { |
988 | $title = 'City'; |
989 | if ($country) { |
990 | $title = $this->location->getCountryLabel($country); |
991 | } |
992 | if ($region && $region != '_none') { |
993 | $title = "$region, $title"; |
994 | } |
995 | if ($city && $city != '_none') { |
996 | $title = "$city, $title"; |
997 | } |
998 | |
999 | return $title; |
1000 | } |
1001 | |
1002 | /** |
1003 | * City report. |
1004 | * |
1005 | * @param string|null $country |
1006 | * The country code. |
1007 | * @param string|null $region |
1008 | * The region code. |
1009 | * @param string|null $city |
1010 | * The city name. |
1011 | */ |
1012 | public function city($country, $region, $city): array { |
1013 | |
1014 | $args = [ |
1015 | NULL, |
1016 | NULL, |
1017 | ]; |
1018 | $view_display = 'city_table'; |
1019 | if ($country) { |
1020 | $args[] = $country; |
1021 | } |
1022 | if ($region) { |
1023 | if ($region = '_none') { |
1024 | $args[] = NULL; |
1025 | } |
1026 | else { |
1027 | $args[] = $region; |
1028 | } |
1029 | } |
1030 | if ($city) { |
1031 | if ($city = '_none') { |
1032 | $args[] = NULL; |
1033 | } |
1034 | else { |
1035 | $args[] = $city; |
1036 | } |
1037 | $view_display = 'recent_view_table'; |
1038 | } |
1039 | |
1040 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
1041 | $first_row['region_table'] = [ |
1042 | '#view_id' => 'visitors', |
1043 | '#view_display' => $view_display, |
1044 | ]; |
1045 | |
1046 | return [ |
1047 | 'visitors_date_filter_form' => $form, |
1048 | |
1049 | 'main' => [ |
1050 | '#type' => 'container', |
1051 | '#attributes' => [ |
1052 | 'class' => ['visitors-main'], |
1053 | ], |
1054 | '1' => [ |
1055 | $this->renderViews($first_row, NULL, $args), |
1056 | ], |
1057 | ], |
1058 | '#attached' => [ |
1059 | 'library' => [ |
1060 | 'visitors/visitors.report', |
1061 | ], |
1062 | ], |
1063 | ]; |
1064 | } |
1065 | |
1066 | /** |
1067 | * Returns a user report. |
1068 | * |
1069 | * @return array |
1070 | * A render array representing the user page content. |
1071 | */ |
1072 | public function user(): array { |
1073 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
1074 | |
1075 | $first_row['users_table'] = [ |
1076 | '#view_id' => 'visitors', |
1077 | '#view_display' => 'users_table', |
1078 | ]; |
1079 | |
1080 | return [ |
1081 | 'visitors_date_filter_form' => $form, |
1082 | |
1083 | 'main' => [ |
1084 | '#type' => 'container', |
1085 | '#attributes' => [ |
1086 | 'class' => ['visitors-main'], |
1087 | ], |
1088 | '1' => [ |
1089 | $this->renderViews($first_row), |
1090 | ], |
1091 | ], |
1092 | '#attached' => [ |
1093 | 'library' => [ |
1094 | 'visitors/visitors.report', |
1095 | ], |
1096 | ], |
1097 | ]; |
1098 | } |
1099 | |
1100 | /** |
1101 | * Returns a social network report. |
1102 | * |
1103 | * @return array |
1104 | * A render array representing the social network page content. |
1105 | */ |
1106 | public function social(): array { |
1107 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
1108 | |
1109 | $first_row['social_visitors_pie'] = [ |
1110 | '#view_id' => 'visitors', |
1111 | '#view_display' => 'social_visitors_pie', |
1112 | ]; |
1113 | |
1114 | return [ |
1115 | 'visitors_date_filter_form' => $form, |
1116 | |
1117 | 'main' => [ |
1118 | '#type' => 'container', |
1119 | '#attributes' => [ |
1120 | 'class' => ['visitors-main'], |
1121 | ], |
1122 | '1' => [ |
1123 | $this->renderViews($first_row), |
1124 | ], |
1125 | ], |
1126 | '#attached' => [ |
1127 | 'library' => [ |
1128 | 'visitors/visitors.report', |
1129 | ], |
1130 | ], |
1131 | ]; |
1132 | } |
1133 | |
1134 | /** |
1135 | * Returns a AI assistant report. |
1136 | * |
1137 | * @return array |
1138 | * A render array representing the AI assistant page content. |
1139 | */ |
1140 | public function ai(): array { |
1141 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
1142 | |
1143 | $first_row['ai_visitors_pie'] = [ |
1144 | '#view_id' => 'visitors', |
1145 | '#view_display' => 'ai_visitors_pie', |
1146 | ]; |
1147 | |
1148 | return [ |
1149 | 'visitors_date_filter_form' => $form, |
1150 | |
1151 | 'main' => [ |
1152 | '#type' => 'container', |
1153 | '#attributes' => [ |
1154 | 'class' => ['visitors-main'], |
1155 | ], |
1156 | '1' => [ |
1157 | $this->renderViews($first_row), |
1158 | ], |
1159 | ], |
1160 | '#attached' => [ |
1161 | 'library' => [ |
1162 | 'visitors/visitors.report', |
1163 | ], |
1164 | ], |
1165 | ]; |
1166 | } |
1167 | |
1168 | /** |
1169 | * Returns a engagement report. |
1170 | * |
1171 | * @return array |
1172 | * A render array representing the engagement page content. |
1173 | */ |
1174 | public function engagement(): array { |
1175 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
1176 | |
1177 | $first_row['duration_table'] = [ |
1178 | '#view_id' => 'visitors', |
1179 | '#view_display' => 'visits_by_duration_table', |
1180 | '#attributes' => [ |
1181 | 'class' => ['layout-column--half'], |
1182 | ], |
1183 | ]; |
1184 | |
1185 | $first_row['pages_table'] = [ |
1186 | '#view_id' => 'visitors', |
1187 | '#view_display' => 'visits_by_pages_table', |
1188 | '#attributes' => [ |
1189 | 'class' => ['layout-column--half'], |
1190 | ], |
1191 | ]; |
1192 | |
1193 | $second_row['visits_by_visit_table'] = [ |
1194 | '#view_id' => 'visitors', |
1195 | '#view_display' => 'visits_by_visit_table', |
1196 | '#attributes' => [ |
1197 | 'class' => ['layout-column--half'], |
1198 | ], |
1199 | ]; |
1200 | $second_row['visits_by_last_visit_table'] = [ |
1201 | '#view_id' => 'visitors', |
1202 | '#view_display' => 'visits_by_last_visit_table', |
1203 | '#attributes' => [ |
1204 | 'class' => ['layout-column--half'], |
1205 | ], |
1206 | ]; |
1207 | |
1208 | return [ |
1209 | 'visitors_date_filter_form' => $form, |
1210 | 'main' => [ |
1211 | '#type' => 'container', |
1212 | '#attributes' => [ |
1213 | 'class' => ['visitors-main'], |
1214 | ], |
1215 | '1' => [ |
1216 | $this->renderViews($first_row, 'layout-row'), |
1217 | ], |
1218 | '2' => [ |
1219 | $this->renderViews($second_row, 'layout-row'), |
1220 | ], |
1221 | ], |
1222 | '#attached' => [ |
1223 | 'library' => [ |
1224 | 'visitors/visitors.report', |
1225 | ], |
1226 | ], |
1227 | ]; |
1228 | } |
1229 | |
1230 | } |