blob: d8434f9ee97c8e119bdbbcc6448f19bf859be22c (
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
110
111
112
113
114
|
<?php
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugin;
use Piwik\Common;
use Piwik\Db;
use Piwik\Tracker\Request;
use Piwik\Plugin\Manager as PluginManager;
/**
* @api
* @since 2.4.0
*/
abstract class VisitDimension
{
protected $name;
protected $fieldName = '';
protected $fieldType = '';
protected $segments = array();
public function __construct()
{
$this->init();
}
protected function init()
{
}
public function install()
{
if (empty($this->fieldName) || empty($this->fieldType)) {
return;
}
try {
$sql = "ALTER TABLE `" . Common::prefixTable("log_visit") . "` ADD `$this->fieldName` $this->fieldType";
Db::exec($sql);
} catch (\Exception $e) {
if (!Db::get()->isErrNo($e, '1060')) {
throw $e;
}
}
}
protected function addSegment(Segment $segment)
{
$sqlSegment = $segment->getSqlSegment();
if (!empty($this->fieldName) && empty($sqlSegment)) {
$segment->setSqlSegment('log_visit.' . $this->fieldName);
}
$type = $segment->getType();
if (empty($type)) {
$segment->setType(Segment::TYPE_DIMENSION);
}
$this->segments[] = $segment;
}
/**
* @return Segment[]
*/
public function getSegments()
{
return $this->segments;
}
public function getFieldName()
{
return $this->fieldName;
}
abstract public function getName();
/** @return \Piwik\Plugin\VisitDimension[] */
public static function getAllDimensions()
{
$plugins = PluginManager::getInstance()->getLoadedPlugins();
$instances = array();
foreach ($plugins as $plugin) {
foreach (self::getDimensions($plugin) as $instance) {
$instances[] = $instance;
}
}
return $instances;
}
/** @return \Piwik\Plugin\VisitDimension[] */
public static function getDimensions(\Piwik\Plugin $plugin)
{
$dimensions = $plugin->findMultipleComponents('Columns', '\\Piwik\\Plugin\\VisitDimension');
$instances = array();
foreach ($dimensions as $dimension) {
$instances[] = new $dimension();
}
return $instances;
}
}
|