Lines: 84.74%
| Line | Hits | Source |
|---|---|---|
| 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 | 40 | return new self( |
| 68 | 40 | $container->get('form_builder'), |
| 69 | 40 | $container->get('string_translation'), |
| 70 | 40 | $container->get('config.factory'), |
| 71 | 40 | $container->get('messenger'), |
| 72 | 40 | $container->get('current_user'), |
| 73 | 40 | $container->get('visitors.location'), |
| 74 | 40 | $container->get('module_handler') |
| 75 | 40 | ); |
| 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 | 40 | $this->formBuilder = $form_builder; |
| 99 | 40 | $this->account = $current_user; |
| 100 | 40 | $this->location = $location; |
| 101 | 40 | $this->moduleHandler = $module_handler; |
| 102 | ||
| 103 | 40 | $this->settings = $config_factory->get('visitors.settings'); |
| 104 | ||
| 105 | 40 | $this->setStringTranslation($string_translation); |
| 106 | 40 | $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 | 32 | $output = []; |
| 121 | // Render each block element. | |
| 122 | 32 | foreach ($blocks as $block) { |
| 123 | 32 | if (empty($block['#view_id'])) { |
| 124 | ||
| 125 | 1 | $build = $block; |
| 126 | } | |
| 127 | else { | |
| 128 | 31 | $view_id = $block['#view_id']; |
| 129 | 31 | $display_id = $block['#view_display']; |
| 130 | ||
| 131 | 31 | $arguments = []; |
| 132 | 31 | if (!is_null($args)) { |
| 133 | 9 | $arguments = is_array($args) ? $args : [$args]; |
| 134 | } | |
| 135 | // The view render element is what views_embed_view() returns, and | |
| 136 | // it is available on every supported Drupal release. | |
| 137 | 31 | $build = [ |
| 138 | 31 | '#type' => 'view', |
| 139 | 31 | '#name' => $view_id, |
| 140 | 31 | '#display_id' => $display_id, |
| 141 | 31 | '#arguments' => $arguments, |
| 142 | 31 | ]; |
| 143 | ||
| 144 | } | |
| 145 | 32 | if (!isset($build['#attributes']) && isset($block['#attributes'])) { |
| 146 | 7 | $build['#attributes'] = $block['#attributes']; |
| 147 | } | |
| 148 | ||
| 149 | 32 | $output[] = $build; |
| 150 | } | |
| 151 | 32 | $prefix = '<div>'; |
| 152 | 32 | if (!empty($class)) { |
| 153 | 11 | $prefix = '<div class="' . $class . '">'; |
| 154 | } | |
| 155 | 32 | return [ |
| 156 | 32 | '#prefix' => $prefix, |
| 157 | 32 | 'blocks' => $output, |
| 158 | 32 | '#suffix' => '</div>', |
| 159 | 32 | ]; |
| 160 | } | |
| 161 | ||
| 162 | /** | |
| 163 | * Returns software report. | |
| 164 | * | |
| 165 | * @return array | |
| 166 | * A render array representing the days of month page content. | |
| 167 | */ | |
| 168 | public function software(): array { | |
| 169 | ||
| 170 | 1 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
| 171 | $first_row = []; | |
| 172 | $second_row = []; | |
| 173 | ||
| 174 | $first_row['os_version_table'] = [ | |
| 175 | '#view_id' => 'visitors', | |
| 176 | '#view_display' => 'os_version_table', | |
| 177 | '#attributes' => [ | |
| 178 | 'class' => ['layout-column--half'], | |
| 179 | ], | |
| 180 | ]; | |
| 181 | 1 | $first_row['browser_version_table'] = [ |
| 182 | 1 | '#view_id' => 'visitors', |
| 183 | 1 | '#view_display' => 'browser_version_table', |
| 184 | 1 | '#attributes' => [ |
| 185 | 1 | 'class' => ['layout-column--half'], |
| 186 | 1 | ], |
| 187 | 1 | ]; |
| 188 | ||
| 189 | $second_row['device_config_table'] = [ | |
| 190 | '#view_id' => 'visitors', | |
| 191 | '#view_display' => 'device_config_table', | |
| 192 | '#attributes' => [ | |
| 193 | 'class' => ['layout-column--half'], | |
| 194 | ], | |
| 195 | ]; | |
| 196 | 1 | $second_row['browser_engine_pie'] = [ |
| 197 | 1 | '#view_id' => 'visitors', |
| 198 | 1 | '#view_display' => 'browser_engine_pie', |
| 199 | 1 | '#attributes' => [ |
| 200 | 1 | 'class' => ['layout-column--half'], |
| 201 | 1 | ], |
| 202 | 1 | ]; |
| 203 | ||
| 204 | $third_row['browser_plugin_list'] = [ | |
| 205 | '#view_id' => 'visitors', | |
| 206 | '#view_display' => 'browser_plugin_list', | |
| 207 | '#attributes' => [ | |
| 208 | 'class' => ['layout-column--half'], | |
| 209 | ], | |
| 210 | ]; | |
| 211 | ||
| 212 | 1 | return [ |
| 213 | 1 | 'visitors_date_filter_form' => $form, |
| 214 | 1 | 'main' => [ |
| 215 | 1 | '#type' => 'container', |
| 216 | 1 | '#attributes' => [ |
| 217 | 1 | 'class' => ['visitors-main'], |
| 218 | 1 | ], |
| 219 | 1 | '1' => [ |
| 220 | 1 | $this->renderViews($first_row, 'layout-row'), |
| 221 | 1 | ], |
| 222 | 1 | '2' => [ |
| 223 | 1 | $this->renderViews($second_row, 'layout-row'), |
| 224 | 1 | ], |
| 225 | 1 | '3' => [ |
| 226 | 1 | $this->renderViews($third_row, 'layout-row'), |
| 227 | 1 | ], |
| 228 | 1 | ], |
| 229 | 1 | '#attached' => [ |
| 230 | 1 | 'library' => [ |
| 231 | 1 | 'visitors/visitors.report', |
| 232 | 1 | ], |
| 233 | 1 | ], |
| 234 | 1 | ]; |
| 235 | } | |
| 236 | ||
| 237 | /** | |
| 238 | * Returns a time report. | |
| 239 | * | |
| 240 | * @return array | |
| 241 | * A render array representing the hours page content. | |
| 242 | */ | |
| 243 | public function time($scope = 'visit'): array { | |
| 244 | 1 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
| 245 | ||
| 246 | $first_row['daily_column'] = [ | |
| 247 | '#view_id' => 'visitors', | |
| 248 | '#view_display' => "daily_column", | |
| 249 | ]; | |
| 250 | ||
| 251 | $second_row['local_hour_column'] = [ | |
| 252 | '#view_id' => 'visitors', | |
| 253 | '#view_display' => "local_hour_column", | |
| 254 | '#attributes' => [ | |
| 255 | 'class' => ['layout-column--half'], | |
| 256 | ], | |
| 257 | ]; | |
| 258 | 1 | $second_row['hour_column'] = [ |
| 259 | 1 | '#view_id' => 'visitors', |
| 260 | 1 | '#view_display' => "hour_column", |
| 261 | 1 | '#attributes' => [ |
| 262 | 1 | 'class' => ['layout-column--half'], |
| 263 | 1 | ], |
| 264 | 1 | ]; |
| 265 | ||
| 266 | $third_row['day_of_week_column'] = [ | |
| 267 | '#view_id' => 'visitors', | |
| 268 | '#view_display' => "day_of_week_column", | |
| 269 | '#attributes' => [ | |
| 270 | 'class' => ['layout-column--half'], | |
| 271 | ], | |
| 272 | ]; | |
| 273 | 1 | $third_row['day_of_month_column'] = [ |
| 274 | 1 | '#view_id' => 'visitors', |
| 275 | 1 | '#view_display' => "day_of_month_column", |
| 276 | 1 | '#attributes' => [ |
| 277 | 1 | 'class' => ['layout-column--half'], |
| 278 | 1 | ], |
| 279 | 1 | ]; |
| 280 | ||
| 281 | $fourth_row['monthly_column'] = [ | |
| 282 | '#view_id' => 'visitors', | |
| 283 | '#view_display' => "monthly_column", | |
| 284 | ]; | |
| 285 | ||
| 286 | 1 | return [ |
| 287 | 1 | 'visitors_date_filter_form' => $form, |
| 288 | ||
| 289 | 1 | 'main' => [ |
| 290 | 1 | '#type' => 'container', |
| 291 | 1 | '#attributes' => [ |
| 292 | 1 | 'class' => ['visitors-main'], |
| 293 | 1 | ], |
| 294 | 1 | '1' => [ |
| 295 | 1 | $this->renderViews($first_row), |
| 296 | 1 | ], |
| 297 | 1 | '2' => [ |
| 298 | 1 | $this->renderViews($second_row, 'layout-row'), |
| 299 | 1 | ], |
| 300 | 1 | '3' => [ |
| 301 | 1 | $this->renderViews($third_row, 'layout-row'), |
| 302 | 1 | ], |
| 303 | 1 | '4' => [ |
| 304 | 1 | $this->renderViews($fourth_row), |
| 305 | 1 | ], |
| 306 | 1 | ], |
| 307 | 1 | '#attached' => [ |
| 308 | 1 | 'library' => [ |
| 309 | 1 | 'visitors/visitors.report', |
| 310 | 1 | ], |
| 311 | 1 | ], |
| 312 | 1 | ]; |
| 313 | } | |
| 314 | ||
| 315 | /** | |
| 316 | * Returns the outbound link report. | |
| 317 | * | |
| 318 | * @return array | |
| 319 | * A render array representing the outlinks page content. | |
| 320 | */ | |
| 321 | public function outlinks(): array { | |
| 322 | 0 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
| 323 | $blocks['outlinks_table'] = [ | |
| 324 | '#view_id' => 'visitors', | |
| 325 | '#view_display' => 'outlinks_table', | |
| 326 | ]; | |
| 327 | ||
| 328 | 0 | return [ |
| 329 | 0 | 'visitors_date_filter_form' => $form, |
| 330 | 0 | 'main' => [ |
| 331 | 0 | '#type' => 'container', |
| 332 | 0 | '#attributes' => [ |
| 333 | 0 | 'class' => ['visitors-main'], |
| 334 | 0 | ], |
| 335 | 0 | '1' => [ |
| 336 | 0 | $this->renderViews($blocks), |
| 337 | 0 | ], |
| 338 | 0 | ], |
| 339 | 0 | ]; |
| 340 | } | |
| 341 | ||
| 342 | /** | |
| 343 | * Returns the audio and video report. | |
| 344 | * | |
| 345 | * @return array | |
| 346 | * A render array representing the media page content. | |
| 347 | */ | |
| 348 | public function media(): array { | |
| 349 | 0 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
| 350 | $blocks['media_table'] = [ | |
| 351 | '#view_id' => 'visitors', | |
| 352 | '#view_display' => 'media_table', | |
| 353 | ]; | |
| 354 | ||
| 355 | 0 | return [ |
| 356 | 0 | 'visitors_date_filter_form' => $form, |
| 357 | 0 | 'main' => [ |
| 358 | 0 | '#type' => 'container', |
| 359 | 0 | '#attributes' => [ |
| 360 | 0 | 'class' => ['visitors-main'], |
| 361 | 0 | ], |
| 362 | 0 | '1' => [ |
| 363 | 0 | $this->renderViews($blocks), |
| 364 | 0 | ], |
| 365 | 0 | ], |
| 366 | 0 | ]; |
| 367 | } | |
| 368 | ||
| 369 | /** | |
| 370 | * Returns the file download report. | |
| 371 | * | |
| 372 | * @return array | |
| 373 | * A render array representing the downloads page content. | |
| 374 | */ | |
| 375 | public function downloads(): array { | |
| 376 | 0 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
| 377 | $blocks['downloads_table'] = [ | |
| 378 | '#view_id' => 'visitors', | |
| 379 | '#view_display' => 'downloads_table', | |
| 380 | ]; | |
| 381 | ||
| 382 | 0 | return [ |
| 383 | 0 | 'visitors_date_filter_form' => $form, |
| 384 | 0 | 'main' => [ |
| 385 | 0 | '#type' => 'container', |
| 386 | 0 | '#attributes' => [ |
| 387 | 0 | 'class' => ['visitors-main'], |
| 388 | 0 | ], |
| 389 | 0 | '1' => [ |
| 390 | 0 | $this->renderViews($blocks), |
| 391 | 0 | ], |
| 392 | 0 | ], |
| 393 | 0 | ]; |
| 394 | } | |
| 395 | ||
| 396 | /** | |
| 397 | * Returns custom events grouped by category. | |
| 398 | * | |
| 399 | * @return array | |
| 400 | * A render array representing the events page. | |
| 401 | */ | |
| 402 | public function events(): array { | |
| 403 | 0 | return $this->eventsReport('event_category_table'); |
| 404 | } | |
| 405 | ||
| 406 | /** | |
| 407 | * Returns site search keywords, referrers, and the daily chart. | |
| 408 | * | |
| 409 | * @return array | |
| 410 | * A render array representing the site search page. | |
| 411 | */ | |
| 412 | public function siteSearch(): array { | |
| 413 | 1 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
| 414 | $blocks = [ | |
| 415 | 'site_search_chart' => [ | |
| 416 | '#view_id' => 'visitors', | |
| 417 | '#view_display' => 'site_search_chart', | |
| 418 | ], | |
| 419 | 'site_search_keywords' => [ | |
| 420 | '#view_id' => 'visitors', | |
| 421 | '#view_display' => 'site_search_keywords', | |
| 422 | ], | |
| 423 | 'site_search_referrers' => [ | |
| 424 | '#view_id' => 'visitors', | |
| 425 | '#view_display' => 'site_search_referrers', | |
| 426 | ], | |
| 427 | ]; | |
| 428 | ||
| 429 | 1 | return [ |
| 430 | 1 | 'visitors_date_filter_form' => $form, |
| 431 | 1 | 'main' => [ |
| 432 | 1 | '#type' => 'container', |
| 433 | 1 | '#attributes' => [ |
| 434 | 1 | 'class' => ['visitors-main'], |
| 435 | 1 | ], |
| 436 | 1 | '1' => [ |
| 437 | 1 | $this->renderViews($blocks), |
| 438 | 1 | ], |
| 439 | 1 | ], |
| 440 | 1 | '#attached' => [ |
| 441 | 1 | 'library' => [ |
| 442 | 1 | 'visitors/visitors.report', |
| 443 | 1 | ], |
| 444 | 1 | ], |
| 445 | 1 | ]; |
| 446 | } | |
| 447 | ||
| 448 | /** | |
| 449 | * Returns custom events grouped by action. | |
| 450 | * | |
| 451 | * @param string|null $category | |
| 452 | * The category to limit the report to. | |
| 453 | * | |
| 454 | * @return array | |
| 455 | * A render array representing the event actions page. | |
| 456 | */ | |
| 457 | public function eventActions(?string $category = NULL): array { | |
| 458 | 0 | $args = ($category === NULL || $category === '') ? NULL : [$category]; |
| 459 | 0 | return $this->eventsReport('event_action_table', $args); |
| 460 | } | |
| 461 | ||
| 462 | /** | |
| 463 | * Returns custom events grouped by name. | |
| 464 | * | |
| 465 | * @param string|null $category | |
| 466 | * The category to limit the report to. | |
| 467 | * @param string|null $action | |
| 468 | * The action to limit the report to. | |
| 469 | * | |
| 470 | * @return array | |
| 471 | * A render array representing the event names page. | |
| 472 | */ | |
| 473 | public function eventNames(?string $category = NULL, ?string $action = NULL): array { | |
| 474 | 0 | $args = NULL; |
| 475 | 0 | $has_category = $category !== NULL && $category !== ''; |
| 476 | 0 | $has_action = $action !== NULL && $action !== ''; |
| 477 | 0 | if ($has_category && $has_action) { |
| 478 | 0 | $args = [$category, $action]; |
| 479 | } | |
| 480 | 0 | return $this->eventsReport('event_name_table', $args); |
| 481 | } | |
| 482 | ||
| 483 | /** | |
| 484 | * Builds an events page from one Visitors view display. | |
| 485 | * | |
| 486 | * @param string $display_id | |
| 487 | * The view display id. | |
| 488 | * @param array|null $args | |
| 489 | * Contextual filter values. | |
| 490 | * | |
| 491 | * @return array | |
| 492 | * A render array with the date filter and the display. | |
| 493 | */ | |
| 494 | protected function eventsReport(string $display_id, ?array $args = NULL): array { | |
| 495 | 0 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
| 496 | 0 | $blocks[$display_id] = [ |
| 497 | 0 | '#view_id' => 'visitors', |
| 498 | 0 | '#view_display' => $display_id, |
| 499 | 0 | ]; |
| 500 | ||
| 501 | 0 | return [ |
| 502 | 0 | 'visitors_date_filter_form' => $form, |
| 503 | 0 | 'main' => [ |
| 504 | 0 | '#type' => 'container', |
| 505 | 0 | '#attributes' => [ |
| 506 | 0 | 'class' => ['visitors-main'], |
| 507 | 0 | ], |
| 508 | 0 | '1' => [ |
| 509 | 0 | $this->renderViews($blocks, NULL, $args), |
| 510 | 0 | ], |
| 511 | 0 | ], |
| 512 | 0 | '#attached' => [ |
| 513 | 0 | 'library' => [ |
| 514 | 0 | 'visitors/visitors.report', |
| 515 | 0 | ], |
| 516 | 0 | ], |
| 517 | 0 | ]; |
| 518 | } | |
| 519 | ||
| 520 | /** | |
| 521 | * Returns the bot report. | |
| 522 | * | |
| 523 | * @return array | |
| 524 | * A render array for bot names and the paths they hit. | |
| 525 | */ | |
| 526 | public function bots(): array { | |
| 527 | 0 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
| 528 | $blocks['bot_table'] = [ | |
| 529 | '#view_id' => 'visitors', | |
| 530 | '#view_display' => 'bot_table', | |
| 531 | ]; | |
| 532 | 0 | $blocks['bot_path_table'] = [ |
| 533 | 0 | '#view_id' => 'visitors', |
| 534 | 0 | '#view_display' => 'bot_path_table', |
| 535 | 0 | ]; |
| 536 | ||
| 537 | 0 | return [ |
| 538 | 0 | 'visitors_date_filter_form' => $form, |
| 539 | 0 | 'main' => [ |
| 540 | 0 | '#type' => 'container', |
| 541 | 0 | '#attributes' => [ |
| 542 | 0 | 'class' => ['visitors-main'], |
| 543 | 0 | ], |
| 544 | 0 | '1' => [ |
| 545 | 0 | $this->renderViews($blocks), |
| 546 | 0 | ], |
| 547 | 0 | ], |
| 548 | 0 | ]; |
| 549 | } | |
| 550 | ||
| 551 | /** | |
| 552 | * Returns a path report. | |
| 553 | * | |
| 554 | * @return array | |
| 555 | * A render array representing the paths page content. | |
| 556 | */ | |
| 557 | public function path(): array { | |
| 558 | 1 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
| 559 | $blocks['path_table'] = [ | |
| 560 | '#view_id' => 'visitors', | |
| 561 | '#view_display' => 'path_table', | |
| 562 | ]; | |
| 563 | ||
| 564 | 1 | return [ |
| 565 | 1 | 'visitors_date_filter_form' => $form, |
| 566 | 1 | 'main' => [ |
| 567 | 1 | '#type' => 'container', |
| 568 | 1 | '#attributes' => [ |
| 569 | 1 | 'class' => ['visitors-main'], |
| 570 | 1 | ], |
| 571 | 1 | '1' => [ |
| 572 | 1 | $this->renderViews($blocks), |
| 573 | 1 | ], |
| 574 | 1 | ], |
| 575 | 1 | ]; |
| 576 | } | |
| 577 | ||
| 578 | /** | |
| 579 | * Returns a path report. | |
| 580 | * | |
| 581 | * @return array | |
| 582 | * A render array representing the paths page content. | |
| 583 | */ | |
| 584 | public function entryPath(): array { | |
| 585 | 1 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
| 586 | $blocks['entry_path_table'] = [ | |
| 587 | '#view_id' => 'visitors', | |
| 588 | '#view_display' => 'entry_path_table', | |
| 589 | ]; | |
| 590 | ||
| 591 | 1 | return [ |
| 592 | 1 | 'visitors_date_filter_form' => $form, |
| 593 | 1 | 'main' => [ |
| 594 | 1 | '#type' => 'container', |
| 595 | 1 | '#attributes' => [ |
| 596 | 1 | 'class' => ['visitors-main'], |
| 597 | 1 | ], |
| 598 | 1 | '1' => [ |
| 599 | 1 | $this->renderViews($blocks), |
| 600 | 1 | ], |
| 601 | 1 | ], |
| 602 | 1 | ]; |
| 603 | } | |
| 604 | ||
| 605 | /** | |
| 606 | * Returns a path report. | |
| 607 | * | |
| 608 | * @return array | |
| 609 | * A render array representing the paths page content. | |
| 610 | */ | |
| 611 | public function exitPath(): array { | |
| 612 | 1 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
| 613 | $blocks['exit_path_table'] = [ | |
| 614 | '#view_id' => 'visitors', | |
| 615 | '#view_display' => 'exit_path_table', | |
| 616 | ]; | |
| 617 | ||
| 618 | 1 | return [ |
| 619 | 1 | 'visitors_date_filter_form' => $form, |
| 620 | 1 | 'main' => [ |
| 621 | 1 | '#type' => 'container', |
| 622 | 1 | '#attributes' => [ |
| 623 | 1 | 'class' => ['visitors-main'], |
| 624 | 1 | ], |
| 625 | 1 | '1' => [ |
| 626 | 1 | $this->renderViews($blocks), |
| 627 | 1 | ], |
| 628 | 1 | ], |
| 629 | 1 | ]; |
| 630 | } | |
| 631 | ||
| 632 | /** | |
| 633 | * Returns a hosts page. | |
| 634 | * | |
| 635 | * @return array | |
| 636 | * A render array representing the hosts page content. | |
| 637 | */ | |
| 638 | public function topHost(): array { | |
| 639 | 1 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
| 640 | $blocks['path'] = [ | |
| 641 | '#view_id' => 'visitors', | |
| 642 | '#view_display' => 'top_host_table', | |
| 643 | ]; | |
| 644 | ||
| 645 | 1 | return [ |
| 646 | 1 | 'visitors_date_filter_form' => $form, |
| 647 | 1 | 'main' => [ |
| 648 | 1 | '#type' => 'container', |
| 649 | 1 | '#attributes' => [ |
| 650 | 1 | 'class' => ['visitors-main'], |
| 651 | 1 | ], |
| 652 | 1 | '1' => [ |
| 653 | 1 | $this->renderViews($blocks), |
| 654 | 1 | ], |
| 655 | 1 | ], |
| 656 | 1 | ]; |
| 657 | } | |
| 658 | ||
| 659 | /** | |
| 660 | * Returns a hosts report. | |
| 661 | * | |
| 662 | * @return array | |
| 663 | * A render array representing the hosts page content. | |
| 664 | */ | |
| 665 | public function recentHost($host): array { | |
| 666 | 1 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
| 667 | $blocks['path'] = [ | |
| 668 | '#view_id' => 'visitors', | |
| 669 | '#view_display' => 'recent_view_table', | |
| 670 | ]; | |
| 671 | ||
| 672 | 1 | return [ |
| 673 | 1 | 'visitors_date_filter_form' => $form, |
| 674 | 1 | 'main' => [ |
| 675 | 1 | '#type' => 'container', |
| 676 | 1 | '#attributes' => [ |
| 677 | 1 | 'class' => ['visitors-main'], |
| 678 | 1 | ], |
| 679 | 1 | '1' => [ |
| 680 | 1 | $this->renderViews($blocks, NULL, [NULL, $host]), |
| 681 | 1 | ], |
| 682 | 1 | ], |
| 683 | 1 | ]; |
| 684 | } | |
| 685 | ||
| 686 | /** | |
| 687 | * Returns a title for the page. | |
| 688 | */ | |
| 689 | public function getHostTitle(string $host) { | |
| 690 | 1 | $title = $this->stringTranslation |
| 691 | 1 | ->translate('Visits from @host', ['@host' => $host]); |
| 692 | ||
| 693 | 1 | return $title; |
| 694 | } | |
| 695 | ||
| 696 | /** | |
| 697 | * Returns a top route page. | |
| 698 | * | |
| 699 | * @return array | |
| 700 | * A render array representing the top pages page content. | |
| 701 | */ | |
| 702 | public function topRoute(): array { | |
| 703 | 1 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
| 704 | $blocks['route'] = [ | |
| 705 | '#view_id' => 'visitors', | |
| 706 | '#view_display' => 'route_table', | |
| 707 | ]; | |
| 708 | ||
| 709 | 1 | return [ |
| 710 | 1 | 'visitors_date_filter_form' => $form, |
| 711 | 1 | 'main' => [ |
| 712 | 1 | '#type' => 'container', |
| 713 | 1 | '#attributes' => [ |
| 714 | 1 | 'class' => ['visitors-main'], |
| 715 | 1 | ], |
| 716 | 1 | '1' => [ |
| 717 | 1 | $this->renderViews($blocks), |
| 718 | 1 | ], |
| 719 | 1 | ], |
| 720 | 1 | ]; |
| 721 | } | |
| 722 | ||
| 723 | /** | |
| 724 | * Returns a path report. | |
| 725 | * | |
| 726 | * @return array | |
| 727 | * A render array representing the paths page content. | |
| 728 | */ | |
| 729 | public function entryRoute(): array { | |
| 730 | 1 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
| 731 | $blocks['entry_route_table'] = [ | |
| 732 | '#view_id' => 'visitors', | |
| 733 | '#view_display' => 'entry_route_table', | |
| 734 | ]; | |
| 735 | ||
| 736 | 1 | return [ |
| 737 | 1 | 'visitors_date_filter_form' => $form, |
| 738 | 1 | 'main' => [ |
| 739 | 1 | '#type' => 'container', |
| 740 | 1 | '#attributes' => [ |
| 741 | 1 | 'class' => ['visitors-main'], |
| 742 | 1 | ], |
| 743 | 1 | '1' => [ |
| 744 | 1 | $this->renderViews($blocks), |
| 745 | 1 | ], |
| 746 | 1 | ], |
| 747 | 1 | ]; |
| 748 | } | |
| 749 | ||
| 750 | /** | |
| 751 | * Returns a exit route report. | |
| 752 | * | |
| 753 | * @return array | |
| 754 | * A render array representing the exit route page content. | |
| 755 | */ | |
| 756 | public function exitRoute(): array { | |
| 757 | 1 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
| 758 | $blocks['exit_route_table'] = [ | |
| 759 | '#view_id' => 'visitors', | |
| 760 | '#view_display' => 'exit_route_table', | |
| 761 | ]; | |
| 762 | ||
| 763 | 1 | return [ |
| 764 | 1 | 'visitors_date_filter_form' => $form, |
| 765 | 1 | 'main' => [ |
| 766 | 1 | '#type' => 'container', |
| 767 | 1 | '#attributes' => [ |
| 768 | 1 | 'class' => ['visitors-main'], |
| 769 | 1 | ], |
| 770 | 1 | '1' => [ |
| 771 | 1 | $this->renderViews($blocks), |
| 772 | 1 | ], |
| 773 | 1 | ], |
| 774 | 1 | ]; |
| 775 | } | |
| 776 | ||
| 777 | /** | |
| 778 | * Returns recent visitors filtered by route. | |
| 779 | * | |
| 780 | * @return array | |
| 781 | * A render array representing page views. | |
| 782 | */ | |
| 783 | public function recentRoute(string $route) { | |
| 784 | 1 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
| 785 | $blocks['route'] = [ | |
| 786 | '#view_id' => 'visitors', | |
| 787 | '#view_display' => 'recent_view_table', | |
| 788 | ]; | |
| 789 | ||
| 790 | 1 | return [ |
| 791 | 1 | 'visitors_date_filter_form' => $form, |
| 792 | 1 | 'main' => [ |
| 793 | 1 | '#type' => 'container', |
| 794 | 1 | '#attributes' => [ |
| 795 | 1 | 'class' => ['visitors-main'], |
| 796 | 1 | ], |
| 797 | 1 | '1' => [ |
| 798 | 1 | $this->renderViews($blocks, NULL, [$route]), |
| 799 | 1 | ], |
| 800 | 1 | ], |
| 801 | 1 | ]; |
| 802 | } | |
| 803 | ||
| 804 | /** | |
| 805 | * Returns a title for the page. | |
| 806 | */ | |
| 807 | public function getRouteTitle(string $route) { | |
| 808 | 1 | $title = $this->stringTranslation |
| 809 | 1 | ->translate('Route @route', ['@route' => $route]); |
| 810 | ||
| 811 | 1 | return $title; |
| 812 | } | |
| 813 | ||
| 814 | /** | |
| 815 | * Returns referrer report. | |
| 816 | */ | |
| 817 | public function nodeViews(int $node): array { | |
| 818 | ||
| 819 | 1 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
| 820 | $blocks['path'] = [ | |
| 821 | '#view_id' => 'visitors', | |
| 822 | '#view_display' => 'referrer_table', | |
| 823 | ]; | |
| 824 | ||
| 825 | 1 | return [ |
| 826 | 1 | 'visitors_date_filter_form' => $form, |
| 827 | 1 | 'main' => [ |
| 828 | 1 | '#type' => 'container', |
| 829 | 1 | '#attributes' => [ |
| 830 | 1 | 'class' => ['visitors-main'], |
| 831 | 1 | ], |
| 832 | 1 | '1' => [ |
| 833 | 1 | $this->renderViews($blocks), |
| 834 | 1 | ], |
| 835 | 1 | ], |
| 836 | 1 | ]; |
| 837 | } | |
| 838 | ||
| 839 | /** | |
| 840 | * Shows report related to devices. | |
| 841 | * | |
| 842 | * @return array | |
| 843 | * A render array representing the days of month page content. | |
| 844 | */ | |
| 845 | public function device(): array { | |
| 846 | ||
| 847 | 1 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
| 848 | $first_blocks = []; | |
| 849 | $second_blocks = []; | |
| 850 | ||
| 851 | $first_blocks['device_type_table'] = [ | |
| 852 | '#view_id' => 'visitors', | |
| 853 | '#view_display' => 'device_type_table', | |
| 854 | '#attributes' => [ | |
| 855 | 'class' => ['layout-column--half'], | |
| 856 | ], | |
| 857 | ]; | |
| 858 | 1 | $first_blocks['device_model_table'] = [ |
| 859 | 1 | '#view_id' => 'visitors', |
| 860 | 1 | '#view_display' => 'device_model_table', |
| 861 | 1 | '#attributes' => [ |
| 862 | 1 | 'class' => ['layout-column--half'], |
| 863 | 1 | ], |
| 864 | 1 | ]; |
| 865 | ||
| 866 | $second_blocks['device_brand_table'] = [ | |
| 867 | '#view_id' => 'visitors', | |
| 868 | '#view_display' => 'device_brand_table', | |
| 869 | '#attributes' => [ | |
| 870 | 'class' => ['layout-column--half'], | |
| 871 | ], | |
| 872 | ]; | |
| 873 | 1 | $second_blocks['device_resolution_table'] = [ |
| 874 | 1 | '#view_id' => 'visitors', |
| 875 | 1 | '#view_display' => 'device_resolution_table', |
| 876 | 1 | '#attributes' => [ |
| 877 | 1 | 'class' => ['layout-column--half'], |
| 878 | 1 | ], |
| 879 | 1 | ]; |
| 880 | ||
| 881 | 1 | return [ |
| 882 | 1 | 'visitors_date_filter_form' => $form, |
| 883 | 1 | 'main' => [ |
| 884 | 1 | '#type' => 'container', |
| 885 | 1 | '#attributes' => [ |
| 886 | 1 | 'class' => ['visitors-main'], |
| 887 | 1 | ], |
| 888 | 1 | '1' => [ |
| 889 | 1 | $this->renderViews($first_blocks, 'layout-row'), |
| 890 | 1 | ], |
| 891 | 1 | '2' => [ |
| 892 | 1 | $this->renderViews($second_blocks, 'layout-row'), |
| 893 | 1 | ], |
| 894 | 1 | ], |
| 895 | 1 | '#attached' => [ |
| 896 | 1 | 'library' => [ |
| 897 | 1 | 'visitors/visitors.report', |
| 898 | 1 | ], |
| 899 | 1 | ], |
| 900 | 1 | ]; |
| 901 | } | |
| 902 | ||
| 903 | /** | |
| 904 | * Returns a hours page. | |
| 905 | * | |
| 906 | * @return array | |
| 907 | * A render array representing the hours page content. | |
| 908 | */ | |
| 909 | public function location(): array { | |
| 910 | 1 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
| 911 | ||
| 912 | $first_row['continent_table'] = [ | |
| 913 | '#view_id' => 'visitors', | |
| 914 | '#view_display' => 'continent_table', | |
| 915 | '#attributes' => [ | |
| 916 | 'class' => ['layout-column--half'], | |
| 917 | ], | |
| 918 | ]; | |
| 919 | ||
| 920 | 1 | $first_row['country_table'] = [ |
| 921 | 1 | '#view_id' => 'visitors', |
| 922 | 1 | '#view_display' => 'country_table', |
| 923 | 1 | '#attributes' => [ |
| 924 | 1 | 'class' => ['layout-column--half'], |
| 925 | 1 | ], |
| 926 | 1 | ]; |
| 927 | ||
| 928 | $second_row['distinct_countries_list'] = [ | |
| 929 | '#view_id' => 'visitors', | |
| 930 | '#view_display' => 'distinct_countries_list', | |
| 931 | '#attributes' => [ | |
| 932 | 'class' => ['layout-column--half'], | |
| 933 | ], | |
| 934 | ]; | |
| 935 | 1 | $second_row['region_table'] = [ |
| 936 | 1 | '#view_id' => 'visitors', |
| 937 | 1 | '#view_display' => 'region_table', |
| 938 | 1 | '#attributes' => [ |
| 939 | 1 | 'class' => ['layout-column--half'], |
| 940 | 1 | ], |
| 941 | 1 | ]; |
| 942 | ||
| 943 | $third_row['language_table'] = [ | |
| 944 | '#view_id' => 'visitors', | |
| 945 | '#view_display' => 'language_table', | |
| 946 | '#attributes' => [ | |
| 947 | 'class' => ['layout-column--half'], | |
| 948 | ], | |
| 949 | ]; | |
| 950 | 1 | $third_row['city_table'] = [ |
| 951 | 1 | '#view_id' => 'visitors', |
| 952 | 1 | '#view_display' => 'city_table', |
| 953 | 1 | '#attributes' => [ |
| 954 | 1 | 'class' => ['layout-column--half'], |
| 955 | 1 | ], |
| 956 | 1 | ]; |
| 957 | ||
| 958 | 1 | return [ |
| 959 | 1 | 'visitors_date_filter_form' => $form, |
| 960 | ||
| 961 | 1 | 'main' => [ |
| 962 | 1 | '#type' => 'container', |
| 963 | 1 | '#attributes' => [ |
| 964 | 1 | 'class' => ['visitors-main'], |
| 965 | 1 | ], |
| 966 | 1 | '1' => [ |
| 967 | 1 | $this->renderViews($first_row, 'layout-row'), |
| 968 | 1 | ], |
| 969 | 1 | '2' => [ |
| 970 | 1 | $this->renderViews($second_row, 'layout-row'), |
| 971 | 1 | ], |
| 972 | 1 | '3' => [ |
| 973 | 1 | $this->renderViews($third_row, 'layout-row'), |
| 974 | 1 | ], |
| 975 | 1 | ], |
| 976 | 1 | '#attached' => [ |
| 977 | 1 | 'library' => [ |
| 978 | 1 | 'visitors/visitors.report', |
| 979 | 1 | ], |
| 980 | 1 | ], |
| 981 | 1 | ]; |
| 982 | } | |
| 983 | ||
| 984 | /** | |
| 985 | * Returns the Continent as the title for the page. | |
| 986 | */ | |
| 987 | public function getContinentTitle($continent) { | |
| 988 | 1 | $title = $this->t('Continent'); |
| 989 | 1 | if ($continent) { |
| 990 | 1 | $title = $this->location->getContinentLabel($continent); |
| 991 | } | |
| 992 | ||
| 993 | 1 | return $title; |
| 994 | } | |
| 995 | ||
| 996 | /** | |
| 997 | * Returns a continent page. | |
| 998 | * | |
| 999 | * @return array | |
| 1000 | * A render array representing the continent page content. | |
| 1001 | */ | |
| 1002 | public function continent($continent): array { | |
| 1003 | 1 | $args = []; |
| 1004 | 1 | $view_display = 'continent_table'; |
| 1005 | 1 | if ($continent) { |
| 1006 | 1 | $args[] = $continent; |
| 1007 | 1 | $view_display = 'country_table'; |
| 1008 | } | |
| 1009 | 1 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
| 1010 | ||
| 1011 | 1 | $first_row['continent_table'] = [ |
| 1012 | 1 | '#view_id' => 'visitors', |
| 1013 | 1 | '#view_display' => $view_display, |
| 1014 | 1 | ]; |
| 1015 | ||
| 1016 | 1 | return [ |
| 1017 | 1 | 'visitors_date_filter_form' => $form, |
| 1018 | ||
| 1019 | 1 | 'main' => [ |
| 1020 | 1 | '#type' => 'container', |
| 1021 | 1 | '#attributes' => [ |
| 1022 | 1 | 'class' => ['visitors-main'], |
| 1023 | 1 | ], |
| 1024 | 1 | '1' => [ |
| 1025 | 1 | $this->renderViews($first_row, NULL, $args), |
| 1026 | 1 | ], |
| 1027 | 1 | ], |
| 1028 | 1 | '#attached' => [ |
| 1029 | 1 | 'library' => [ |
| 1030 | 1 | 'visitors/visitors.report', |
| 1031 | 1 | ], |
| 1032 | 1 | ], |
| 1033 | 1 | ]; |
| 1034 | } | |
| 1035 | ||
| 1036 | /** | |
| 1037 | * Returns the Country as the title for the page. | |
| 1038 | */ | |
| 1039 | public function getCountryTitle($country) { | |
| 1040 | 1 | $title = $this->t('Country'); |
| 1041 | 1 | if ($country) { |
| 1042 | 1 | $title = $this->location->getCountryLabel($country); |
| 1043 | } | |
| 1044 | ||
| 1045 | 1 | return $title; |
| 1046 | } | |
| 1047 | ||
| 1048 | /** | |
| 1049 | * Returns a country page. | |
| 1050 | * | |
| 1051 | * @return array | |
| 1052 | * A render array representing the country page content. | |
| 1053 | */ | |
| 1054 | public function country($country): array { | |
| 1055 | 2 | $args = []; |
| 1056 | $view_id = 'visitors'; | |
| 1057 | 2 | $view_display = 'country_table'; |
| 1058 | 2 | if ($country) { |
| 1059 | $args[] = NULL; | |
| 1060 | 2 | $args[] = NULL; |
| 1061 | 2 | $args[] = $country; |
| 1062 | 2 | $view_display = 'recent_view_table'; |
| 1063 | } | |
| 1064 | 2 | if ($this->moduleHandler->moduleExists('visitors_geoip')) { |
| 1065 | 1 | $args = [$country]; |
| 1066 | $view_id = 'visitors'; | |
| 1067 | 1 | $view_display = 'region_table'; |
| 1068 | } | |
| 1069 | ||
| 1070 | 2 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
| 1071 | 2 | $first_row['country_table'] = [ |
| 1072 | 2 | '#view_id' => $view_id, |
| 1073 | 2 | '#view_display' => $view_display, |
| 1074 | 2 | ]; |
| 1075 | ||
| 1076 | 2 | return [ |
| 1077 | 2 | 'visitors_date_filter_form' => $form, |
| 1078 | ||
| 1079 | 2 | 'main' => [ |
| 1080 | 2 | '#type' => 'container', |
| 1081 | 2 | '#attributes' => [ |
| 1082 | 2 | 'class' => ['visitors-main'], |
| 1083 | 2 | ], |
| 1084 | 2 | '1' => [ |
| 1085 | 2 | $this->renderViews($first_row, NULL, $args), |
| 1086 | 2 | ], |
| 1087 | 2 | ], |
| 1088 | 2 | '#attached' => [ |
| 1089 | 2 | 'library' => [ |
| 1090 | 2 | 'visitors/visitors.report', |
| 1091 | 2 | ], |
| 1092 | 2 | ], |
| 1093 | 2 | ]; |
| 1094 | } | |
| 1095 | ||
| 1096 | /** | |
| 1097 | * Display the performance report. | |
| 1098 | */ | |
| 1099 | public function performance($sequence = NULL): array { | |
| 1100 | $view_display = NULL; | |
| 1101 | switch ($sequence) { | |
| 1102 | 3 | case 'hour': |
| 1103 | 1 | $view_display = 'performance_hourly_column'; |
| 1104 | 1 | break; |
| 1105 | ||
| 1106 | 2 | case 'day': |
| 1107 | 1 | $view_display = 'performance_daily_column'; |
| 1108 | 1 | break; |
| 1109 | ||
| 1110 | 1 | case 'week': |
| 1111 | default: | |
| 1112 | 1 | $view_display = 'performance_weekly_column'; |
| 1113 | break; | |
| 1114 | } | |
| 1115 | ||
| 1116 | 3 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
| 1117 | ||
| 1118 | 3 | $first_row['performance_column'] = [ |
| 1119 | 3 | '#view_id' => 'visitors', |
| 1120 | 3 | '#view_display' => $view_display, |
| 1121 | 3 | ]; |
| 1122 | ||
| 1123 | 3 | return [ |
| 1124 | 3 | 'visitors_date_filter_form' => $form, |
| 1125 | 3 | 'visitors_performance' => [ |
| 1126 | 3 | '1' => $this->renderViews($first_row, 'layout-row'), |
| 1127 | 3 | ], |
| 1128 | 3 | ]; |
| 1129 | } | |
| 1130 | ||
| 1131 | /** | |
| 1132 | * The region page title. | |
| 1133 | */ | |
| 1134 | public function getRegionTitle($country, $region) { | |
| 1135 | 1 | $title = 'Region'; |
| 1136 | 1 | if ($country) { |
| 1137 | 1 | $title = $this->location->getCountryLabel($country); |
| 1138 | } | |
| 1139 | 1 | if ($region) { |
| 1140 | 1 | if ($region == '_none') { |
| 1141 | 1 | $region = 'Unknown'; |
| 1142 | } | |
| 1143 | 1 | $title = "$region, $title"; |
| 1144 | } | |
| 1145 | 1 | return $title; |
| 1146 | } | |
| 1147 | ||
| 1148 | /** | |
| 1149 | * Country report. | |
| 1150 | * | |
| 1151 | * @param string $country | |
| 1152 | * The country code. | |
| 1153 | * @param string|null $region | |
| 1154 | * The region code. | |
| 1155 | */ | |
| 1156 | public function region($country, $region): array { | |
| 1157 | 1 | $args = []; |
| 1158 | 1 | $view_display = 'region_table'; |
| 1159 | 1 | if ($country) { |
| 1160 | 1 | $args[] = $country; |
| 1161 | } | |
| 1162 | 1 | if ($region) { |
| 1163 | 1 | if ($region != '_none') { |
| 1164 | 1 | $args[] = $region; |
| 1165 | } | |
| 1166 | 1 | $view_display = 'city_table'; |
| 1167 | } | |
| 1168 | 1 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
| 1169 | 1 | $first_row['region_table'] = [ |
| 1170 | 1 | '#view_id' => 'visitors', |
| 1171 | 1 | '#view_display' => $view_display, |
| 1172 | 1 | ]; |
| 1173 | ||
| 1174 | 1 | return [ |
| 1175 | 1 | 'visitors_date_filter_form' => $form, |
| 1176 | ||
| 1177 | 1 | 'main' => [ |
| 1178 | 1 | '#type' => 'container', |
| 1179 | 1 | '#attributes' => [ |
| 1180 | 1 | 'class' => ['visitors-main'], |
| 1181 | 1 | ], |
| 1182 | 1 | '1' => [ |
| 1183 | 1 | $this->renderViews($first_row, NULL, $args), |
| 1184 | 1 | ], |
| 1185 | 1 | ], |
| 1186 | 1 | '#attached' => [ |
| 1187 | 1 | 'library' => [ |
| 1188 | 1 | 'visitors/visitors.report', |
| 1189 | 1 | ], |
| 1190 | 1 | ], |
| 1191 | 1 | ]; |
| 1192 | } | |
| 1193 | ||
| 1194 | /** | |
| 1195 | * The city page title. | |
| 1196 | */ | |
| 1197 | public function getCityTitle($country, $region, $city) { | |
| 1198 | 1 | $title = 'City'; |
| 1199 | 1 | if ($country) { |
| 1200 | 1 | $title = $this->location->getCountryLabel($country); |
| 1201 | } | |
| 1202 | 1 | if ($region && $region != '_none') { |
| 1203 | 1 | $title = "$region, $title"; |
| 1204 | } | |
| 1205 | 1 | if ($city && $city != '_none') { |
| 1206 | 1 | $title = "$city, $title"; |
| 1207 | } | |
| 1208 | ||
| 1209 | 1 | return $title; |
| 1210 | } | |
| 1211 | ||
| 1212 | /** | |
| 1213 | * City report. | |
| 1214 | * | |
| 1215 | * @param string|null $country | |
| 1216 | * The country code. | |
| 1217 | * @param string|null $region | |
| 1218 | * The region code. | |
| 1219 | * @param string|null $city | |
| 1220 | * The city name. | |
| 1221 | */ | |
| 1222 | public function city($country, $region, $city): array { | |
| 1223 | ||
| 1224 | 1 | $args = [ |
| 1225 | 1 | NULL, |
| 1226 | 1 | NULL, |
| 1227 | 1 | ]; |
| 1228 | 1 | $view_display = 'city_table'; |
| 1229 | 1 | if ($country) { |
| 1230 | 1 | $args[] = $country; |
| 1231 | } | |
| 1232 | 1 | if ($region) { |
| 1233 | 1 | if ($region = '_none') { |
| 1234 | 1 | $args[] = NULL; |
| 1235 | } | |
| 1236 | else { | |
| 1237 | $args[] = $region; | |
| 1238 | } | |
| 1239 | } | |
| 1240 | 1 | if ($city) { |
| 1241 | 1 | if ($city = '_none') { |
| 1242 | 1 | $args[] = NULL; |
| 1243 | } | |
| 1244 | else { | |
| 1245 | $args[] = $city; | |
| 1246 | } | |
| 1247 | 1 | $view_display = 'recent_view_table'; |
| 1248 | } | |
| 1249 | ||
| 1250 | 1 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
| 1251 | 1 | $first_row['region_table'] = [ |
| 1252 | 1 | '#view_id' => 'visitors', |
| 1253 | 1 | '#view_display' => $view_display, |
| 1254 | 1 | ]; |
| 1255 | ||
| 1256 | 1 | return [ |
| 1257 | 1 | 'visitors_date_filter_form' => $form, |
| 1258 | ||
| 1259 | 1 | 'main' => [ |
| 1260 | 1 | '#type' => 'container', |
| 1261 | 1 | '#attributes' => [ |
| 1262 | 1 | 'class' => ['visitors-main'], |
| 1263 | 1 | ], |
| 1264 | 1 | '1' => [ |
| 1265 | 1 | $this->renderViews($first_row, NULL, $args), |
| 1266 | 1 | ], |
| 1267 | 1 | ], |
| 1268 | 1 | '#attached' => [ |
| 1269 | 1 | 'library' => [ |
| 1270 | 1 | 'visitors/visitors.report', |
| 1271 | 1 | ], |
| 1272 | 1 | ], |
| 1273 | 1 | ]; |
| 1274 | } | |
| 1275 | ||
| 1276 | /** | |
| 1277 | * Returns a user report. | |
| 1278 | * | |
| 1279 | * @return array | |
| 1280 | * A render array representing the user page content. | |
| 1281 | */ | |
| 1282 | public function user(): array { | |
| 1283 | 1 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
| 1284 | ||
| 1285 | $first_row['users_table'] = [ | |
| 1286 | '#view_id' => 'visitors', | |
| 1287 | '#view_display' => 'users_table', | |
| 1288 | ]; | |
| 1289 | ||
| 1290 | 1 | return [ |
| 1291 | 1 | 'visitors_date_filter_form' => $form, |
| 1292 | ||
| 1293 | 1 | 'main' => [ |
| 1294 | 1 | '#type' => 'container', |
| 1295 | 1 | '#attributes' => [ |
| 1296 | 1 | 'class' => ['visitors-main'], |
| 1297 | 1 | ], |
| 1298 | 1 | '1' => [ |
| 1299 | 1 | $this->renderViews($first_row), |
| 1300 | 1 | ], |
| 1301 | 1 | ], |
| 1302 | 1 | '#attached' => [ |
| 1303 | 1 | 'library' => [ |
| 1304 | 1 | 'visitors/visitors.report', |
| 1305 | 1 | ], |
| 1306 | 1 | ], |
| 1307 | 1 | ]; |
| 1308 | } | |
| 1309 | ||
| 1310 | /** | |
| 1311 | * Returns the referrer channel overview. | |
| 1312 | * | |
| 1313 | * @return array | |
| 1314 | * A render array representing the overview page. | |
| 1315 | */ | |
| 1316 | public function referrers(): array { | |
| 1317 | 1 | return $this->acquisitionReport([ |
| 1318 | 1 | 'referrer_overview_pie', |
| 1319 | 1 | 'referrer_overview_table', |
| 1320 | 1 | ]); |
| 1321 | } | |
| 1322 | ||
| 1323 | /** | |
| 1324 | * Returns every referrer channel and name. | |
| 1325 | * | |
| 1326 | * @return array | |
| 1327 | * A render array representing the all-referrers page. | |
| 1328 | */ | |
| 1329 | public function allReferrers(): array { | |
| 1330 | 0 | return $this->acquisitionReport(['referrers_all_table']); |
| 1331 | } | |
| 1332 | ||
| 1333 | /** | |
| 1334 | * Returns search engines and keywords. | |
| 1335 | * | |
| 1336 | * @return array | |
| 1337 | * A render array representing the search engines page. | |
| 1338 | */ | |
| 1339 | public function searchEngines(): array { | |
| 1340 | 0 | return $this->acquisitionReport([ |
| 1341 | 0 | 'search_engines_table', |
| 1342 | 0 | 'search_keywords_table', |
| 1343 | 0 | ]); |
| 1344 | } | |
| 1345 | ||
| 1346 | /** | |
| 1347 | * Returns keywords for one search engine. | |
| 1348 | * | |
| 1349 | * @param string $referer_name | |
| 1350 | * The search engine name. | |
| 1351 | * | |
| 1352 | * @return array | |
| 1353 | * A render array representing the keyword page. | |
| 1354 | */ | |
| 1355 | public function searchEngineKeywords(string $referer_name): array { | |
| 1356 | 0 | return $this->acquisitionReport( |
| 1357 | 0 | ['search_engine_keywords'], |
| 1358 | 0 | [$referer_name], |
| 1359 | 0 | ); |
| 1360 | } | |
| 1361 | ||
| 1362 | /** | |
| 1363 | * Returns search engines for one keyword. | |
| 1364 | * | |
| 1365 | * @param string $referer_keyword | |
| 1366 | * The keyword, or "not-defined" when none was stored. | |
| 1367 | * | |
| 1368 | * @return array | |
| 1369 | * A render array representing the search engine page. | |
| 1370 | */ | |
| 1371 | public function searchKeywordEngines(string $referer_keyword): array { | |
| 1372 | 0 | return $this->acquisitionReport( |
| 1373 | 0 | ['search_keyword_engines'], |
| 1374 | 0 | [$referer_keyword], |
| 1375 | 0 | ); |
| 1376 | } | |
| 1377 | ||
| 1378 | /** | |
| 1379 | * Returns referring websites. | |
| 1380 | * | |
| 1381 | * @return array | |
| 1382 | * A render array representing the websites page. | |
| 1383 | */ | |
| 1384 | public function websites(): array { | |
| 1385 | 0 | return $this->acquisitionReport(['websites_table']); |
| 1386 | } | |
| 1387 | ||
| 1388 | /** | |
| 1389 | * Returns URLs for one referring website. | |
| 1390 | * | |
| 1391 | * @param string $referer_name | |
| 1392 | * The website host. | |
| 1393 | * | |
| 1394 | * @return array | |
| 1395 | * A render array representing the URL page. | |
| 1396 | */ | |
| 1397 | public function websiteUrls(string $referer_name): array { | |
| 1398 | 0 | return $this->acquisitionReport(['website_urls'], [$referer_name]); |
| 1399 | } | |
| 1400 | ||
| 1401 | /** | |
| 1402 | * Returns a social network report. | |
| 1403 | * | |
| 1404 | * @return array | |
| 1405 | * A render array representing the social network page content. | |
| 1406 | */ | |
| 1407 | public function social(): array { | |
| 1408 | 1 | return $this->acquisitionReport([ |
| 1409 | 1 | 'social_visitors_pie', |
| 1410 | 1 | 'social_referrers_table', |
| 1411 | 1 | ]); |
| 1412 | } | |
| 1413 | ||
| 1414 | /** | |
| 1415 | * Returns URLs for one social network. | |
| 1416 | * | |
| 1417 | * @param string $referer_name | |
| 1418 | * The social network name. | |
| 1419 | * | |
| 1420 | * @return array | |
| 1421 | * A render array representing the URL page. | |
| 1422 | */ | |
| 1423 | public function socialUrls(string $referer_name): array { | |
| 1424 | 0 | return $this->acquisitionReport(['social_urls'], [$referer_name]); |
| 1425 | } | |
| 1426 | ||
| 1427 | /** | |
| 1428 | * Returns a AI assistant report. | |
| 1429 | * | |
| 1430 | * @return array | |
| 1431 | * A render array representing the AI assistant page content. | |
| 1432 | */ | |
| 1433 | public function ai(): array { | |
| 1434 | 1 | return $this->acquisitionReport([ |
| 1435 | 1 | 'ai_visitors_pie', |
| 1436 | 1 | 'ai_visitors_table', |
| 1437 | 1 | ]); |
| 1438 | } | |
| 1439 | ||
| 1440 | /** | |
| 1441 | * Returns human visits compared with AI agent visits. | |
| 1442 | * | |
| 1443 | * @return array | |
| 1444 | * A render array representing the AI agent page. | |
| 1445 | */ | |
| 1446 | public function aiAgents(): array { | |
| 1447 | 0 | return $this->acquisitionReport(['ai_agent_table']); |
| 1448 | } | |
| 1449 | ||
| 1450 | /** | |
| 1451 | * Returns entry pages for one AI assistant. | |
| 1452 | * | |
| 1453 | * @param string $referer_name | |
| 1454 | * The AI assistant name. | |
| 1455 | * | |
| 1456 | * @return array | |
| 1457 | * A render array representing the entry page report. | |
| 1458 | */ | |
| 1459 | public function aiEntryPages(string $referer_name): array { | |
| 1460 | 0 | return $this->acquisitionReport(['ai_entry_pages'], [$referer_name]); |
| 1461 | } | |
| 1462 | ||
| 1463 | /** | |
| 1464 | * Returns campaigns. | |
| 1465 | * | |
| 1466 | * @return array | |
| 1467 | * A render array representing the campaigns page. | |
| 1468 | */ | |
| 1469 | public function campaigns(): array { | |
| 1470 | 0 | return $this->acquisitionReport(['campaigns_table']); |
| 1471 | } | |
| 1472 | ||
| 1473 | /** | |
| 1474 | * Returns keywords for one campaign. | |
| 1475 | * | |
| 1476 | * @param string $referer_name | |
| 1477 | * The campaign name. | |
| 1478 | * | |
| 1479 | * @return array | |
| 1480 | * A render array representing the keyword page. | |
| 1481 | */ | |
| 1482 | public function campaignKeywords(string $referer_name): array { | |
| 1483 | 0 | return $this->acquisitionReport( |
| 1484 | 0 | ['campaign_keywords'], |
| 1485 | 0 | [$referer_name], |
| 1486 | 0 | ); |
| 1487 | } | |
| 1488 | ||
| 1489 | /** | |
| 1490 | * Builds an acquisition page from Visitors view displays. | |
| 1491 | * | |
| 1492 | * @param string[] $displays | |
| 1493 | * View display ids. | |
| 1494 | * @param string[] $args | |
| 1495 | * Contextual filter values. | |
| 1496 | * | |
| 1497 | * @return array | |
| 1498 | * A render array with the date filter and the displays. | |
| 1499 | */ | |
| 1500 | protected function acquisitionReport(array $displays, array $args = []): array { | |
| 1501 | 3 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
| 1502 | 3 | $blocks = []; |
| 1503 | 3 | foreach ($displays as $display_id) { |
| 1504 | 3 | $blocks[$display_id] = [ |
| 1505 | 3 | '#view_id' => 'visitors', |
| 1506 | 3 | '#view_display' => $display_id, |
| 1507 | 3 | ]; |
| 1508 | } | |
| 1509 | ||
| 1510 | 3 | return [ |
| 1511 | 3 | 'visitors_date_filter_form' => $form, |
| 1512 | 3 | 'main' => [ |
| 1513 | 3 | '#type' => 'container', |
| 1514 | 3 | '#attributes' => [ |
| 1515 | 3 | 'class' => ['visitors-main'], |
| 1516 | 3 | ], |
| 1517 | 3 | '1' => [ |
| 1518 | 3 | $this->renderViews($blocks, NULL, $args === [] ? NULL : $args), |
| 1519 | 3 | ], |
| 1520 | 3 | ], |
| 1521 | 3 | '#attached' => [ |
| 1522 | 3 | 'library' => [ |
| 1523 | 3 | 'visitors/visitors.report', |
| 1524 | 3 | ], |
| 1525 | 3 | ], |
| 1526 | 3 | ]; |
| 1527 | } | |
| 1528 | ||
| 1529 | /** | |
| 1530 | * Returns a engagement report. | |
| 1531 | * | |
| 1532 | * @return array | |
| 1533 | * A render array representing the engagement page content. | |
| 1534 | */ | |
| 1535 | public function engagement(): array { | |
| 1536 | 1 | $form = $this->formBuilder->getForm('Drupal\visitors\Form\DateFilterForm'); |
| 1537 | ||
| 1538 | $first_row['duration_table'] = [ | |
| 1539 | '#view_id' => 'visitors', | |
| 1540 | '#view_display' => 'visits_by_duration_table', | |
| 1541 | '#attributes' => [ | |
| 1542 | 'class' => ['layout-column--half'], | |
| 1543 | ], | |
| 1544 | ]; | |
| 1545 | ||
| 1546 | 1 | $first_row['pages_table'] = [ |
| 1547 | 1 | '#view_id' => 'visitors', |
| 1548 | 1 | '#view_display' => 'visits_by_pages_table', |
| 1549 | 1 | '#attributes' => [ |
| 1550 | 1 | 'class' => ['layout-column--half'], |
| 1551 | 1 | ], |
| 1552 | 1 | ]; |
| 1553 | ||
| 1554 | $second_row['visits_by_visit_table'] = [ | |
| 1555 | '#view_id' => 'visitors', | |
| 1556 | '#view_display' => 'visits_by_visit_table', | |
| 1557 | '#attributes' => [ | |
| 1558 | 'class' => ['layout-column--half'], | |
| 1559 | ], | |
| 1560 | ]; | |
| 1561 | 1 | $second_row['visits_by_last_visit_table'] = [ |
| 1562 | 1 | '#view_id' => 'visitors', |
| 1563 | 1 | '#view_display' => 'visits_by_last_visit_table', |
| 1564 | 1 | '#attributes' => [ |
| 1565 | 1 | 'class' => ['layout-column--half'], |
| 1566 | 1 | ], |
| 1567 | 1 | ]; |
| 1568 | ||
| 1569 | 1 | return [ |
| 1570 | 1 | 'visitors_date_filter_form' => $form, |
| 1571 | 1 | 'main' => [ |
| 1572 | 1 | '#type' => 'container', |
| 1573 | 1 | '#attributes' => [ |
| 1574 | 1 | 'class' => ['visitors-main'], |
| 1575 | 1 | ], |
| 1576 | 1 | '1' => [ |
| 1577 | 1 | $this->renderViews($first_row, 'layout-row'), |
| 1578 | 1 | ], |
| 1579 | 1 | '2' => [ |
| 1580 | 1 | $this->renderViews($second_row, 'layout-row'), |
| 1581 | 1 | ], |
| 1582 | 1 | ], |
| 1583 | 1 | '#attached' => [ |
| 1584 | 1 | 'library' => [ |
| 1585 | 1 | 'visitors/visitors.report', |
| 1586 | 1 | ], |
| 1587 | 1 | ], |
| 1588 | 1 | ]; |
| 1589 | } | |
| 1590 | ||
| 1591 | } |