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

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattab <matthieu.aubry@gmail.com>2013-07-21 12:01:35 +0400
committermattab <matthieu.aubry@gmail.com>2013-07-21 12:01:36 +0400
commitaca8ec33a85e0a70b818b6227145041717d7a69e (patch)
tree41377e3a9737d63222522ef93ecf8483f3faddfa /core/Archive
parent0a63210e3eae7562af1a3dbee340eb1ee140db3d (diff)
Refs #4059 Work in progress: Conversion to use Namespaces: Period*, Metrics, Segment, SegmentExpression, PluginsManager.
Removed some deprecated code.
Diffstat (limited to 'core/Archive')
-rw-r--r--core/Archive/DataCollection.php27
-rw-r--r--core/Archive/DataTableFactory.php228
-rw-r--r--core/Archive/Parameters.php13
3 files changed, 143 insertions, 125 deletions
diff --git a/core/Archive/DataCollection.php b/core/Archive/DataCollection.php
index 1f4a29382d..4b05615c21 100644
--- a/core/Archive/DataCollection.php
+++ b/core/Archive/DataCollection.php
@@ -9,15 +9,20 @@
* @package Piwik
*/
-namespace Piwik;
+namespace Piwik\Archive;
+
+use Exception;
+use Piwik\Archive\DataTableFactory;
+use Piwik\DataTable;
+
/**
* This class is used to hold and transform archive data for the Archive class.
*
* Archive data is loaded into an instance of this type, can be indexed by archive
* metadata (such as the site ID, period string, etc.), and can be transformed into
- * Piwik_DataTable and Piwik_DataTable_Array instances.
+ * DataTable and Set instances.
*/
-class Archive_DataCollection
+class DataCollection
{
/**
* The archive data, indexed first by site ID and then by period date range. Eg,
@@ -192,18 +197,18 @@ class Archive_DataCollection
/**
* Returns archive data as a DataTable indexed by metadata. Indexed data will
- * be represented by Piwik_DataTable_Array instances.
+ * be represented by Set instances.
*
* @param array $resultIndices An array mapping metadata names to pretty labels
* for them. Each archive data row will be indexed
* by the metadata specified here.
*
* Eg, array('site' => 'idSite', 'period' => 'Date')
- * @return Piwik_DataTable|Piwik_DataTable_Array
+ * @return \Piwik\DataTable|Set
*/
public function getDataTable($resultIndices)
{
- $dataTableFactory = new Piwik_Archive_DataTableFactory(
+ $dataTableFactory = new DataTableFactory(
$this->dataNames, $this->dataType, $this->sitesId, $this->periods, $this->defaultRow);
$index = $this->getArray($resultIndices);
@@ -212,7 +217,7 @@ class Archive_DataCollection
/**
* Returns archive data as a DataTable indexed by metadata. Indexed data will
- * be represented by Piwik_DataTable_Array instances. Each DataTable will have
+ * be represented by Set instances. Each DataTable will have
* its subtable IDs set.
*
* This function will only work if blob data was loaded and only one record
@@ -227,21 +232,21 @@ class Archive_DataCollection
* @param bool $addMetadataSubtableId Whether to add the DB subtable ID as metadata
* to each datatable, or not.
* @throws Exception
- * @return Piwik_DataTable|Piwik_DataTable_Array
+ * @return \Piwik\DataTable|Set
*/
public function getExpandedDataTable($resultIndices, $idSubtable = null, $addMetadataSubtableId = false)
{
if ($this->dataType != 'blob') {
- throw new Exception("Archive_DataCollection: cannot call getExpandedDataTable with "
+ throw new Exception("DataCollection: cannot call getExpandedDataTable with "
. "{$this->dataType} data types. Only works with blob data.");
}
if (count($this->dataNames) !== 1) {
- throw new Exception("Archive_DataCollection: cannot call getExpandedDataTable with "
+ throw new Exception("DataCollection: cannot call getExpandedDataTable with "
. "more than one record.");
}
- $dataTableFactory = new Piwik_Archive_DataTableFactory(
+ $dataTableFactory = new DataTableFactory(
$this->dataNames, 'blob', $this->sitesId, $this->periods, $this->defaultRow);
$dataTableFactory->expandDataTable($addMetadataSubtableId);
$dataTableFactory->useSubtable($idSubtable);
diff --git a/core/Archive/DataTableFactory.php b/core/Archive/DataTableFactory.php
index e0d516aeb6..319db1d904 100644
--- a/core/Archive/DataTableFactory.php
+++ b/core/Archive/DataTableFactory.php
@@ -9,67 +9,71 @@
* @package Piwik
*/
-use Piwik\Archive_DataCollection;
+namespace Piwik\Archive;
+
use Piwik\Site;
+use Piwik\DataTable;
+use Piwik\DataTable\Row;
+
const FIX_ME_OMG = 'this is a warning and reminder to fix this code ';
/**
- * Creates a Piwik_DataTable or Piwik_DataTable_Array instance based on an array
- * index created by Archive_DataCollection.
- *
- * This class is only used by Archive_DataCollection.
+ * Creates a DataTable or Set instance based on an array
+ * index created by DataCollection.
+ *
+ * This class is only used by DataCollection.
*/
-class Piwik_Archive_DataTableFactory
+class DataTableFactory
{
/**
- * @see Archive_DataCollection::$dataNames.
+ * @see DataCollection::$dataNames.
*/
private $dataNames;
-
+
/**
- * @see Archive_DataCollection::$dataType.
+ * @see DataCollection::$dataType.
*/
private $dataType;
-
+
/**
* Whether to expand the DataTables that're created or not. Expanding a DataTable
* means creating DataTables using subtable blobs and correctly setting the subtable
* IDs of all DataTables.
- *
+ *
* @var bool
*/
private $expandDataTable = false;
-
+
/**
* Whether to add the subtable ID used in the database to the in-memory DataTables
* as metadata or not.
- *
+ *
* @var bool
*/
private $addMetadataSubtableId = false;
-
+
/**
- * @see Archive_DataCollection::$sitesId.
+ * @see DataCollection::$sitesId.
*/
private $sitesId;
-
+
/**
- * @see Archive_DataCollection::$periods.
+ * @see DataCollection::$periods.
*/
private $periods;
-
+
/**
* The ID of the subtable to create a DataTable for. Only relevant for blob data.
- *
+ *
* @var int|null
*/
private $idSubtable = null;
-
+
/**
- * @see Archive_DataCollection::$defaultRow.
+ * @see DataCollection::$defaultRow.
*/
private $defaultRow;
-
+
/**
* Constructor.
*/
@@ -83,11 +87,11 @@ class Piwik_Archive_DataTableFactory
$this->periods = $periods;
$this->defaultRow = $defaultRow;
}
-
+
/**
* Tells the factory instance to expand the DataTables that are created by
* creating subtables and setting the subtable IDs of rows w/ subtables correctly.
- *
+ *
* @param bool $addMetadataSubtableId Whether to add the subtable ID used in the
* database to the in-memory DataTables as
* metadata or not.
@@ -108,21 +112,21 @@ class Piwik_Archive_DataTableFactory
public function useSubtable($idSubtable)
{
if (count($this->dataNames) !== 1) {
- throw new Exception("Piwik_Archive_DataTableFactory: Getting subtables for multiple records in one"
- . " archive query is not currently supported.");
+ throw new Exception("DataTableFactory: Getting subtables for multiple records in one"
+ . " archive query is not currently supported.");
}
-
+
$this->idSubtable = $idSubtable;
}
-
+
/**
- * Creates a Piwik_DataTable|Piwik_DataTable_Array instance using an index of
+ * Creates a DataTable|Set instance using an index of
* archive data.
- *
- * @param array $index @see Archive_DataCollection
+ *
+ * @param array $index @see DataCollection
* @param array $resultIndices an array mapping metadata names with pretty metadata
* labels.
- * @return Piwik_DataTable|Piwik_DataTable_Array
+ * @return DataTable|Set
*/
public function make($index, $resultIndices)
{
@@ -134,50 +138,50 @@ class Piwik_Archive_DataTableFactory
) {
$index = $this->defaultRow;
}
-
+
$dataTable = $this->createDataTable($index, $keyMetadata = array());
} else {
$dataTable = $this->createDataTableArrayFromIndex($index, $resultIndices);
}
-
+
$this->transformMetadata($dataTable);
return $dataTable;
}
/**
- * Creates a Piwik_DataTable|Piwik_DataTable_Array instance using an array
+ * Creates a DataTable|Set instance using an array
* of blobs.
- *
+ *
* If only one record is being queried, a single DataTable will
- * be returned. Otherwise, a DataTable_Array is returned that indexes
+ * be returned. Otherwise, a DataTable\Map is returned that indexes
* DataTables by record name.
- *
+ *
* If expandDataTable was called, and only one record is being queried,
* the created DataTable's subtables will be expanded.
- *
+ *
* @param array $blobRow
- * @return Piwik_DataTable|Piwik_DataTable_Array
+ * @return DataTable|Set
*/
private function makeFromBlobRow($blobRow)
{
if ($blobRow === false) {
- return new Piwik_DataTable();
+ return new DataTable();
}
-
+
if (count($this->dataNames) === 1) {
return $this->makeDataTableFromSingleBlob($blobRow);
} else {
return $this->makeIndexedByRecordNameDataTable($blobRow);
}
}
-
+
/**
* Creates a DataTable for one record from an archive data row.
- *
+ *
* @see makeFromBlobRow
- *
+ *
* @param array $blobRow
- * @return Piwik_DataTable
+ * @return DataTable
*/
private function makeDataTableFromSingleBlob($blobRow)
{
@@ -185,101 +189,101 @@ class Piwik_Archive_DataTableFactory
if ($this->idSubtable !== null) {
$recordName .= '_' . $this->idSubtable;
}
-
+
if (!empty($blobRow[$recordName])) {
- $table = Piwik_DataTable::fromSerializedArray($blobRow[$recordName]);
+ $table = DataTable::fromSerializedArray($blobRow[$recordName]);
} else {
- $table = new Piwik_DataTable();
+ $table = new DataTable();
}
-
+
// set table metadata
- $table->metadata = Archive_DataCollection::getDataRowMetadata($blobRow);
-
+ $table->metadata = DataCollection::getDataRowMetadata($blobRow);
+
if ($this->expandDataTable) {
$table->enableRecursiveFilters();
$this->setSubtables($table, $blobRow);
}
-
+
return $table;
}
-
+
/**
* Creates a DataTable for every record in an archive data row and puts them
- * in a DataTable_Array instance.
- *
+ * in a DataTable\Map instance.
+ *
* @param array $blobRow
- * @return Piwik_DataTable_Array
+ * @return DataTable\Map
*/
private function makeIndexedByRecordNameDataTable($blobRow)
{
- $table = new Piwik_DataTable_Array();
+ $table = new DataTable\Map();
$table->setKeyName('recordName');
-
- $tableMetadata = Archive_DataCollection::getDataRowMetadata($blobRow);
-
+
+ $tableMetadata = DataCollection::getDataRowMetadata($blobRow);
+
foreach ($blobRow as $name => $blob) {
- $newTable = Piwik_DataTable::fromSerializedArray($blob);
+ $newTable = DataTable::fromSerializedArray($blob);
$newTable->metadata = $tableMetadata;
-
+
$table->addTable($newTable, $name);
}
-
+
return $table;
}
-
+
/**
- * Creates a Piwik_DataTable_Array from an array index.
- *
- * @param array $index @see Archive_DataCollection
+ * Creates a Set from an array index.
+ *
+ * @param array $index @see DataCollection
* @param array $resultIndices @see make
* @param array $keyMetadata The metadata to add to the table when it's created.
- * @return Piwik_DataTable_Array
+ * @return Set
*/
private function createDataTableArrayFromIndex($index, $resultIndices, $keyMetadata = array())
{
$resultIndexLabel = reset($resultIndices);
$resultIndex = key($resultIndices);
-
+
array_shift($resultIndices);
-
- $result = new Piwik_DataTable_Array();
+
+ $result = new DataTable\Map();
$result->setKeyName($resultIndexLabel);
-
+
foreach ($index as $label => $value) {
$keyMetadata[$resultIndex] = $label;
-
+
if (empty($resultIndices)) {
$newTable = $this->createDataTable($value, $keyMetadata);
} else {
$newTable = $this->createDataTableArrayFromIndex($value, $resultIndices, $keyMetadata);
}
-
+
$result->addTable($newTable, $this->prettifyIndexLabel($resultIndex, $label));
}
-
+
return $result;
}
-
+
/**
- * Creates a Piwik_DataTable instance from an index row.
- *
+ * Creates a DataTable instance from an index row.
+ *
* @param array|false $data An archive data row.
* @param array $keyMetadata The metadata to add to the table(s) when created.
- * @return Piwik_DataTable|Piwik_DataTable_Array
+ * @return DataTable|DataTable\Map
*/
private function createDataTable($data, $keyMetadata)
{
if ($this->dataType == 'blob') {
$result = $this->makeFromBlobRow($data);
} else {
- $table = new Piwik_DataTable_Simple();
-
+ $table = new DataTable\Simple();
+
if (!empty($data)) {
- $table->metadata = Archive_DataCollection::getDataRowMetadata($data);
-
- Archive_DataCollection::removeMetadataFromDataRow($data);
-
- $table->addRow(new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => $data)));
+ $table->metadata = DataCollection::getDataRowMetadata($data);
+
+ DataCollection::removeMetadataFromDataRow($data);
+
+ $table->addRow(new Row(array(Row::COLUMNS => $data)));
} else {
// if we're querying numeric data, we couldn't find any, and we're only
// looking for one metric, add a row w/ one column w/ value 0. this is to
@@ -288,39 +292,39 @@ class Piwik_Archive_DataTableFactory
// would break.
if (count($this->dataNames) == 1) {
$name = reset($this->dataNames);
- $table->addRow(new Piwik_DataTable_Row(array(
- Piwik_DataTable_Row::COLUMNS => array($name => 0)
- )));
+ $table->addRow(new Row(array(
+ Row::COLUMNS => array($name => 0)
+ )));
}
}
-
+
$result = $table;
}
-
+
if (!isset($keyMetadata['site'])) {
$keyMetadata['site'] = reset($this->sitesId);
}
-
+
if (!isset($keyMetadata['period'])) {
reset($this->periods);
$keyMetadata['period'] = key($this->periods);
}
-
- // Note: $result can be a DataTable_Array
+
+ // Note: $result can be a DataTable\Map
$result->filter(function ($table) use ($keyMetadata) {
foreach ($keyMetadata as $name => $value) {
$table->setMetadata($name, $value);
}
});
-
+
return $result;
}
-
+
/**
* Creates DataTables from $dataTable's subtable blobs (stored in $blobRow) and sets
* the subtable IDs of each DataTable row.
- *
- * @param Piwik_DataTable $dataTable
+ *
+ * @param DataTable $dataTable
* @param array $blobRow An array associating record names (w/ subtable if applicable)
* with blob values. This should hold every subtable blob for
* the loaded DataTable.
@@ -328,18 +332,18 @@ class Piwik_Archive_DataTableFactory
private function setSubtables($dataTable, $blobRow)
{
$dataName = reset($this->dataNames);
-
+
foreach ($dataTable->getRows() as $row) {
$sid = $row->getIdSubDataTable();
if ($sid === null) {
continue;
}
-
- $blobName = $dataName."_".$sid;
+
+ $blobName = $dataName . "_" . $sid;
if (isset($blobRow[$blobName])) {
- $subtable = Piwik_DataTable::fromSerializedArray($blobRow[$blobName]);
+ $subtable = DataTable::fromSerializedArray($blobRow[$blobName]);
$this->setSubtables($subtable, $blobRow);
-
+
// we edit the subtable ID so that it matches the newly table created in memory
// NB: we dont overwrite the datatableid in the case we are displaying the table expanded.
if ($this->addMetadataSubtableId) {
@@ -347,12 +351,12 @@ class Piwik_Archive_DataTableFactory
// see Renderer/Php.php
$row->addMetadata('idsubdatatable_in_db', $row->getIdSubDataTable());
}
-
+
$row->setSubtable($subtable);
}
}
}
-
+
/**
* Converts site IDs and period string ranges into Site instances and
* Period instances in DataTable metadata.
@@ -360,24 +364,24 @@ class Piwik_Archive_DataTableFactory
private function transformMetadata($table)
{
$periods = $this->periods;
- $table->filter(function ($table) use($periods) {
+ $table->filter(function ($table) use ($periods) {
$table->metadata['site'] = new Site($table->metadata['site']);
$table->metadata['period'] = empty($periods[$table->metadata['period']])
- ? FIX_ME_OMG
- : $periods[$table->metadata['period']];
+ ? FIX_ME_OMG
+ : $periods[$table->metadata['period']];
});
}
-
+
/**
* Returns the pretty version of an index label.
- *
+ *
* @param string $labelType eg, 'site', 'period', etc.
* @param string $label eg, '0', '1', '2012-01-01,2012-01-31', etc.
* @return string
*/
private function prettifyIndexLabel($labelType, $label)
{
- if(empty($this->periods[$label])) {
+ if (empty($this->periods[$label])) {
return $label; // BAD BUG FIXME
}
if ($labelType == 'period') { // prettify period labels
diff --git a/core/Archive/Parameters.php b/core/Archive/Parameters.php
index aa03d3beed..8db15dcbb5 100644
--- a/core/Archive/Parameters.php
+++ b/core/Archive/Parameters.php
@@ -1,10 +1,19 @@
<?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
+ */
-namespace Piwik;
+namespace Piwik\Archive;
use Exception;
use Piwik\Segment;
-class Archive_Parameters
+class Parameters
{
/**
* The list of site IDs to query archive data for.