Welcome to mirror list, hosted at ThFree Co, Russian Federation.

VisitorLog.php « Live « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 742a5d69b3854f1d9fd635585e303e446c3b724b (plain)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/**
 * Piwik - Open source web analytics
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 *
 * @category Piwik_Plugins
 * @package Live
 */
namespace Piwik\Plugins\Live;

use Piwik\Common;
use Piwik\Piwik;
use Piwik\Plugin\Visualization;
use Piwik\View;

/**
 * A special DataTable visualization for the Live.getLastVisitsDetails API method.
 */
class VisitorLog extends Visualization
{
    const ID = 'Piwik\Plugins\Live\VisitorLog';
    const TEMPLATE_FILE = "@Live/_dataTableViz_visitorLog.twig";

    public function beforeLoadDataTable()
    {
        $this->requestConfig->addPropertiesThatShouldBeAvailableClientSide(array(
            'filter_limit',
            'filter_offset',
            'filter_sort_column',
            'filter_sort_order',
        ));

        $this->requestConfig->filter_sort_column = 'idVisit';
        $this->requestConfig->filter_sort_order  = 'asc';
        $this->requestConfig->filter_limit       = 20;
        $this->requestConfig->disable_generic_filters = true;

        $offset = Common::getRequestVar('filter_offset', 0);
        $limit  = Common::getRequestVar('filter_limit', $this->requestConfig->filter_limit);

        $this->config->filters[] = array('Limit', array($offset, $limit));
    }

    /**
     * Configure visualization.
     */
    public function beforeRender()
    {
        $this->config->datatable_js_type = 'VisitorLog';
        $this->config->enable_sort       = false;
        $this->config->show_search       = false;
        $this->config->show_exclude_low_population = false;
        $this->config->show_offset_information     = false;
        $this->config->show_all_views_icons        = false;
        $this->config->show_table_all_columns      = false;
        $this->config->show_export_as_rss_feed     = false;

        $this->config->documentation = Piwik::translate('Live_VisitorLogDocumentation', array('<br />', '<br />'));

        $filterEcommerce = Common::getRequestVar('filterEcommerce', 0, 'int');
        $this->config->custom_parameters = array(
            // set a very high row count so that the next link in the footer of the data table is always shown
            'totalRows'         => 10000000,

            'filterEcommerce'   => $filterEcommerce,
            'pageUrlNotDefined' => Piwik::translate('General_NotDefined', Piwik::translate('Actions_ColumnPageURL')),

            'smallWidth'        => 1 == Common::getRequestVar('small', 0, 'int'),
        );

        $this->config->footer_icons = array(
            array(
                'class'   => 'tableAllColumnsSwitch',
                'buttons' => array(
                    array(
                        'id'    => static::ID,
                        'title' => Piwik::translate('Live_LinkVisitorLog'),
                        'icon'  => 'plugins/Zeitgeist/images/table.png'
                    )
                )
            )
        );

        // determine if each row has ecommerce activity or not
        if ($filterEcommerce) {
            $this->dataTable->filter(
                'ColumnCallbackAddMetadata',
                array(
                    'actionDetails',
                    'hasEcommerce',
                    function ($actionDetails) use ($filterEcommerce) {
                        foreach ($actionDetails as $action) {
                            $isEcommerceOrder = $action['type'] == 'ecommerceOrder'
                                       && $filterEcommerce == \Piwik\Plugins\Goals\Controller::ECOMMERCE_LOG_SHOW_ORDERS;
                            $isAbandonedCart = $action['type'] == 'ecommerceAbandonedCart'
                                       && $filterEcommerce == \Piwik\Plugins\Goals\Controller::ECOMMERCE_LOG_SHOW_ABANDONED_CARTS;
                            if($isAbandonedCart || $isEcommerceOrder) {
                                return true;
                            }
                        }
                        return false;
                    }
                )
            );
        }
    }
}