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

Array.php « Archive « core - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cd9472a245381164ff751c9e70f7f53a76cf0f33 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?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
 * @package Piwik
 */

/**
 * Piwik_Archive_Array is used to store multiple archives, 
 * for example one archive for a given day for each Piwik website
 *
 * @package Piwik
 * @subpackage Piwik_Archive
 */
abstract class Piwik_Archive_Array extends Piwik_Archive
{	
	/**
	 * This array contains one Piwik_Archive per entry in the period
	 * 
	 * @var Piwik_Archive[]
	 */
	protected $archives = array();
	
	abstract protected function getIndexName();
	abstract protected function getDataTableLabelValue( $archive );

	/**
	 * Destructor
	 */
	public function __destruct()
	{
		foreach($this->archives as $archive)
		{
			destroy($archive);
		}
		$this->archives = array();
	}

	/**
	 * Prepares each archive in the array
	 */
	public function prepareArchive()
	{
		foreach($this->archives as $archive)
		{
			$archive->prepareArchive();
		}
	}
	
	/**
	 * Returns a newly created Piwik_DataTable_Array.
	 *
	 * @return Piwik_DataTable_Array
	 */
	protected function getNewDataTableArray()
	{
		$table = new Piwik_DataTable_Array();
		$table->setKeyName($this->getIndexName());
		return $table;
	}
	
	/**
	 * Returns a DataTable_Array containing numeric values 
	 * of the element $name from the archives in this Archive_Array.
	 *
	 * @param string  $name  Name of the mysql table field to load eg. Referers_distinctKeywords
	 * @return Piwik_DataTable_Array  containing the requested numeric value for each Archive
	 */
	public function getNumeric( $name )
	{
		$table = $this->getNewDataTableArray();
		
		foreach($this->archives as $archive)
		{
			$numeric = $archive->getNumeric( $name ) ;
			$subTable = $archive->makeDataTable($isSimple = true);
			$subTable->addRowsFromArray( array( $numeric ) );
			$table->addTable($subTable, $this->getDataTableLabelValue($archive));
		}
		
		return $table;
	}
	
	/**
	 * Returns a DataTable_Array containing values 
	 * of the element $name from the archives in this Archive_Array.
	 *
	 * The value to be returned are blob values (stored in the archive_numeric_* tables in the DB).	 * 
	 * It can return anything from strings, to serialized PHP arrays or PHP objects, etc.
	 *
	 * @param string  $name  Name of the mysql table field to load eg. Referers_keywordBySearchEngine
	 * @return Piwik_DataTable_Array  containing the requested blob values for each Archive
	 */
	public function getBlob( $name )
	{
		$table = $this->getNewDataTableArray();
		
		foreach($this->archives as $archive)
		{
			$blob = $archive->getBlob( $name ) ;
			$subTable = $archive->makeNewDataTable($isSimple = true);
			$subTable->addRowsFromArray( array('blob' => $blob));
			$table->addTable($subTable, $this->getDataTableLabelValue($archive));
		}
		return $table;
	}
	
	/**
	 * Given a BLOB field name (eg. 'Referers_searchEngineByKeyword'), it will return a Piwik_DataTable_Array
	 * which is an array of Piwik_DataTable, ordered by chronological order
	 * 
	 * @param string  $name        Name of the mysql table field to load
	 * @param int     $idSubTable  optional idSubDataTable
	 * @return Piwik_DataTable_Array
	 * @throws Exception  If the value cannot be found
	 */
	public function getDataTable( $name, $idSubTable = null )
	{		
		$table = $this->getNewDataTableArray();
		foreach($this->archives as $archive)
		{
			$subTable =  $archive->getDataTable( $name, $idSubTable ) ;
			$table->addTable($subTable, $this->getDataTableLabelValue($archive));
		}
		return $table;
	}
	
	
	/**
	 * Same as getDataTable() except that it will also load in memory
	 * all the subtables for the DataTable $name. 
	 * You can then access the subtables by using the Piwik_DataTable_Manager::getInstance()->getTable($idSubTable);
	 *
	 * @param string  $name        Name of the mysql table field to load
	 * @param int     $idSubTable  optional idSubDataTable
	 * @return Piwik_DataTable_Array
	 */
	public function getDataTableExpanded($name, $idSubTable = null)
	{
		$table = $this->getNewDataTableArray();
		foreach($this->archives as $archive)
		{
			$subTable =  $archive->getDataTableExpanded( $name, $idSubTable ) ;
			$table->addTable($subTable, $this->getDataTableLabelValue($archive));
		}
		return $table;
	}
}