Completed
Push — master ( 7682df...b1b8c7 )
by Timo
23:42 queued 14:36
created

SearchStatisticsModuleController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 3
Bugs 0 Features 3
Metric Value
c 3
b 0
f 3
dl 0
loc 54
rs 10
wmc 2
lcom 1
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
B indexAction() 0 32 2
1
<?php
2
namespace ApacheSolrForTypo3\Solr\Backend\SolrModule;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2016 Thomas Hohn <[email protected]>
8
 *  All rights reserved
9
 *
10
 *  This script is part of the TYPO3 project. The TYPO3 project is
11
 *  free software; you can redistribute it and/or modify
12
 *  it under the terms of the GNU General Public License as published by
13
 *  the Free Software Foundation; either version 2 of the License, or
14
 *  (at your option) any later version.
15
 *
16
 *  The GNU General Public License can be found at
17
 *  http://www.gnu.org/copyleft/gpl.html.
18
 *
19
 *  This script is distributed in the hope that it will be useful,
20
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 *  GNU General Public License for more details.
23
 *
24
 *  This copyright notice MUST APPEAR in all copies of the script!
25
 ***************************************************************/
26
27
use ApacheSolrForTypo3\Solr\Domain\Search\Statistics\StatisticsRepository;
28
use TYPO3\CMS\Core\Utility\GeneralUtility;
29
30
/**
31
 * Search Statistics Module
32
 *
33
 * @author Thomas Hohn <[email protected]>
34
 */
35
class SearchStatisticsModuleController extends AbstractModuleController
36
{
37
    /**
38
     * Module name, used to identify a module f.e. in URL parameters.
39
     *
40
     * @var string
41
     */
42
    protected $moduleName = 'SearchStatistics';
43
44
    /**
45
     * Module title, shows up in the module menu.
46
     *
47
     * @var string
48
     */
49
    protected $moduleTitle = 'Search Statistics';
50
51
    /**
52
     * Index action, shows an overview of the state of the Solr index
53
     *
54
     * @return void
55
     */
56
    public function indexAction()
57
    {
58
        // TODO make time frame user adjustable, for now it's last 30 days
59
60
        $siteRootPageId = $this->site->getRootPageId();
61
        $statisticsRepository = GeneralUtility::makeInstance(StatisticsRepository::class);
62
63
        // @TODO: Do we want Typoscript constants to restrict the results?
64
        $this->view->assign(
65
            'top_search_phrases',
66
            $statisticsRepository->getTopKeyWordsWithHits($siteRootPageId, 30, 5)
67
        );
68
        $this->view->assign(
69
            'top_search_phrases_without_hits',
70
            $statisticsRepository->getTopKeyWordsWithoutHits($siteRootPageId, 30, 5)
71
        );
72
        $this->view->assign(
73
            'search_phrases_statistics',
74
            $statisticsRepository->getSearchStatistics($siteRootPageId, 30, 100)
75
        );
76
77
        $labels = [];
78
        $data = [];
79
        $chartData = $statisticsRepository->getQueriesOverTime($siteRootPageId, 30, 86400);
80
        foreach ($chartData as $bucket) {
81
            $labels[] = strftime('%x', $bucket['tstamp']);
82
            $data[] = (int)$bucket['numQueries'];
83
        }
84
85
        $this->view->assign('queriesChartLabels', json_encode($labels));
86
        $this->view->assign('queriesChartData', json_encode($data));
87
    }
88
}
89