File: Base.php

package info (click to toggle)
matomo 5.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 95,068 kB
  • sloc: php: 289,425; xml: 127,249; javascript: 112,130; python: 202; sh: 178; makefile: 20; sql: 10
file content (77 lines) | stat: -rw-r--r-- 2,782 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php

/**
 * Matomo - free/libre analytics platform
 *
 * @link    https://matomo.org
 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

namespace Piwik\Plugins\UserCountry\Reports;

use Piwik\Piwik;
use Piwik\Plugin\ViewDataTable;
use Piwik\Plugins\UserCountry\UserCountry;
use Piwik\Url;

abstract class Base extends \Piwik\Plugin\Report
{
    protected function init()
    {
        $this->categoryId = 'General_Visitors';
        $this->subcategoryId = 'UserCountry_SubmenuLocations';
        $this->hasGoalMetrics = true;
    }

    protected function getGeoIPReportDocSuffix()
    {
        return Piwik::translate(
            'UserCountry_GeoIPDocumentationSuffix',
            [
                Url::getExternalLinkTag('http://www.maxmind.com/?rId=piwik'),
                '</a>',
                Url::getExternalLinkTag('http://www.maxmind.com/en/city_accuracy?rId=piwik'),
                '</a>',
            ]
        );
    }

    /**
     * Checks if a datatable for a view is empty and if so, displays a message in the footer
     * telling users to configure GeoIP.
     */
    protected function checkIfNoDataForGeoIpReport(ViewDataTable $view)
    {
        $view->config->filters[] = function ($dataTable) use ($view) {
            // if there's only one row whose label is 'Unknown', display a message saying there's no data
            if (
                $dataTable->getRowsCount() == 1
                && $dataTable->getFirstRow()->getColumn('label') == Piwik::translate('General_Unknown')
            ) {
                $footerMessage = Piwik::translate('UserCountry_NoDataForGeoIPReport1');

                $userCountry = new UserCountry();
                // if GeoIP is working, don't display this part of the message
                if (!$userCountry->isGeoIPWorking()) {
                    $params = ['module' => 'UserCountry', 'action' => 'adminIndex'];
                    $footerMessage .= ' ' . Piwik::translate(
                        'UserCountry_NoDataForGeoIPReport2',
                        [
                            '<a target="_blank" href="' . Url::getCurrentQueryStringWithParametersModified($params) . '">',
                            '</a>',
                            Url::getExternalLinkTag('https://db-ip.com/?refid=mtm'),
                            '</a>',
                        ]
                    );
                } else {
                    $footerMessage .= ' ' . Piwik::translate(
                        'UserCountry_ToGeolocateOldVisits',
                        [Url::getExternalLinkTag('https://matomo.org/faq/how-to/faq_167'), '</a>']
                    );
                }

                $view->config->show_footer_message = $footerMessage;
            }
        };
    }
}