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
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/API/DataTableGenericFilter.php12
-rw-r--r--core/API/DataTableManipulator.php22
-rw-r--r--core/API/DataTableManipulator/Flattener.php16
-rw-r--r--core/API/DataTableManipulator/LabelFilter.php12
-rw-r--r--core/API/DocumentationGenerator.php2
-rw-r--r--core/API/Request.php5
-rw-r--r--core/API/ResponseBuilder.php32
-rw-r--r--core/Archive.php57
-rw-r--r--core/Archive/DataCollection.php27
-rw-r--r--core/Archive/DataTableFactory.php228
-rw-r--r--core/Archive/Parameters.php13
-rw-r--r--core/ArchiveProcessor.php43
-rw-r--r--core/ArchiveProcessor/Day.php14
-rw-r--r--core/ArchiveProcessor/Period.php26
-rw-r--r--core/ArchiveProcessor/Rules.php26
-rw-r--r--core/AssetManager.php2
-rw-r--r--core/Common.php2
-rw-r--r--core/Controller.php43
-rw-r--r--core/Controller/Admin.php4
-rw-r--r--core/DataAccess/ArchiveSelector.php61
-rw-r--r--core/DataAccess/ArchiveTableCreator.php22
-rw-r--r--core/DataAccess/ArchiveWriter.php21
-rw-r--r--core/DataAccess/LogAggregator.php19
-rw-r--r--core/DataTable.php174
-rw-r--r--core/DataTable/Filter.php24
-rw-r--r--core/DataTable/Filter/AddColumnsProcessedMetrics.php19
-rw-r--r--core/DataTable/Filter/AddColumnsProcessedMetricsGoal.php17
-rw-r--r--core/DataTable/Filter/AddConstantMetadata.php12
-rw-r--r--core/DataTable/Filter/AddSummaryRow.php23
-rw-r--r--core/DataTable/Filter/BeautifyRangeLabels.php10
-rw-r--r--core/DataTable/Filter/BeautifyTimeRangeLabels.php8
-rwxr-xr-xcore/DataTable/Filter/CalculateEvolutionFilter.php31
-rwxr-xr-xcore/DataTable/Filter/ColumnCallbackAddColumn.php12
-rw-r--r--core/DataTable/Filter/ColumnCallbackAddColumnPercentage.php7
-rw-r--r--core/DataTable/Filter/ColumnCallbackAddColumnQuotient.php19
-rw-r--r--core/DataTable/Filter/ColumnCallbackAddMetadata.php24
-rw-r--r--core/DataTable/Filter/ColumnCallbackDeleteRow.php12
-rw-r--r--core/DataTable/Filter/ColumnCallbackReplace.php18
-rw-r--r--core/DataTable/Filter/ColumnDelete.php25
-rw-r--r--core/DataTable/Filter/ExcludeLowPopulation.php22
-rwxr-xr-xcore/DataTable/Filter/GroupBy.php14
-rw-r--r--core/DataTable/Filter/Limit.php14
-rw-r--r--core/DataTable/Filter/MetadataCallbackAddMetadata.php14
-rw-r--r--core/DataTable/Filter/MetadataCallbackReplace.php16
-rw-r--r--core/DataTable/Filter/Null.php12
-rw-r--r--core/DataTable/Filter/Pattern.php12
-rw-r--r--core/DataTable/Filter/PatternRecursive.php21
-rw-r--r--core/DataTable/Filter/RangeCheck.php12
-rw-r--r--core/DataTable/Filter/ReplaceColumnNames.php24
-rw-r--r--core/DataTable/Filter/ReplaceSummaryRowLabel.php17
-rw-r--r--core/DataTable/Filter/SafeDecodeLabel.php13
-rw-r--r--core/DataTable/Filter/Sort.php62
-rw-r--r--core/DataTable/Filter/Truncate.php15
-rw-r--r--core/DataTable/Manager.php20
-rw-r--r--core/DataTable/Map.php (renamed from core/DataTable/Array.php)55
-rw-r--r--core/DataTable/Renderer.php34
-rw-r--r--core/DataTable/Renderer/Console.php25
-rw-r--r--core/DataTable/Renderer/Csv.php30
-rw-r--r--core/DataTable/Renderer/Html.php22
-rw-r--r--core/DataTable/Renderer/Json.php13
-rw-r--r--core/DataTable/Renderer/Php.php34
-rw-r--r--core/DataTable/Renderer/Rss.php22
-rw-r--r--core/DataTable/Renderer/Tsv.php7
-rw-r--r--core/DataTable/Renderer/Xml.php43
-rw-r--r--core/DataTable/Row.php71
-rw-r--r--core/DataTable/Row/DataTableSummaryRow.php (renamed from core/DataTable/Row/DataTableSummary.php)17
-rw-r--r--core/DataTable/Simple.php11
-rw-r--r--core/Date.php107
-rw-r--r--core/Db/Adapter.php3
-rw-r--r--core/Db/Schema/Myisam.php3
-rw-r--r--core/EventDispatcher.php39
-rw-r--r--core/FrontController.php12
-rw-r--r--core/JqplotDataGenerator.php3
-rw-r--r--core/JqplotDataGenerator/Evolution.php5
-rw-r--r--core/Loader.php20
-rw-r--r--core/Period.php56
-rw-r--r--core/Period/Day.php6
-rw-r--r--core/Period/Month.php8
-rw-r--r--core/Period/Range.php53
-rw-r--r--core/Period/Week.php8
-rw-r--r--core/Period/Year.php6
-rw-r--r--core/Piwik.php8
-rw-r--r--core/Plugin.php22
-rw-r--r--core/Plugin/MetadataLoader.php47
-rw-r--r--core/PluginsArchiver.php14
-rw-r--r--core/PluginsManager.php52
-rw-r--r--core/ReportRenderer.php14
-rw-r--r--core/Site.php6
-rw-r--r--core/Tracker.php9
-rw-r--r--core/Tracker/Cache.php3
-rw-r--r--core/Translate.php45
-rw-r--r--core/Twig.php8
-rw-r--r--core/Updates/0.6-rc1.php4
-rwxr-xr-xcore/Updates/1.10-b4.php2
-rwxr-xr-xcore/Updates/1.10.1.php2
-rw-r--r--core/Updates/1.11-b1.php2
-rw-r--r--core/Updates/1.12-b15.php2
-rw-r--r--core/Updates/1.2-rc1.php4
-rw-r--r--core/Updates/1.2-rc2.php2
-rw-r--r--core/Updates/1.5-rc6.php2
-rw-r--r--core/Updates/1.6-rc1.php2
-rw-r--r--core/Updates/1.8.3-b1.php2
-rwxr-xr-xcore/Updates/1.9-b19.php2
-rwxr-xr-xcore/Updates/1.9.3-b10.php2
-rw-r--r--core/Updates/1.9.3-b3.php4
-rw-r--r--core/ViewDataTable.php50
-rw-r--r--core/ViewDataTable/GenerateGraphHTML/ChartEvolution.php6
-rw-r--r--core/ViewDataTable/HtmlTable.php7
-rw-r--r--core/ViewDataTable/HtmlTable/AllColumns.php3
-rw-r--r--core/ViewDataTable/HtmlTable/Goals.php11
-rw-r--r--core/ViewDataTable/Sparkline.php7
111 files changed, 1387 insertions, 1102 deletions
diff --git a/core/API/DataTableGenericFilter.php b/core/API/DataTableGenericFilter.php
index 22f691c505..fec5bb7e94 100644
--- a/core/API/DataTableGenericFilter.php
+++ b/core/API/DataTableGenericFilter.php
@@ -9,6 +9,8 @@
* @package Piwik
*/
use Piwik\Common;
+use Piwik\DataTable;
+use Piwik\DataTable\Filter\AddColumnsProcessedMetricsGoal;
/**
* @package Piwik
@@ -31,7 +33,7 @@ class Piwik_API_DataTableGenericFilter
/**
* Filters the given data table
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
*/
public function filter($table)
{
@@ -39,7 +41,7 @@ class Piwik_API_DataTableGenericFilter
}
/**
- * Returns an array containing the information of the generic Piwik_DataTable_Filter
+ * Returns an array containing the information of the generic Filter
* to be applied automatically to the data resulting from the API calls.
*
* Order to apply the filters:
@@ -71,7 +73,7 @@ class Piwik_API_DataTableGenericFilter
),
'AddColumnsProcessedMetricsGoal' => array(
'filter_update_columns_when_show_all_goals' => array('integer'),
- 'idGoal' => array('string', Piwik_DataTable_Filter_AddColumnsProcessedMetricsGoal::GOALS_OVERVIEW),
+ 'idGoal' => array('string', AddColumnsProcessedMetricsGoal::GOALS_OVERVIEW),
),
'Sort' => array(
'filter_sort_column' => array('string'),
@@ -95,12 +97,12 @@ class Piwik_API_DataTableGenericFilter
* Apply generic filters to the DataTable object resulting from the API Call.
* Disable this feature by setting the parameter disable_generic_filters to 1 in the API call request.
*
- * @param Piwik_DataTable $datatable
+ * @param DataTable $datatable
* @return bool
*/
protected function applyGenericFilters($datatable)
{
- if ($datatable instanceof Piwik_DataTable_Array) {
+ if ($datatable instanceof DataTable\Map) {
$tables = $datatable->getArray();
$filterWasApplied = false;
foreach ($tables as $table) {
diff --git a/core/API/DataTableManipulator.php b/core/API/DataTableManipulator.php
index a8d88fda43..03541cf4ff 100644
--- a/core/API/DataTableManipulator.php
+++ b/core/API/DataTableManipulator.php
@@ -8,7 +8,9 @@
* @category Piwik
* @package Piwik
*/
-use Piwik\Period_Range;
+use Piwik\DataTable\Row;
+use Piwik\Period\Range;
+use Piwik\DataTable;
/**
* Base class for manipulating data tables.
@@ -52,15 +54,15 @@ abstract class Piwik_API_DataTableManipulator
* data table arrays. It calls back the template method self::doManipulate for each table.
* This way, data table arrays can be handled in a transparent fashion.
*
- * @param Piwik_DataTable_Array|Piwik_DataTable $dataTable
+ * @param DataTable\Map|DataTable $dataTable
* @throws Exception
- * @return Piwik_DataTable_Array|Piwik_DataTable
+ * @return DataTable\Map|DataTable
*/
protected function manipulate($dataTable)
{
- if ($dataTable instanceof Piwik_DataTable_Array) {
+ if ($dataTable instanceof DataTable\Map) {
return $this->manipulateDataTableArray($dataTable);
- } else if ($dataTable instanceof Piwik_DataTable) {
+ } else if ($dataTable instanceof DataTable) {
return $this->manipulateDataTable($dataTable);
} else {
return $dataTable;
@@ -81,7 +83,7 @@ abstract class Piwik_API_DataTableManipulator
}
/**
- * Manipulates a single Piwik_DataTable instance. Derived classes must define
+ * Manipulates a single DataTable instance. Derived classes must define
* this function.
*/
protected abstract function manipulateDataTable($dataTable);
@@ -90,10 +92,10 @@ abstract class Piwik_API_DataTableManipulator
* Load the subtable for a row.
* Returns null if none is found.
*
- * @param Piwik_DataTable $dataTable
- * @param Piwik_DataTable_Row $row
+ * @param DataTable $dataTable
+ * @param Row $row
*
- * @return Piwik_DataTable
+ * @return DataTable
*/
protected function loadSubtable($dataTable, $row)
{
@@ -111,7 +113,7 @@ abstract class Piwik_API_DataTableManipulator
$request['idSubtable'] = $idSubTable;
if ($dataTable) {
$period = $dataTable->metadata['period'];
- if ($period instanceof Period_Range) {
+ if ($period instanceof Range) {
$request['date'] = $period->getDateStart().','.$period->getDateEnd();
} else {
$request['date'] = $period->getDateStart()->toString();
diff --git a/core/API/DataTableManipulator/Flattener.php b/core/API/DataTableManipulator/Flattener.php
index 4f700ac854..6ccae47fdd 100644
--- a/core/API/DataTableManipulator/Flattener.php
+++ b/core/API/DataTableManipulator/Flattener.php
@@ -8,6 +8,8 @@
* @category Piwik
* @package Piwik
*/
+use Piwik\DataTable;
+use Piwik\DataTable\Row;
/**
* This class is responsible for flattening data tables.
@@ -40,8 +42,8 @@ class Piwik_API_DataTableManipulator_Flattener extends Piwik_API_DataTableManipu
public $recursiveLabelSeparator = ' - ';
/**
- * @param Piwik_DataTable $dataTable
- * @return Piwik_DataTable|Piwik_DataTable_Array
+ * @param DataTable $dataTable
+ * @return DataTable|DataTable\Map
*/
public function flatten($dataTable)
{
@@ -56,8 +58,8 @@ class Piwik_API_DataTableManipulator_Flattener extends Piwik_API_DataTableManipu
* Template method called from self::manipulate.
* Flatten each data table.
*
- * @param Piwik_DataTable $dataTable
- * @return Piwik_DataTable
+ * @param DataTable $dataTable
+ * @return DataTable
*/
protected function manipulateDataTable($dataTable)
{
@@ -73,12 +75,12 @@ class Piwik_API_DataTableManipulator_Flattener extends Piwik_API_DataTableManipu
}
/**
- * @param Piwik_DataTable_Row $row
- * @param Piwik_DataTable $dataTable
+ * @param Row $row
+ * @param DataTable $dataTable
* @param string $labelPrefix
* @param bool $parentLogo
*/
- private function flattenRow(Piwik_DataTable_Row $row, Piwik_DataTable $dataTable,
+ private function flattenRow(Row $row, DataTable $dataTable,
$labelPrefix = '', $parentLogo = false)
{
$label = $row->getColumn('label');
diff --git a/core/API/DataTableManipulator/LabelFilter.php b/core/API/DataTableManipulator/LabelFilter.php
index 550dbde69b..56ccd4366e 100644
--- a/core/API/DataTableManipulator/LabelFilter.php
+++ b/core/API/DataTableManipulator/LabelFilter.php
@@ -9,6 +9,8 @@
* @package Piwik
*/
use Piwik\Common;
+use Piwik\DataTable;
+use Piwik\DataTable\Row;
/**
* This class is responsible for handling the label parameter that can be
@@ -38,10 +40,10 @@ class Piwik_API_DataTableManipulator_LabelFilter extends Piwik_API_DataTableMani
* are not needed.
*
* @param string $labels the labels to search for
- * @param Piwik_DataTable $dataTable the data table to be filtered
+ * @param DataTable $dataTable the data table to be filtered
* @param bool $addLabelIndex Whether to add label_index metadata describing which
* label a row corresponds to.
- * @return Piwik_DataTable
+ * @return DataTable
*/
public function filter($labels, $dataTable, $addLabelIndex = false)
{
@@ -58,8 +60,8 @@ class Piwik_API_DataTableManipulator_LabelFilter extends Piwik_API_DataTableMani
* Method for the recursive descend
*
* @param array $labelParts
- * @param Piwik_DataTable $dataTable
- * @return Piwik_DataTable_Row|false
+ * @param DataTable $dataTable
+ * @return Row|false
*/
private function doFilterRecursiveDescend($labelParts, $dataTable)
{
@@ -137,7 +139,7 @@ class Piwik_API_DataTableManipulator_LabelFilter extends Piwik_API_DataTableMani
}
/**
- * Filter a Piwik_DataTable instance. See @filter for more info.
+ * Filter a DataTable instance. See @filter for more info.
*/
protected function manipulateDataTable($dataTable)
{
diff --git a/core/API/DocumentationGenerator.php b/core/API/DocumentationGenerator.php
index 19150ce1da..e928409dfa 100644
--- a/core/API/DocumentationGenerator.php
+++ b/core/API/DocumentationGenerator.php
@@ -25,7 +25,7 @@ class Piwik_API_DocumentationGenerator
*/
public function __construct()
{
- $plugins = PluginsManager::getInstance()->getLoadedPluginsName();
+ $plugins = \Piwik\PluginsManager::getInstance()->getLoadedPluginsName();
foreach ($plugins as $plugin) {
$plugin = Common::unprefixClass($plugin);
try {
diff --git a/core/API/Request.php b/core/API/Request.php
index 4af8db7500..7a7569e59c 100644
--- a/core/API/Request.php
+++ b/core/API/Request.php
@@ -11,6 +11,7 @@
use Piwik\Piwik;
use Piwik\Common;
use Piwik\Access;
+use Piwik\DataTable;
/**
* An API request is the object used to make a call to the API and get the result.
@@ -121,7 +122,7 @@ class Piwik_API_Request
* It then calls the API Proxy which will call the requested method.
*
* @throws Piwik_FrontController_PluginDeactivatedException
- * @return Piwik_DataTable|mixed The data resulting from the API call
+ * @return DataTable|mixed The data resulting from the API call
*/
public function process()
{
@@ -137,7 +138,7 @@ class Piwik_API_Request
list($module, $method) = $this->extractModuleAndMethod($moduleMethod);
- if (!PluginsManager::getInstance()->isPluginActivated($module)) {
+ if (!\Piwik\PluginsManager::getInstance()->isPluginActivated($module)) {
throw new Piwik_FrontController_PluginDeactivatedException($module);
}
$moduleClass = "Piwik_" . $module . "_API";
diff --git a/core/API/ResponseBuilder.php b/core/API/ResponseBuilder.php
index 8040721329..c9bc6eec91 100644
--- a/core/API/ResponseBuilder.php
+++ b/core/API/ResponseBuilder.php
@@ -8,8 +8,12 @@
* @category Piwik
* @package Piwik
*/
+use Piwik\DataTable\Renderer\Json;
+use Piwik\DataTable\Simple;
+use Piwik\DataTable\Renderer;
use Piwik\Piwik;
use Piwik\Common;
+use Piwik\DataTable;
/**
* @package Piwik
@@ -38,7 +42,7 @@ class Piwik_API_ResponseBuilder
/**
* This method processes the data resulting from the API call.
*
- * - If the data resulted from the API call is a Piwik_DataTable then
+ * - If the data resulted from the API call is a DataTable then
* - we apply the standard filters if the parameters have been found
* in the URL. For example to offset,limit the Table you can add the following parameters to any API
* call that returns a DataTable: filter_limit=10&filter_offset=20
@@ -75,8 +79,8 @@ class Piwik_API_ResponseBuilder
// If the returned value is an object DataTable we
// apply the set of generic filters if asked in the URL
// and we render the DataTable according to the format specified in the URL
- if ($value instanceof Piwik_DataTable
- || $value instanceof Piwik_DataTable_Array
+ if ($value instanceof DataTable
+ || $value instanceof DataTable\Map
) {
return $this->handleDataTable($value);
}
@@ -121,7 +125,7 @@ class Piwik_API_ResponseBuilder
}
try {
- $renderer = Piwik_DataTable_Renderer::factory($format);
+ $renderer = Renderer::factory($format);
} catch (Exception $exceptionRenderer) {
return "Error: " . $e->getMessage() . " and: " . $exceptionRenderer->getMessage();
}
@@ -174,7 +178,7 @@ class Piwik_API_ResponseBuilder
/**
* Apply the specified renderer to the DataTable
*
- * @param Piwik_DataTable|array $dataTable
+ * @param DataTable|array $dataTable
* @return string
*/
protected function getRenderedDataTable($dataTable)
@@ -192,7 +196,7 @@ class Piwik_API_ResponseBuilder
$method = Common::getRequestVar('method', '', 'string', $this->request);
- $renderer = Piwik_DataTable_Renderer::factory($format);
+ $renderer = Renderer::factory($format);
$renderer->setTable($dataTable);
$renderer->setRenderSubTables(Common::getRequestVar('expanded', false, 'int', $this->request));
$renderer->setHideIdSubDatableFromResponse(Common::getRequestVar('hideIdSubDatable', false, 'int', $this->request));
@@ -268,7 +272,7 @@ class Piwik_API_ResponseBuilder
*/
protected function handleScalar($scalar)
{
- $dataTable = new Piwik_DataTable_Simple();
+ $dataTable = new Simple();
$dataTable->addRowsFromArray(array($scalar));
return $this->getRenderedDataTable($dataTable);
}
@@ -276,7 +280,7 @@ class Piwik_API_ResponseBuilder
/**
* Handles the given data table
*
- * @param Piwik_DataTable $datatable
+ * @param DataTable $datatable
* @return string
*/
protected function handleDataTable($datatable)
@@ -404,10 +408,10 @@ class Piwik_API_ResponseBuilder
/**
* Render a multidimensional array to Json
- * Handle Piwik_DataTable|Piwik_DataTable_Array elements in the first dimension only, following case does not work:
+ * Handle DataTable|Set elements in the first dimension only, following case does not work:
* array(
* array(
- * Piwik_DataTable,
+ * DataTable,
* 2 => array(
* 1,
* 2
@@ -415,7 +419,7 @@ class Piwik_API_ResponseBuilder
* ),
* );
*
- * @param array $array can contain scalar, arrays, Piwik_DataTable and Piwik_DataTable_Array
+ * @param array $array can contain scalar, arrays, DataTable and Set
* @return string
*/
public static function convertMultiDimensionalArrayToJson($array)
@@ -440,10 +444,10 @@ class Piwik_API_ResponseBuilder
$json .= Common::json_encode($value);
break;
- // Case dimension is a Piwik_DataTable_Array or a Piwik_DataTable
- case ($value instanceof Piwik_DataTable_Array || $value instanceof Piwik_DataTable):
+ // Case dimension is a Set or a DataTable
+ case ($value instanceof DataTable\Map || $value instanceof DataTable):
- $XMLRenderer = new Piwik_DataTable_Renderer_Json();
+ $XMLRenderer = new Json();
$XMLRenderer->setTable($value);
$renderedReport = $XMLRenderer->render();
$json .= $renderedReport;
diff --git a/core/Archive.php b/core/Archive.php
index ddc0cb453e..a0412b4ae6 100644
--- a/core/Archive.php
+++ b/core/Archive.php
@@ -9,8 +9,13 @@
* @package Piwik
*/
namespace Piwik;
+use Piwik\Archive\Parameters;
+use Piwik\Period\Range;
use Piwik\Piwik;
use Piwik\Metrics;
+use Piwik\Date;
+use Piwik\ArchiveProcessor\Rules;
+use Piwik\DataAccess\ArchiveSelector;
/**
* The archive object is used to query specific data for a day or a period of statistics for a given website.
@@ -93,16 +98,16 @@ class Archive
private $forceIndexedByDate;
/**
- * @var Archive_Parameters
+ * @var Parameters
*/
private $params;
/**
- * @param Archive_Parameters $params
+ * @param Parameters $params
* @param bool $forceIndexedBySite Whether to force index the result of a query by site ID.
* @param bool $forceIndexedByDate Whether to force index the result of a query by period.
*/
- protected function __construct(Archive_Parameters $params, $forceIndexedBySite = false,
+ protected function __construct(Parameters $params, $forceIndexedBySite = false,
$forceIndexedByDate = false)
{
$this->params = $params;
@@ -115,7 +120,7 @@ class Archive
*
* @param $idSites
* @param string $period 'day', 'week', 'month', 'year' or 'range'
- * @param Piwik_Date|string $strDate 'YYYY-MM-DD', magic keywords (ie, 'today'; @see Piwik_Date::factory())
+ * @param Date|string $strDate 'YYYY-MM-DD', magic keywords (ie, 'today'; @see Date::factory())
* or date range (ie, 'YYYY-MM-DD,YYYY-MM-DD').
* @param bool|string $segment Segment definition - defaults to false for backward compatibility.
* @param bool|string $_restrictSitesToLogin Used only when running as a scheduled task.
@@ -126,7 +131,7 @@ class Archive
$websiteIds = Site::getIdSitesFromIdSitesString($idSites, $_restrictSitesToLogin);
if (Period::isMultiplePeriod($strDate, $period)) {
- $oPeriod = new Period_Range($period, $strDate);
+ $oPeriod = new Range($period, $strDate);
$allPeriods = $oPeriod->getSubperiods();
} else {
$timezone = count($websiteIds) == 1 ? Site::getTimezoneFor($websiteIds[0]) : false;
@@ -150,7 +155,7 @@ class Archive
$forceIndexedByDate = true;
}
- $params = new Archive_Parameters();
+ $params = new Parameters();
$params->setIdSites($idSites);
$params->setPeriods($periods);
$params->setSegment($segment);
@@ -212,7 +217,7 @@ class Archive
*
* @param string|array $names One or more archive names, eg, 'nb_visits', 'Referers_distinctKeywords',
* etc.
- * @return Piwik_DataTable|false False if no value with the given names. Based on the number
+ * @return DataTable|false False if no value with the given names. Based on the number
* of sites/periods, the result can be a DataTable_Array, which
* contains DataTable instances.
*/
@@ -226,13 +231,13 @@ class Archive
* This method will build a dataTable from the blob value $name in the current archive.
*
* For example $name = 'Referers_searchEngineByKeyword' will return a
- * Piwik_DataTable containing all the keywords. If a $idSubtable is given, the method
+ * DataTable containing all the keywords. If a $idSubtable is given, the method
* will return the subTable of $name. If 'all' is supplied for $idSubtable every subtable
* will be returned.
*
* @param string $name The name of the record to get.
* @param int|string|null $idSubtable The subtable ID (if any) or 'all' if requesting every datatable.
- * @return Piwik_DataTable|false
+ * @return DataTable|false
*/
public function getDataTable($name, $idSubtable = null)
{
@@ -243,13 +248,13 @@ class Archive
/**
* 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::getTable() function.
+ * Manager::getTable() function.
*
* @param string $name The name of the record to get.
* @param int|string|null $idSubtable The subtable ID (if any) or self::ID_SUBTABLE_LOAD_ALL_SUBTABLES if requesting every datatable.
* @param bool $addMetadataSubtableId Whether to add the DB subtable ID as metadata to each datatable,
* or not.
- * @return Piwik_DataTable
+ * @return DataTable
*/
public function getDataTableExpanded($name, $idSubtable = null, $addMetadataSubtableId = true)
{
@@ -280,11 +285,11 @@ class Archive
* @param string $name
* @param int $idSite
* @param string $period
- * @param Piwik_Date $date
+ * @param Date $date
* @param string $segment
* @param bool $expanded
* @param int|null $idSubtable
- * @return Piwik_DataTable|Piwik_DataTable_Array
+ * @return DataTable|DataTable\Map
*/
public static function getDataTableFromArchive($name, $idSite, $period, $date, $segment, $expanded, $idSubtable = null)
{
@@ -315,7 +320,7 @@ class Archive
* @param array|string $archiveNames
* @param $archiveDataType
* @param null|int $idSubtable
- * @return Archive_DataCollection
+ * @return DataCollection
*/
private function get($archiveNames, $archiveDataType, $idSubtable = null)
{
@@ -332,7 +337,7 @@ class Archive
}
}
- $result = new Archive_DataCollection(
+ $result = new Archive\DataCollection(
$archiveNames, $archiveDataType, $this->params->getIdSites(), $this->params->getPeriods(), $defaultRow = null);
$archiveIds = $this->getArchiveIds($archiveNames);
@@ -341,7 +346,7 @@ class Archive
}
$loadAllSubtables = $idSubtable == self::ID_SUBTABLE_LOAD_ALL_SUBTABLES;
- $archiveData = Piwik_DataAccess_ArchiveSelector::getArchiveData($archiveIds, $archiveNames, $archiveDataType, $loadAllSubtables);
+ $archiveData = ArchiveSelector::getArchiveData($archiveIds, $archiveNames, $archiveDataType, $loadAllSubtables);
foreach ($archiveData as $row) {
// values are grouped by idsite (site ID), date1-date2 (date range), then name (field name)
$idSite = $row['idsite'];
@@ -365,7 +370,7 @@ class Archive
* Returns archive IDs for the sites, periods and archive names that are being
* queried. This function will use the idarchive cache if it has the right data,
* query archive tables for IDs w/o launching archiving, or launch archiving and
- * get the idarchive from Piwik_ArchiveProcessor instances.
+ * get the idarchive from ArchiveProcessor instances.
*/
private function getArchiveIds($archiveNames)
{
@@ -388,7 +393,7 @@ class Archive
// cache id archives for plugins we haven't processed yet
if (!empty($archiveGroups)) {
- if (!Piwik_ArchiveProcessor_Rules::isArchivingDisabledFor($this->params->getSegment(), $this->getPeriodLabel())) {
+ if (!Rules::isArchivingDisabledFor($this->params->getSegment(), $this->getPeriodLabel())) {
$this->cacheArchiveIdsAfterLaunching($archiveGroups, $plugins);
} else {
$this->cacheArchiveIdsWithoutLaunching($plugins);
@@ -413,7 +418,7 @@ class Archive
}
/**
- * @return Archive_Parameters
+ * @return Parameters
*/
public function getParams()
{
@@ -430,7 +435,7 @@ class Archive
*/
private function cacheArchiveIdsAfterLaunching($archiveGroups, $plugins)
{
- $today = Piwik_Date::today();
+ $today = Date::today();
/* @var Period $period */
foreach ($this->params->getPeriods() as $period) {
@@ -459,9 +464,9 @@ class Archive
}
if ($period->getLabel() == 'day') {
- $processing = new Piwik_ArchiveProcessor_Day($period, $site, $this->params->getSegment());
+ $processing = new ArchiveProcessor\Day($period, $site, $this->params->getSegment());
} else {
- $processing = new Piwik_ArchiveProcessor_Period($period, $site, $this->params->getSegment());
+ $processing = new ArchiveProcessor\Period($period, $site, $this->params->getSegment());
}
// process for each plugin as well
@@ -493,7 +498,7 @@ class Archive
*/
private function cacheArchiveIdsWithoutLaunching($plugins)
{
- $idarchivesByReport = Piwik_DataAccess_ArchiveSelector::getArchiveIds(
+ $idarchivesByReport = ArchiveSelector::getArchiveIds(
$this->params->getIdSites(), $this->params->getPeriods(), $this->params->getSegment(), $plugins);
// initialize archive ID cache for each report
@@ -518,7 +523,7 @@ class Archive
*/
private function getDoneStringForPlugin($plugin)
{
- return Piwik_ArchiveProcessor_Rules::getDoneStringFlagFor($this->params->getSegment(), $this->getPeriodLabel(), $plugin);
+ return Rules::getDoneStringFlagFor($this->params->getSegment(), $this->getPeriodLabel(), $plugin);
}
private function getPeriodLabel()
@@ -529,7 +534,7 @@ class Archive
/**
* Returns an array describing what metadata to use when indexing a query result.
- * For use with Archive_DataCollection.
+ * For use with DataCollection.
*
* @return array
*/
@@ -637,7 +642,7 @@ class Archive
$plugin = substr($report, 0, strpos($report, '_'));
if (empty($plugin)
- || !Piwik_PluginsManager::getInstance()->isPluginActivated($plugin)
+ || !\Piwik\PluginsManager::getInstance()->isPluginActivated($plugin)
) {
$pluginStr = empty($plugin) ? '' : "($plugin)";
throw new Exception("Error: The report '$report' was requested but it is not available "
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.
diff --git a/core/ArchiveProcessor.php b/core/ArchiveProcessor.php
index 63b16ebd93..46cde2533e 100644
--- a/core/ArchiveProcessor.php
+++ b/core/ArchiveProcessor.php
@@ -8,19 +8,27 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik;
+use Exception;
+use Piwik\ArchiveProcessor\Rules;
use Piwik\Config;
use Piwik\Period;
use Piwik\Piwik;
+use Piwik\Date;
use Piwik\Segment;
use Piwik\Site;
+use Piwik\DataAccess\ArchiveSelector;
+use Piwik\DataAccess\ArchiveWriter;
+use Piwik\DataAccess\LogAggregator;
+use Zend_Registry;
/**
* The ArchiveProcessor class is used by the Archive object to make sure the given Archive is processed and available in the DB.
*
* @package Piwik
- * @subpackage Piwik_ArchiveProcessor
+ * @subpackage ArchiveProcessor
*/
-abstract class Piwik_ArchiveProcessor
+abstract class ArchiveProcessor
{
/**
* Flag stored at the end of the archiving
@@ -53,7 +61,7 @@ abstract class Piwik_ArchiveProcessor
protected $idArchive;
/**
- * @var Piwik_DataAccess_ArchiveWriter
+ * @var \Piwik\DataAccess\ArchiveWriter
*/
protected $archiveWriter;
@@ -65,7 +73,7 @@ abstract class Piwik_ArchiveProcessor
protected $temporaryArchive;
/**
- * @var Piwik_DataAccess_LogAggregator
+ * @var LogAggregator
*/
protected $logAggregator = null;
@@ -105,12 +113,12 @@ abstract class Piwik_ArchiveProcessor
}
/**
- * @return Piwik_DataAccess_LogAggregator
+ * @return LogAggregator
*/
public function getLogAggregator()
{
if (empty($this->logAggregator)) {
- $this->logAggregator = new Piwik_DataAccess_LogAggregator($this->getPeriod()->getDateStart(), $this->getPeriod()->getDateEnd(),
+ $this->logAggregator = new LogAggregator($this->getPeriod()->getDateStart(), $this->getPeriod()->getDateEnd(),
$this->getSite(), $this->getSegment());
}
return $this->logAggregator;
@@ -212,7 +220,7 @@ abstract class Piwik_ArchiveProcessor
$period = $this->getPeriod();
$segment = $this->getSegment();
- $idAndVisits = Piwik_DataAccess_ArchiveSelector::getArchiveIdAndVisits($site, $period, $segment, $minDatetimeArchiveProcessedUTC, $requestedPlugin);
+ $idAndVisits = ArchiveSelector::getArchiveIdAndVisits($site, $period, $segment, $minDatetimeArchiveProcessedUTC, $requestedPlugin);
if (!$idAndVisits) {
return false;
}
@@ -257,14 +265,14 @@ abstract class Piwik_ArchiveProcessor
protected function doesRequestedPluginIncludeVisitsSummary($requestedPlugin)
{
- $processAllReportsIncludingVisitsSummary = Piwik_ArchiveProcessor_Rules::shouldProcessReportsAllPlugins($this->getSegment(), $this->getPeriod()->getLabel());
+ $processAllReportsIncludingVisitsSummary = Rules::shouldProcessReportsAllPlugins($this->getSegment(), $this->getPeriod()->getLabel());
$doesRequestedPluginIncludeVisitsSummary = $processAllReportsIncludingVisitsSummary || $requestedPlugin == 'VisitsSummary';
return $doesRequestedPluginIncludeVisitsSummary;
}
protected function computeNewArchive($requestedPlugin, $enforceProcessCoreMetricsOnly)
{
- $archiveWriter = new Piwik_DataAccess_ArchiveWriter($this->getSite()->getId(), $this->getSegment(), $this->getPeriod(), $requestedPlugin, $this->isArchiveTemporary());
+ $archiveWriter = new ArchiveWriter($this->getSite()->getId(), $this->getSegment(), $this->getPeriod(), $requestedPlugin, $this->isArchiveTemporary());
$archiveWriter->initNewArchive();
$this->archiveWriter = $archiveWriter;
@@ -286,14 +294,15 @@ abstract class Piwik_ArchiveProcessor
$isVisitsToday = $this->getNumberOfVisits() > 0;
if ($isVisitsToday
- && !$enforceProcessCoreMetricsOnly) {
+ && !$enforceProcessCoreMetricsOnly
+ ) {
$this->compute();
}
$archiveWriter->finalizeArchive();
if ($isVisitsToday && $this->period->getLabel() != 'day') {
- Piwik_DataAccess_ArchiveSelector::purgeOutdatedArchives($this->getPeriod()->getDateStart());
+ ArchiveSelector::purgeOutdatedArchives($this->getPeriod()->getDateStart());
}
return $archiveWriter->getIdArchive();
@@ -317,7 +326,7 @@ abstract class Piwik_ArchiveProcessor
return $endDateTimestamp;
}
// Temporary archive
- return Piwik_ArchiveProcessor_Rules::getMinTimeProcessedForTemporaryArchive($this->getDateStart(), $this->getPeriod(), $this->getSegment(), $this->getSite());
+ return Rules::getMinTimeProcessedForTemporaryArchive($this->getDateStart(), $this->getPeriod(), $this->getSegment(), $this->getSite());
}
public function isArchiveTemporary()
@@ -356,7 +365,7 @@ abstract class Piwik_ArchiveProcessor
*/
abstract protected function compute();
- protected static function determineIfArchivePermanent(Piwik_Date $dateEnd)
+ protected static function determineIfArchivePermanent(Date $dateEnd)
{
$now = time();
$endTimestampUTC = strtotime($dateEnd->getDateEndUTC());
@@ -369,7 +378,7 @@ abstract class Piwik_ArchiveProcessor
}
/**
- * @return Piwik_Date
+ * @return Date
*/
public function getDateEnd()
{
@@ -377,7 +386,7 @@ abstract class Piwik_ArchiveProcessor
}
/**
- * @return Piwik_Date
+ * @return Date
*/
public function getDateStart()
{
@@ -429,7 +438,7 @@ abstract class Piwik_ArchiveProcessor
*/
public function shouldProcessReportsForPlugin($pluginName)
{
- if (Piwik_ArchiveProcessor_Rules::shouldProcessReportsAllPlugins($this->getSegment(), $this->getPeriod()->getLabel())) {
+ if (Rules::shouldProcessReportsAllPlugins($this->getSegment(), $this->getPeriod()->getLabel())) {
return true;
}
// If any other segment, only process if the requested report belong to this plugin
@@ -437,7 +446,7 @@ abstract class Piwik_ArchiveProcessor
if ($pluginBeingProcessed == $pluginName) {
return true;
}
- if (!PluginsManager::getInstance()->isPluginLoaded($pluginBeingProcessed)) {
+ if (!\Piwik\PluginsManager::getInstance()->isPluginLoaded($pluginBeingProcessed)) {
return true;
}
return false;
diff --git a/core/ArchiveProcessor/Day.php b/core/ArchiveProcessor/Day.php
index 8d17b34ad2..ba8fbb3ae6 100644
--- a/core/ArchiveProcessor/Day.php
+++ b/core/ArchiveProcessor/Day.php
@@ -8,19 +8,23 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\ArchiveProcessor;
use Piwik\Metrics;
+use Piwik\ArchiveProcessor;
+use Piwik_DataArray;
+use Piwik\DataTable;
/**
* This class
* @package Piwik
- * @subpackage Piwik_ArchiveProcessor
+ * @subpackage ArchiveProcessor
*/
-class Piwik_ArchiveProcessor_Day extends Piwik_ArchiveProcessor
+class Day extends ArchiveProcessor
{
/**
* Converts the given array to a datatable
* @param Piwik_DataArray $array
- * @return Piwik_DataTable
+ * @return \Piwik\DataTable
*/
static public function getDataTableFromDataArray(Piwik_DataArray $array)
{
@@ -31,10 +35,10 @@ class Piwik_ArchiveProcessor_Day extends Piwik_ArchiveProcessor
if (!empty($dataArrayTwoLevels)) {
$subtableByLabel = array();
foreach ($dataArrayTwoLevels as $label => $subTable) {
- $subtableByLabel[$label] = Piwik_DataTable::makeFromIndexedArray($subTable);
+ $subtableByLabel[$label] = DataTable::makeFromIndexedArray($subTable);
}
}
- return Piwik_DataTable::makeFromIndexedArray($dataArray, $subtableByLabel);
+ return DataTable::makeFromIndexedArray($dataArray, $subtableByLabel);
}
/**
diff --git a/core/ArchiveProcessor/Period.php b/core/ArchiveProcessor/Period.php
index 0350adb034..6f7085c1a9 100644
--- a/core/ArchiveProcessor/Period.php
+++ b/core/ArchiveProcessor/Period.php
@@ -8,10 +8,18 @@
* @category Piwik
* @package Piwik
*/
+
+namespace Piwik\ArchiveProcessor;
+
+use Exception;
use Piwik\Archive;
use Piwik\Metrics;
use Piwik\Piwik;
use Piwik\Common;
+use Piwik\ArchiveProcessor;
+use Piwik\DataTable;
+use Piwik\DataTable\Map;
+use Piwik\DataTable\Manager;
/**
* This class provides generic methods to archive data for a period (week / month / year).
@@ -21,9 +29,9 @@ use Piwik\Common;
* Public methods can be called by the plugins that hook on the event 'ArchiveProcessing_Period.compute'
*
* @package Piwik
- * @subpackage Piwik_ArchiveProcessor
+ * @subpackage ArchiveProcessor
*/
-class Piwik_ArchiveProcessor_Period extends Piwik_ArchiveProcessor
+class Period extends ArchiveProcessor
{
/**
* Array of (column name before => column name renamed) of the columns for which sum operation is invalid.
@@ -58,7 +66,7 @@ class Piwik_ArchiveProcessor_Period extends Piwik_ArchiveProcessor
* @param int $maximumRowsInDataTableLevelZero Max row count of parent datatable to archive
* @param int $maximumRowsInSubDataTable Max row count of children datatable(s) to archive
* @param string $columnToSortByBeforeTruncation Column name to sort by, before truncating rows (ie. if there are more rows than the specified max row count)
- * @param array $columnAggregationOperations Operations for aggregating columns, @see Piwik_DataTable_Row::sumRow()
+ * @param array $columnAggregationOperations Operations for aggregating columns, @see Row::sumRow()
* @param array $invalidSummedColumnNameToRenamedName (current_column_name => new_column_name) for columns that must change names when summed
* (eg. unique visitors go from nb_uniq_visitors to sum_daily_nb_uniq_visitors)
*
@@ -75,7 +83,7 @@ class Piwik_ArchiveProcessor_Period extends Piwik_ArchiveProcessor
$invalidSummedColumnNameToRenamedName = null)
{
// We clean up below all tables created during this function call (and recursive calls)
- $latestUsedTableId = Piwik_DataTable_Manager::getInstance()->getMostRecentTableId();
+ $latestUsedTableId = Manager::getInstance()->getMostRecentTableId();
if (!is_array($recordNames)) {
$recordNames = array($recordNames);
}
@@ -91,7 +99,7 @@ class Piwik_ArchiveProcessor_Period extends Piwik_ArchiveProcessor
Common::destroy($table);
$this->insertBlobRecord($recordName, $blob);
}
- Piwik_DataTable_Manager::getInstance()->deleteAll($latestUsedTableId);
+ Manager::getInstance()->deleteAll($latestUsedTableId);
return $nameToCount;
}
@@ -147,18 +155,18 @@ class Piwik_ArchiveProcessor_Period extends Piwik_ArchiveProcessor
*
* @param string $name
* @param array $invalidSummedColumnNameToRenamedName columns in the array (old name, new name) to be renamed as the sum operation is not valid on them (eg. nb_uniq_visitors->sum_daily_nb_uniq_visitors)
- * @param array $columnAggregationOperations Operations for aggregating columns, @see Piwik_DataTable_Row::sumRow()
- * @return Piwik_DataTable
+ * @param array $columnAggregationOperations Operations for aggregating columns, @see Row::sumRow()
+ * @return DataTable
*/
protected function getRecordDataTableSum($name, $invalidSummedColumnNameToRenamedName, $columnAggregationOperations = null)
{
- $table = new Piwik_DataTable();
+ $table = new DataTable();
if (!empty($columnAggregationOperations)) {
$table->setColumnAggregationOperations($columnAggregationOperations);
}
$data = $this->archiver->getDataTableExpanded($name, $idSubTable = null, $addMetadataSubtableId = false);
- if ($data instanceof Piwik_DataTable_Array) {
+ if ($data instanceof DataTable\Map) {
foreach ($data->getArray() as $date => $tableToSum) {
$table->addDataTable($tableToSum);
}
diff --git a/core/ArchiveProcessor/Rules.php b/core/ArchiveProcessor/Rules.php
index de856f470b..d58c7e5fb3 100644
--- a/core/ArchiveProcessor/Rules.php
+++ b/core/ArchiveProcessor/Rules.php
@@ -8,17 +8,21 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\ArchiveProcessor;
+
+use Exception;
use Piwik\Config;
-use Piwik\Period;
use Piwik\Piwik;
use Piwik\Common;
use Piwik\Segment;
use Piwik\Site;
+use Piwik\Date;
+use Piwik_Tracker_Cache;
/**
* This class contains Archiving rules/logic which are used in several places
*/
-class Piwik_ArchiveProcessor_Rules
+class Rules
{
const OPTION_TODAY_ARCHIVE_TTL = 'todayArchiveTimeToLive';
@@ -98,10 +102,10 @@ class Piwik_ArchiveProcessor_Rules
* Given a monthly archive table, will delete all reports that are now outdated,
* or reports that ended with an error
*
- * @param Piwik_Date $date
+ * @param \Piwik\Date $date
* @return int|bool False, or timestamp indicating which archives to delete
*/
- public static function shouldPurgeOutdatedArchives(Piwik_Date $date)
+ public static function shouldPurgeOutdatedArchives(Date $date)
{
if (self::$purgeDisabledByTests) {
return false;
@@ -128,10 +132,10 @@ class Piwik_ArchiveProcessor_Rules
if (self::isBrowserTriggerEnabled()) {
// If Browser Archiving is enabled, it is likely there are many more temporary archives
// We delete more often which is safe, since reports are re-processed on demand
- $purgeArchivesOlderThan = Piwik_Date::factory(time() - 2 * $temporaryArchivingTimeout)->getDateTime();
+ $purgeArchivesOlderThan = Date::factory(time() - 2 * $temporaryArchivingTimeout)->getDateTime();
} else {
// If archive.php via Cron is building the reports, we should keep all temporary reports from today
- $purgeArchivesOlderThan = Piwik_Date::factory('today')->getDateTime();
+ $purgeArchivesOlderThan = Date::factory('today')->getDateTime();
}
return $purgeArchivesOlderThan;
}
@@ -140,12 +144,12 @@ class Piwik_ArchiveProcessor_Rules
return false;
}
- public static function getMinTimeProcessedForTemporaryArchive(Piwik_Date $dateStart, Period $period, Segment $segment, Site $site)
+ public static function getMinTimeProcessedForTemporaryArchive(Date $dateStart, \Piwik\Period $period, Segment $segment, Site $site)
{
$now = time();
- $minimumArchiveTime = $now - Piwik_ArchiveProcessor_Rules::getTodayArchiveTimeToLive();
+ $minimumArchiveTime = $now - Rules::getTodayArchiveTimeToLive();
- $isArchivingDisabled = Piwik_ArchiveProcessor_Rules::isArchivingDisabledFor($segment, $period->getLabel());
+ $isArchivingDisabled = Rules::isArchivingDisabledFor($segment, $period->getLabel());
if ($isArchivingDisabled) {
if ($period->getNumberOfSubperiods() == 0
&& $dateStart->getTimestamp() <= $now
@@ -156,7 +160,7 @@ class Piwik_ArchiveProcessor_Rules
// This week, this month, this year:
// accept any archive that was processed today after 00:00:01 this morning
$timezone = $site->getTimezone();
- $minimumArchiveTime = Piwik_Date::factory(Piwik_Date::factory('now', $timezone)->getDateStartUTC())->setTimezone($timezone)->getTimestamp();
+ $minimumArchiveTime = Date::factory(Date::factory('now', $timezone)->getDateStartUTC())->setTimezone($timezone)->getTimestamp();
}
}
return $minimumArchiveTime;
@@ -207,7 +211,7 @@ class Piwik_ArchiveProcessor_Rules
protected static function isRequestAuthorizedToArchive()
{
return !self::$archivingDisabledByTests &&
- (Piwik_ArchiveProcessor_Rules::isBrowserTriggerEnabled()
+ (Rules::isBrowserTriggerEnabled()
|| Common::isPhpCliMode()
|| (Piwik::isUserIsSuperUser()
&& Common::isArchivePhpTriggered()));
diff --git a/core/AssetManager.php b/core/AssetManager.php
index f82f691c20..f175bc5c41 100644
--- a/core/AssetManager.php
+++ b/core/AssetManager.php
@@ -81,7 +81,7 @@ class Piwik_AssetManager
*/
public static function generateAssetsCacheBuster()
{
- $pluginList = md5(implode(",", PluginsManager::getInstance()->getLoadedPluginsName()));
+ $pluginList = md5(implode(",", \Piwik\PluginsManager::getInstance()->getLoadedPluginsName()));
$cacheBuster = md5(Common::getSalt() . $pluginList . PHP_VERSION . Piwik_Version::VERSION);
return $cacheBuster;
}
diff --git a/core/Common.php b/core/Common.php
index c7ed91eacd..da6e8892b5 100644
--- a/core/Common.php
+++ b/core/Common.php
@@ -105,7 +105,7 @@ class Common
*/
public static function isGoalPluginEnabled()
{
- return PluginsManager::getInstance()->isPluginActivated('Goals');
+ return \Piwik\PluginsManager::getInstance()->isPluginActivated('Goals');
}
/*
diff --git a/core/Controller.php b/core/Controller.php
index 646b1552b1..0d6aa3ec64 100644
--- a/core/Controller.php
+++ b/core/Controller.php
@@ -9,11 +9,14 @@
* @package Piwik
*/
use Piwik\Config;
+use Piwik\DataTable\Filter\CalculateEvolutionFilter;
use Piwik\Period;
-use Piwik\Period_Range;
+use Piwik\Period\Month;
+use Piwik\Period\Range;
use Piwik\Piwik;
use Piwik\Common;
use Piwik\Access;
+use Piwik\Date;
use Piwik\Site;
@@ -39,9 +42,9 @@ abstract class Piwik_Controller
protected $strDate;
/**
- * Piwik_Date object or null if the requested date is a range
+ * Date object or null if the requested date is a range
*
- * @var Piwik_Date|null
+ * @var Date|null
*/
protected $date;
@@ -85,7 +88,7 @@ abstract class Piwik_Controller
*
* @param string $date today, yesterday, YYYY-MM-DD
* @param string $defaultTimezone default timezone to use
- * @return Piwik_Date
+ * @return Date
*/
protected function getDateParameterInTimezone($date, $defaultTimezone)
{
@@ -103,17 +106,17 @@ abstract class Piwik_Controller
}
$timezone = $defaultTimezone;
}
- return Piwik_Date::factory($date, $timezone);
+ return Date::factory($date, $timezone);
}
/**
* Sets the date to be used by all other methods in the controller.
* If the date has to be modified, it should be called just after the controller construct
*
- * @param Piwik_Date $date
+ * @param Date $date
* @return void
*/
- protected function setDate(Piwik_Date $date)
+ protected function setDate(Date $date)
{
$this->date = $date;
$strDate = $this->date->toString();
@@ -299,8 +302,8 @@ abstract class Piwik_Controller
*/
public static function getDateRangeRelativeToEndDate($period, $lastN, $endDate, $site)
{
- $last30Relative = new Period_Range($period, $lastN, $site->getTimezone());
- $last30Relative->setDefaultEndDate(Piwik_Date::factory($endDate));
+ $last30Relative = new Range($period, $lastN, $site->getTimezone());
+ $last30Relative->setDefaultEndDate(Date::factory($endDate));
$date = $last30Relative->getDateStart()->toString() . "," . $last30Relative->getDateEnd()->toString();
return $date;
}
@@ -355,11 +358,11 @@ abstract class Piwik_Controller
/**
* Sets the first date available in the calendar
*
- * @param Piwik_Date $minDate
+ * @param Date $minDate
* @param Piwik_View $view
* @return void
*/
- protected function setMinDateView(Piwik_Date $minDate, $view)
+ protected function setMinDateView(Date $minDate, $view)
{
$view->minDateYear = $minDate->toString('Y');
$view->minDateMonth = $minDate->toString('m');
@@ -369,11 +372,11 @@ abstract class Piwik_Controller
/**
* Sets "today" in the calendar. Today does not always mean "UTC" today, eg. for websites in UTC+12.
*
- * @param Piwik_Date $maxDate
+ * @param Date $maxDate
* @param Piwik_View $view
* @return void
*/
- protected function setMaxDateView(Piwik_Date $maxDate, $view)
+ protected function setMaxDateView(Date $maxDate, $view)
{
$view->maxDateYear = $maxDate->toString('Y');
$view->maxDateMonth = $maxDate->toString('m');
@@ -404,10 +407,10 @@ abstract class Piwik_Controller
$rawDate = Common::getRequestVar('date');
$periodStr = Common::getRequestVar('period');
if ($periodStr != 'range') {
- $date = Piwik_Date::factory($this->strDate);
+ $date = Date::factory($this->strDate);
$period = Period::factory($periodStr, $date);
} else {
- $period = new Period_Range($periodStr, $rawDate, $this->site->getTimezone());
+ $period = new Range($periodStr, $rawDate, $this->site->getTimezone());
}
$view->rawDate = $rawDate;
$view->prettyDate = self::getCalendarPrettyDate($period);
@@ -416,10 +419,10 @@ abstract class Piwik_Controller
$view->siteMainUrl = $this->site->getMainUrl();
$datetimeMinDate = $this->site->getCreationDate()->getDatetime();
- $minDate = Piwik_Date::factory($datetimeMinDate, $this->site->getTimezone());
+ $minDate = Date::factory($datetimeMinDate, $this->site->getTimezone());
$this->setMinDateView($minDate, $view);
- $maxDate = Piwik_Date::factory('now', $this->site->getTimezone());
+ $maxDate = Date::factory('now', $this->site->getTimezone());
$this->setMaxDateView($maxDate, $view);
// Setting current period start & end dates, for pre-setting the calendar when "Date Range" is selected
@@ -768,7 +771,7 @@ abstract class Piwik_Controller
*/
public static function getCalendarPrettyDate($period)
{
- if ($period instanceof Piwik_Period_Month) // show month name when period is for a month
+ if ($period instanceof Month) // show month name when period is for a month
{
return $period->getLocalizedLongString();
} else {
@@ -786,7 +789,7 @@ abstract class Piwik_Controller
*/
public static function getPrettyDate($date, $period)
{
- return self::getCalendarPrettyDate(Period::factory($period, Piwik_Date::factory($date)));
+ return self::getCalendarPrettyDate(Period::factory($period, Date::factory($date)));
}
@@ -805,7 +808,7 @@ abstract class Piwik_Controller
*/
protected function getEvolutionHtml($date, $currentValue, $pastDate, $pastValue)
{
- $evolutionPercent = Piwik_DataTable_Filter_CalculateEvolutionFilter::calculate(
+ $evolutionPercent = CalculateEvolutionFilter::calculate(
$currentValue, $pastValue, $precision = 1);
// do not display evolution if evolution percent is 0 and current value is 0
diff --git a/core/Controller/Admin.php b/core/Controller/Admin.php
index dd98dbc835..a6c58b46a6 100644
--- a/core/Controller/Admin.php
+++ b/core/Controller/Admin.php
@@ -54,10 +54,10 @@ abstract class Piwik_Controller_Admin extends Piwik_Controller
$view->isSuperUser = Piwik::isUserIsSuperUser();
// for old geoip plugin warning
- $view->usingOldGeoIPPlugin = PluginsManager::getInstance()->isPluginActivated('GeoIP');
+ $view->usingOldGeoIPPlugin = \Piwik\PluginsManager::getInstance()->isPluginActivated('GeoIP');
// for cannot find installed plugin warning
- $missingPlugins = PluginsManager::getInstance()->getMissingPlugins();
+ $missingPlugins = \Piwik\PluginsManager::getInstance()->getMissingPlugins();
if (!empty($missingPlugins)) {
$pluginsLink = Piwik_Url::getCurrentQueryStringWithParametersModified(array(
'module' => 'CorePluginsAdmin', 'action' => 'index'
diff --git a/core/DataAccess/ArchiveSelector.php b/core/DataAccess/ArchiveSelector.php
index 5c7abde8c6..8ed467ba90 100644
--- a/core/DataAccess/ArchiveSelector.php
+++ b/core/DataAccess/ArchiveSelector.php
@@ -8,12 +8,19 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataAccess;
+
+use Exception;
+use Piwik\ArchiveProcessor\Rules;
use Piwik\Period;
-use Piwik\Period_Range;
+use Piwik\Period\Range;
use Piwik\Piwik;
use Piwik\Common;
+use Piwik\Date;
+use Piwik\ArchiveProcessor;
use Piwik\Segment;
use Piwik\Site;
+use Piwik\DataAccess\ArchiveTableCreator;
/**
* Data Access object used to query archives
@@ -29,7 +36,7 @@ use Piwik\Site;
* - value = the actual data (a numeric value, or a blob of compressed serialized data)
*
*/
-class Piwik_DataAccess_ArchiveSelector
+class ArchiveSelector
{
const NB_VISITS_RECORD_LOOKED_UP = "nb_visits";
@@ -47,7 +54,7 @@ class Piwik_DataAccess_ArchiveSelector
$timeStampWhere = '';
if ($minDatetimeArchiveProcessedUTC) {
$timeStampWhere = " AND ts_archived >= ? ";
- $bindSQL[] = Piwik_Date::factory($minDatetimeArchiveProcessedUTC)->getDatetime();
+ $bindSQL[] = Date::factory($minDatetimeArchiveProcessedUTC)->getDatetime();
}
$pluginOrVisitsSummary = array("VisitsSummary", $requestedPlugin);
@@ -55,7 +62,7 @@ class Piwik_DataAccess_ArchiveSelector
$sqlWhereArchiveName = self::getNameCondition($pluginOrVisitsSummary, $segment);
$sqlQuery = " SELECT idarchive, value, name, date1 as startDate
- FROM " . Piwik_DataAccess_ArchiveTableCreator::getNumericTable($dateStart) . "``
+ FROM " . ArchiveTableCreator::getNumericTable($dateStart) . "``
WHERE idsite = ?
AND date1 = ?
AND date2 = ?
@@ -112,7 +119,7 @@ class Piwik_DataAccess_ArchiveSelector
protected static function getMostRecentIdArchiveFromResults(Segment $segment, $requestedPlugin, $results)
{
$idArchive = false;
- $namesRequestedPlugin = Piwik_ArchiveProcessor_Rules::getDoneFlags(array($requestedPlugin), $segment);
+ $namesRequestedPlugin = Rules::getDoneFlags(array($requestedPlugin), $segment);
foreach ($results as $result) {
if ($idArchive === false
&& in_array($result['name'], $namesRequestedPlugin)
@@ -151,7 +158,7 @@ class Piwik_DataAccess_ArchiveSelector
$monthToPeriods = array();
foreach ($periods as $period) {
/** @var Period $period */
- $table = Piwik_DataAccess_ArchiveTableCreator::getNumericTable($period->getDateStart());
+ $table = ArchiveTableCreator::getNumericTable($period->getDateStart());
$monthToPeriods[$table][] = $period;
}
@@ -162,7 +169,7 @@ class Piwik_DataAccess_ArchiveSelector
// if looking for a range archive. NOTE: we assume there's only one period if its a range.
$bind = array($firstPeriod->getId());
- if ($firstPeriod instanceof Period_Range) {
+ if ($firstPeriod instanceof Range) {
$dateCondition = "date1 = ? AND date2 = ?";
$bind[] = $firstPeriod->getDateStart()->toString('Y-m-d');
$bind[] = $firstPeriod->getDateEnd()->toString('Y-m-d');
@@ -232,11 +239,11 @@ class Piwik_DataAccess_ArchiveSelector
throw new Exception("Unexpected: id archive not found for period '$period' '");
}
// $period = "2009-01-04,2009-01-04",
- $date = Piwik_Date::factory(substr($period, 0, 10));
+ $date = Date::factory(substr($period, 0, 10));
if ($archiveDataType == 'numeric') {
- $table = Piwik_DataAccess_ArchiveTableCreator::getNumericTable($date);
+ $table = ArchiveTableCreator::getNumericTable($date);
} else {
- $table = Piwik_DataAccess_ArchiveTableCreator::getBlobTable($date);
+ $table = ArchiveTableCreator::getBlobTable($date);
}
$sql = sprintf($getValuesSql, $table, implode(',', $ids));
$dataRows = Piwik_FetchAll($sql, $bind);
@@ -260,20 +267,20 @@ class Piwik_DataAccess_ArchiveSelector
{
// the flags used to tell how the archiving process for a specific archive was completed,
// if it was completed
- $doneFlags = Piwik_ArchiveProcessor_Rules::getDoneFlags($plugins, $segment);
+ $doneFlags = Rules::getDoneFlags($plugins, $segment);
$allDoneFlags = "'" . implode("','", $doneFlags) . "'";
// create the SQL to find archives that are DONE
return "(name IN ($allDoneFlags)) AND " .
- " (value = '" . Piwik_ArchiveProcessor::DONE_OK . "' OR " .
- " value = '" . Piwik_ArchiveProcessor::DONE_OK_TEMPORARY . "')";
+ " (value = '" . ArchiveProcessor::DONE_OK . "' OR " .
+ " value = '" . ArchiveProcessor::DONE_OK_TEMPORARY . "')";
}
- static public function purgeOutdatedArchives(Piwik_Date $dateStart)
+ static public function purgeOutdatedArchives(Date $dateStart)
{
- $purgeArchivesOlderThan = Piwik_ArchiveProcessor_Rules::shouldPurgeOutdatedArchives($dateStart);
+ $purgeArchivesOlderThan = Rules::shouldPurgeOutdatedArchives($dateStart);
if (!$purgeArchivesOlderThan) {
return;
}
@@ -285,48 +292,48 @@ class Piwik_DataAccess_ArchiveSelector
self::deleteArchivesWithPeriodRange($dateStart);
Piwik::log("Purging temporary archives: done [ purged archives older than $purgeArchivesOlderThan in "
- . $dateStart->toString("Y-m") ." ] [Deleted IDs: " . implode (',', $idArchivesToDelete) . "]");
+ . $dateStart->toString("Y-m") . " ] [Deleted IDs: " . implode(',', $idArchivesToDelete) . "]");
}
/*
* Deleting "Custom Date Range" reports after 1 day, since they can be re-processed and would take up un-necessary space
*/
- protected static function deleteArchivesWithPeriodRange(Piwik_Date $date)
+ protected static function deleteArchivesWithPeriodRange(Date $date)
{
$query = "DELETE FROM %s WHERE period = ? AND ts_archived < ?";
- $yesterday = Piwik_Date::factory('yesterday')->getDateTime();
+ $yesterday = Date::factory('yesterday')->getDateTime();
$bind = array(Piwik::$idPeriods['range'], $yesterday);
- $numericTable = Piwik_DataAccess_ArchiveTableCreator::getNumericTable($date);
+ $numericTable = ArchiveTableCreator::getNumericTable($date);
Piwik_Query(sprintf($query, $numericTable), $bind);
Piwik::log("Purging Custom Range archives: done [ purged archives older than $yesterday from $numericTable / blob ]");
try {
- Piwik_Query(sprintf($query, Piwik_DataAccess_ArchiveTableCreator::getBlobTable($date)), $bind);
+ Piwik_Query(sprintf($query, ArchiveTableCreator::getBlobTable($date)), $bind);
} catch (Exception $e) {
// Individual blob tables could be missing
}
}
- protected static function deleteArchiveIds(Piwik_Date $date, $idArchivesToDelete)
+ protected static function deleteArchiveIds(Date $date, $idArchivesToDelete)
{
$query = "DELETE FROM %s WHERE idarchive IN (" . implode(',', $idArchivesToDelete) . ")";
- Piwik_Query(sprintf($query, Piwik_DataAccess_ArchiveTableCreator::getNumericTable($date)));
+ Piwik_Query(sprintf($query, ArchiveTableCreator::getNumericTable($date)));
try {
- Piwik_Query(sprintf($query, Piwik_DataAccess_ArchiveTableCreator::getBlobTable($date)));
+ Piwik_Query(sprintf($query, ArchiveTableCreator::getBlobTable($date)));
} catch (Exception $e) {
// Individual blob tables could be missing
}
}
- protected static function getTemporaryArchiveIdsOlderThan(Piwik_Date $date, $purgeArchivesOlderThan)
+ protected static function getTemporaryArchiveIdsOlderThan(Date $date, $purgeArchivesOlderThan)
{
$query = "SELECT idarchive
- FROM ". Piwik_DataAccess_ArchiveTableCreator::getNumericTable($date) ."
+ FROM " . ArchiveTableCreator::getNumericTable($date) . "
WHERE name LIKE 'done%'
- AND (( value = " . Piwik_ArchiveProcessor::DONE_OK_TEMPORARY . "
+ AND (( value = " . ArchiveProcessor::DONE_OK_TEMPORARY . "
AND ts_archived < ?)
- OR value = " . Piwik_ArchiveProcessor::DONE_ERROR . ")";
+ OR value = " . ArchiveProcessor::DONE_ERROR . ")";
$result = Piwik_FetchAll($query, array($purgeArchivesOlderThan));
$idArchivesToDelete = array();
diff --git a/core/DataAccess/ArchiveTableCreator.php b/core/DataAccess/ArchiveTableCreator.php
index d36206d1fe..9b2fb6797d 100644
--- a/core/DataAccess/ArchiveTableCreator.php
+++ b/core/DataAccess/ArchiveTableCreator.php
@@ -1,6 +1,11 @@
<?php
+namespace Piwik\DataAccess;
+
+use Exception;
use Piwik\Piwik;
use Piwik\Common;
+use Piwik\Date;
+use Zend_Registry;
/**
* Piwik - Open source web analytics
@@ -12,7 +17,7 @@ use Piwik\Common;
* @package Piwik
*/
-class Piwik_DataAccess_ArchiveTableCreator
+class ArchiveTableCreator
{
const NUMERIC_TABLE = "numeric";
@@ -20,17 +25,17 @@ class Piwik_DataAccess_ArchiveTableCreator
static public $tablesAlreadyInstalled = null;
- static public function getNumericTable(Piwik_Date $date)
+ static public function getNumericTable(Date $date)
{
return self::getTable($date, self::NUMERIC_TABLE);
}
- static public function getBlobTable(Piwik_Date $date)
+ static public function getBlobTable(Date $date)
{
return self::getTable($date, self::BLOB_TABLE);
}
- static protected function getTable(Piwik_Date $date, $type)
+ static protected function getTable(Date $date, $type)
{
$tableNamePrefix = "archive_" . $type;
$tableName = $tableNamePrefix . "_" . $date->toString('Y_m');
@@ -68,6 +73,7 @@ class Piwik_DataAccess_ArchiveTableCreator
{
self::$tablesAlreadyInstalled = null;
}
+
static public function refreshTableList($forceReload = false)
{
self::$tablesAlreadyInstalled = Piwik::getTablesInstalled($forceReload);
@@ -87,7 +93,8 @@ class Piwik_DataAccess_ArchiveTableCreator
$archiveTables = array();
foreach (self::$tablesAlreadyInstalled as $table) {
if (strpos($table, 'archive_numeric_') !== false
- || strpos($table, 'archive_blob_') !== false ) {
+ || strpos($table, 'archive_blob_') !== false
+ ) {
$archiveTables[] = $table;
}
}
@@ -103,13 +110,12 @@ class Piwik_DataAccess_ArchiveTableCreator
static public function getTypeFromTableName($tableName)
{
- if(strpos($tableName, 'archive_numeric_') !== false) {
+ if (strpos($tableName, 'archive_numeric_') !== false) {
return self::NUMERIC_TABLE;
}
- if(strpos($tableName, 'archive_blob_') !== false) {
+ if (strpos($tableName, 'archive_blob_') !== false) {
return self::BLOB_TABLE;
}
return false;
}
-
} \ No newline at end of file
diff --git a/core/DataAccess/ArchiveWriter.php b/core/DataAccess/ArchiveWriter.php
index 2c7841a19c..ef04212b74 100644
--- a/core/DataAccess/ArchiveWriter.php
+++ b/core/DataAccess/ArchiveWriter.php
@@ -8,18 +8,25 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataAccess;
+
+use Exception;
+use Piwik\ArchiveProcessor\Rules;
use Piwik\Config;
+use Piwik\DataAccess\ArchiveTableCreator;
use Piwik\Period;
use Piwik\Piwik;
use Piwik\Common;
+use Piwik\ArchiveProcessor;
use Piwik\Segment;
+use Zend_Registry;
/**
* This class is used to create a new Archive.
* An Archive is a set of reports (numeric and data tables).
* New data can be inserted in the archive with insertRecord/insertBulkRecords
*/
-class Piwik_DataAccess_ArchiveWriter
+class ArchiveWriter
{
const PREFIX_SQL_LOCK = "locked_";
@@ -38,7 +45,7 @@ class Piwik_DataAccess_ArchiveWriter
$this->idSite = $idSite;
$this->segment = $segment;
$this->period = $period;
- $this->doneFlag = Piwik_ArchiveProcessor_Rules::getDoneStringFlagFor($segment, $period->getLabel(), $requestedPlugin);
+ $this->doneFlag = Rules::getDoneStringFlagFor($segment, $period->getLabel(), $requestedPlugin);
$this->isArchiveTemporary = $isArchiveTemporary;
$this->dateStart = $this->period->getDateStart();
@@ -106,7 +113,7 @@ class Piwik_DataAccess_ArchiveWriter
protected function logArchiveStatusAsIncomplete()
{
- $statusWhileProcessing = Piwik_ArchiveProcessor::DONE_ERROR;
+ $statusWhileProcessing = ArchiveProcessor::DONE_ERROR;
$this->insertRecord($this->doneFlag, $statusWhileProcessing);
}
@@ -148,9 +155,9 @@ class Piwik_DataAccess_ArchiveWriter
protected function logArchiveStatusAsFinal()
{
- $status = Piwik_ArchiveProcessor::DONE_OK;
+ $status = ArchiveProcessor::DONE_OK;
if ($this->isArchiveTemporary) {
- $status = Piwik_ArchiveProcessor::DONE_OK_TEMPORARY;
+ $status = ArchiveProcessor::DONE_OK_TEMPORARY;
}
$this->insertRecord($this->doneFlag, $status);
}
@@ -236,12 +243,12 @@ class Piwik_DataAccess_ArchiveWriter
if (is_numeric($value)) {
return $this->getTableNumeric();
}
- return Piwik_DataAccess_ArchiveTableCreator::getBlobTable($this->dateStart);
+ return ArchiveTableCreator::getBlobTable($this->dateStart);
}
protected function getTableNumeric()
{
- return Piwik_DataAccess_ArchiveTableCreator::getNumericTable($this->dateStart);
+ return ArchiveTableCreator::getNumericTable($this->dateStart);
}
protected function getInsertFields()
diff --git a/core/DataAccess/LogAggregator.php b/core/DataAccess/LogAggregator.php
index e21ff15b5e..72e94e8b70 100644
--- a/core/DataAccess/LogAggregator.php
+++ b/core/DataAccess/LogAggregator.php
@@ -8,16 +8,23 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataAccess;
+
+use PDOStatement;
use Piwik\Common;
use Piwik\Metrics;
+use Piwik\Date;
use Piwik\Segment;
use Piwik\Site;
+use Piwik_RankingQuery;
+use Piwik_Tracker_GoalManager;
+use Zend_Registry;
/**
* This class queries the Visitor logs tables (visits, actions, conversions, ecommerce)
* and returns aggregate data.
*/
-class Piwik_DataAccess_LogAggregator
+class LogAggregator
{
const LOG_VISIT_TABLE = 'log_visit';
@@ -47,10 +54,10 @@ class Piwik_DataAccess_LogAggregator
const FIELDS_SEPARATOR = ", \n\t\t\t";
- /** @var \Piwik_Date */
+ /** @var \Piwik\Date */
protected $dateStart;
- /** @var \Piwik_Date */
+ /** @var \Piwik\Date */
protected $dateEnd;
/** @var \Piwik\Site */
@@ -59,7 +66,7 @@ class Piwik_DataAccess_LogAggregator
/** @var \Piwik\Segment */
protected $segment;
- public function __construct(Piwik_Date $dateStart, Piwik_Date $dateEnd, Site $site, Segment $segment)
+ public function __construct(Date $dateStart, Date $dateEnd, Site $site, Segment $segment)
{
$this->dateStart = $dateStart;
$this->dateEnd = $dateEnd;
@@ -241,10 +248,10 @@ class Piwik_DataAccess_LogAggregator
}
return $dimensions;
}
-
+
/**
* Prefixes a column name with a table name if not already done.
- *
+ *
* @param string $column eg, 'location_provider'
* @param string $tableName eg, 'log_visit'
* @return string eg, 'log_visit.location_provider'
diff --git a/core/DataTable.php b/core/DataTable.php
index c92935868c..a1dd872ec5 100644
--- a/core/DataTable.php
+++ b/core/DataTable.php
@@ -9,7 +9,17 @@
* @package Piwik
*/
+namespace Piwik;
+
+use Closure;
+use Exception;
use Piwik\Common;
+use Piwik\DataTable\Manager;
+use Piwik\DataTable\Renderer\Html;
+use Piwik\DataTable\Row;
+use Piwik\DataTable\Filter;
+use Piwik\DataTable\Row\DataTableSummaryRow;
+use ReflectionClass;
/**
* @see Common::destroy()
@@ -21,7 +31,7 @@ require_once PIWIK_INCLUDE_PATH . '/core/Common.php';
* ---- DataTable
* A DataTable is a data structure used to store complex tables of data.
*
- * A DataTable is composed of multiple DataTable_Row.
+ * A DataTable is composed of multiple DataTable\Row.
* A DataTable can be applied one or several DataTable_Filter.
* A DataTable can be given to a DataTable_Renderer that would export the data under a given format (XML, HTML, etc.).
*
@@ -31,7 +41,7 @@ require_once PIWIK_INCLUDE_PATH . '/core/Common.php';
* - efficient way of loading data from an external source (from a PHP array structure)
* - very simple interface to get data from the table
*
- * ---- DataTable_Row
+ * ---- DataTable\Row
* A DataTableRow in the table is defined by
* - multiple columns (a label, multiple values, ...)
* - optional metadata
@@ -45,7 +55,7 @@ require_once PIWIK_INCLUDE_PATH . '/core/Common.php';
* - metadata = array('logo' => '/plugins/UserSettings/images/browsers/FF.gif')
* - no sub DataTable
*
- * A more complex example would be a DataTable_Row that is associated to a sub DataTable.
+ * A more complex example would be a DataTable\Row that is associated to a sub DataTable.
* For example, for the row of the search engine Google,
* we want to get the list of keywords associated, with their statistics.
* - columns = array( 'label' => 'Google',
@@ -54,8 +64,8 @@ require_once PIWIK_INCLUDE_PATH . '/core/Common.php';
* 'returning_visits' => 77)
* - metadata = array( 'logo' => '/plugins/Referers/images/searchEngines/google.com.png',
* 'url' => 'http://google.com')
- * - DataTable = DataTable containing several DataTable_Row containing the keywords information for this search engine
- * Example of one DataTable_Row
+ * - DataTable = DataTable containing several DataTable\Row containing the keywords information for this search engine
+ * Example of one DataTable\Row
* - the keyword columns specific to this search engine =
* array( 'label' => 'Piwik', // the keyword
* 'visitors' => 155, // Piwik has been searched on Google by 155 visitors
@@ -67,7 +77,7 @@ require_once PIWIK_INCLUDE_PATH . '/core/Common.php';
*
* ---- DataTable_Filter
* A DataTable_Filter is a applied to a DataTable and so
- * can filter information in the multiple DataTable_Row.
+ * can filter information in the multiple DataTable\Row.
*
* For example a DataTable_Filter can:
* - remove rows from the table,
@@ -132,12 +142,12 @@ require_once PIWIK_INCLUDE_PATH . '/core/Common.php';
* [ keyword2, +1000% ]
* [ keyword3, -430% ]
*
- * @see Piwik_DataTable_Row A Piwik_DataTable is composed of Piwik_DataTable_Row
+ * @see Piwik_DataTable\Row A DataTable is composed of Piwik_DataTable\Row
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable
+class DataTable
{
/** Name for metadata that describes when a report was archived. */
const ARCHIVED_DATE_METADATA_NAME = 'archived_date';
@@ -151,9 +161,9 @@ class Piwik_DataTable
private static $maximumDepthLevelAllowed = self::MAX_DEPTH_DEFAULT;
/**
- * Array of Piwik_DataTable_Row
+ * Array of Row
*
- * @var Piwik_DataTable_Row[]
+ * @var Row[]
*/
protected $rows = array();
@@ -197,7 +207,7 @@ class Piwik_DataTable
protected $tableSortedBy = false;
/**
- * List of Piwik_DataTable_Filter queued to this table
+ * List of Filter queued to this table
*
* @var array
*/
@@ -230,7 +240,7 @@ class Piwik_DataTable
protected $rowsIndexByLabel = array();
/**
- * @var Piwik_DataTable_Row
+ * @var \Piwik\DataTable\Row
*/
protected $summaryRow = null;
@@ -251,7 +261,7 @@ class Piwik_DataTable
/**
* The operations that should be used when aggregating columns from multiple rows.
- * @see self::addDataTable() and Piwik_DataTable_Row::sumRow()
+ * @see self::addDataTable() and Piwik_DataTable\Row::sumRow()
*/
protected $columnAggregationOperations = array();
@@ -264,7 +274,7 @@ class Piwik_DataTable
*/
public function __construct()
{
- $this->currentId = Piwik_DataTable_Manager::getInstance()->addTable($this);
+ $this->currentId = Manager::getInstance()->addTable($this);
}
/**
@@ -282,7 +292,7 @@ class Piwik_DataTable
Common::destroy($row);
}
unset($this->rows);
- Piwik_DataTable_Manager::getInstance()->setTableDeleted($this->getId());
+ Manager::getInstance()->setTableDeleted($this->getId());
$depth--;
}
}
@@ -302,7 +312,7 @@ class Piwik_DataTable
if ($this->enableRecursiveSort === true) {
foreach ($this->getRows() as $row) {
if (($idSubtable = $row->getIdSubDataTable()) !== null) {
- $table = Piwik_DataTable_Manager::getInstance()->getTable($idSubtable);
+ $table = Manager::getInstance()->getTable($idSubtable);
$table->enableRecursiveSort();
$table->sort($functionCallback, $columnSortedBy);
}
@@ -363,7 +373,7 @@ class Piwik_DataTable
/**
* Apply a filter to this datatable
*
- * @param string|Closure $className Class name, eg. "Sort" or "Piwik_DataTable_Filter_Sort".
+ * @param string|Closure $className Class name, eg. "Sort" or "Sort".
* If this variable is a closure, it will get executed immediately.
* @param array $parameters Array of parameters to the filter, eg. array('nb_visits', 'asc')
*/
@@ -374,8 +384,8 @@ class Piwik_DataTable
return;
}
- if (!class_exists($className, false)) {
- $className = "Piwik_DataTable_Filter_" . $className;
+ if (!class_exists($className, true)) {
+ $className = 'Piwik\DataTable\Filter\\' . $className;
}
$reflectionObj = new ReflectionClass($className);
@@ -394,8 +404,8 @@ class Piwik_DataTable
* Queue a DataTable_Filter that will be applied when applyQueuedFilters() is called.
* (just before sending the datatable back to the browser (or API, etc.)
*
- * @param string $className The class name of the filter, eg. Piwik_DataTable_Filter_Limit
- * @param array $parameters The parameters to give to the filter, eg. array( $offset, $limit) for the filter Piwik_DataTable_Filter_Limit
+ * @param string $className The class name of the filter, eg. Limit
+ * @param array $parameters The parameters to give to the filter, eg. array( $offset, $limit) for the filter Limit
*/
public function queueFilter($className, $parameters = array())
{
@@ -428,9 +438,9 @@ class Piwik_DataTable
*
* @example tests/core/DataTable.test.php
*
- * @param Piwik_DataTable $tableToSum
+ * @param \Piwik\DataTable $tableToSum
*/
- public function addDataTable(Piwik_DataTable $tableToSum)
+ public function addDataTable(DataTable $tableToSum)
{
foreach ($tableToSum->getRows() as $row) {
$labelToLookFor = $row->getColumn('label');
@@ -449,7 +459,7 @@ class Piwik_DataTable
// if the row has the subtable already
// then we have to recursively sum the subtables
if (($idSubTable = $row->getIdSubDataTable()) !== null) {
- $subTable = Piwik_DataTable_Manager::getInstance()->getTable($idSubTable);
+ $subTable = Manager::getInstance()->getTable($idSubTable);
$subTable->setColumnAggregationOperations($this->columnAggregationOperations);
$rowFound->sumSubtable($subTable);
}
@@ -458,15 +468,15 @@ class Piwik_DataTable
}
/**
- * Returns the Piwik_DataTable_Row that has a column 'label' with the value $label
+ * Returns the Row that has a column 'label' with the value $label
*
* @param string $label Value of the column 'label' of the row to return
- * @return Piwik_DataTable_Row|false The row if found, false otherwise
+ * @return \Piwik\DataTable\Row|false The row if found, false otherwise
*/
public function getRowFromLabel($label)
{
$rowId = $this->getRowIdFromLabel($label);
- if ($rowId instanceof Piwik_DataTable_Row) {
+ if ($rowId instanceof Row) {
return $rowId;
}
if (is_int($rowId) && isset($this->rows[$rowId])) {
@@ -506,11 +516,11 @@ class Piwik_DataTable
*
* @param bool $keepFilters
*
- * @return Piwik_DataTable
+ * @return \Piwik\DataTable
*/
public function getEmptyClone($keepFilters = true)
{
- $clone = new Piwik_DataTable;
+ $clone = new DataTable;
if ($keepFilters) {
$clone->queuedFilters = $this->queuedFilters;
}
@@ -536,7 +546,7 @@ class Piwik_DataTable
* Returns the ith row in the array
*
* @param int $id
- * @return Piwik_DataTable_Row or false if not found
+ * @return \Piwik\DataTable\Row or false if not found
*/
public function getRowFromId($id)
{
@@ -555,7 +565,7 @@ class Piwik_DataTable
* Returns a row that has the subtable ID matching the parameter
*
* @param int $idSubTable
- * @return Piwik_DataTable_Row|false if not found
+ * @return \Piwik\DataTable\Row|false if not found
*/
public function getRowFromIdSubDataTable($idSubTable)
{
@@ -571,10 +581,10 @@ class Piwik_DataTable
/**
* Add a row to the table and rebuild the index if necessary
*
- * @param Piwik_DataTable_Row $row to add at the end of the array
- * @return Piwik_DataTable_Row
+ * @param \Piwik\DataTable\Row $row to add at the end of the array
+ * @return \Piwik\DataTable\Row
*/
- public function addRow(Piwik_DataTable_Row $row)
+ public function addRow(Row $row)
{
// if there is a upper limit on the number of allowed rows and the table is full,
// add the new row to the summary row
@@ -583,8 +593,8 @@ class Piwik_DataTable
) {
if ($this->summaryRow === null) // create the summary row if necessary
{
- $this->addSummaryRow(new Piwik_DataTable_Row(array(
- Piwik_DataTable_Row::COLUMNS => $row->getColumns()
+ $this->addSummaryRow(new Row(array(
+ Row::COLUMNS => $row->getColumns()
)));
$this->summaryRow->setColumn('label', self::LABEL_SUMMARY_ROW);
} else {
@@ -609,10 +619,10 @@ class Piwik_DataTable
/**
* Sets the summary row (a dataTable can have only one summary row)
*
- * @param Piwik_DataTable_Row $row
- * @return Piwik_DataTable_Row Returns $row.
+ * @param Row $row
+ * @return Row Returns $row.
*/
- public function addSummaryRow(Piwik_DataTable_Row $row)
+ public function addSummaryRow(Row $row)
{
$this->summaryRow = $row;
return $row;
@@ -631,7 +641,7 @@ class Piwik_DataTable
/**
* Adds a new row from a PHP array data structure
*
- * @param array $row eg. array(Piwik_DataTable_Row::COLUMNS => array( 'visits' => 13, 'test' => 'toto'),)
+ * @param array $row eg. array(Row::COLUMNS => array( 'visits' => 13, 'test' => 'toto'),)
*/
public function addRowFromArray($row)
{
@@ -649,9 +659,9 @@ class Piwik_DataTable
}
/**
- * Returns the array of Piwik_DataTable_Row
+ * Returns the array of Row
*
- * @return Piwik_DataTable_Row[]
+ * @return Row[]
*/
public function getRows()
{
@@ -746,7 +756,7 @@ class Piwik_DataTable
/**
* Returns the first row of the DataTable
*
- * @return Piwik_DataTable_Row
+ * @return \Piwik\DataTable\Row
*/
public function getFirstRow()
{
@@ -763,7 +773,7 @@ class Piwik_DataTable
/**
* Returns the last row of the DataTable
*
- * @return Piwik_DataTable_Row
+ * @return Row
*/
public function getLastRow()
{
@@ -789,7 +799,7 @@ class Piwik_DataTable
$totalCount = 0;
foreach ($this->rows as $row) {
if (($idSubTable = $row->getIdSubDataTable()) !== null) {
- $subTable = Piwik_DataTable_Manager::getInstance()->getTable($idSubTable);
+ $subTable = Manager::getInstance()->getTable($idSubTable);
$count = $subTable->getRowsCountRecursive();
$totalCount += $count;
}
@@ -825,7 +835,7 @@ class Piwik_DataTable
foreach ($this->getRows() as $row) {
$row->renameColumn($oldName, $newName);
if (($idSubDataTable = $row->getIdSubDataTable()) !== null) {
- Piwik_DataTable_Manager::getInstance()->getTable($idSubDataTable)->renameColumn($oldName, $newName);
+ Manager::getInstance()->getTable($idSubDataTable)->renameColumn($oldName, $newName);
}
}
if (!is_null($this->summaryRow)) {
@@ -846,7 +856,7 @@ class Piwik_DataTable
$row->deleteColumn($name);
}
if (($idSubDataTable = $row->getIdSubDataTable()) !== null) {
- Piwik_DataTable_Manager::getInstance()->getTable($idSubDataTable)->deleteColumns($names, $deleteRecursiveInSubtables);
+ Manager::getInstance()->getTable($idSubDataTable)->deleteColumns($names, $deleteRecursiveInSubtables);
}
}
if (!is_null($this->summaryRow)) {
@@ -932,7 +942,7 @@ class Piwik_DataTable
*/
public function __toString()
{
- $renderer = new Piwik_DataTable_Renderer_Html();
+ $renderer = new Html();
$renderer->setTable($this);
return (string)$renderer;
}
@@ -941,11 +951,11 @@ class Piwik_DataTable
* Returns true if both DataTable are exactly the same.
* Used in unit tests.
*
- * @param Piwik_DataTable $table1
- * @param Piwik_DataTable $table2
+ * @param \Piwik\DataTable $table1
+ * @param \Piwik\DataTable $table2
* @return bool
*/
- public static function isEqual(Piwik_DataTable $table1, Piwik_DataTable $table2)
+ public static function isEqual(DataTable $table1, DataTable $table2)
{
$rows1 = $table1->getRows();
$rows2 = $table2->getRows();
@@ -960,7 +970,7 @@ class Piwik_DataTable
foreach ($rows1 as $row1) {
$row2 = $table2->getRowFromLabel($row1->getColumn('label'));
if ($row2 === false
- || !Piwik_DataTable_Row::isEqual($row1, $row2)
+ || !Row::isEqual($row1, $row2)
) {
return false;
}
@@ -1010,12 +1020,12 @@ class Piwik_DataTable
if ($depth > self::$maximumDepthLevelAllowed) {
$depth = 0;
- throw new Exception("Maximum recursion level of " . self::$maximumDepthLevelAllowed . " reached. Maybe you have set a DataTable_Row with an associated DataTable belonging already to one of its parent tables?");
+ throw new Exception("Maximum recursion level of " . self::$maximumDepthLevelAllowed . " reached. Maybe you have set a DataTable\Row with an associated DataTable belonging already to one of its parent tables?");
}
if (!is_null($maximumRowsInDataTable)) {
$this->filter('AddSummaryRow',
array($maximumRowsInDataTable - 1,
- Piwik_DataTable::LABEL_SUMMARY_ROW,
+ DataTable::LABEL_SUMMARY_ROW,
$columnToSortByBeforeTruncation)
);
}
@@ -1026,7 +1036,7 @@ class Piwik_DataTable
$aSerializedDataTable = array();
foreach ($this->rows as $row) {
if (($idSubTable = $row->getIdSubDataTable()) !== null) {
- $subTable = Piwik_DataTable_Manager::getInstance()->getTable($idSubTable);
+ $subTable = Manager::getInstance()->getTable($idSubTable);
$depth++;
$aSerializedDataTable = $aSerializedDataTable + $subTable->getSerialized($maximumRowsInSubDataTable, $maximumRowsInSubDataTable, $columnToSortByBeforeTruncation);
$depth--;
@@ -1057,7 +1067,7 @@ class Piwik_DataTable
* Does not load recursively all the sub DataTable.
* They will be loaded only when requesting them specifically.
*
- * The function creates all the necessary DataTable_Row
+ * The function creates all the necessary DataTable\Row
*
* @param string $stringSerialized string of serialized datatable
* @throws Exception
@@ -1078,8 +1088,8 @@ class Piwik_DataTable
* array(
* // row1
* array(
- * Piwik_DataTable_Row::COLUMNS => array( col1_name => value1, col2_name => value2, ...),
- * Piwik_DataTable_Row::METADATA => array( metadata1_name => value1, ...), // see Piwik_DataTable_Row
+ * Row::COLUMNS => array( col1_name => value1, col2_name => value2, ...),
+ * Row::METADATA => array( metadata1_name => value1, ...), // see Row
* ),
* // row2
* array( ... ),
@@ -1089,7 +1099,7 @@ class Piwik_DataTable
{
foreach ($array as $id => $row) {
if (is_array($row)) {
- $row = new Piwik_DataTable_Row($row);
+ $row = new Row($row);
}
if ($id == self::ID_SUMMARY_ROW) {
$this->summaryRow = $row;
@@ -1140,10 +1150,10 @@ class Piwik_DataTable
// case when the array is indexed by the default numeric index
if (array_keys($array) == array_keys(array_fill(0, count($array), true))) {
foreach ($array as $row) {
- $this->addRow(new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => array($row))));
+ $this->addRow(new Row(array(Row::COLUMNS => array($row))));
}
} else {
- $this->addRow(new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => $array)));
+ $this->addRow(new Row(array(Row::COLUMNS => $array)));
}
// we have converted our simple array to one single row
// => we exit the method as the job is now finished
@@ -1171,10 +1181,10 @@ class Piwik_DataTable
throw $e;
}
}
- $row = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => $row));
+ $row = new Row(array(Row::COLUMNS => $row));
} // other (string, numbers...) => we build a line from this value
else {
- $row = new Piwik_DataTable_Row(array(Piwik_DataTable_Row::COLUMNS => array($key => $row)));
+ $row = new Row(array(Row::COLUMNS => array($key => $row)));
}
$this->addRow($row);
}
@@ -1188,8 +1198,8 @@ class Piwik_DataTable
* )
* to a DataTable, ie. with the internal structure
* array (
- * array( Piwik_DataTable_Row::COLUMNS => array('label' => LABEL, col1 => X, col2 => Y)),
- * array( Piwik_DataTable_Row::COLUMNS => array('label' => LABEL2, col1 => X, col2 => Y)),
+ * array( Row::COLUMNS => array('label' => LABEL, col1 => X, col2 => Y)),
+ * array( Row::COLUMNS => array('label' => LABEL2, col1 => X, col2 => Y)),
* )
*
* It also works with array having only one value per row, eg.
@@ -1199,18 +1209,18 @@ class Piwik_DataTable
* )
* would be converted to:
* array (
- * array( Piwik_DataTable_Row::COLUMNS => array('label' => LABEL, 'value' => X)),
- * array( Piwik_DataTable_Row::COLUMNS => array('label' => LABEL2, 'value' => Y)),
+ * array( Row::COLUMNS => array('label' => LABEL, 'value' => X)),
+ * array( Row::COLUMNS => array('label' => LABEL2, 'value' => Y)),
* )
*
*
* @param array $array Indexed array, two formats are supported
* @param array|null $subtablePerLabel An indexed array of up to one DataTable to associate as a sub table
- * @return Piwik_DataTable
+ * @return \Piwik\DataTable
*/
public static function makeFromIndexedArray($array, $subtablePerLabel = null)
{
- $table = new Piwik_DataTable();
+ $table = new DataTable();
$cleanRow = array();
foreach ($array as $label => $row) {
// Support the case of an $array of single values
@@ -1218,12 +1228,12 @@ class Piwik_DataTable
$row = array('value' => $row);
}
// Put the 'label' column first
- $cleanRow[Piwik_DataTable_Row::COLUMNS] = array('label' => $label) + $row;
+ $cleanRow[Row::COLUMNS] = array('label' => $label) + $row;
// Assign subtable if specified
if (isset($subtablePerLabel[$label])) {
- $cleanRow[Piwik_DataTable_Row::DATATABLE_ASSOCIATED] = $subtablePerLabel[$label];
+ $cleanRow[Row::DATATABLE_ASSOCIATED] = $subtablePerLabel[$label];
}
- $table->addRow(new Piwik_DataTable_Row($cleanRow));
+ $table->addRow(new Row($cleanRow));
}
return $table;
}
@@ -1326,7 +1336,7 @@ class Piwik_DataTable
return array(false, $i);
} else // if we're adding missing rows, add a new row
{
- $row = new Piwik_DataTable_Row_DataTableSummary();
+ $row = new DataTableSummaryRow();
$row->setColumns(array('label' => $segment) + $missingRowColumns);
$next = $table->addRow($row);
@@ -1348,7 +1358,7 @@ class Piwik_DataTable
return array(false, $i);
} else if ($i != $pathLength - 1) // create subtable if missing, but only if not on the last segment
{
- $table = new Piwik_DataTable();
+ $table = new DataTable();
$table->setMaximumAllowedRows($maxSubtableRows);
$table->setColumnAggregationOperations($this->columnAggregationOperations);
$next->setSubtable($table);
@@ -1371,11 +1381,11 @@ class Piwik_DataTable
* @param bool $useMetadataColumn If true and if $labelColumn is supplied, the parent row's
* label will be added as metadata.
*
- * @return Piwik_DataTable
+ * @return \Piwik\DataTable
*/
public function mergeSubtables($labelColumn = false, $useMetadataColumn = false)
{
- $result = new Piwik_DataTable();
+ $result = new DataTable();
foreach ($this->getRows() as $row) {
$subtable = $row->getSubtable();
if ($subtable !== false) {
@@ -1423,18 +1433,18 @@ class Piwik_DataTable
* Returns a new DataTable created with data from a 'simple' array.
*
* @param array $array
- * @return Piwik_DataTable
+ * @return \Piwik\DataTable
*/
public static function makeFromSimpleArray($array)
{
- $dataTable = new Piwik_DataTable();
+ $dataTable = new DataTable();
$dataTable->addRowsFromSimpleArray($array);
return $dataTable;
}
/**
* Set the aggregation operation for a column, e.g. "min".
- * @see self::addDataTable() and Piwik_DataTable_Row::sumRow()
+ * @see self::addDataTable() and Piwik_DataTable\Row::sumRow()
*
* @param string $columnName
* @param string $operation
@@ -1467,11 +1477,11 @@ class Piwik_DataTable
* Creates a new DataTable instance from a serialize()'d array of rows.
*
* @param string $data
- * @return Piwik_DataTable
+ * @return \Piwik\DataTable
*/
public static function fromSerializedArray($data)
{
- $result = new Piwik_DataTable();
+ $result = new DataTable();
$result->addRowsFromSerializedArray($data);
return $result;
}
diff --git a/core/DataTable/Filter.php b/core/DataTable/Filter.php
index 455c5aa6e7..43cb33f2a0 100644
--- a/core/DataTable/Filter.php
+++ b/core/DataTable/Filter.php
@@ -8,6 +8,12 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable;
+
+use Exception;
+use Piwik\DataTable;
+use Piwik\DataTable\Manager;
+use Piwik\DataTable\Row;
/**
* A filter is applied instantly to a given DataTable and can
@@ -21,9 +27,9 @@
* and can do whatever is necessary on the data (in the filter() method).
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-abstract class Piwik_DataTable_Filter
+abstract class Filter
{
/**
* @var bool
@@ -32,19 +38,19 @@ abstract class Piwik_DataTable_Filter
/**
* @throws Exception
- * @param Piwik_DataTable $table
+ * @param DataTable $table
*/
public function __construct($table)
{
- if (!($table instanceof Piwik_DataTable)) {
- throw new Exception("The filter accepts only a Piwik_DataTable object.");
+ if (!($table instanceof DataTable)) {
+ throw new Exception("The filter accepts only a DataTable object.");
}
}
/**
* Filters the given data table
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
*/
abstract public function filter($table);
@@ -61,16 +67,16 @@ abstract class Piwik_DataTable_Filter
/**
* Filters a subtable
*
- * @param Piwik_DataTable_Row $row
+ * @param Row $row
* @return mixed
*/
- public function filterSubTable(Piwik_DataTable_Row $row)
+ public function filterSubTable(Row $row)
{
if (!$this->enableRecursive) {
return;
}
if ($row->isSubtableLoaded()) {
- $subTable = Piwik_DataTable_Manager::getInstance()->getTable($row->getIdSubDataTable());
+ $subTable = Manager::getInstance()->getTable($row->getIdSubDataTable());
$this->filter($subTable);
}
}
diff --git a/core/DataTable/Filter/AddColumnsProcessedMetrics.php b/core/DataTable/Filter/AddColumnsProcessedMetrics.php
index 73baf7aaa9..dc41dacdc7 100644
--- a/core/DataTable/Filter/AddColumnsProcessedMetrics.php
+++ b/core/DataTable/Filter/AddColumnsProcessedMetrics.php
@@ -8,22 +8,27 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Filter;
+
+use Piwik\DataTable\Filter;
+use Piwik\DataTable\Row;
use Piwik\Metrics;
+use Piwik\DataTable;
/**
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Filter_AddColumnsProcessedMetrics extends Piwik_DataTable_Filter
+class AddColumnsProcessedMetrics extends Filter
{
protected $invalidDivision = 0;
protected $roundPrecision = 2;
protected $deleteRowsWithNoVisit = true;
/**
- * @param Piwik_DataTable $table
+ * @param DataTable $table
* @param bool $deleteRowsWithNoVisit Automatically set to true when filter_add_columns_when_show_all_columns is found in the API request
- * @return Piwik_DataTable_Filter_AddColumnsProcessedMetrics
+ * @return AddColumnsProcessedMetrics
*/
public function __construct($table, $deleteRowsWithNoVisit = true)
{
@@ -34,7 +39,7 @@ class Piwik_DataTable_Filter_AddColumnsProcessedMetrics extends Piwik_DataTable_
/**
* Filters the given data table
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
*/
public function filter($table)
{
@@ -97,7 +102,7 @@ class Piwik_DataTable_Filter_AddColumnsProcessedMetrics extends Piwik_DataTable_
* - raw datatables coming from the archive DB, which columns are int indexed
* - datatables processed resulting of API calls, which columns have human readable english names
*
- * @param Piwik_DataTable_Row $row
+ * @param Row $row
* @param int $columnIdRaw see consts in Archive::
* @param bool $mappingIdToName
* @return mixed Value of column, false if not found
@@ -108,7 +113,7 @@ class Piwik_DataTable_Filter_AddColumnsProcessedMetrics extends Piwik_DataTable_
$mappingIdToName = Metrics::$mappingFromIdToName;
}
$columnIdReadable = $mappingIdToName[$columnIdRaw];
- if ($row instanceof Piwik_DataTable_Row) {
+ if ($row instanceof Row) {
$raw = $row->getColumn($columnIdRaw);
if ($raw !== false) {
return $raw;
diff --git a/core/DataTable/Filter/AddColumnsProcessedMetricsGoal.php b/core/DataTable/Filter/AddColumnsProcessedMetricsGoal.php
index 99d822bbd0..422df1adcf 100644
--- a/core/DataTable/Filter/AddColumnsProcessedMetricsGoal.php
+++ b/core/DataTable/Filter/AddColumnsProcessedMetricsGoal.php
@@ -8,14 +8,19 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Filter;
+
+use Exception;
use Piwik\Metrics;
use Piwik\Piwik;
+use Piwik\DataTable;
+use Piwik\DataTable\Filter\AddColumnsProcessedMetrics;
/**
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Filter_AddColumnsProcessedMetricsGoal extends Piwik_DataTable_Filter_AddColumnsProcessedMetrics
+class AddColumnsProcessedMetricsGoal extends AddColumnsProcessedMetrics
{
/**
* Process main goal metrics: conversion rate, revenue per visit
@@ -41,13 +46,13 @@ class Piwik_DataTable_Filter_AddColumnsProcessedMetricsGoal extends Piwik_DataTa
* - nb conversions
* - revenue per visit
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
* @param bool $enable should be true (automatically set to true when filter_update_columns_when_show_all_goals is found in the API request)
* @param string $processOnlyIdGoal Defines what metrics to add (don't process metrics when you don't display them)
* If self::GOALS_FULL_TABLE, all Goal metrics (and per goal metrics) will be processed
* If self::GOALS_OVERVIEW, only the main goal metrics will be added
* If an int > 0, then will process only metrics for this specific Goal
- * @return Piwik_DataTable_Filter_AddColumnsProcessedMetricsGoal
+ * @return \Piwik\DataTable\Filter\AddColumnsProcessedMetricsGoal
*/
public function __construct($table, $enable = true, $processOnlyIdGoal)
{
@@ -61,13 +66,13 @@ class Piwik_DataTable_Filter_AddColumnsProcessedMetricsGoal extends Piwik_DataTa
/**
* Filters the given data table
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
*/
public function filter($table)
{
// Add standard processed metrics
parent::filter($table);
- $roundingPrecision = Piwik_Tracker_GoalManager::REVENUE_PRECISION;
+ $roundingPrecision = \Piwik_Tracker_GoalManager::REVENUE_PRECISION;
$expectedColumns = array();
foreach ($table->getRows() as $key => $row) {
$currentColumns = $row->getColumns();
diff --git a/core/DataTable/Filter/AddConstantMetadata.php b/core/DataTable/Filter/AddConstantMetadata.php
index 4bff5aa813..f3682f5b10 100644
--- a/core/DataTable/Filter/AddConstantMetadata.php
+++ b/core/DataTable/Filter/AddConstantMetadata.php
@@ -8,6 +8,10 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Filter;
+
+use Piwik\DataTable;
+use Piwik\DataTable\Filter;
/**
* Add a new metadata column to the table.
@@ -16,14 +20,14 @@
* This value is fixed for all icons so we simply add the same value for all rows.
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Filter_AddConstantMetadata extends Piwik_DataTable_Filter
+class AddConstantMetadata extends Filter
{
/**
* Creates a new filter and sets all required parameters
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
* @param string $metadataName
* @param mixed $metadataValue
*/
@@ -37,7 +41,7 @@ class Piwik_DataTable_Filter_AddConstantMetadata extends Piwik_DataTable_Filter
/**
* Filters the given data table
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
*/
public function filter($table)
{
diff --git a/core/DataTable/Filter/AddSummaryRow.php b/core/DataTable/Filter/AddSummaryRow.php
index ca0cb1882f..12504fa033 100644
--- a/core/DataTable/Filter/AddSummaryRow.php
+++ b/core/DataTable/Filter/AddSummaryRow.php
@@ -8,6 +8,11 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Filter;
+
+use Piwik\DataTable;
+use Piwik\DataTable\Filter;
+use Piwik\DataTable\Row;
/**
* Add a new row to the table containing a summary
@@ -23,14 +28,14 @@
* This row is assigned a label of 'Others'.
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Filter_AddSummaryRow extends Piwik_DataTable_Filter
+class AddSummaryRow extends Filter
{
/**
* Creates a new filter and set all required parameters
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
* @param int $startRowToSummarize
* @param int $labelSummaryRow
* @param null $columnToSortByBeforeTruncating
@@ -38,7 +43,7 @@ class Piwik_DataTable_Filter_AddSummaryRow extends Piwik_DataTable_Filter
*/
public function __construct($table,
$startRowToSummarize,
- $labelSummaryRow = Piwik_DataTable::LABEL_SUMMARY_ROW,
+ $labelSummaryRow = DataTable::LABEL_SUMMARY_ROW,
$columnToSortByBeforeTruncating = null,
$deleteRows = true)
{
@@ -52,7 +57,7 @@ class Piwik_DataTable_Filter_AddSummaryRow extends Piwik_DataTable_Filter
/**
* Adds a summary row to the given data table
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
*/
public function filter($table)
{
@@ -62,14 +67,14 @@ class Piwik_DataTable_Filter_AddSummaryRow extends Piwik_DataTable_Filter
if ($table->getRowsCount() <= $this->startRowToSummarize + 1) {
return;
}
-
+
$rows = $table->getRows();
$count = $table->getRowsCount();
- $newRow = new Piwik_DataTable_Row();
+ $newRow = new Row();
for ($i = $this->startRowToSummarize; $i < $count; $i++) {
if (!isset($rows[$i])) {
- // case when the last row is a summary row, it is not indexed by $cout but by Piwik_DataTable::ID_SUMMARY_ROW
- $summaryRow = $table->getRowFromId(Piwik_DataTable::ID_SUMMARY_ROW);
+ // case when the last row is a summary row, it is not indexed by $cout but by DataTable::ID_SUMMARY_ROW
+ $summaryRow = $table->getRowFromId(DataTable::ID_SUMMARY_ROW);
//FIXME: I'm not sure why it could return false, but it was reported in: http://forum.piwik.org/read.php?2,89324,page=1#msg-89442
if ($summaryRow) {
diff --git a/core/DataTable/Filter/BeautifyRangeLabels.php b/core/DataTable/Filter/BeautifyRangeLabels.php
index 329bcf3308..5e2c0c1336 100644
--- a/core/DataTable/Filter/BeautifyRangeLabels.php
+++ b/core/DataTable/Filter/BeautifyRangeLabels.php
@@ -8,6 +8,10 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Filter;
+
+use Piwik\DataTable;
+use Piwik\DataTable\Filter\ColumnCallbackReplace;
/**
* A DataTable filter that replaces range label columns with prettier,
@@ -26,7 +30,7 @@
* This filter can also be extended to beautify ranges differently based
* on the range values.
*/
-class Piwik_DataTable_Filter_BeautifyRangeLabels extends Piwik_DataTable_Filter_ColumnCallbackReplace
+class BeautifyRangeLabels extends ColumnCallbackReplace
{
/**
* The string to use when the range being beautified is between 1-1 units.
@@ -44,7 +48,7 @@ class Piwik_DataTable_Filter_BeautifyRangeLabels extends Piwik_DataTable_Filter_
/**
* Constructor.
*
- * @param Piwik_DataTable $table The DataTable that will be filtered.
+ * @param DataTable $table The DataTable that will be filtered.
* @param string $labelSingular The string to use when the range being beautified
* is equal to '1-1 units'.
* @param string $labelPlural The string to use when the range being beautified
@@ -85,7 +89,7 @@ class Piwik_DataTable_Filter_BeautifyRangeLabels extends Piwik_DataTable_Filter_
// get the lower bound
sscanf($value, "%d", $lowerBound);
- if ($lowerBound !== NULL) {
+ if ($lowerBound !== null) {
$plusEncoded = urlencode('+');
$plusLen = strlen($plusEncoded);
$len = strlen($value);
diff --git a/core/DataTable/Filter/BeautifyTimeRangeLabels.php b/core/DataTable/Filter/BeautifyTimeRangeLabels.php
index 1a2dffce5a..f8fcb59b77 100644
--- a/core/DataTable/Filter/BeautifyTimeRangeLabels.php
+++ b/core/DataTable/Filter/BeautifyTimeRangeLabels.php
@@ -8,6 +8,10 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Filter;
+
+use Piwik\DataTable;
+use Piwik\DataTable\Filter\BeautifyRangeLabels;
/**
* A DataTable filter replaces range labels that are in seconds with
@@ -17,7 +21,7 @@
* so range values that span values that are less than one minute are
* displayed in seconds but other ranges are displayed in minutes.
*/
-class Piwik_DataTable_Filter_BeautifyTimeRangeLabels extends Piwik_DataTable_Filter_BeautifyRangeLabels
+class BeautifyTimeRangeLabels extends BeautifyRangeLabels
{
/**
* A format string used to create pretty range labels when the range's
@@ -31,7 +35,7 @@ class Piwik_DataTable_Filter_BeautifyTimeRangeLabels extends Piwik_DataTable_Fil
/**
* Constructor.
*
- * @param Piwik_DataTable $table The DataTable this filter will run over.
+ * @param DataTable $table The DataTable this filter will run over.
* @param string $labelSecondsPlural A string to use when beautifying range labels
* whose lower bound is between 0 and 60. Must be
* a format string that takes two numeric params.
diff --git a/core/DataTable/Filter/CalculateEvolutionFilter.php b/core/DataTable/Filter/CalculateEvolutionFilter.php
index e38fb93136..f8d5886d25 100755
--- a/core/DataTable/Filter/CalculateEvolutionFilter.php
+++ b/core/DataTable/Filter/CalculateEvolutionFilter.php
@@ -8,7 +8,12 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Filter;
+
+use Piwik\DataTable;
+use Piwik\DataTable\Row;
use Piwik\Site;
+use Piwik\DataTable\Filter\ColumnCallbackAddColumnPercentage;
/**
* A DataTable filter that calculates the evolution of a metric and adds
@@ -21,7 +26,7 @@ use Piwik\Site;
* The evolution metric is calculated as:
* <code>((currentValue - pastValue) / pastValue) * 100</code>
*/
-class Piwik_DataTable_Filter_CalculateEvolutionFilter extends Piwik_DataTable_Filter_ColumnCallbackAddColumnPercentage
+class CalculateEvolutionFilter extends ColumnCallbackAddColumnPercentage
{
/**
* The the DataTable that contains past data.
@@ -36,11 +41,11 @@ class Piwik_DataTable_Filter_CalculateEvolutionFilter extends Piwik_DataTable_Fi
/**
* Constructor.
*
- * @param Piwik_DataTable $table The DataTable being filtered.
- * @param string $pastDataTable
- * @param string $columnToAdd
- * @param string $columnToRead
- * @param int $quotientPrecision
+ * @param DataTable $table The DataTable being filtered.
+ * @param string $pastDataTable
+ * @param string $columnToAdd
+ * @param string $columnToRead
+ * @param int $quotientPrecision
*/
function __construct($table, $pastDataTable, $columnToAdd, $columnToRead, $quotientPrecision = 0)
{
@@ -56,7 +61,7 @@ class Piwik_DataTable_Filter_CalculateEvolutionFilter extends Piwik_DataTable_Fi
* Returns the difference between the column in the specific row and its
* sister column in the past DataTable.
*
- * @param Piwik_DataTable_Row $row
+ * @param Row $row
* @return int|float
*/
protected function getDividend($row)
@@ -86,7 +91,7 @@ class Piwik_DataTable_Filter_CalculateEvolutionFilter extends Piwik_DataTable_Fi
* Returns the value of the column in $row's sister row in the past
* DataTable.
*
- * @param Piwik_DataTable_Row $row
+ * @param Row $row
* @return int|float
*/
protected function getDivisor($row)
@@ -100,7 +105,7 @@ class Piwik_DataTable_Filter_CalculateEvolutionFilter extends Piwik_DataTable_Fi
/**
* Calculates and formats a quotient based on a divisor and dividend.
*
- * Unlike Piwik_DataTable_Filter_ColumnCallbackAddColumnPercentage's,
+ * Unlike ColumnCallbackAddColumnPercentage's,
* version of this method, this method will return 100% if the past
* value of a metric is 0, and the current value is not 0. For a
* value representative of an evolution, this makes sense.
@@ -119,7 +124,7 @@ class Piwik_DataTable_Filter_CalculateEvolutionFilter extends Piwik_DataTable_Fi
/**
* Utility function. Returns the current row in the past DataTable.
*
- * @param Piwik_DataTable_Row $row The row in the 'current' DataTable.
+ * @param Row $row The row in the 'current' DataTable.
*/
private function getPastRowFromCurrent($row)
{
@@ -129,10 +134,10 @@ class Piwik_DataTable_Filter_CalculateEvolutionFilter extends Piwik_DataTable_Fi
/**
* Calculates the evolution percentage for two arbitrary values.
*
- * @param float|int $currentValue The current metric value.
- * @param float|int $pastValue The value of the metric in the past. We measure the % change
+ * @param float|int $currentValue The current metric value.
+ * @param float|int $pastValue The value of the metric in the past. We measure the % change
* from this value to $currentValue.
- * @param float|int $quotientPrecision The quotient precision to round to.
+ * @param float|int $quotientPrecision The quotient precision to round to.
*
* @return string The evolution percent 15%
*/
diff --git a/core/DataTable/Filter/ColumnCallbackAddColumn.php b/core/DataTable/Filter/ColumnCallbackAddColumn.php
index 4aa8b008e4..e65ab52e40 100755
--- a/core/DataTable/Filter/ColumnCallbackAddColumn.php
+++ b/core/DataTable/Filter/ColumnCallbackAddColumn.php
@@ -8,14 +8,18 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Filter;
+
+use Piwik\DataTable;
+use Piwik\DataTable\Filter;
/**
* Adds a new column to every row of a DataTable based on the result of callback.
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Filter_ColumnCallbackAddColumn extends Piwik_DataTable_Filter
+class ColumnCallbackAddColumn extends Filter
{
/**
* The names of the columns to pass to the callback.
@@ -41,7 +45,7 @@ class Piwik_DataTable_Filter_ColumnCallbackAddColumn extends Piwik_DataTable_Fil
/**
* Constructor.
*
- * @param Piwik_DataTable $table The DataTable that will be filtered.
+ * @param DataTable $table The DataTable that will be filtered.
* @param array|string $columns The names of the columns to pass to the callback.
* @param string $columnToAdd The name of the column to add.
* @param mixed $functionToApply The callback to apply to each row of a DataTable.
@@ -65,7 +69,7 @@ class Piwik_DataTable_Filter_ColumnCallbackAddColumn extends Piwik_DataTable_Fil
* Executes a callback on every row of the supplied table and adds the result of
* the callback as a new column to each row.
*
- * @param Piwik_DataTable $table The table to filter.
+ * @param DataTable $table The table to filter.
*/
public function filter($table)
{
diff --git a/core/DataTable/Filter/ColumnCallbackAddColumnPercentage.php b/core/DataTable/Filter/ColumnCallbackAddColumnPercentage.php
index 5ac99ce678..92ad07185c 100644
--- a/core/DataTable/Filter/ColumnCallbackAddColumnPercentage.php
+++ b/core/DataTable/Filter/ColumnCallbackAddColumnPercentage.php
@@ -8,7 +8,10 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Filter;
+
use Piwik\Piwik;
+use Piwik\DataTable\Filter\ColumnCallbackAddColumnQuotient;
/**
* Add a new column to the table which is a percentage based on the value resulting
@@ -23,9 +26,9 @@ use Piwik\Piwik;
* $dataTable->queueFilter('ColumnCallbackAddColumnPercentage', array('nb_visits', 'nb_visits_percentage', $nbVisits, 1));
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Filter_ColumnCallbackAddColumnPercentage extends Piwik_DataTable_Filter_ColumnCallbackAddColumnQuotient
+class ColumnCallbackAddColumnPercentage extends ColumnCallbackAddColumnQuotient
{
/**
* Formats the given value
diff --git a/core/DataTable/Filter/ColumnCallbackAddColumnQuotient.php b/core/DataTable/Filter/ColumnCallbackAddColumnQuotient.php
index b5573bb731..4e95a8a9a2 100644
--- a/core/DataTable/Filter/ColumnCallbackAddColumnQuotient.php
+++ b/core/DataTable/Filter/ColumnCallbackAddColumnQuotient.php
@@ -8,15 +8,20 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Filter;
+
+use Piwik\DataTable;
+use Piwik\DataTable\Filter;
+use Piwik\DataTable\Row;
/**
* Adds a new column that is a division of two columns of the current row.
* Useful to process bounce rates, exit rates, average time on page, etc.
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Filter_ColumnCallbackAddColumnQuotient extends Piwik_DataTable_Filter
+class ColumnCallbackAddColumnQuotient extends Filter
{
protected $table;
protected $columnValueToRead;
@@ -28,7 +33,7 @@ class Piwik_DataTable_Filter_ColumnCallbackAddColumnQuotient extends Piwik_DataT
protected $getDivisorFromSummaryRow;
/**
- * @param Piwik_DataTable $table
+ * @param DataTable $table
* @param string $columnNameToAdd
* @param string $columnValueToRead
* @param number|string $divisorValueOrDivisorColumnName
@@ -57,7 +62,7 @@ class Piwik_DataTable_Filter_ColumnCallbackAddColumnQuotient extends Piwik_DataT
/**
* Filters the given data table
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
*/
public function filter($table)
{
@@ -101,7 +106,7 @@ class Piwik_DataTable_Filter_ColumnCallbackAddColumnQuotient extends Piwik_DataT
* Returns the dividend to use when calculating the new column value. Can
* be overridden by descendent classes to customize behavior.
*
- * @param Piwik_DataTable_Row $row The row being modified.
+ * @param Row $row The row being modified.
* @return int|float
*/
protected function getDividend($row)
@@ -113,7 +118,7 @@ class Piwik_DataTable_Filter_ColumnCallbackAddColumnQuotient extends Piwik_DataT
* Returns the divisor to use when calculating the new column value. Can
* be overridden by descendent classes to customize behavior.
*
- * @param Piwik_DataTable_Row $row The row being modified.
+ * @param Row $row The row being modified.
* @return int|float
*/
protected function getDivisor($row)
@@ -121,7 +126,7 @@ class Piwik_DataTable_Filter_ColumnCallbackAddColumnQuotient extends Piwik_DataT
if (!is_null($this->totalValueUsedAsDivisor)) {
return $this->totalValueUsedAsDivisor;
} else if ($this->getDivisorFromSummaryRow) {
- $summaryRow = $this->table->getRowFromId(Piwik_DataTable::ID_SUMMARY_ROW);
+ $summaryRow = $this->table->getRowFromId(DataTable::ID_SUMMARY_ROW);
return $summaryRow->getColumn($this->columnNameUsedAsDivisor);
} else {
return $row->getColumn($this->columnNameUsedAsDivisor);
diff --git a/core/DataTable/Filter/ColumnCallbackAddMetadata.php b/core/DataTable/Filter/ColumnCallbackAddMetadata.php
index b181f4c177..166c9e740a 100644
--- a/core/DataTable/Filter/ColumnCallbackAddMetadata.php
+++ b/core/DataTable/Filter/ColumnCallbackAddMetadata.php
@@ -8,6 +8,10 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Filter;
+
+use Piwik\DataTable;
+use Piwik\DataTable\Filter;
/**
* Add a new 'metadata' column to the table based on the value resulting
@@ -17,9 +21,9 @@
* with the icon URI built from the label (LINUX => UserSettings/icons/linux.png)
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Filter_ColumnCallbackAddMetadata extends Piwik_DataTable_Filter
+class ColumnCallbackAddMetadata extends Filter
{
private $columnsToRead;
private $functionToApply;
@@ -28,12 +32,12 @@ class Piwik_DataTable_Filter_ColumnCallbackAddMetadata extends Piwik_DataTable_F
private $applyToSummaryRow;
/**
- * @param Piwik_DataTable $table
- * @param string|array $columnsToRead
- * @param string $metadataToAdd
- * @param string $functionToApply
- * @param array $functionParameters
- * @param bool $applyToSummaryRow
+ * @param DataTable $table
+ * @param string|array $columnsToRead
+ * @param string $metadataToAdd
+ * @param string $functionToApply
+ * @param array $functionParameters
+ * @param bool $applyToSummaryRow
*/
public function __construct($table, $columnsToRead, $metadataToAdd, $functionToApply = null,
$functionParameters = null, $applyToSummaryRow = true)
@@ -54,12 +58,12 @@ class Piwik_DataTable_Filter_ColumnCallbackAddMetadata extends Piwik_DataTable_F
/**
* Filters the given data table
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
*/
public function filter($table)
{
foreach ($table->getRows() as $key => $row) {
- if (!$this->applyToSummaryRow && $key == Piwik_DataTable::ID_SUMMARY_ROW) {
+ if (!$this->applyToSummaryRow && $key == DataTable::ID_SUMMARY_ROW) {
continue;
}
diff --git a/core/DataTable/Filter/ColumnCallbackDeleteRow.php b/core/DataTable/Filter/ColumnCallbackDeleteRow.php
index dbe0684cf8..66c0eded79 100644
--- a/core/DataTable/Filter/ColumnCallbackDeleteRow.php
+++ b/core/DataTable/Filter/ColumnCallbackDeleteRow.php
@@ -8,21 +8,25 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Filter;
+
+use Piwik\DataTable;
+use Piwik\DataTable\Filter;
/**
* Delete all rows for which a given function returns false for a given column.
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Filter_ColumnCallbackDeleteRow extends Piwik_DataTable_Filter
+class ColumnCallbackDeleteRow extends Filter
{
private $columnToFilter;
private $function;
private $functionParams;
/**
- * @param Piwik_DataTable $table
+ * @param DataTable $table
* @param string $columnToFilter
* @param callback $function
* @param array $functionParams
@@ -43,7 +47,7 @@ class Piwik_DataTable_Filter_ColumnCallbackDeleteRow extends Piwik_DataTable_Fil
/**
* Filters the given data table
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
*/
public function filter($table)
{
diff --git a/core/DataTable/Filter/ColumnCallbackReplace.php b/core/DataTable/Filter/ColumnCallbackReplace.php
index f1c2d65f3a..4b2110eff3 100644
--- a/core/DataTable/Filter/ColumnCallbackReplace.php
+++ b/core/DataTable/Filter/ColumnCallbackReplace.php
@@ -8,15 +8,21 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Filter;
+
+use Piwik\DataTable;
+use Piwik\DataTable\Filter;
+use Piwik\DataTable\Row;
+use Piwik\Piwik;
/**
* Replace a column value with a new value resulting
* from the function called with the column's value
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Filter_ColumnCallbackReplace extends Piwik_DataTable_Filter
+class ColumnCallbackReplace extends Filter
{
private $columnsToFilter;
private $functionToApply;
@@ -24,7 +30,7 @@ class Piwik_DataTable_Filter_ColumnCallbackReplace extends Piwik_DataTable_Filte
private $extraColumnParameters;
/**
- * @param Piwik_DataTable $table
+ * @param DataTable $table
* @param array|string $columnsToFilter
* @param callback $functionToApply
* @param array|null $functionParameters
@@ -48,7 +54,7 @@ class Piwik_DataTable_Filter_ColumnCallbackReplace extends Piwik_DataTable_Filte
/**
* Filters the given data table
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
*/
public function filter($table)
{
@@ -79,7 +85,7 @@ class Piwik_DataTable_Filter_ColumnCallbackReplace extends Piwik_DataTable_Filte
/**
* Replaces the given column within given row with the given value
*
- * @param Piwik_DataTable_Row $row
+ * @param Row $row
* @param string $columnToFilter
* @param mixed $newValue
*/
@@ -91,7 +97,7 @@ class Piwik_DataTable_Filter_ColumnCallbackReplace extends Piwik_DataTable_Filte
/**
* Returns the element that should be replaced
*
- * @param Piwik_DataTable_Row $row
+ * @param Row $row
* @param string $columnToFilter
* @return mixed
*/
diff --git a/core/DataTable/Filter/ColumnDelete.php b/core/DataTable/Filter/ColumnDelete.php
index 709d56a02e..5540634ef8 100644
--- a/core/DataTable/Filter/ColumnDelete.php
+++ b/core/DataTable/Filter/ColumnDelete.php
@@ -8,15 +8,19 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Filter;
+
+use Piwik\DataTable;
+use Piwik\DataTable\Filter;
/**
* Filter that will remove columns from a DataTable using either a blacklist,
* whitelist or both.
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Filter_ColumnDelete extends Piwik_DataTable_Filter
+class ColumnDelete extends Filter
{
/**
* The columns that should be removed from DataTable rows.
@@ -51,13 +55,13 @@ class Piwik_DataTable_Filter_ColumnDelete extends Piwik_DataTable_Filter
/**
* Constructor.
*
- * @param Piwik_DataTable $table
- * @param array|string $columnsToRemove An array of column names or a comma-separated list of
+ * @param DataTable $table
+ * @param array|string $columnsToRemove An array of column names or a comma-separated list of
* column names. These columns will be removed.
- * @param array|string $columnsToKeep An array of column names that should be kept or a
+ * @param array|string $columnsToKeep An array of column names that should be kept or a
* comma-separated list of column names. Columns not in
* this list will be removed.
- * @param bool $deleteIfZeroOnly
+ * @param bool $deleteIfZeroOnly
*/
public function __construct($table, $columnsToRemove, $columnsToKeep = array(), $deleteIfZeroOnly = false)
{
@@ -80,7 +84,7 @@ class Piwik_DataTable_Filter_ColumnDelete extends Piwik_DataTable_Filter
* Filters the given DataTable. Removes columns that are not desired from
* each DataTable row.
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
*/
public function filter($table)
{
@@ -112,15 +116,16 @@ class Piwik_DataTable_Filter_ColumnDelete extends Piwik_DataTable_Filter
$keep = false;
// @see self::APPEND_TO_COLUMN_NAME_TO_KEEP
- foreach($this->columnsToKeep as $nameKeep => $true) {
- if(strpos($name, $nameKeep . self::APPEND_TO_COLUMN_NAME_TO_KEEP) === 0) {
+ foreach ($this->columnsToKeep as $nameKeep => $true) {
+ if (strpos($name, $nameKeep . self::APPEND_TO_COLUMN_NAME_TO_KEEP) === 0) {
$keep = true;
}
}
if (!$keep
&& $name != 'label' // label cannot be removed via whitelisting
- && !isset($this->columnsToKeep[$name])) {
+ && !isset($this->columnsToKeep[$name])
+ ) {
$row->deleteColumn($name);
}
}
diff --git a/core/DataTable/Filter/ExcludeLowPopulation.php b/core/DataTable/Filter/ExcludeLowPopulation.php
index 9f4d5c723c..07699ea2ea 100644
--- a/core/DataTable/Filter/ExcludeLowPopulation.php
+++ b/core/DataTable/Filter/ExcludeLowPopulation.php
@@ -8,6 +8,10 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Filter;
+
+use Piwik\DataTable;
+use Piwik\DataTable\Filter;
/**
* Delete all rows that have a $columnToFilter value less than the $minimumValue
@@ -17,16 +21,16 @@
* You can obviously apply this filter on a percentaged column, eg. remove all countries with the column 'percent_visits' less than 0.05
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Filter_ExcludeLowPopulation extends Piwik_DataTable_Filter
+class ExcludeLowPopulation extends Filter
{
const MINIMUM_SIGNIFICANT_PERCENTAGE_THRESHOLD = 0.02;
-
+
/**
* The minimum value to enforce in a datatable for a specified column. Rows found with
* a value less than this are removed.
- *
+ *
* @var number
*/
private $minimumValue;
@@ -34,7 +38,7 @@ class Piwik_DataTable_Filter_ExcludeLowPopulation extends Piwik_DataTable_Filter
/**
* Constructor
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
* @param string $columnToFilter column to filter
* @param number|Closure $minimumValue minimum value
* @param bool $minimumPercentageThreshold
@@ -43,7 +47,7 @@ class Piwik_DataTable_Filter_ExcludeLowPopulation extends Piwik_DataTable_Filter
{
parent::__construct($table);
$this->columnToFilter = $columnToFilter;
-
+
if ($minimumValue == 0) {
if ($minimumPercentageThreshold === false) {
$minimumPercentageThreshold = self::MINIMUM_SIGNIFICANT_PERCENTAGE_THRESHOLD;
@@ -52,14 +56,14 @@ class Piwik_DataTable_Filter_ExcludeLowPopulation extends Piwik_DataTable_Filter
$sumValues = array_sum($allValues);
$minimumValue = $sumValues * $minimumPercentageThreshold;
}
-
+
$this->minimumValue = $minimumValue;
}
/**
* Executes filter and removes all rows below the defined minimum
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
*/
public function filter($table)
{
@@ -67,7 +71,7 @@ class Piwik_DataTable_Filter_ExcludeLowPopulation extends Piwik_DataTable_Filter
$isValueHighPopulation = function ($value) use ($minimumValue) {
return $value >= $minimumValue;
};
-
+
$table->filter('ColumnCallbackDeleteRow', array($this->columnToFilter, $isValueHighPopulation));
}
}
diff --git a/core/DataTable/Filter/GroupBy.php b/core/DataTable/Filter/GroupBy.php
index 166994cd29..2dbc839c59 100755
--- a/core/DataTable/Filter/GroupBy.php
+++ b/core/DataTable/Filter/GroupBy.php
@@ -8,6 +8,10 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Filter;
+
+use Piwik\DataTable;
+use Piwik\DataTable\Filter;
/**
* DataTable filter that will group DataTable rows together based on the results
@@ -16,9 +20,9 @@
* NOTE: This filter should never be queued, it must be applied directly on a DataTable.
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Filter_GroupBy extends Piwik_DataTable_Filter
+class GroupBy extends Filter
{
/**
* The name of the columns to reduce.
@@ -40,7 +44,7 @@ class Piwik_DataTable_Filter_GroupBy extends Piwik_DataTable_Filter
/**
* Constructor.
*
- * @param Piwik_DataTable $table The DataTable to filter.
+ * @param DataTable $table The DataTable to filter.
* @param string $groupByColumn The column name to reduce.
* @param mixed $reduceFunction The reduce function. This must alter the $groupByColumn in some way.
* @param array $parameters Extra parameters to supply to the reduce function.
@@ -57,7 +61,7 @@ class Piwik_DataTable_Filter_GroupBy extends Piwik_DataTable_Filter
/**
* Applies the reduce function to each row and merges rows w/ the same reduce result.
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
*/
public function filter($table)
{
@@ -66,7 +70,7 @@ class Piwik_DataTable_Filter_GroupBy extends Piwik_DataTable_Filter
foreach ($table->getRows() as $rowId => $row) {
// skip the summary row
- if ($rowId == Piwik_DataTable::ID_SUMMARY_ROW) {
+ if ($rowId == DataTable::ID_SUMMARY_ROW) {
continue;
}
diff --git a/core/DataTable/Filter/Limit.php b/core/DataTable/Filter/Limit.php
index 7845727948..5d751ddbc4 100644
--- a/core/DataTable/Filter/Limit.php
+++ b/core/DataTable/Filter/Limit.php
@@ -8,19 +8,23 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Filter;
+
+use Piwik\DataTable;
+use Piwik\DataTable\Filter;
/**
* Delete all rows from the table that are not in the offset,offset+limit range
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Filter_Limit extends Piwik_DataTable_Filter
+class Limit extends Filter
{
/**
* Filter constructor.
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
* @param int $offset Starting row (indexed from 0)
* @param int $limit Number of rows to keep (specify -1 to keep all rows)
* @param bool $keepSummaryRow Whether to keep the summary row or not.
@@ -40,14 +44,14 @@ class Piwik_DataTable_Filter_Limit extends Piwik_DataTable_Filter
/**
* Limits the given data table
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
*/
public function filter($table)
{
$table->setRowsCountBeforeLimitFilter();
if ($this->keepSummaryRow) {
- $summaryRow = $table->getRowFromId(Piwik_DataTable::ID_SUMMARY_ROW);
+ $summaryRow = $table->getRowFromId(DataTable::ID_SUMMARY_ROW);
}
// we delete from 0 to offset
diff --git a/core/DataTable/Filter/MetadataCallbackAddMetadata.php b/core/DataTable/Filter/MetadataCallbackAddMetadata.php
index dbfc1728ee..b24402c870 100644
--- a/core/DataTable/Filter/MetadataCallbackAddMetadata.php
+++ b/core/DataTable/Filter/MetadataCallbackAddMetadata.php
@@ -8,6 +8,10 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Filter;
+
+use Piwik\DataTable;
+use Piwik\DataTable\Filter;
/**
* Add a new metadata to the table based on the value resulting
@@ -18,9 +22,9 @@
* the path of the logo for this search engine URL (which has the format URL.png).
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Filter_MetadataCallbackAddMetadata extends Piwik_DataTable_Filter
+class MetadataCallbackAddMetadata extends Filter
{
private $metadataToRead;
private $functionToApply;
@@ -28,7 +32,7 @@ class Piwik_DataTable_Filter_MetadataCallbackAddMetadata extends Piwik_DataTable
private $applyToSummaryRow;
/**
- * @param Piwik_DataTable $table
+ * @param DataTable $table
* @param string|array $metadataToRead
* @param string $metadataToAdd
* @param callback $functionToApply
@@ -50,12 +54,12 @@ class Piwik_DataTable_Filter_MetadataCallbackAddMetadata extends Piwik_DataTable
}
/**
- * @param Piwik_DataTable $table
+ * @param DataTable $table
*/
public function filter($table)
{
foreach ($table->getRows() as $key => $row) {
- if (!$this->applyToSummaryRow && $key == Piwik_DataTable::ID_SUMMARY_ROW) {
+ if (!$this->applyToSummaryRow && $key == DataTable::ID_SUMMARY_ROW) {
continue;
}
diff --git a/core/DataTable/Filter/MetadataCallbackReplace.php b/core/DataTable/Filter/MetadataCallbackReplace.php
index 4e6e5990de..32051c1e6f 100644
--- a/core/DataTable/Filter/MetadataCallbackReplace.php
+++ b/core/DataTable/Filter/MetadataCallbackReplace.php
@@ -8,18 +8,24 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Filter;
+
+use Piwik\DataTable;
+use Piwik\DataTable\Filter\ColumnCallbackReplace;
+use Piwik\DataTable\Row;
+use false;
/**
* Replace a metadata value with a new value resulting
* from the function called with the metadata's value
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Filter_MetadataCallbackReplace extends Piwik_DataTable_Filter_ColumnCallbackReplace
+class MetadataCallbackReplace extends ColumnCallbackReplace
{
/**
- * @param Piwik_DataTable $table
+ * @param DataTable $table
* @param array|string $metadataToFilter
* @param callback $functionToApply
* @param null|array $functionParameters
@@ -32,7 +38,7 @@ class Piwik_DataTable_Filter_MetadataCallbackReplace extends Piwik_DataTable_Fil
}
/**
- * @param Piwik_DataTable_Row $row
+ * @param Row $row
* @param string $metadataToFilter
* @param mixed $newValue
*/
@@ -42,7 +48,7 @@ class Piwik_DataTable_Filter_MetadataCallbackReplace extends Piwik_DataTable_Fil
}
/**
- * @param Piwik_DataTable_Row $row
+ * @param Row $row
* @param string $metadataToFilter
* @return array|false|mixed
*/
diff --git a/core/DataTable/Filter/Null.php b/core/DataTable/Filter/Null.php
index 240dc53c41..7b9cb0d623 100644
--- a/core/DataTable/Filter/Null.php
+++ b/core/DataTable/Filter/Null.php
@@ -8,18 +8,22 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Filter;
+
+use Piwik\DataTable;
+use Piwik\DataTable\Filter;
/**
* Filter template.
* You can use it if you want to create a new filter.
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Filter_Null extends Piwik_DataTable_Filter
+class Null extends Filter
{
/**
- * @param Piwik_DataTable $table
+ * @param DataTable $table
*/
public function __construct($table)
{
@@ -27,7 +31,7 @@ class Piwik_DataTable_Filter_Null extends Piwik_DataTable_Filter
}
/**
- * @param Piwik_DataTable $table
+ * @param DataTable $table
*/
public function filter($table)
{
diff --git a/core/DataTable/Filter/Pattern.php b/core/DataTable/Filter/Pattern.php
index 4a1ef8fd99..8ac29a89f8 100644
--- a/core/DataTable/Filter/Pattern.php
+++ b/core/DataTable/Filter/Pattern.php
@@ -8,6 +8,10 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Filter;
+
+use Piwik\DataTable;
+use Piwik\DataTable\Filter;
/**
* Delete all rows for which the given $columnToFilter do not contain the $patternToSearch
@@ -15,9 +19,9 @@
* Example: from the keyword report, keep only the rows for which the label contains "piwik"
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Filter_Pattern extends Piwik_DataTable_Filter
+class Pattern extends Filter
{
private $columnToFilter;
private $patternToSearch;
@@ -25,7 +29,7 @@ class Piwik_DataTable_Filter_Pattern extends Piwik_DataTable_Filter
private $invertedMatch;
/**
- * @param Piwik_DataTable $table
+ * @param DataTable $table
* @param string $columnToFilter
* @param string $patternToSearch
* @param bool $invertedMatch
@@ -65,7 +69,7 @@ class Piwik_DataTable_Filter_Pattern extends Piwik_DataTable_Filter
}
/**
- * @param Piwik_DataTable $table
+ * @param DataTable $table
*/
public function filter($table)
{
diff --git a/core/DataTable/Filter/PatternRecursive.php b/core/DataTable/Filter/PatternRecursive.php
index 088546fee5..168c6a520a 100644
--- a/core/DataTable/Filter/PatternRecursive.php
+++ b/core/DataTable/Filter/PatternRecursive.php
@@ -8,6 +8,13 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Filter;
+
+use Exception;
+use Piwik\DataTable;
+use Piwik\DataTable\Filter;
+use Piwik\DataTable\Filter\Pattern;
+use Piwik\DataTable\Manager;
/**
* Delete all rows for which
@@ -18,16 +25,16 @@
* Example: from the pages viewed report, keep only the rows that contain "piwik" or for which a subpage contains "piwik".
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Filter_PatternRecursive extends Piwik_DataTable_Filter
+class PatternRecursive extends Filter
{
private $columnToFilter;
private $patternToSearch;
private $patternToSearchQuoted;
/**
- * @param Piwik_DataTable $table
+ * @param DataTable $table
* @param string $columnToFilter
* @param string $patternToSearch
*/
@@ -35,13 +42,13 @@ class Piwik_DataTable_Filter_PatternRecursive extends Piwik_DataTable_Filter
{
parent::__construct($table);
$this->patternToSearch = $patternToSearch;
- $this->patternToSearchQuoted = Piwik_DataTable_Filter_Pattern::getPatternQuoted($patternToSearch);
+ $this->patternToSearchQuoted = Pattern::getPatternQuoted($patternToSearch);
$this->patternToSearch = $patternToSearch; //preg_quote($patternToSearch);
$this->columnToFilter = $columnToFilter;
}
/**
- * @param Piwik_DataTable $table
+ * @param DataTable $table
* @return int
*/
public function filter($table)
@@ -56,7 +63,7 @@ class Piwik_DataTable_Filter_PatternRecursive extends Piwik_DataTable_Filter
try {
$idSubTable = $row->getIdSubDataTable();
- $subTable = Piwik_DataTable_Manager::getInstance()->getTable($idSubTable);
+ $subTable = Manager::getInstance()->getTable($idSubTable);
// we delete the row if we couldn't find the pattern in any row in the
// children hierarchy
@@ -69,7 +76,7 @@ class Piwik_DataTable_Filter_PatternRecursive extends Piwik_DataTable_Filter
}
if ($patternNotFoundInChildren
- && !Piwik_DataTable_Filter_Pattern::match($this->patternToSearch, $this->patternToSearchQuoted, $row->getColumn($this->columnToFilter), $invertedMatch = false)
+ && !Pattern::match($this->patternToSearch, $this->patternToSearchQuoted, $row->getColumn($this->columnToFilter), $invertedMatch = false)
) {
$table->deleteRow($key);
}
diff --git a/core/DataTable/Filter/RangeCheck.php b/core/DataTable/Filter/RangeCheck.php
index ebfea03d7f..5fc2db1c9c 100644
--- a/core/DataTable/Filter/RangeCheck.php
+++ b/core/DataTable/Filter/RangeCheck.php
@@ -8,20 +8,24 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Filter;
+
+use Piwik\DataTable;
+use Piwik\DataTable\Filter;
/**
* Check range
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Filter_RangeCheck extends Piwik_DataTable_Filter
+class RangeCheck extends Filter
{
static public $minimumValue = 0.00;
static public $maximumValue = 100.0;
/**
- * @param Piwik_DataTable $table
+ * @param DataTable $table
* @param string $columnToFilter name of the column to filter
* @param float $minimumValue minimum value for range
* @param float $maximumValue maximum value for range
@@ -41,7 +45,7 @@ class Piwik_DataTable_Filter_RangeCheck extends Piwik_DataTable_Filter
/**
* Executes the filter an adjusts all columns to fit the defined range
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
*/
public function filter($table)
{
diff --git a/core/DataTable/Filter/ReplaceColumnNames.php b/core/DataTable/Filter/ReplaceColumnNames.php
index c2b2beca79..abf802b82a 100644
--- a/core/DataTable/Filter/ReplaceColumnNames.php
+++ b/core/DataTable/Filter/ReplaceColumnNames.php
@@ -8,8 +8,14 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Filter;
+
+use Piwik\DataTable\Filter;
+use Piwik\DataTable\Simple;
use Piwik\Metrics;
use Piwik\Piwik;
+use Piwik\DataTable;
+use Piwik_Tracker_GoalManager;
/**
* This filter replaces column names using a mapping table that maps from the old name to the new name.
@@ -24,14 +30,14 @@ use Piwik\Piwik;
* You can specify the mapping array to apply in the constructor.
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Filter_ReplaceColumnNames extends Piwik_DataTable_Filter
+class ReplaceColumnNames extends Filter
{
protected $mappingToApply;
/**
- * @param Piwik_DataTable $table Table
+ * @param DataTable $table Table
* @param array $mappingToApply Mapping to apply. Must have the format
* array( OLD_COLUMN_NAME => NEW_COLUMN NAME,
* OLD_COLUMN_NAME2 => NEW_COLUMN NAME2,
@@ -49,11 +55,11 @@ class Piwik_DataTable_Filter_ReplaceColumnNames extends Piwik_DataTable_Filter
/**
* Executes the filter and renames the defined columns
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
*/
public function filter($table)
{
- if($table instanceof Piwik_DataTable_Simple) {
+ if ($table instanceof Simple) {
$this->filterSimple($table);
} else {
$this->filterTable($table);
@@ -70,13 +76,13 @@ class Piwik_DataTable_Filter_ReplaceColumnNames extends Piwik_DataTable_Filter
}
}
- protected function filterSimple(Piwik_DataTable_Simple $table)
+ protected function filterSimple(Simple $table)
{
foreach ($table->getRows() as $row) {
- $columns = array_keys( $row->getColumns() );
- foreach($columns as $column) {
+ $columns = array_keys($row->getColumns());
+ foreach ($columns as $column) {
$newName = $this->getRenamedColumn($column);
- if($newName) {
+ if ($newName) {
$row->renameColumn($column, $newName);
}
}
diff --git a/core/DataTable/Filter/ReplaceSummaryRowLabel.php b/core/DataTable/Filter/ReplaceSummaryRowLabel.php
index b89f05871c..2e65716922 100644
--- a/core/DataTable/Filter/ReplaceSummaryRowLabel.php
+++ b/core/DataTable/Filter/ReplaceSummaryRowLabel.php
@@ -8,16 +8,21 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Filter;
+
+use Piwik\DataTable;
+use Piwik\DataTable\Filter;
+use Piwik\DataTable\Manager;
/**
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Filter_ReplaceSummaryRowLabel extends Piwik_DataTable_Filter
+class ReplaceSummaryRowLabel extends Filter
{
/**
- * @param Piwik_DataTable $table
+ * @param DataTable $table
* @param string|null $newLabel new label for summary row
*/
public function __construct($table, $newLabel = null)
@@ -32,13 +37,13 @@ class Piwik_DataTable_Filter_ReplaceSummaryRowLabel extends Piwik_DataTable_Filt
/**
* Updates the summary row label
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
*/
public function filter($table)
{
$rows = $table->getRows();
foreach ($rows as $row) {
- if ($row->getColumn('label') == Piwik_DataTable::LABEL_SUMMARY_ROW) {
+ if ($row->getColumn('label') == DataTable::LABEL_SUMMARY_ROW) {
$row->setColumn('label', $this->newLabel);
break;
}
@@ -47,7 +52,7 @@ class Piwik_DataTable_Filter_ReplaceSummaryRowLabel extends Piwik_DataTable_Filt
// recurse
foreach ($rows as $row) {
if ($row->isSubtableLoaded()) {
- $subTable = Piwik_DataTable_Manager::getInstance()->getTable($row->getIdSubDataTable());
+ $subTable = Manager::getInstance()->getTable($row->getIdSubDataTable());
$this->filter($subTable);
}
}
diff --git a/core/DataTable/Filter/SafeDecodeLabel.php b/core/DataTable/Filter/SafeDecodeLabel.php
index ef8643b77f..ecb183c6cb 100644
--- a/core/DataTable/Filter/SafeDecodeLabel.php
+++ b/core/DataTable/Filter/SafeDecodeLabel.php
@@ -8,18 +8,22 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Filter;
+
+use Piwik\DataTable;
+use Piwik\DataTable\Filter;
/**
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Filter_SafeDecodeLabel extends Piwik_DataTable_Filter
+class SafeDecodeLabel extends Filter
{
private $columnToDecode;
static private $outputHtml = true;
/**
- * @param Piwik_DataTable $table
+ * @param DataTable $table
*/
public function __construct($table)
{
@@ -57,7 +61,7 @@ class Piwik_DataTable_Filter_SafeDecodeLabel extends Piwik_DataTable_Filter
/**
* Decodes all columns of the given data table
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
*/
public function filter($table)
{
@@ -71,5 +75,4 @@ class Piwik_DataTable_Filter_SafeDecodeLabel extends Piwik_DataTable_Filter
}
}
}
-
}
diff --git a/core/DataTable/Filter/Sort.php b/core/DataTable/Filter/Sort.php
index 014362b45d..72bc433bef 100644
--- a/core/DataTable/Filter/Sort.php
+++ b/core/DataTable/Filter/Sort.php
@@ -8,22 +8,28 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Filter;
+
+use Piwik\DataTable\Filter;
+use Piwik\DataTable\Simple;
+use Piwik\DataTable\Row;
use Piwik\Metrics;
+use Piwik\DataTable;
/**
* Sort the DataTable based on the value of column $columnToSort ordered by $order.
* Possible to specify a natural sorting (see php.net/natsort for details)
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Filter_Sort extends Piwik_DataTable_Filter
+class Sort extends Filter
{
protected $columnToSort;
protected $order;
/**
- * @param Piwik_DataTable $table
+ * @param DataTable $table
* @param string $columnToSort name of the column to sort by
* @param string $order order (asc|desc)
* @param bool $naturalSort use natural sort?
@@ -65,27 +71,27 @@ class Piwik_DataTable_Filter_Sort extends Piwik_DataTable_Filter
*/
public function sort($a, $b)
{
- return !isset($a->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort])
- && !isset($b->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort])
+ return !isset($a->c[Row::COLUMNS][$this->columnToSort])
+ && !isset($b->c[Row::COLUMNS][$this->columnToSort])
? 0
: (
- !isset($a->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort])
+ !isset($a->c[Row::COLUMNS][$this->columnToSort])
? 1
: (
- !isset($b->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort])
+ !isset($b->c[Row::COLUMNS][$this->columnToSort])
? -1
- : (($a->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort] != $b->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort]
- || !isset($a->c[Piwik_DataTable_Row::COLUMNS]['label']))
+ : (($a->c[Row::COLUMNS][$this->columnToSort] != $b->c[Row::COLUMNS][$this->columnToSort]
+ || !isset($a->c[Row::COLUMNS]['label']))
? ($this->sign * (
- $a->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort]
- < $b->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort]
+ $a->c[Row::COLUMNS][$this->columnToSort]
+ < $b->c[Row::COLUMNS][$this->columnToSort]
? -1
: 1)
)
: -1 * $this->sign * strnatcasecmp(
- $a->c[Piwik_DataTable_Row::COLUMNS]['label'],
- $b->c[Piwik_DataTable_Row::COLUMNS]['label'])
+ $a->c[Row::COLUMNS]['label'],
+ $b->c[Row::COLUMNS]['label'])
)
)
);
@@ -100,16 +106,16 @@ class Piwik_DataTable_Filter_Sort extends Piwik_DataTable_Filter
*/
function naturalSort($a, $b)
{
- return !isset($a->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort])
- && !isset($b->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort])
+ return !isset($a->c[Row::COLUMNS][$this->columnToSort])
+ && !isset($b->c[Row::COLUMNS][$this->columnToSort])
? 0
- : (!isset($a->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort])
+ : (!isset($a->c[Row::COLUMNS][$this->columnToSort])
? 1
- : (!isset($b->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort])
+ : (!isset($b->c[Row::COLUMNS][$this->columnToSort])
? -1
: $this->sign * strnatcasecmp(
- $a->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort],
- $b->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort]
+ $a->c[Row::COLUMNS][$this->columnToSort],
+ $b->c[Row::COLUMNS][$this->columnToSort]
)
)
);
@@ -124,16 +130,16 @@ class Piwik_DataTable_Filter_Sort extends Piwik_DataTable_Filter
*/
function sortString($a, $b)
{
- return !isset($a->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort])
- && !isset($b->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort])
+ return !isset($a->c[Row::COLUMNS][$this->columnToSort])
+ && !isset($b->c[Row::COLUMNS][$this->columnToSort])
? 0
- : (!isset($a->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort])
+ : (!isset($a->c[Row::COLUMNS][$this->columnToSort])
? 1
- : (!isset($b->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort])
+ : (!isset($b->c[Row::COLUMNS][$this->columnToSort])
? -1
: $this->sign *
- strcasecmp($a->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort],
- $b->c[Piwik_DataTable_Row::COLUMNS][$this->columnToSort]
+ strcasecmp($a->c[Row::COLUMNS][$this->columnToSort],
+ $b->c[Row::COLUMNS][$this->columnToSort]
)
)
);
@@ -142,7 +148,7 @@ class Piwik_DataTable_Filter_Sort extends Piwik_DataTable_Filter
/**
* Sets the column to be used for sorting
*
- * @param Piwik_DataTable_Row $row
+ * @param Row $row
* @return int
*/
protected function selectColumnToSort($row)
@@ -179,12 +185,12 @@ class Piwik_DataTable_Filter_Sort extends Piwik_DataTable_Filter
/**
* Sorts the given data table by defined column and sorting method
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
* @return mixed
*/
public function filter($table)
{
- if ($table instanceof Piwik_DataTable_Simple) {
+ if ($table instanceof Simple) {
return;
}
if (empty($this->columnToSort)) {
diff --git a/core/DataTable/Filter/Truncate.php b/core/DataTable/Filter/Truncate.php
index 7c917034f9..1cd6f98bf0 100644
--- a/core/DataTable/Filter/Truncate.php
+++ b/core/DataTable/Filter/Truncate.php
@@ -8,15 +8,20 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Filter;
+
+use Piwik\DataTable;
+use Piwik\DataTable\Filter;
+use Piwik\DataTable\Manager;
/**
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Filter_Truncate extends Piwik_DataTable_Filter
+class Truncate extends Filter
{
/**
- * @param Piwik_DataTable $table
+ * @param DataTable $table
* @param int $truncateAfter
*/
public function __construct($table, $truncateAfter)
@@ -28,7 +33,7 @@ class Piwik_DataTable_Filter_Truncate extends Piwik_DataTable_Filter
/**
* Truncates the table after X rows and adds a summary row
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
*/
public function filter($table)
{
@@ -38,7 +43,7 @@ class Piwik_DataTable_Filter_Truncate extends Piwik_DataTable_Filter
foreach ($table->getRows() as $row) {
if ($row->isSubtableLoaded()) {
$idSubTable = $row->getIdSubDataTable();
- $subTable = Piwik_DataTable_Manager::getInstance()->getTable($idSubTable);
+ $subTable = Manager::getInstance()->getTable($idSubTable);
$subTable->filter('Truncate', array($this->truncateAfter));
}
}
diff --git a/core/DataTable/Manager.php b/core/DataTable/Manager.php
index 21dc600481..b32463b176 100644
--- a/core/DataTable/Manager.php
+++ b/core/DataTable/Manager.php
@@ -9,7 +9,11 @@
* @package Piwik
*/
+namespace Piwik\DataTable;
+
+use Exception;
use Piwik\Common;
+use Piwik\DataTable;
/**
* The DataTable_Manager registers all the instanciated DataTable and provides an
@@ -17,16 +21,16 @@ use Piwik\Common;
* At the end of archiving, the ArchiveProcessor will read the stored datatable and record them in the DB.
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Manager
+class Manager
{
static private $instance = null;
/**
* Returns instance
*
- * @return Piwik_DataTable_Manager
+ * @return \Piwik\DataTable\Manager
*/
static public function getInstance()
{
@@ -52,7 +56,7 @@ class Piwik_DataTable_Manager
/**
* Add a DataTable to the registry
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
* @return int Index of the table in the manager array
*/
public function addTable($table)
@@ -69,7 +73,7 @@ class Piwik_DataTable_Manager
*
* @param int $idTable
* @throws Exception If the table can't be found
- * @return Piwik_DataTable The table
+ * @return DataTable The table
*/
public function getTable($idTable)
{
@@ -134,9 +138,9 @@ class Piwik_DataTable_Manager
*/
public function dumpAllTables()
{
- echo "<hr />Piwik_DataTable_Manager->dumpAllTables()<br />";
+ echo "<hr />Manager->dumpAllTables()<br />";
foreach ($this->tables as $id => $table) {
- if (!($table instanceof Piwik_DataTable)) {
+ if (!($table instanceof DataTable)) {
echo "Error table $id is not instance of datatable<br />";
var_export($table);
} else {
@@ -146,6 +150,6 @@ class Piwik_DataTable_Manager
echo "<br />";
}
}
- echo "<br />-- End Piwik_DataTable_Manager->dumpAllTables()<hr />";
+ echo "<br />-- End Manager->dumpAllTables()<hr />";
}
}
diff --git a/core/DataTable/Array.php b/core/DataTable/Map.php
index 0274a65fe5..7bda0c1984 100644
--- a/core/DataTable/Array.php
+++ b/core/DataTable/Map.php
@@ -8,27 +8,28 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable;
/**
* The DataTable_Array is a way to store an array of dataTable.
- * The Piwik_DataTable_Array implements some of the features of the Piwik_DataTable such as queueFilter, getRowsCount.
+ * The Set implements some of the features of the DataTable such as queueFilter, getRowsCount.
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Array
+class Map
{
/**
- * Array containing the DataTable withing this Piwik_DataTable_Array
+ * Array containing the DataTable withing this Set
*
- * @var Piwik_DataTable[]
+ * @var DataTable[]
*/
protected $array = array();
/**
* This is the label used to index the tables.
* For example if the tables are indexed using the timestamp of each period
- * eg. $this->array[1045886960] = new Piwik_DataTable();
+ * eg. $this->array[1045886960] = new DataTable();
* the keyName would be 'timestamp'.
*
* This label is used in the Renderer (it becomes a column name or the XML description tag)
@@ -70,7 +71,7 @@ class Piwik_DataTable_Array
/**
* Queue a filter to the DataTable_Array will queue this filter to every DataTable of the DataTable_Array.
*
- * @param string $className Filter name, eg. Piwik_DataTable_Filter_Limit
+ * @param string $className Filter name, eg. Limit
* @param array $parameters Filter parameters, eg. array( 50, 10 )
*/
public function queueFilter($className, $parameters = array())
@@ -106,7 +107,7 @@ class Piwik_DataTable_Array
/**
* Returns the array of DataTable
*
- * @return Piwik_DataTable[]
+ * @return DataTable[]
*/
public function getArray()
{
@@ -117,7 +118,7 @@ class Piwik_DataTable_Array
* Returns the table with the specified label.
*
* @param string $label
- * @return Piwik_DataTable
+ * @return DataTable
*/
public function getTable($label)
{
@@ -128,7 +129,7 @@ class Piwik_DataTable_Array
* Returns the first row
* This method can be used to treat DataTable and DataTable_Array in the same way
*
- * @return Piwik_DataTable_Row
+ * @return Row
*/
public function getFirstRow()
{
@@ -144,7 +145,7 @@ class Piwik_DataTable_Array
/**
* Adds a new DataTable to the DataTable_Array
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
* @param string $label Label used to index this table in the array
*/
public function addTable($table, $label)
@@ -287,19 +288,19 @@ class Piwik_DataTable_Array
* This function can be used, for example, to smoosh IndexedBySite archive
* query results into one DataTable w/ different rows differentiated by site ID.
*
- * @return Piwik_DataTable|Piwik_DataTable_Array
+ * @return DataTable|Set
*/
public function mergeChildren()
{
$firstChild = reset($this->array);
- if ($firstChild instanceof Piwik_DataTable_Array) {
+ if ($firstChild instanceof Set) {
$result = $firstChild->getEmptyClone();
foreach ($this->array as $label => $subTableArray) {
foreach ($subTableArray->array as $innerLabel => $subTable) {
if (!isset($result->array[$innerLabel])) {
- $dataTable = new Piwik_DataTable();
+ $dataTable = new DataTable();
$dataTable->metadata = $subTable->metadata;
$result->addTable($dataTable, $innerLabel);
@@ -309,7 +310,7 @@ class Piwik_DataTable_Array
}
}
} else {
- $result = new Piwik_DataTable();
+ $result = new DataTable();
foreach ($this->array as $label => $subTable) {
$this->copyRowsAndSetLabel($result, $subTable, $label);
@@ -323,21 +324,21 @@ class Piwik_DataTable_Array
* Utility function used by mergeChildren. Copies the rows from one table,
* sets their 'label' columns to a value and adds them to another table.
*
- * @param Piwik_DataTable $toTable The table to copy rows to.
- * @param Piwik_DataTable $fromTable The table to copy rows from.
+ * @param DataTable $toTable The table to copy rows to.
+ * @param DataTable $fromTable The table to copy rows from.
* @param string $label The value to set the 'label' column of every copied row.
*/
- private function copyRowsAndSetLabel($toTable, $fromTable, $label)
+ private function copyRowsAndSetLabel(DataTable $toTable, DataTable $fromTable, $label)
{
foreach ($fromTable->getRows() as $fromRow) {
$oldColumns = $fromRow->getColumns();
unset($oldColumns['label']);
$columns = array_merge(array('label' => $label), $oldColumns);
- $row = new Piwik_DataTable_Row(array(
- Piwik_DataTable_Row::COLUMNS => $columns,
- Piwik_DataTable_Row::METADATA => $fromRow->getMetadata(),
- Piwik_DataTable_Row::DATATABLE_ASSOCIATED => $fromRow->getIdSubDataTable()
+ $row = new Row(array(
+ Row::COLUMNS => $columns,
+ Row::METADATA => $fromRow->getMetadata(),
+ Row::DATATABLE_ASSOCIATED => $fromRow->getIdSubDataTable()
));
$toTable->addRow($row);
}
@@ -347,9 +348,9 @@ class Piwik_DataTable_Array
* Adds a DataTable to all the tables in this array
* NOTE: Will only add $tableToSum if the childTable has some rows
*
- * @param Piwik_DataTable $tableToSum
+ * @param DataTable $tableToSum
*/
- public function addDataTable(Piwik_DataTable $tableToSum)
+ public function addDataTable(DataTable $tableToSum)
{
foreach ($this->getArray() as $childTable) {
if ($childTable->getRowsCount() > 0) {
@@ -364,7 +365,7 @@ class Piwik_DataTable_Array
*
* @see Piwik_DataTable::mergeSubtables
*
- * @return Piwik_DataTable_Array
+ * @return Set
*/
public function mergeSubtables()
{
@@ -379,11 +380,11 @@ class Piwik_DataTable_Array
* Returns a new DataTable_Array w/o any child DataTables, but with
* the same key name as this instance.
*
- * @return Piwik_DataTable_Array
+ * @return Set
*/
public function getEmptyClone()
{
- $newTableArray = new Piwik_DataTable_Array;
+ $newTableArray = new Map;
$newTableArray->setKeyName($this->getKeyName());
return $newTableArray;
}
diff --git a/core/DataTable/Renderer.php b/core/DataTable/Renderer.php
index 68fcf88fe5..88f3f9ff37 100644
--- a/core/DataTable/Renderer.php
+++ b/core/DataTable/Renderer.php
@@ -8,21 +8,26 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable;
+
+use Exception;
use Piwik\Metrics;
use Piwik\Piwik;
+use Piwik\DataTable;
+use Piwik\DataTable\Simple;
/**
* A DataTable Renderer can produce an output given a DataTable object.
* All new Renderers must be copied in DataTable/Renderer and added to the factory() method.
* To use a renderer, simply do:
- * $render = new Piwik_DataTable_Renderer_Xml();
+ * $render = new Xml();
* $render->setTable($dataTable);
* echo $render;
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-abstract class Piwik_DataTable_Renderer
+abstract class Renderer
{
protected $table;
protected $exception;
@@ -59,7 +64,6 @@ abstract class Piwik_DataTable_Renderer
*/
public $idSite = 'all';
-
public function __construct()
{
}
@@ -135,16 +139,16 @@ abstract class Piwik_DataTable_Renderer
/**
* Set the DataTable to be rendered
*
- * @param Piwik_DataTable|Piwik_DataTable_Simple|Piwik_DataTable_Array $table table to be rendered
+ * @param DataTable|Simple|DataTable\Map $table table to be rendered
* @throws Exception
*/
public function setTable($table)
{
if (!is_array($table)
- && !($table instanceof Piwik_DataTable)
- && !($table instanceof Piwik_DataTable_Array)
+ && !($table instanceof DataTable)
+ && !($table instanceof DataTable\Map)
) {
- throw new Exception("DataTable renderers renderer accepts only Piwik_DataTable and Piwik_DataTable_Array instances, and array instances.");
+ throw new Exception("DataTable renderers renderer accepts only DataTable and Set instances, and array instances.");
}
$this->table = $table;
}
@@ -163,7 +167,6 @@ abstract class Piwik_DataTable_Renderer
$this->exception = $exception;
}
-
/**
* @var array
*/
@@ -190,20 +193,19 @@ abstract class Piwik_DataTable_Renderer
*
* @param string $name
* @throws Exception If the renderer is unknown
- * @return Piwik_DataTable_Renderer
+ * @return \Piwik\DataTable\Renderer
*/
static public function factory($name)
{
- $name = ucfirst(strtolower($name));
- $className = 'Piwik_DataTable_Renderer_' . $name;
-
+ $className = ucfirst(strtolower($name));
+ $className = 'Piwik\DataTable\Renderer\\' . $className;
try {
- Piwik_Loader::loadClass($className);
+ \Piwik\Loader::loadClass($className);
return new $className;
} catch (Exception $e) {
$availableRenderers = implode(', ', self::getRenderers());
@header('Content-Type: text/plain; charset=utf-8');
- throw new Exception(Piwik_TranslateException('General_ExceptionInvalidRendererFormat', array($name, $availableRenderers)));
+ throw new Exception(Piwik_TranslateException('General_ExceptionInvalidRendererFormat', array($className, $availableRenderers)));
}
}
@@ -365,7 +367,7 @@ abstract class Piwik_DataTable_Renderer
* - empty array (ie, array())
* - array w/ arrays/DataTable instances as values (ie,
* array('name' => 'myreport',
- * 'reportData' => new Piwik_DataTable())
+ * 'reportData' => new DataTable())
* OR array('name' => 'myreport',
* 'reportData' => array(...)) )
*
diff --git a/core/DataTable/Renderer/Console.php b/core/DataTable/Renderer/Console.php
index c78b4eda1f..594c80427f 100644
--- a/core/DataTable/Renderer/Console.php
+++ b/core/DataTable/Renderer/Console.php
@@ -8,14 +8,19 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Renderer;
+
+use Piwik\DataTable;
+use Piwik\DataTable\Manager;
+use Piwik\DataTable\Renderer;
/**
* Simple output
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage Piwik_DataTable_Renderer_ConsoleDataTable
*/
-class Piwik_DataTable_Renderer_Console extends Piwik_DataTable_Renderer
+class Console extends Renderer
{
/**
* Prefix
@@ -60,13 +65,13 @@ class Piwik_DataTable_Renderer_Console extends Piwik_DataTable_Renderer
/**
* Computes the output of the given array of data tables
*
- * @param Piwik_DataTable_Array $tableArray data tables to render
+ * @param DataTable\Map $tableArray data tables to render
* @param string $prefix prefix to output before table data
* @return string
*/
- protected function renderDataTableArray(Piwik_DataTable_Array $tableArray, $prefix)
+ protected function renderDataTableArray(DataTable\Map $tableArray, $prefix)
{
- $output = "Piwik_DataTable_Array<hr />";
+ $output = "Set<hr />";
$prefix = $prefix . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
foreach ($tableArray->getArray() as $descTable => $table) {
$output .= $prefix . "<b>" . $descTable . "</b><br />";
@@ -79,7 +84,7 @@ class Piwik_DataTable_Renderer_Console extends Piwik_DataTable_Renderer
/**
* Computes the given dataTable output and returns the string/binary
*
- * @param Piwik_DataTable $table data table to render
+ * @param DataTable $table data table to render
* @param string $prefix prefix to output before table data
* @return string
*/
@@ -87,10 +92,10 @@ class Piwik_DataTable_Renderer_Console extends Piwik_DataTable_Renderer
{
if (is_array($table)) // convert array to DataTable
{
- $table = Piwik_DataTable::makeFromSimpleArray($table);
+ $table = DataTable::makeFromSimpleArray($table);
}
- if ($table instanceof Piwik_DataTable_Array) {
+ if ($table instanceof DataTable\Map) {
return $this->renderDataTableArray($table, $prefix);
}
@@ -105,7 +110,7 @@ class Piwik_DataTable_Renderer_Console extends Piwik_DataTable_Renderer
$dataTableArrayBreak = false;
$columns = array();
foreach ($row->getColumns() as $column => $value) {
- if ($value instanceof Piwik_DataTable_Array) {
+ if ($value instanceof DataTable\Map) {
$output .= $this->renderDataTableArray($value, $prefix);
$dataTableArrayBreak = true;
break;
@@ -136,7 +141,7 @@ class Piwik_DataTable_Renderer_Console extends Piwik_DataTable_Renderer
if ($row->isSubtableLoaded()) {
$depth++;
$output .= $this->renderTable(
- Piwik_DataTable_Manager::getInstance()->getTable(
+ Manager::getInstance()->getTable(
$row->getIdSubDataTable()
),
$prefix . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
diff --git a/core/DataTable/Renderer/Csv.php b/core/DataTable/Renderer/Csv.php
index 9b2f5505d6..03074897d4 100644
--- a/core/DataTable/Renderer/Csv.php
+++ b/core/DataTable/Renderer/Csv.php
@@ -8,10 +8,16 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Renderer;
+
+use Piwik\DataTable\Simple;
+use Piwik\DataTable\Renderer;
use Piwik\Period;
-use Piwik\Period_Range;
+use Piwik\Period\Range;
use Piwik\Piwik;
use Piwik\Common;
+use Piwik\Date;
+use Piwik\DataTable;
/**
* CSV export
@@ -23,9 +29,9 @@ use Piwik\Common;
* Formatting and layout are ignored.
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Renderer_Csv extends Piwik_DataTable_Renderer
+class Csv extends Renderer
{
/**
* Column separator
@@ -119,7 +125,7 @@ class Piwik_DataTable_Renderer_Csv extends Piwik_DataTable_Renderer
/**
* Computes the output of the given data table
*
- * @param Piwik_DataTable|array $table
+ * @param DataTable|array $table
* @param array $allColumns
* @return string
*/
@@ -127,10 +133,10 @@ class Piwik_DataTable_Renderer_Csv extends Piwik_DataTable_Renderer
{
if (is_array($table)) // convert array to DataTable
{
- $table = Piwik_DataTable::makeFromSimpleArray($table);
+ $table = DataTable::makeFromSimpleArray($table);
}
- if ($table instanceof Piwik_DataTable_Array) {
+ if ($table instanceof DataTable\Map) {
$str = $this->renderDataTableArray($table, $allColumns);
} else {
$str = $this->renderDataTable($table, $allColumns);
@@ -141,7 +147,7 @@ class Piwik_DataTable_Renderer_Csv extends Piwik_DataTable_Renderer
/**
* Computes the output of the given data table array
*
- * @param Piwik_DataTable_Array $table
+ * @param DataTable\Map $table
* @param array $allColumns
* @return string
*/
@@ -176,13 +182,13 @@ class Piwik_DataTable_Renderer_Csv extends Piwik_DataTable_Renderer
/**
* Converts the output of the given simple data table
*
- * @param Piwik_DataTable_Simple $table
+ * @param Simple $table
* @param array $allColumns
* @return string
*/
protected function renderDataTable($table, &$allColumns = array())
{
- if ($table instanceof Piwik_DataTable_Simple) {
+ if ($table instanceof Simple) {
$row = $table->getFirstRow();
if ($row !== false) {
$columnNameToValue = $row->getColumns();
@@ -352,11 +358,11 @@ class Piwik_DataTable_Renderer_Csv extends Piwik_DataTable_Renderer
if ($period || $date) // in test cases, there are no request params set
{
if ($period == 'range') {
- $period = new Period_Range($period, $date);
+ $period = new Range($period, $date);
} else if (strpos($date, ',') !== false) {
- $period = new Period_Range('range', $date);
+ $period = new Range('range', $date);
} else {
- $period = Period::factory($period, Piwik_Date::factory($date));
+ $period = Period::factory($period, Date::factory($date));
}
$prettyDate = $period->getLocalizedLongString();
diff --git a/core/DataTable/Renderer/Html.php b/core/DataTable/Renderer/Html.php
index 1d620f74cc..035726a9ed 100644
--- a/core/DataTable/Renderer/Html.php
+++ b/core/DataTable/Renderer/Html.php
@@ -8,15 +8,21 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Renderer;
+
+use Exception;
+use Piwik\DataTable;
+use Piwik\DataTable\Simple;
+use Piwik\DataTable\Renderer;
/**
* Simple HTML output
* Does not work with recursive DataTable (i.e., when a row can be associated with a subDataTable).
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Renderer_Html extends Piwik_DataTable_Renderer
+class Html extends Renderer
{
protected $tableId;
protected $allColumns;
@@ -71,23 +77,23 @@ class Piwik_DataTable_Renderer_Html extends Piwik_DataTable_Renderer
/**
* Computes the output for the given data table
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
* @return string
*/
protected function renderTable($table)
{
if (is_array($table)) // convert array to DataTable
{
- $table = Piwik_DataTable::makeFromSimpleArray($table);
+ $table = DataTable::makeFromSimpleArray($table);
}
- if ($table instanceof Piwik_DataTable_Array) {
+ if ($table instanceof DataTable\Map) {
foreach ($table->getArray() as $date => $subtable) {
if ($subtable->getRowsCount()) {
$this->buildTableStructure($subtable, '_' . $table->getKeyName(), $date);
}
}
- } else // Piwik_DataTable_Simple
+ } else // Simple
{
if ($table->getRowsCount()) {
$this->buildTableStructure($table);
@@ -101,7 +107,7 @@ class Piwik_DataTable_Renderer_Html extends Piwik_DataTable_Renderer
/**
* Adds the given data table to the table structure array
*
- * @param Piwik_DataTable_Simple $table
+ * @param Simple $table
* @param null|string $columnToAdd
* @param null|string $valueToAdd
* @throws Exception
@@ -117,7 +123,7 @@ class Piwik_DataTable_Renderer_Html extends Piwik_DataTable_Renderer
* ROW1 = col1 | col2 | col3 | metadata | idSubTable
* ROW2 = col1 | col2 (no value but appears) | col3 | metadata | idSubTable
*/
- if (!($table instanceof Piwik_DataTable)) {
+ if (!($table instanceof DataTable)) {
throw new Exception("HTML Renderer does not work with this combination of parameters");
}
foreach ($table->getRows() as $row) {
diff --git a/core/DataTable/Renderer/Json.php b/core/DataTable/Renderer/Json.php
index 92e0830316..f5f6fc12bb 100644
--- a/core/DataTable/Renderer/Json.php
+++ b/core/DataTable/Renderer/Json.php
@@ -8,17 +8,22 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Renderer;
+
+use Piwik\DataTable\Renderer;
use Piwik\Piwik;
use Piwik\Common;
+use Piwik\DataTable;
+use Piwik\DataTable\Renderer\Php;
/**
* JSON export.
* Works with recursive DataTable (when a row can be associated with a subDataTable).
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Renderer_Json extends Piwik_DataTable_Renderer
+class Json extends Renderer
{
/**
* Computes the dataTable output and returns the string/binary
@@ -50,7 +55,7 @@ class Piwik_DataTable_Renderer_Json extends Piwik_DataTable_Renderer
/**
* Computes the output for the given data table
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
* @return string
*/
protected function renderTable($table)
@@ -61,7 +66,7 @@ class Piwik_DataTable_Renderer_Json extends Piwik_DataTable_Renderer
$array = array($array);
}
} else {
- $renderer = new Piwik_DataTable_Renderer_Php();
+ $renderer = new Php();
$renderer->setTable($table);
$renderer->setRenderSubTables($this->isRenderSubtables());
$renderer->setSerialize(false);
diff --git a/core/DataTable/Renderer/Php.php b/core/DataTable/Renderer/Php.php
index ec66701cbe..6717746295 100644
--- a/core/DataTable/Renderer/Php.php
+++ b/core/DataTable/Renderer/Php.php
@@ -8,7 +8,14 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Renderer;
+
+use Exception;
+use Piwik\DataTable\Manager;
+use Piwik\DataTable\Simple;
+use Piwik\DataTable\Renderer;
use Piwik\Piwik;
+use Piwik\DataTable;
/**
* Returns the equivalent PHP array for a given DataTable.
@@ -19,9 +26,9 @@ use Piwik\Piwik;
* Works with recursive DataTable (when a row can be associated with a subDataTable).
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Renderer_Php extends Piwik_DataTable_Renderer
+class Php extends Renderer
{
protected $prettyDisplay = false;
protected $serialize = true;
@@ -63,7 +70,7 @@ class Piwik_DataTable_Renderer_Php extends Piwik_DataTable_Renderer
/**
* Computes the dataTable output and returns the string/binary
*
- * @param null|Piwik_DataTable_Array|Piwik_DataTable_Simple $dataTable
+ * @param null|DataTable\Map|Simple $dataTable
* @return string
*/
public function render($dataTable = null)
@@ -116,7 +123,7 @@ class Piwik_DataTable_Renderer_Php extends Piwik_DataTable_Renderer
* 'col2_name' => value2,
* 'metadata1_name' => value_metadata )
*
- * @param null|Piwik_DataTable_Array|Piwik_DataTable_Simple $dataTable
+ * @param null|DataTable\Map|Simple $dataTable
* @return array Php array representing the 'flat' version of the datatable
*/
public function flatRender($dataTable = null)
@@ -130,7 +137,7 @@ class Piwik_DataTable_Renderer_Php extends Piwik_DataTable_Renderer
if (self::shouldWrapArrayBeforeRendering($flatArray)) {
$flatArray = array($flatArray);
}
- } else if ($dataTable instanceof Piwik_DataTable_Array) {
+ } else if ($dataTable instanceof DataTable\Map) {
$flatArray = array();
foreach ($dataTable->getArray() as $keyName => $table) {
$serializeSave = $this->serialize;
@@ -138,7 +145,7 @@ class Piwik_DataTable_Renderer_Php extends Piwik_DataTable_Renderer
$flatArray[$keyName] = $this->flatRender($table);
$this->serialize = $serializeSave;
}
- } else if ($dataTable instanceof Piwik_DataTable_Simple) {
+ } else if ($dataTable instanceof Simple) {
$flatArray = $this->renderSimpleTable($dataTable);
// if we return only one numeric value then we print out the result in a simple <result> tag
@@ -146,7 +153,6 @@ class Piwik_DataTable_Renderer_Php extends Piwik_DataTable_Renderer
if (count($flatArray) == 1) {
$flatArray = current($flatArray);
}
-
} // A normal DataTable needs to be handled specifically
else {
$array = $this->renderTable($dataTable);
@@ -191,11 +197,11 @@ class Piwik_DataTable_Renderer_Php extends Piwik_DataTable_Renderer
*/
public function originalRender()
{
- Piwik::checkObjectTypeIs($this->table, array('Piwik_DataTable_Simple', 'Piwik_DataTable'));
+ Piwik::checkObjectTypeIs($this->table, array('Simple', 'DataTable'));
- if ($this->table instanceof Piwik_DataTable_Simple) {
+ if ($this->table instanceof Simple) {
$array = $this->renderSimpleTable($this->table);
- } elseif ($this->table instanceof Piwik_DataTable) {
+ } elseif ($this->table instanceof DataTable) {
$array = $this->renderTable($this->table);
}
@@ -208,7 +214,7 @@ class Piwik_DataTable_Renderer_Php extends Piwik_DataTable_Renderer
/**
* Converts the given data table to an array
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
* @return array
*/
protected function renderTable($table)
@@ -222,14 +228,14 @@ class Piwik_DataTable_Renderer_Php extends Piwik_DataTable_Renderer
'idsubdatatable' => $row->getIdSubDataTable(),
);
- if ($id == Piwik_DataTable::ID_SUMMARY_ROW) {
+ if ($id == DataTable::ID_SUMMARY_ROW) {
$newRow['issummaryrow'] = true;
}
if ($this->isRenderSubtables()
&& $row->isSubtableLoaded()
) {
- $subTable = $this->renderTable(Piwik_DataTable_Manager::getInstance()->getTable($row->getIdSubDataTable()));
+ $subTable = $this->renderTable(Manager::getInstance()->getTable($row->getIdSubDataTable()));
$newRow['subtable'] = $subTable;
if ($this->hideIdSubDatatable === false
&& isset($newRow['metadata']['idsubdatatable_in_db'])
@@ -250,7 +256,7 @@ class Piwik_DataTable_Renderer_Php extends Piwik_DataTable_Renderer
/**
* Converts the simple data table to an array
*
- * @param Piwik_DataTable_Simple $table
+ * @param Simple $table
* @return array
*/
protected function renderSimpleTable($table)
diff --git a/core/DataTable/Renderer/Rss.php b/core/DataTable/Renderer/Rss.php
index 2c1fd05114..2b131d25df 100644
--- a/core/DataTable/Renderer/Rss.php
+++ b/core/DataTable/Renderer/Rss.php
@@ -8,17 +8,24 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Renderer;
+
+use Exception;
use Piwik\Common;
+use Piwik\DataTable\Renderer;
+use Piwik\Date;
+use Piwik\DataTable;
+use Piwik_Url;
/**
* RSS Feed.
- * The RSS renderer can be used only on Piwik_DataTable_Array that are arrays of Piwik_DataTable.
- * A RSS feed contains one dataTable per element in the Piwik_DataTable_Array.
+ * The RSS renderer can be used only on Set that are arrays of DataTable.
+ * A RSS feed contains one dataTable per element in the Set.
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Renderer_Rss extends Piwik_DataTable_Renderer
+class Rss extends Renderer
{
/**
* Computes the dataTable output and returns the string/binary
@@ -46,13 +53,13 @@ class Piwik_DataTable_Renderer_Rss extends Piwik_DataTable_Renderer
/**
* Computes the output for the given data table
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
* @return string
* @throws Exception
*/
protected function renderTable($table)
{
- if (!($table instanceof Piwik_DataTable_Array)
+ if (!($table instanceof DataTable\Map)
|| $table->getKeyName() != 'date'
) {
throw new Exception("RSS feeds can be generated for one specific website &idSite=X." .
@@ -72,7 +79,7 @@ class Piwik_DataTable_Renderer_Rss extends Piwik_DataTable_Renderer
$pudDate = date('r', $timestamp);
- $dateInSiteTimezone = Piwik_Date::factory($timestamp)->setTimezone($site->getTimezone())->toString('Y-m-d');
+ $dateInSiteTimezone = Date::factory($timestamp)->setTimezone($site->getTimezone())->toString('Y-m-d');
$thisPiwikUrl = Common::sanitizeInputValue($piwikUrl . "&date=$dateInSiteTimezone");
$siteName = $site->getName();
$title = $siteName . " on " . $date;
@@ -189,7 +196,6 @@ class Piwik_DataTable_Renderer_Rss extends Piwik_DataTable_Renderer
}
}
$html .= "</tr>";
-
}
$html .= "\n\n</table>";
return $html;
diff --git a/core/DataTable/Renderer/Tsv.php b/core/DataTable/Renderer/Tsv.php
index 4835853143..3f6aea5b53 100644
--- a/core/DataTable/Renderer/Tsv.php
+++ b/core/DataTable/Renderer/Tsv.php
@@ -8,6 +8,9 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Renderer;
+
+use Piwik\DataTable\Renderer\Csv;
/**
* TSV export
@@ -16,9 +19,9 @@
* TSV is therefore the 'CSV' that is Excel compatible
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Renderer_Tsv extends Piwik_DataTable_Renderer_Csv
+class Tsv extends Csv
{
/**
* Constructor
diff --git a/core/DataTable/Renderer/Xml.php b/core/DataTable/Renderer/Xml.php
index ba00e6d39e..4a9fdbdec5 100644
--- a/core/DataTable/Renderer/Xml.php
+++ b/core/DataTable/Renderer/Xml.php
@@ -8,7 +8,15 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Renderer;
+
+use Exception;
+use Piwik\DataTable\Renderer\Php;
+use Piwik\DataTable\Simple;
+use Piwik\DataTable\Renderer;
use Piwik\Piwik;
+use Piwik\DataTable;
+use DataTable\Map;
/**
* XML export of a given DataTable.
@@ -18,9 +26,9 @@ use Piwik\Piwik;
* Works with recursive DataTable (when a row can be associated with a subDataTable).
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Renderer_Xml extends Piwik_DataTable_Renderer
+class Xml extends Renderer
{
/**
* Computes the dataTable output and returns the string/binary
@@ -55,7 +63,7 @@ class Piwik_DataTable_Renderer_Xml extends Piwik_DataTable_Renderer
/**
* Converts the given data table to an array
*
- * @param Piwik_DataTable $table data table to convert
+ * @param DataTable $table data table to convert
* @return array
*/
protected function getArrayFromDataTable($table)
@@ -64,7 +72,7 @@ class Piwik_DataTable_Renderer_Xml extends Piwik_DataTable_Renderer
return $table;
}
- $renderer = new Piwik_DataTable_Renderer_Php();
+ $renderer = new Php();
$renderer->setRenderSubTables($this->isRenderSubtables());
$renderer->setSerialize(false);
$renderer->setTable($table);
@@ -75,7 +83,7 @@ class Piwik_DataTable_Renderer_Xml extends Piwik_DataTable_Renderer
/**
* Computes the output for the given data table
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
* @param bool $returnOnlyDataTableXml
* @param string $prefixLines
* @return array|string
@@ -84,7 +92,7 @@ class Piwik_DataTable_Renderer_Xml extends Piwik_DataTable_Renderer
protected function renderTable($table, $returnOnlyDataTableXml = false, $prefixLines = '')
{
$array = $this->getArrayFromDataTable($table);
- if ($table instanceof Piwik_DataTable_Array) {
+ if ($table instanceof DataTable\Map) {
$out = $this->renderDataTableArray($table, $array, $prefixLines);
if ($returnOnlyDataTableXml) {
@@ -102,7 +110,7 @@ class Piwik_DataTable_Renderer_Xml extends Piwik_DataTable_Renderer
$out = "<result />";
return $out;
}
- if ($table instanceof Piwik_DataTable_Simple) {
+ if ($table instanceof Simple) {
if (is_array($array)) {
$out = $this->renderDataTableSimple($array);
} else {
@@ -125,7 +133,7 @@ class Piwik_DataTable_Renderer_Xml extends Piwik_DataTable_Renderer
return $out;
}
- if ($table instanceof Piwik_DataTable) {
+ if ($table instanceof DataTable) {
$out = $this->renderDataTable($array);
if ($returnOnlyDataTableXml) {
return $out;
@@ -191,16 +199,16 @@ class Piwik_DataTable_Renderer_Xml extends Piwik_DataTable_Renderer
$result .= $prefixLines . $prefix . "\n";
$result .= $this->renderArray($value, $prefixLines . "\t");
$result .= $prefixLines . $suffix . "\n";
- } else if ($value instanceof Piwik_DataTable
- || $value instanceof Piwik_DataTable_Array
+ } else if ($value instanceof DataTable
+ || $value instanceof DataTable\Map
) {
if ($value->getRowsCount() == 0) {
$result .= $prefixLines . $emptyNode . "\n";
} else {
$result .= $prefixLines . $prefix . "\n";
- if ($value instanceof Piwik_DataTable_Array) {
+ if ($value instanceof DataTable\Map) {
$result .= $this->renderDataTableArray($value, $this->getArrayFromDataTable($value), $prefixLines);
- } else if ($value instanceof Piwik_DataTable_Simple) {
+ } else if ($value instanceof Simple) {
$result .= $this->renderDataTableSimple($this->getArrayFromDataTable($value), $prefixLines);
} else {
$result .= $this->renderDataTable($this->getArrayFromDataTable($value), $prefixLines);
@@ -225,7 +233,7 @@ class Piwik_DataTable_Renderer_Xml extends Piwik_DataTable_Renderer
/**
* Computes the output for the given data table array
*
- * @param Piwik_DataTable_Array $table
+ * @param DataTable\Map $table
* @param array $array
* @param string $prefixLines
* @return string
@@ -243,7 +251,7 @@ class Piwik_DataTable_Renderer_Xml extends Piwik_DataTable_Renderer
foreach ($array as $valueAttribute => $value) {
if (empty($value)) {
$xml .= $prefixLines . "\t<result $nameDescriptionAttribute=\"$valueAttribute\" />\n";
- } elseif ($value instanceof Piwik_DataTable_Array) {
+ } elseif ($value instanceof DataTable\Map) {
$out = $this->renderTable($value, true);
//TODO somehow this code is not tested, cover this case
$xml .= "\t<result $nameDescriptionAttribute=\"$valueAttribute\">\n$out</result>\n";
@@ -267,7 +275,7 @@ class Piwik_DataTable_Renderer_Xml extends Piwik_DataTable_Renderer
// array
// 'nb_uniq_visitors' => string '28'
// 'nb_visits' => string '11'
- if ($firstTable instanceof Piwik_DataTable_Simple) {
+ if ($firstTable instanceof Simple) {
$xml = '';
$nameDescriptionAttribute = $table->getKeyName();
foreach ($array as $valueAttribute => $dataTableSimple) {
@@ -309,7 +317,7 @@ class Piwik_DataTable_Renderer_Xml extends Piwik_DataTable_Renderer
// 'label' => string 'piwik bis'
// 'nb_uniq_visitors' => int 20
// 'nb_visits' => int 120
- if ($firstTable instanceof Piwik_DataTable) {
+ if ($firstTable instanceof DataTable) {
$xml = '';
$nameDescriptionAttribute = $table->getKeyName();
foreach ($array as $keyName => $arrayForSingleDate) {
@@ -325,14 +333,13 @@ class Piwik_DataTable_Renderer_Xml extends Piwik_DataTable_Renderer
return $xml;
}
- if ($firstTable instanceof Piwik_DataTable_Array) {
+ if ($firstTable instanceof DataTable\Map) {
$xml = '';
$tables = $table->getArray();
$nameDescriptionAttribute = $table->getKeyName();
foreach ($tables as $valueAttribute => $tableInArray) {
$out = $this->renderTable($tableInArray, true, $prefixLines . "\t");
$xml .= $prefixLines . "\t<result $nameDescriptionAttribute=\"$valueAttribute\">\n" . $out . $prefixLines . "\t</result>\n";
-
}
return $xml;
}
diff --git a/core/DataTable/Row.php b/core/DataTable/Row.php
index 4b2b42a695..841ff5f5d6 100644
--- a/core/DataTable/Row.php
+++ b/core/DataTable/Row.php
@@ -8,7 +8,12 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable;
+
+use Exception;
+use Piwik\DataTable\Manager;
use Piwik\Metrics;
+use Piwik\DataTable;
/**
* A DataTable is composed of rows.
@@ -27,9 +32,9 @@ use Piwik\Metrics;
* serialized and recorded in the DB millions of times. This object size is critical and must be under control.
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Row
+class Row
{
/**
* List of columns that cannot be summed. An associative array for speed.
@@ -45,7 +50,7 @@ class Piwik_DataTable_Row
* This array contains the row information:
* - array indexed by self::COLUMNS contains the columns, pairs of (column names, value)
* - (optional) array indexed by self::METADATA contains the metadata, pairs of (metadata name, value)
- * - (optional) integer indexed by self::DATATABLE_ASSOCIATED contains the ID of the Piwik_DataTable associated to this row.
+ * - (optional) integer indexed by self::DATATABLE_ASSOCIATED contains the ID of the DataTable associated to this row.
* This ID can be used to read the DataTable from the DataTable_Manager.
*
* @var array
@@ -61,22 +66,21 @@ class Piwik_DataTable_Row
const METADATA = 1;
const DATATABLE_ASSOCIATED = 3;
-
/**
* Efficient load of the Row structure from a well structured php array
*
* @param array $row The row array has the structure
* array(
- * Piwik_DataTable_Row::COLUMNS => array(
+ * Row::COLUMNS => array(
* 'label' => 'Piwik',
* 'column1' => 42,
* 'visits' => 657,
* 'time_spent' => 155744,
* ),
- * Piwik_DataTable_Row::METADATA => array(
+ * Row::METADATA => array(
* 'logo' => 'test.png'
* ),
- * Piwik_DataTable_Row::DATATABLE_ASSOCIATED => #Piwik_DataTable object
+ * Row::DATATABLE_ASSOCIATED => #DataTable object
* (but in the row only the ID will be stored)
* )
*/
@@ -93,7 +97,7 @@ class Piwik_DataTable_Row
$this->c[self::METADATA] = $row[self::METADATA];
}
if (isset($row[self::DATATABLE_ASSOCIATED])
- && $row[self::DATATABLE_ASSOCIATED] instanceof Piwik_DataTable
+ && $row[self::DATATABLE_ASSOCIATED] instanceof DataTable
) {
$this->setSubtable($row[self::DATATABLE_ASSOCIATED]);
}
@@ -134,7 +138,7 @@ class Piwik_DataTable_Row
public function __destruct()
{
if ($this->isSubtableLoaded()) {
- Piwik_DataTable_Manager::getInstance()->deleteTable($this->getIdSubDataTable());
+ Manager::getInstance()->deleteTable($this->getIdSubDataTable());
$this->c[self::DATATABLE_ASSOCIATED] = null;
}
}
@@ -257,12 +261,12 @@ class Piwik_DataTable_Row
/**
* Returns the associated subtable, if one exists.
*
- * @return Piwik_DataTable|false
+ * @return DataTable|false
*/
public function getSubtable()
{
if ($this->isSubtableLoaded()) {
- return Piwik_DataTable_Manager::getInstance()->getTable($this->getIdSubDataTable());
+ return Manager::getInstance()->getTable($this->getIdSubDataTable());
}
return false;
}
@@ -272,31 +276,30 @@ class Piwik_DataTable_Row
* If this row doesn't have a SubDataTable yet, we create a new one.
* Then we add the values of the given DataTable to this row's DataTable.
*
- * @param Piwik_DataTable $subTable Table to sum to this row's subDatatable
+ * @param DataTable $subTable Table to sum to this row's subDatatable
* @see Piwik_DataTable::addDataTable() for the algorithm used for the sum
*/
- public function sumSubtable(Piwik_DataTable $subTable)
+ public function sumSubtable(DataTable $subTable)
{
if ($this->isSubtableLoaded()) {
$thisSubTable = $this->getSubtable();
} else {
- $thisSubTable = new Piwik_DataTable();
+ $thisSubTable = new DataTable();
$this->addSubtable($thisSubTable);
}
$thisSubTable->setColumnAggregationOperations($subTable->getColumnAggregationOperations());
$thisSubTable->addDataTable($subTable);
}
-
/**
* Set a DataTable to be associated to this row.
* If the row already has a DataTable associated to it, throws an Exception.
*
- * @param Piwik_DataTable $subTable DataTable to associate to this row
- * @return Piwik_DataTable Returns $subTable.
+ * @param DataTable $subTable DataTable to associate to this row
+ * @return DataTable Returns $subTable.
* @throws Exception
*/
- public function addSubtable(Piwik_DataTable $subTable)
+ public function addSubtable(DataTable $subTable)
{
if (!is_null($this->c[self::DATATABLE_ASSOCIATED])) {
throw new Exception("Adding a subtable to the row, but it already has a subtable associated.");
@@ -308,10 +311,10 @@ class Piwik_DataTable_Row
* Set a DataTable to this row. If there is already
* a DataTable associated, it is simply overwritten.
*
- * @param Piwik_DataTable $subTable DataTable to associate to this row
- * @return Piwik_DataTable Returns $subTable.
+ * @param DataTable $subTable DataTable to associate to this row
+ * @return DataTable Returns $subTable.
*/
- public function setSubtable(Piwik_DataTable $subTable)
+ public function setSubtable(DataTable $subTable)
{
// Hacking -1 to ensure value is negative, so we know the table was loaded
// @see isSubtableLoaded()
@@ -456,22 +459,22 @@ class Piwik_DataTable_Row
* If the column already exists in $this then we have
* this.columns[idThisCol] += $row.columns[idThisCol]
*
- * @param Piwik_DataTable_Row $rowToSum
- * @param bool $enableCopyMetadata
- * @param array $aggregationOperations for columns that should not be summed, determine which
+ * @param \Piwik\DataTable\Row $rowToSum
+ * @param bool $enableCopyMetadata
+ * @param array $aggregationOperations for columns that should not be summed, determine which
* aggregation should be used (min, max).
* format: column name => function name
*/
- public function sumRow(Piwik_DataTable_Row $rowToSum, $enableCopyMetadata = true, $aggregationOperations = null)
+ public function sumRow(Row $rowToSum, $enableCopyMetadata = true, $aggregationOperations = null)
{
foreach ($rowToSum->getColumns() as $columnToSumName => $columnToSumValue) {
if (!isset(self::$unsummableColumns[$columnToSumName])) // make sure we can add this column
{
$thisColumnValue = $this->getColumn($columnToSumName);
- $operation = (is_array($aggregationOperations) && isset($aggregationOperations[$columnToSumName]) ?
+ $operation = (is_array($aggregationOperations) && isset($aggregationOperations[$columnToSumName]) ?
strtolower($aggregationOperations[$columnToSumName]) : 'sum');
-
+
// max_actions is a core metric that is generated in ArchiveProcess_Day. Therefore, it can be
// present in any data table and is not part of the $aggregationOperations mechanism.
if ($columnToSumName == Metrics::INDEX_MAX_ACTIONS) {
@@ -536,13 +539,13 @@ class Piwik_DataTable_Row
public function isSummaryRow()
{
- return $this->getColumn('label') === Piwik_DataTable::LABEL_SUMMARY_ROW;
+ return $this->getColumn('label') === DataTable::LABEL_SUMMARY_ROW;
}
/**
* Helper function: sums 2 values
*
- * @param number|bool $thisColumnValue
+ * @param number|bool $thisColumnValue
* @param number|array $columnToSumValue
*
* @throws Exception
@@ -577,7 +580,7 @@ class Piwik_DataTable_Row
} else if ($columnToSumValue === false) {
return $thisColumnValue;
} else {
- throw new Exception("Trying to add two strings values in DataTable_Row::sumRowArray: "
+ throw new Exception("Trying to add two strings values in DataTable\Row::sumRowArray: "
. "'$thisColumnValue' + '$columnToSumValue'");
}
}
@@ -616,11 +619,11 @@ class Piwik_DataTable_Row
* - if they have exactly the same columns / metadata
* - if they have a subDataTable associated, then we check that both of them are the same.
*
- * @param Piwik_DataTable_Row $row1 first to compare
- * @param Piwik_DataTable_Row $row2 second to compare
+ * @param \Piwik\DataTable\Row $row1 first to compare
+ * @param \Piwik\DataTable\Row $row2 second to compare
* @return bool
*/
- static public function isEqual(Piwik_DataTable_Row $row1, Piwik_DataTable_Row $row2)
+ static public function isEqual(Row $row1, Row $row2)
{
//same columns
$cols1 = $row1->getColumns();
@@ -651,7 +654,7 @@ class Piwik_DataTable_Row
) {
$subtable1 = $row1->getSubtable();
$subtable2 = $row2->getSubtable();
- if (!Piwik_DataTable::isEqual($subtable1, $subtable2)) {
+ if (!DataTable::isEqual($subtable1, $subtable2)) {
return false;
}
}
diff --git a/core/DataTable/Row/DataTableSummary.php b/core/DataTable/Row/DataTableSummaryRow.php
index c3acafdc66..f4203d9489 100644
--- a/core/DataTable/Row/DataTableSummary.php
+++ b/core/DataTable/Row/DataTableSummaryRow.php
@@ -8,6 +8,11 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable\Row;
+
+use Piwik\DataTable;
+use Piwik\DataTable\Manager;
+use Piwik\DataTable\Row;
/**
* This class creates a row from a given DataTable.
@@ -15,15 +20,15 @@
* - for each numeric column, the returned "summary" column is the sum of all the subRows
* - for every other column, it is ignored and will not be in the "summary row"
*
- * @see Piwik_DataTable_Row::sumRow() for more information on the algorithm
+ * @see \DataTable\Row::sumRow() for more information on the algorithm
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Row_DataTableSummary extends Piwik_DataTable_Row
+class DataTableSummaryRow extends Row
{
/**
- * @param Piwik_DataTable $subTable
+ * @param DataTable $subTable
*/
function __construct($subTable = null)
{
@@ -41,7 +46,7 @@ class Piwik_DataTable_Row_DataTableSummary extends Piwik_DataTable_Row
{
$id = $this->getIdSubDataTable();
if ($id !== null) {
- $subtable = Piwik_DataTable_Manager::getInstance()->getTable($id);
+ $subtable = Manager::getInstance()->getTable($id);
$this->sumTable($subtable);
}
}
@@ -49,7 +54,7 @@ class Piwik_DataTable_Row_DataTableSummary extends Piwik_DataTable_Row
/**
* Sums a tables row with this one.
*
- * @param Piwik_DataTable $table
+ * @param DataTable $table
*/
private function sumTable($table)
{
diff --git a/core/DataTable/Simple.php b/core/DataTable/Simple.php
index 7189fb0b2e..d7f9c430ad 100644
--- a/core/DataTable/Simple.php
+++ b/core/DataTable/Simple.php
@@ -8,21 +8,22 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\DataTable;
/**
- * The DataTable_Simple is used to provide an easy way to create simple DataGrid.
- * A DataTable_Simple actually is a DataTable with 2 columns: 'label' and 'value'.
+ * The DataTable\Simple is used to provide an easy way to create simple DataGrid.
+ * A DataTable\Simple is a DataTable with 2 columns: 'label' and 'value'.
*
- * It is usually best to return a DataTable_Simple instead of
+ * It is usually best to return a DataTable\Simple instead of
* a PHP array (or other custom data structure) in API methods:
* - the generic filters can be applied automatically (offset, limit, pattern search, sort, etc.)
* - the renderer can be applied (XML, PHP, HTML, etc.)
* So you don't have to write specific renderer for your data, it is already available in all the formats supported natively by Piwik.
*
* @package Piwik
- * @subpackage Piwik_DataTable
+ * @subpackage DataTable
*/
-class Piwik_DataTable_Simple extends Piwik_DataTable
+class Simple extends DataTable
{
/**
* Loads (append) in the DataTable the array information
diff --git a/core/Date.php b/core/Date.php
index 0753514cf9..3fb96665e0 100644
--- a/core/Date.php
+++ b/core/Date.php
@@ -9,12 +9,15 @@
* @package Piwik
*/
+namespace Piwik;
+use Exception;
+
/**
* Date object widely used in Piwik.
*
* @package Piwik
*/
-class Piwik_Date
+class Date
{
/**
* The stored timestamp is always UTC based.
@@ -33,7 +36,7 @@ class Piwik_Date
const DATE_TIME_FORMAT = 'Y-m-d H:i:s';
/**
- * Builds a Piwik_Date object
+ * Builds a Date object
*
* @param int $timestamp
* @param string $timezone
@@ -42,21 +45,21 @@ class Piwik_Date
protected function __construct($timestamp, $timezone = 'UTC')
{
if (!is_int($timestamp)) {
- throw new Exception("Piwik_Date is expecting a unix timestamp");
+ throw new Exception("Date is expecting a unix timestamp");
}
$this->timezone = $timezone;
$this->timestamp = $timestamp;
}
/**
- * Returns a Piwik_Date objects.
+ * Returns a Date objects.
*
- * @param string|self $dateString 'today' 'yesterday' or any YYYY-MM-DD or timestamp
+ * @param string|\Piwik\Date $dateString 'today' 'yesterday' or any YYYY-MM-DD or timestamp
* @param string $timezone if specified, the dateString will be relative to this $timezone.
* For example, today in UTC+12 will be a timestamp in the future for UTC.
* This is different from using ->setTimezone()
* @throws Exception
- * @return Piwik_Date
+ * @return \Piwik\Date
*/
public static function factory($dateString, $timezone = null)
{
@@ -83,7 +86,7 @@ class Piwik_Date
) {
throw $invalidDateException;
} else {
- $date = new Piwik_Date($dateString);
+ $date = new Date($dateString);
}
$timestamp = $date->getTimestamp();
// can't be doing web analytics before the 1st website
@@ -96,7 +99,7 @@ class Piwik_Date
}
$timestamp = self::adjustForTimezone($timestamp, $timezone);
- return Piwik_Date::factory($timestamp);
+ return Date::factory($timestamp);
}
/**
@@ -117,7 +120,7 @@ class Piwik_Date
public function getDateStartUTC()
{
$dateStartUTC = gmdate('Y-m-d', $this->timestamp);
- $date = Piwik_Date::factory($dateStartUTC)->setTimezone($this->timezone);
+ $date = Date::factory($dateStartUTC)->setTimezone($this->timezone);
return $date->toString(self::DATE_TIME_FORMAT);
}
@@ -129,7 +132,7 @@ class Piwik_Date
public function getDateEndUTC()
{
$dateEndUTC = gmdate('Y-m-d 23:59:59', $this->timestamp);
- $date = Piwik_Date::factory($dateEndUTC)->setTimezone($this->timezone);
+ $date = Date::factory($dateEndUTC)->setTimezone($this->timezone);
return $date->toString(self::DATE_TIME_FORMAT);
}
@@ -139,11 +142,11 @@ class Piwik_Date
* Doesn't modify $this
*
* @param string $timezone 'UTC', 'Europe/London', ...
- * @return Piwik_Date
+ * @return \Piwik\Date
*/
public function setTimezone($timezone)
{
- return new Piwik_Date($this->timestamp, $timezone);
+ return new Date($this->timestamp, $timezone);
}
/**
@@ -238,10 +241,10 @@ class Piwik_Date
/**
* Returns true if the current date is older than the given $date
*
- * @param Piwik_Date $date
+ * @param \Piwik\Date $date
* @return bool
*/
- public function isLater(Piwik_Date $date)
+ public function isLater(Date $date)
{
return $this->getTimestamp() > $date->getTimestamp();
}
@@ -249,10 +252,10 @@ class Piwik_Date
/**
* Returns true if the current date is earlier than the given $date
*
- * @param Piwik_Date $date
+ * @param \Piwik\Date $date
* @return bool
*/
- public function isEarlier(Piwik_Date $date)
+ public function isEarlier(Date $date)
{
return $this->getTimestamp() < $date->getTimestamp();
}
@@ -284,10 +287,10 @@ class Piwik_Date
* Returns 0 if equal, -1 if current week is earlier or 1 if current week is later
* Example: 09.Jan.2007 13:07:25 -> compareWeek(2); -> 0
*
- * @param Piwik_Date $date
+ * @param \Piwik\Date $date
* @return int 0 = equal, 1 = later, -1 = earlier
*/
- public function compareWeek(Piwik_Date $date)
+ public function compareWeek(Date $date)
{
$currentWeek = date('W', $this->getTimestamp());
$toCompareWeek = date('W', $date->getTimestamp());
@@ -305,10 +308,10 @@ class Piwik_Date
* Returns 0 if equal, -1 if current month is earlier or 1 if current month is later
* For example: 10.03.2000 -> 15.03.1950 -> 0
*
- * @param Piwik_Date $date Month to compare
+ * @param \Piwik\Date $date Month to compare
* @return int 0 = equal, 1 = later, -1 = earlier
*/
- public function compareMonth(Piwik_Date $date)
+ public function compareMonth(Date $date)
{
$currentMonth = date('n', $this->getTimestamp());
$toCompareMonth = date('n', $date->getTimestamp());
@@ -328,47 +331,47 @@ class Piwik_Date
*/
public function isToday()
{
- return $this->toString('Y-m-d') === Piwik_Date::factory('today', $this->timezone)->toString('Y-m-d');
+ return $this->toString('Y-m-d') === Date::factory('today', $this->timezone)->toString('Y-m-d');
}
/**
* Returns a date object set to now (same as today, except that the time is also set)
*
- * @return Piwik_Date
+ * @return \Piwik\Date
*/
public static function now()
{
- return new Piwik_Date(time());
+ return new Date(time());
}
/**
* Returns a date object set to today midnight
*
- * @return Piwik_Date
+ * @return \Piwik\Date
*/
public static function today()
{
- return new Piwik_Date(strtotime(date("Y-m-d 00:00:00")));
+ return new Date(strtotime(date("Y-m-d 00:00:00")));
}
/**
* Returns a date object set to yesterday midnight
*
- * @return Piwik_Date
+ * @return \Piwik\Date
*/
public static function yesterday()
{
- return new Piwik_Date(strtotime("yesterday"));
+ return new Date(strtotime("yesterday"));
}
/**
* Returns a date object set to yesterday same time of day
*
- * @return Piwik_Date
+ * @return \Piwik\Date
*/
public static function yesterdaySameTime()
{
- return new Piwik_Date(strtotime("yesterday " . date('H:i:s')));
+ return new Date(strtotime("yesterday " . date('H:i:s')));
}
/**
@@ -376,11 +379,11 @@ class Piwik_Date
* Doesn't modify $this
*
* @param string $time HH:MM:SS
- * @return Piwik_Date The new date with the time part set
+ * @return \Piwik\Date The new date with the time part set
*/
public function setTime($time)
{
- return new Piwik_Date(strtotime(date("Y-m-d", $this->timestamp) . " $time"), $this->timezone);
+ return new Date(strtotime(date("Y-m-d", $this->timestamp) . " $time"), $this->timezone);
}
/**
@@ -389,7 +392,7 @@ class Piwik_Date
* Doesn't modify $this
*
* @param int $day Day eg. 31
- * @return Piwik_Date new date
+ * @return \Piwik\Date new date
*/
public function setDay($day)
{
@@ -402,7 +405,7 @@ class Piwik_Date
$day,
date('Y', $ts)
);
- return new Piwik_Date($result, $this->timezone);
+ return new Date($result, $this->timezone);
}
/**
@@ -411,7 +414,7 @@ class Piwik_Date
* Doesn't modify $this
*
* @param int $year 2010
- * @return Piwik_Date new date
+ * @return \Piwik\Date new date
*/
public function setYear($year)
{
@@ -424,16 +427,16 @@ class Piwik_Date
date('j', $ts),
$year
);
- return new Piwik_Date($result, $this->timezone);
+ return new Date($result, $this->timezone);
}
/**
- * Subtracts days from the existing date object and returns a new Piwik_Date object
+ * Subtracts days from the existing date object and returns a new Date object
* Returned is the new date object
* Doesn't modify $this
*
* @param int $n
- * @return Piwik_Date new date
+ * @return \Piwik\Date new date
*/
public function subDay($n)
{
@@ -441,16 +444,16 @@ class Piwik_Date
return clone $this;
}
$ts = strtotime("-$n day", $this->timestamp);
- return new Piwik_Date($ts, $this->timezone);
+ return new Date($ts, $this->timezone);
}
/**
- * Subtracts weeks from the existing date object and returns a new Piwik_Date object
+ * Subtracts weeks from the existing date object and returns a new Date object
* Returned is the new date object
* Doesn't modify $this
*
* @param int $n
- * @return Piwik_Date new date
+ * @return \Piwik\Date new date
*/
public function subWeek($n)
{
@@ -463,7 +466,7 @@ class Piwik_Date
* Doesn't modify $this
*
* @param int $n
- * @return Piwik_Date new date
+ * @return \Piwik\Date new date
*/
public function subMonth($n)
{
@@ -479,7 +482,7 @@ class Piwik_Date
1, // we set the day to 1
date('Y', $ts)
);
- return new Piwik_Date($result, $this->timezone);
+ return new Date($result, $this->timezone);
}
/**
@@ -488,7 +491,7 @@ class Piwik_Date
* Doesn't modify $this
*
* @param int $n
- * @return Piwik_Date new date
+ * @return \Piwik\Date new date
*/
public function subYear($n)
{
@@ -504,7 +507,7 @@ class Piwik_Date
1, // we set the day to 1
date('Y', $ts) - $n
);
- return new Piwik_Date($result, $this->timezone);
+ return new Date($result, $this->timezone);
}
/**
@@ -539,12 +542,12 @@ class Piwik_Date
* Doesn't modify $this
*
* @param int $n Number of days to add
- * @return Piwik_Date new date
+ * @return \Piwik\Date new date
*/
public function addDay($n)
{
$ts = strtotime("+$n day", $this->timestamp);
- return new Piwik_Date($ts, $this->timezone);
+ return new Date($ts, $this->timezone);
}
/**
@@ -553,12 +556,12 @@ class Piwik_Date
* Doesn't modify $this
*
* @param int $n Number of hours to add
- * @return Piwik_Date new date
+ * @return \Piwik\Date new date
*/
public function addHour($n)
{
$ts = self::addHourTo($this->timestamp, $n);
- return new Piwik_Date($ts, $this->timezone);
+ return new Date($ts, $this->timezone);
}
/**
@@ -599,7 +602,7 @@ class Piwik_Date
* Doesn't modify $this
*
* @param int $n Number of hours to substract
- * @return Piwik_Date new date
+ * @return \Piwik\Date new date
*/
public function subHour($n)
{
@@ -613,7 +616,7 @@ class Piwik_Date
*
* @param int $n
* @param string $period period to add (WEEK, DAY,...)
- * @return Piwik_Date new date
+ * @return \Piwik\Date new date
*/
public function addPeriod($n, $period)
{
@@ -622,7 +625,7 @@ class Piwik_Date
} else {
$ts = strtotime("+$n $period", $this->timestamp);
}
- return new Piwik_Date($ts, $this->timezone);
+ return new Date($ts, $this->timezone);
}
/**
@@ -632,7 +635,7 @@ class Piwik_Date
*
* @param int $n
* @param string $period period to sub
- * @return Piwik_Date new date
+ * @return \Piwik\Date new date
*/
public function subPeriod($n, $period)
{
diff --git a/core/Db/Adapter.php b/core/Db/Adapter.php
index de3412e9a6..db9214b82a 100644
--- a/core/Db/Adapter.php
+++ b/core/Db/Adapter.php
@@ -8,6 +8,7 @@
* @category Piwik
* @package Piwik
*/
+use Piwik\Loader;
/**
* @package Piwik
@@ -39,7 +40,7 @@ class Piwik_Db_Adapter
}
$className = self::getAdapterClassName($adapterName);
- Piwik_Loader::loadClass($className);
+ Loader::loadClass($className);
/*
* 5.2.1 fixes various bugs with references that caused PDO_MYSQL getConnection()
diff --git a/core/Db/Schema/Myisam.php b/core/Db/Schema/Myisam.php
index a0eb2a7038..274e6f82e0 100644
--- a/core/Db/Schema/Myisam.php
+++ b/core/Db/Schema/Myisam.php
@@ -11,6 +11,7 @@
use Piwik\Config;
use Piwik\Piwik;
use Piwik\Common;
+use Piwik\Date;
/**
* MySQL schema
@@ -535,7 +536,7 @@ class Piwik_Db_Schema_Myisam implements Piwik_Db_Schema_Interface
// note that the token_auth value is anonymous, which is assigned by default as well in the Login plugin
$db = Zend_Registry::get('db');
$db->query("INSERT INTO " . Common::prefixTable("user") . "
- VALUES ( 'anonymous', '', 'anonymous', 'anonymous@example.org', 'anonymous', '" . Piwik_Date::factory('now')->getDatetime() . "' );");
+ VALUES ( 'anonymous', '', 'anonymous', 'anonymous@example.org', 'anonymous', '" . Date::factory('now')->getDatetime() . "' );");
}
/**
diff --git a/core/EventDispatcher.php b/core/EventDispatcher.php
index 8496013cab..7c311e4dd4 100644
--- a/core/EventDispatcher.php
+++ b/core/EventDispatcher.php
@@ -9,11 +9,14 @@
* @package Piwik
*/
+namespace Piwik;
+use Piwik\Plugin;
+
/**
* This class allows code to post events from anywhere in Piwik and for
* plugins to associate callbacks to be executed when events are posted.
*/
-class Piwik_EventDispatcher
+class EventDispatcher
{
// implementation details for postEvent
const EVENT_CALLBACK_GROUP_FIRST = 0;
@@ -31,7 +34,7 @@ class Piwik_EventDispatcher
public static function getInstance()
{
if (self::$instance === null) {
- self::$instance = new Piwik_EventDispatcher();
+ self::$instance = new EventDispatcher();
}
return self::$instance;
}
@@ -66,7 +69,7 @@ class Piwik_EventDispatcher
* loaded after the event is fired.
* @param array|null $plugins The plugins to post events to. If null, the event
* is posted to all plugins. The elements of this array
- * can be either the Piwik_Plugin objects themselves
+ * can be either the Plugin objects themselves
* or their string names.
*/
public function postEvent($eventName, $params, $pending = false, $plugins = null)
@@ -76,7 +79,7 @@ class Piwik_EventDispatcher
}
if (empty($plugins)) {
- $plugins = PluginsManager::getInstance()->getLoadedPlugins();
+ $plugins = \Piwik\PluginsManager::getInstance()->getLoadedPlugins();
}
$callbacks = array();
@@ -84,7 +87,7 @@ class Piwik_EventDispatcher
// collect all callbacks to execute
foreach ($plugins as $plugin) {
if (is_string($plugin)) {
- $plugin = PluginsManager::getInstance()->getLoadedPlugin($plugin);
+ $plugin = \Piwik\PluginsManager::getInstance()->getLoadedPlugin($plugin);
}
$hooks = $plugin->getListHooksRegistered();
@@ -150,7 +153,7 @@ class Piwik_EventDispatcher
/**
* Re-posts all pending events to the given plugin.
*
- * @param Piwik_Plugin $plugin
+ * @param Plugin $plugin
*/
public function postPendingEventsTo($plugin)
{
@@ -182,27 +185,3 @@ class Piwik_EventDispatcher
}
}
-/**
- * Post an event to the dispatcher which will notice the observers.
- *
- * @param string $eventName The event name.
- * @param array $params The parameter array to forward to observer callbacks.
- * @param bool $pending
- * @param null $plugins
- * @return void
- */
-function Piwik_PostEvent($eventName, $params = array(), $pending = false, $plugins = null)
-{
- Piwik_EventDispatcher::getInstance()->postEvent($eventName, $params, $pending, $plugins);
-}
-
-/**
- * Register an action to execute for a given event
- *
- * @param string $eventName Name of event
- * @param callable $function Callback hook
- */
-function Piwik_AddAction($eventName, $function)
-{
- Piwik_EventDispatcher::getInstance()->addObserver($eventName, $function);
-}
diff --git a/core/FrontController.php b/core/FrontController.php
index cda6d1dae2..9d777ed4b6 100644
--- a/core/FrontController.php
+++ b/core/FrontController.php
@@ -12,7 +12,7 @@ use Piwik\Config;
use Piwik\Piwik;
use Piwik\Common;
use Piwik\Access;
-use Piwik\PluginsManager;
+use Piwik\Translate;
/**
* @see core/PluginsManager.php
@@ -97,7 +97,7 @@ class Piwik_FrontController
throw new Exception("Invalid module name '$module'");
}
- if (!PluginsManager::getInstance()->isPluginActivated($module)) {
+ if (!\Piwik\PluginsManager::getInstance()->isPluginActivated($module)) {
throw new Piwik_FrontController_PluginDeactivatedException($module);
}
@@ -236,7 +236,7 @@ class Piwik_FrontController
Piwik::dieIfDirectoriesNotWritable($directoriesToCheck);
Common::assignCliParametersToRequest();
- Piwik_Translate::getInstance()->loadEnglishTranslation();
+ Translate::getInstance()->loadEnglishTranslation();
$exceptionToThrow = $this->createConfigObject();
@@ -247,7 +247,7 @@ class Piwik_FrontController
$this->handleMaintenanceMode();
$this->handleSSLRedirection();
- $pluginsManager = PluginsManager::getInstance();
+ $pluginsManager = \Piwik\PluginsManager::getInstance();
$pluginsToLoad = Config::getInstance()->Plugins['Plugins'];
$pluginsManager->loadPlugins($pluginsToLoad);
@@ -274,7 +274,7 @@ class Piwik_FrontController
Piwik_PostEvent('FrontController.dispatchCoreAndPluginUpdatesScreen');
- PluginsManager::getInstance()->installLoadedPlugins();
+ \Piwik\PluginsManager::getInstance()->installLoadedPlugins();
// ensure the current Piwik URL is known for later use
if (method_exists('Piwik\Piwik', 'getPiwikUrl')) {
@@ -299,7 +299,7 @@ class Piwik_FrontController
}
Piwik::raiseMemoryLimitIfNecessary();
- Piwik_Translate::getInstance()->reloadLanguage();
+ Translate::getInstance()->reloadLanguage();
$pluginsManager->postLoadPlugins();
Piwik_PostEvent('FrontController.checkForUpdates');
diff --git a/core/JqplotDataGenerator.php b/core/JqplotDataGenerator.php
index 3a1abd16b6..4ae3c493b2 100644
--- a/core/JqplotDataGenerator.php
+++ b/core/JqplotDataGenerator.php
@@ -11,6 +11,7 @@
use Piwik\Common;
use Piwik\Metrics;
+use Piwik\DataTable;
/**
* Generates JSON data used to configure and populate JQPlot graphs.
@@ -71,7 +72,7 @@ class Piwik_JqplotDataGenerator
/**
* Generates JSON graph data and returns it.
*
- * @param Piwik_DataTable|Piwik_DataTable_Array $dataTable
+ * @param DataTable|DataTable\Map $dataTable
* @return string
*/
public function generate($dataTable)
diff --git a/core/JqplotDataGenerator/Evolution.php b/core/JqplotDataGenerator/Evolution.php
index 50fd2a61a2..47c85f0724 100644
--- a/core/JqplotDataGenerator/Evolution.php
+++ b/core/JqplotDataGenerator/Evolution.php
@@ -10,6 +10,7 @@
*/
use Piwik\Piwik;
use Piwik\Common;
+use Piwik\DataTable;
/**
* Generates JQPlot JSON data/config for evolution graphs.
@@ -29,8 +30,8 @@ class Piwik_JqplotDataGenerator_Evolution extends Piwik_JqplotDataGenerator
protected function initChartObjectData($dataTable)
{
// if the loaded datatable is a simple DataTable, it is most likely a plugin plotting some custom data
- // we don't expect plugin developers to return a well defined Piwik_DataTable_Array
- if ($dataTable instanceof Piwik_DataTable) {
+ // we don't expect plugin developers to return a well defined Set
+ if ($dataTable instanceof DataTable) {
return parent::initChartObjectData($dataTable);
}
diff --git a/core/Loader.php b/core/Loader.php
index c0d2d14622..fc913112e9 100644
--- a/core/Loader.php
+++ b/core/Loader.php
@@ -9,12 +9,16 @@
* @package Piwik
*/
+namespace Piwik;
+
+use Exception;
+
/**
* Piwik auto loader
*
* @package Piwik
*/
-class Piwik_Loader
+class Loader
{
// our class search path; current directory is intentionally excluded
protected static $dirs = array('/core/', '/plugins/');
@@ -42,8 +46,9 @@ class Piwik_Loader
return $class;
}
- if (!strncmp($class, 'Piwik/', 6)) {
- return substr($class, 6);
+ $vendorPrefixToRemove = 'Piwik/';
+ if (strpos($class, $vendorPrefixToRemove) === 0) {
+ return substr($class, strlen($vendorPrefixToRemove));
}
return $class;
@@ -58,8 +63,9 @@ class Piwik_Loader
public static function loadClass($class)
{
$classPath = self::getClassFileName($class);
- if ($class == 'Piwik'
- || !strncmp($class, 'Piwik', 5) /* catches Piwik_ and Piwik\ */ ) {
+ if (strpos($class, '\Piwik') === 0
+ || strpos($class, 'Piwik') === 0)
+ {
// Piwik classes are in core/ or plugins/
do {
// auto-discover class location
@@ -107,7 +113,7 @@ class Piwik_Loader
// Note: only one __autoload per PHP instance
if (function_exists('spl_autoload_register')) {
// use the SPL autoload stack
- spl_autoload_register(array('Piwik_Loader', 'autoload'));
+ spl_autoload_register(array('Piwik\Loader', 'autoload'));
// preserve any existing __autoload
if (function_exists('__autoload')) {
@@ -116,6 +122,6 @@ if (function_exists('spl_autoload_register')) {
} else {
function __autoload($class)
{
- Piwik_Loader::autoload($class);
+ Loader::autoload($class);
}
}
diff --git a/core/Period.php b/core/Period.php
index f816b58c02..7edf4ea810 100644
--- a/core/Period.php
+++ b/core/Period.php
@@ -11,11 +11,11 @@
namespace Piwik;
use Exception;
use Piwik\Piwik;
-use Piwik_Date;
-use Piwik_Period_Day;
-use Piwik_Period_Month;
-use Piwik\Period_Range;
-use Piwik_Period_Week;
+use Piwik\Date;
+use Piwik\Period\Day;
+use Piwik\Period\Month;
+use Piwik\Period\Range;
+use Piwik\Period\Week;
use Piwik_Period_Year;
/**
@@ -47,14 +47,14 @@ abstract class Period
protected $label = null;
/**
- * @var Piwik_Date
+ * @var Date
*/
protected $date = null;
static protected $errorAvailablePeriods = 'day, week, month, year, range';
/**
* Constructor
- * @param Piwik_Date $date
+ * @param Date $date
*/
public function __construct($date)
{
@@ -64,23 +64,23 @@ abstract class Period
/**
* @param string $strPeriod "day", "week", "month", "year"
- * @param Piwik_Date $date Piwik_Date object
+ * @param Date $date Date object
* @throws Exception
* @return \Piwik\Period
*/
- static public function factory($strPeriod, Piwik_Date $date)
+ static public function factory($strPeriod, Date $date)
{
switch ($strPeriod) {
case 'day':
- return new Piwik_Period_Day($date);
+ return new Day($date);
break;
case 'week':
- return new Piwik_Period_Week($date);
+ return new Week($date);
break;
case 'month':
- return new Piwik_Period_Month($date);
+ return new Month($date);
break;
case 'year':
@@ -106,13 +106,13 @@ abstract class Period
return
is_string($dateString)
&& (preg_match('/^(last|previous){1}([0-9]*)$/D', $dateString, $regs)
- || Period_Range::parseDateRange($dateString))
+ || Range::parseDateRange($dateString))
&& $period != 'range';
}
/**
* The advanced factory method is easier to use from the API than the factory
- * method above. It doesn't require an instance of Piwik_Date and works for
+ * method above. It doesn't require an instance of Date and works for
* period=range. Generally speaking, anything that can be passed as period
* and range to the API methods can directly be forwarded to this factory
* method in order to get a suitable instance of Period.
@@ -124,9 +124,9 @@ abstract class Period
static public function advancedFactory($strPeriod, $strDate)
{
if (Period::isMultiplePeriod($strDate, $strPeriod) || $strPeriod == 'range') {
- return new Period_Range($strPeriod, $strDate);
+ return new Range($strPeriod, $strDate);
}
- return Period::factory($strPeriod, Piwik_Date::factory($strDate));
+ return Period::factory($strPeriod, Date::factory($strDate));
}
/**
@@ -145,15 +145,15 @@ abstract class Period
}
if ($period == 'range') {
- $oPeriod = new Period_Range('range', $date, $timezone, Piwik_Date::factory('today', $timezone));
+ $oPeriod = new Period\Range('range', $date, $timezone, Date::factory('today', $timezone));
} else {
- if (!($date instanceof Piwik_Date)) {
+ if (!($date instanceof Date)) {
if ($date == 'now' || $date == 'today') {
- $date = date('Y-m-d', Piwik_Date::factory('now', $timezone)->getTimestamp());
+ $date = date('Y-m-d', Date::factory('now', $timezone)->getTimestamp());
} elseif ($date == 'yesterday' || $date == 'yesterdaySameTime') {
- $date = date('Y-m-d', Piwik_Date::factory('now', $timezone)->subDay(1)->getTimestamp());
+ $date = date('Y-m-d', Date::factory('now', $timezone)->subDay(1)->getTimestamp());
}
- $date = Piwik_Date::factory($date);
+ $date = Date::factory($date);
}
$oPeriod = Period::factory($period, $date);
}
@@ -163,7 +163,7 @@ abstract class Period
/**
* Returns the first day of the period
*
- * @return Piwik_Date First day of the period
+ * @return Date First day of the period
*/
public function getDateStart()
{
@@ -185,7 +185,7 @@ abstract class Period
/**
* Returns the last day of the period ; can be a date in the future
*
- * @return Piwik_Date Last day of the period
+ * @return Date Last day of the period
*/
public function getDateEnd()
{
@@ -219,7 +219,7 @@ abstract class Period
}
/**
- * @return Piwik_Date
+ * @return Date
*/
protected function getDate()
{
@@ -227,16 +227,16 @@ abstract class Period
}
/**
- * Checks if the given date is an instance of Piwik_Date
+ * Checks if the given date is an instance of Date
*
- * @param Piwik_Date $date
+ * @param Date $date
*
* @throws Exception
*/
protected function checkInputDate($date)
{
- if (!($date instanceof Piwik_Date)) {
- throw new Exception("The date must be a Piwik_Date object. " . var_export($date, true));
+ if (!($date instanceof Date)) {
+ throw new Exception("The date must be a Date object. " . var_export($date, true));
}
}
diff --git a/core/Period/Day.php b/core/Period/Day.php
index 198662dbe7..a4ed18fbba 100644
--- a/core/Period/Day.php
+++ b/core/Period/Day.php
@@ -8,13 +8,15 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\Period;
+use Exception;
use Piwik\Period;
/**
* @package Piwik
* @subpackage Period
*/
-class Piwik_Period_Day extends Period
+class Day extends Period
{
protected $label = 'day';
@@ -76,7 +78,7 @@ class Piwik_Period_Day extends Period
*/
public function addSubperiod($date)
{
- throw new Exception("Adding a subperiod is not supported for Piwik_Period_Day");
+ throw new Exception("Adding a subperiod is not supported for Day");
}
/**
diff --git a/core/Period/Month.php b/core/Period/Month.php
index c65bc4179e..5434bd6efe 100644
--- a/core/Period/Month.php
+++ b/core/Period/Month.php
@@ -8,13 +8,15 @@
* @category Piwik
* @package Piwik
*/
-use Piwik\Period;
+namespace Piwik\Period;
+
+use Piwik\Period\Day;
/**
* @package Piwik
* @subpackage Period
*/
-class Piwik_Period_Month extends Period
+class Month extends Period
{
protected $label = 'month';
@@ -68,7 +70,7 @@ class Piwik_Period_Month extends Period
$startMonth = $date->setDay(1);
$currentDay = clone $startMonth;
while ($currentDay->compareMonth($startMonth) == 0) {
- $this->addSubperiod(new Piwik_Period_Day($currentDay));
+ $this->addSubperiod(new Day($currentDay));
$currentDay = $currentDay->addDay(1);
}
}
diff --git a/core/Period/Range.php b/core/Period/Range.php
index 8922adfa83..65e4854de0 100644
--- a/core/Period/Range.php
+++ b/core/Period/Range.php
@@ -8,13 +8,14 @@
* @category Piwik
* @package Piwik
*/
-namespace Piwik;
+namespace Piwik\Period;
+
use Exception;
use Piwik\Common;
use Piwik\Period;
-use Piwik_Date;
-use Piwik_Period_Month;
-use Piwik_Period_Week;
+use Piwik\Date;
+use Piwik\Period\Month;
+use Piwik\Period\Week;
/**
* from a starting date to an ending date
@@ -22,7 +23,7 @@ use Piwik_Period_Week;
* @package Piwik
* @subpackage Period
*/
-class Period_Range extends Period
+class Range extends Period
{
protected $label = 'range';
@@ -30,7 +31,7 @@ class Period_Range extends Period
* @param string $strPeriod
* @param string $strDate
* @param string $timezone
- * @param bool|Piwik_Date $today
+ * @param bool|Date $today
*/
public function __construct($strPeriod, $strDate, $timezone = 'UTC', $today = false)
{
@@ -39,7 +40,7 @@ class Period_Range extends Period
$this->defaultEndDate = null;
$this->timezone = $timezone;
if ($today === false) {
- $today = Piwik_Date::factory('today', $this->timezone);
+ $today = Date::factory('today', $this->timezone);
}
$this->today = $today;
}
@@ -74,7 +75,7 @@ class Period_Range extends Period
/**
* Returns the start date of the period
*
- * @return Piwik_Date
+ * @return Date
* @throws Exception
*/
public function getDateStart()
@@ -100,12 +101,12 @@ class Period_Range extends Period
/**
*
* @param string $period
- * @param Piwik_Date $date
+ * @param Date $date
* @param int $n
* @throws Exception
- * @return Piwik_Date
+ * @return Date
*/
- static public function removePeriod($period, Piwik_Date $date, $n)
+ static public function removePeriod($period, Date $date, $n)
{
switch ($period) {
case 'day':
@@ -155,9 +156,9 @@ class Period_Range extends Period
/**
* Sets the default end date of the period
*
- * @param Piwik_Date $oDate
+ * @param Date $oDate
*/
- public function setDefaultEndDate(Piwik_Date $oDate)
+ public function setDefaultEndDate(Date $oDate)
{
$this->defaultEndDate = $oDate;
}
@@ -180,7 +181,7 @@ class Period_Range extends Period
if (!is_null($this->defaultEndDate)) {
$defaultEndDate = $this->defaultEndDate;
} else {
- $defaultEndDate = Piwik_Date::factory('now', $this->timezone);
+ $defaultEndDate = Date::factory('now', $this->timezone);
}
$period = $this->strPeriod;
@@ -201,10 +202,10 @@ class Period_Range extends Period
$lastN = abs($lastN);
$startDate = self::removePeriod($period, $endDate, $lastN);
- } elseif ($dateRange = Period_Range::parseDateRange($this->strDate)) {
+ } elseif ($dateRange = Range::parseDateRange($this->strDate)) {
$strDateStart = $dateRange[1];
$strDateEnd = $dateRange[2];
- $startDate = Piwik_Date::factory($strDateStart);
+ $startDate = Date::factory($strDateStart);
if ($strDateEnd == 'today') {
$strDateEnd = 'now';
@@ -216,7 +217,7 @@ class Period_Range extends Period
if (strpos($strDateEnd, '-') === false) {
$timezone = $this->timezone;
}
- $endDate = Piwik_Date::factory($strDateEnd, $timezone);
+ $endDate = Date::factory($strDateEnd, $timezone);
} else {
throw new Exception(Piwik_TranslateException('General_ExceptionInvalidDateRange', array($this->strDate, ' \'lastN\', \'previousN\', \'YYYY-MM-DD,YYYY-MM-DD\'')));
}
@@ -251,7 +252,7 @@ class Period_Range extends Period
/**
* Returns the end date of the period
*
- * @return null|Piwik_Date
+ * @return null|Date
*/
public function getDateEnd()
{
@@ -274,7 +275,7 @@ class Period_Range extends Period
|| $startDate == $endDate) {
$endOfPeriod = null;
- $month = new Piwik_Period_Month($startDate);
+ $month = new Month($startDate);
$endOfMonth = $month->getDateEnd();
$startOfMonth = $month->getDateStart();
if ($startDate == $startOfMonth
@@ -293,7 +294,7 @@ class Period_Range extends Period
} else {
// From start date,
// Process end of week
- $week = new Piwik_Period_Week($startDate);
+ $week = new Week($startDate);
$startOfWeek = $week->getDateStart();
$endOfWeek = $week->getDateEnd();
@@ -327,8 +328,8 @@ class Period_Range extends Period
/**
* Adds new subperiods
*
- * @param Piwik_Date $startDate
- * @param Piwik_Date $endDate
+ * @param Date $startDate
+ * @param Date $endDate
* @param string $period
*/
protected function fillArraySubPeriods($startDate, $endDate, $period)
@@ -375,14 +376,14 @@ class Period_Range extends Period
if ($period != 'range' && !preg_match('/(last|previous)([0-9]*)/', $date, $regs)) {
if (strpos($date, ',')) // date in the form of 2011-01-01,2011-02-02
{
- $rangePeriod = new Period_Range($period, $date);
+ $rangePeriod = new Range($period, $date);
- $lastStartDate = Period_Range::removePeriod($period, $rangePeriod->getDateStart(), $n = 1);
- $lastEndDate = Period_Range::removePeriod($period, $rangePeriod->getDateEnd(), $n = 1);
+ $lastStartDate = Range::removePeriod($period, $rangePeriod->getDateStart(), $n = 1);
+ $lastEndDate = Range::removePeriod($period, $rangePeriod->getDateEnd(), $n = 1);
$strLastDate = "$lastStartDate,$lastEndDate";
} else {
- $lastPeriod = Period_Range::removePeriod($period, Piwik_Date::factory($date), $n = 1);
+ $lastPeriod = Range::removePeriod($period, Date::factory($date), $n = 1);
$strLastDate = $lastPeriod->toString();
}
}
diff --git a/core/Period/Week.php b/core/Period/Week.php
index 1933a0aa5c..370a05656b 100644
--- a/core/Period/Week.php
+++ b/core/Period/Week.php
@@ -8,13 +8,15 @@
* @category Piwik
* @package Piwik
*/
-use Piwik\Period;
+namespace Piwik\Period;
+
+use Piwik\Period\Day;
/**
* @package Piwik
* @subpackage Period
*/
-class Piwik_Period_Week extends Period
+class Week extends Period
{
protected $label = 'week';
@@ -88,7 +90,7 @@ class Piwik_Period_Week extends Period
$currentDay = clone $startWeek;
while ($currentDay->compareWeek($startWeek) == 0) {
- $this->addSubperiod(new Piwik_Period_Day($currentDay));
+ $this->addSubperiod(new Day($currentDay));
$currentDay = $currentDay->addDay(1);
}
}
diff --git a/core/Period/Year.php b/core/Period/Year.php
index d83e2ac842..56cc52fa6b 100644
--- a/core/Period/Year.php
+++ b/core/Period/Year.php
@@ -9,6 +9,8 @@
* @package Piwik
*/
use Piwik\Period;
+use Piwik\Date;
+use Piwik\Period\Month;
/**
* @package Piwik
@@ -63,8 +65,8 @@ class Piwik_Period_Year extends Period
$year = $this->date->toString("Y");
for ($i = 1; $i <= 12; $i++) {
- $this->addSubperiod(new Piwik_Period_Month(
- Piwik_Date::factory("$year-$i-01")
+ $this->addSubperiod(new Month(
+ Date::factory("$year-$i-01")
)
);
}
diff --git a/core/Piwik.php b/core/Piwik.php
index 5f2c57e111..5edff85b19 100644
--- a/core/Piwik.php
+++ b/core/Piwik.php
@@ -23,7 +23,7 @@ use Piwik_Log_Error;
use Piwik_Log_Exception;
use Piwik_Log_Formatter_ScreenFormatter;
use Piwik_Log_Message;
-use Piwik_Plugin;
+use Piwik\Plugin;
use Piwik_Session;
use Piwik\Site;
use Piwik_Tracker;
@@ -1250,7 +1250,7 @@ class Piwik
return "$usage Mb";
}
- /*
+/*
* Amounts, Percentages, Currency, Time, Math Operations, and Pretty Printing
*/
@@ -1842,11 +1842,11 @@ class Piwik
/**
* Returns the plugin currently being used to display the page
*
- * @return Piwik_Plugin
+ * @return Plugin
*/
static public function getCurrentPlugin()
{
- return PluginsManager::getInstance()->getLoadedPlugin(Piwik::getModule());
+ return \Piwik\PluginsManager::getInstance()->getLoadedPlugin(Piwik::getModule());
}
/**
diff --git a/core/Plugin.php b/core/Plugin.php
index bec854cd9e..06aa0534ec 100644
--- a/core/Plugin.php
+++ b/core/Plugin.php
@@ -8,7 +8,9 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik;
use Piwik\Common;
+use Piwik\Plugin\MetadataLoader;
/**
* @see core/Plugin/MetadataLoader.php
@@ -16,30 +18,30 @@ use Piwik\Common;
require_once PIWIK_INCLUDE_PATH . '/core/Plugin/MetadataLoader.php';
/**
- * Abstract class to define a Piwik_Plugin.
+ * Abstract class to define a Plugin.
* Any plugin has to at least implement the abstract methods of this class.
*
* @package Piwik
*/
-class Piwik_Plugin
+class Plugin
{
/**
* Name of this plugin.
- *
+ *
* @var string
*/
protected $pluginName;
-
+
/**
* Holds plugin metadata.
- *
+ *
* @var array
*/
private $pluginInformation;
-
+
/**
* Constructor.
- *
+ *
* @param string|bool $pluginName A plugin name to force. If not supplied, it is set
* to last part of the class name.
*/
@@ -49,11 +51,11 @@ class Piwik_Plugin
$pluginName = Common::unprefixClass(get_class($this));
}
$this->pluginName = $pluginName;
-
- $metadataLoader = new Piwik_Plugin_MetadataLoader($pluginName);
+
+ $metadataLoader = new MetadataLoader($pluginName);
$this->pluginInformation = $metadataLoader->load();
}
-
+
/**
* Returns the plugin details
* - 'description' => string // 1-2 sentence description of the plugin
diff --git a/core/Plugin/MetadataLoader.php b/core/Plugin/MetadataLoader.php
index f2e6191dc2..335442f31c 100644
--- a/core/Plugin/MetadataLoader.php
+++ b/core/Plugin/MetadataLoader.php
@@ -8,8 +8,11 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik\Plugin;
+
+use Exception;
use Piwik\Common;
-use Piwik\PluginsManager;
+use Piwik_Version;
/**
* @see core/Version.php
@@ -21,24 +24,24 @@ require_once PIWIK_INCLUDE_PATH . '/core/Version.php';
* - plugin.piwik.json
* - colors.piwik.json
*/
-class Piwik_Plugin_MetadataLoader
+class MetadataLoader
{
const PLUGIN_JSON_FILENAME = 'plugin.piwik.json';
const COLORS_JSON_FILENAME = 'colors.piwik.json';
-
+
const SHORT_COLOR_LENGTH = 4;
const LONG_COLOR_LENGTH = 7;
-
+
/**
* The name of the plugin whose metadata will be loaded.
- *
+ *
* @var string
*/
private $pluginName;
-
+
/**
* Constructor.
- *
+ *
* @param string $pluginName Name of the plugin to load metadata.
*/
public function __construct($pluginName)
@@ -48,7 +51,7 @@ class Piwik_Plugin_MetadataLoader
/**
* Loads plugin metadata. @see Piwik_Plugin::getInformation.
- *
+ *
* @return array
*/
public function load()
@@ -59,7 +62,7 @@ class Piwik_Plugin_MetadataLoader
$this->loadPluginColorsJson()
);
}
-
+
private function getDefaultPluginInformation()
{
$descriptionKey = $this->pluginName . '_PluginDescription';
@@ -74,21 +77,21 @@ class Piwik_Plugin_MetadataLoader
'theme' => false,
);
}
-
+
private function loadPluginInfoJson()
{
- $path = PluginsManager::getPluginsDirectory() . $this->pluginName . '/' . self::PLUGIN_JSON_FILENAME;
+ $path = \Piwik\PluginsManager::getPluginsDirectory() . $this->pluginName . '/' . self::PLUGIN_JSON_FILENAME;
return $this->loadJsonMetadata($path);
}
-
+
private function loadPluginColorsJson()
{
- $path = PluginsManager::getPluginsDirectory() . $this->pluginName . '/' . self::COLORS_JSON_FILENAME;
+ $path = \Piwik\PluginsManager::getPluginsDirectory() . $this->pluginName . '/' . self::COLORS_JSON_FILENAME;
$info = $this->loadJsonMetadata($path);
$info = $this->cleanAndValidatePluginColorsJson($path, $info);
return $info;
}
-
+
private function cleanAndValidatePluginColorsJson($path, $info)
{
// check that if "colors" exists, it is an array
@@ -96,17 +99,17 @@ class Piwik_Plugin_MetadataLoader
if (!is_array($colors)) {
throw new Exception("The 'colors' value in '$path' must be an object mapping names with colors.");
}
-
+
// validate each color
foreach ($colors as $color) {
if (!$this->isStringColorValid($color)) {
throw new Exception("Invalid color string '$color' in '$path'.");
}
}
-
+
return array("colors" => $colors); // make sure only 'colors' element is loaded
}
-
+
private function isStringColorValid($color)
{
if (strlen($color) !== self::SHORT_COLOR_LENGTH
@@ -114,25 +117,25 @@ class Piwik_Plugin_MetadataLoader
) {
return false;
}
-
+
if ($color[0] !== '#') {
return false;
}
-
+
return ctype_xdigit(substr($color, 1)); // check if other digits are hex
}
-
+
private function loadJsonMetadata($path)
{
if (!file_exists($path)) {
return array();
}
-
+
$json = file_get_contents($path);
if (!$json) {
return array();
}
-
+
$info = Common::json_decode($json, $assoc = true);
if (!is_array($info)
|| empty($info)
diff --git a/core/PluginsArchiver.php b/core/PluginsArchiver.php
index aac3b936da..dd49ba37e7 100644
--- a/core/PluginsArchiver.php
+++ b/core/PluginsArchiver.php
@@ -1,5 +1,4 @@
<?php
-
/**
* Piwik - Open source web analytics
*
@@ -9,17 +8,22 @@
* @category Piwik
* @package Piwik_PluginArchiver
*/
+
+namespace Piwik;
use Piwik\Config;
use Piwik\Common;
+use Piwik\ArchiveProcessor;
+use Piwik\ArchiveProcessor\Day;
+use Piwik\DataAccess\LogAggregator;
/**
* Plugins that archive metrics for websites can implement an Archiver that extends this class
*/
-abstract class Piwik_PluginsArchiver
+abstract class PluginsArchiver
{
protected $processor;
- public function __construct(Piwik_ArchiveProcessor $processing)
+ public function __construct(ArchiveProcessor $processing)
{
$this->maximumRows = Config::getInstance()->General['datatable_archiving_maximum_rows_standard'];
$this->processor = $processing;
@@ -38,7 +42,7 @@ abstract class Piwik_PluginsArchiver
}
/**
- * @return Piwik_ArchiveProcessor_Day|Piwik_ArchiveProcessor_Period
+ * @return Day|Period
*/
protected function getProcessor()
{
@@ -46,7 +50,7 @@ abstract class Piwik_PluginsArchiver
}
/**
- * @return Piwik_DataAccess_LogAggregator
+ * @return \Piwik\DataAccess\LogAggregator
*/
protected function getLogAggregator()
{
diff --git a/core/PluginsManager.php b/core/PluginsManager.php
index 4fb4c82f68..4660a37cd2 100644
--- a/core/PluginsManager.php
+++ b/core/PluginsManager.php
@@ -14,6 +14,9 @@ namespace Piwik;
use Piwik\Config;
use Piwik\Piwik;
use Piwik\Common;
+use Piwik\EventDispatcher;
+use Piwik\Translate;
+use Piwik\Plugin\MetadataLoader;
/**
* @see core/Menu/Abstract.php
@@ -337,7 +340,7 @@ class PluginsManager
{
$plugins = $this->getLoadedPlugins();
foreach($plugins as $plugin) {
- /* @var $plugin Piwik_Plugin */
+ /* @var $plugin Plugin */
if($plugin->isTheme()
&& $plugin->getPluginName() != self::DEFAULT_THEME) {
return $plugin->getPluginName();
@@ -385,7 +388,7 @@ class PluginsManager
public function loadPluginTranslations($language = false)
{
if (empty($language)) {
- $language = Piwik_Translate::getInstance()->getLanguageToLoad();
+ $language = Translate::getInstance()->getLanguageToLoad();
}
$plugins = $this->getLoadedPlugins();
@@ -419,11 +422,11 @@ class PluginsManager
/**
* Returns an array of key,value with the following format: array(
- * 'UserCountry' => Piwik_Plugin $pluginObject,
- * 'UserSettings' => Piwik_Plugin $pluginObject,
+ * 'UserCountry' => Plugin $pluginObject,
+ * 'UserSettings' => Plugin $pluginObject,
* );
*
- * @return array,Piwik_Plugin
+ * @return array,Plugin
*/
public function getLoadedPlugins()
{
@@ -431,7 +434,7 @@ class PluginsManager
}
/**
- * Returns the given Piwik_Plugin object
+ * Returns the given Plugin object
*
* @param string $name
* @throws Exception
@@ -484,7 +487,7 @@ class PluginsManager
$this->addLoadedPlugin($pluginName, $newPlugin);
- Piwik_EventDispatcher::getInstance()->postPendingEventsTo($newPlugin);
+ EventDispatcher::getInstance()->postPendingEventsTo($newPlugin);
return $newPlugin;
}
@@ -508,19 +511,18 @@ class PluginsManager
if (!file_exists($path)) {
// Create the smallest minimal Piwik Plugin
// Eg. Used for Zeitgeist default theme which does not have a Zeitgeist.php file
- return new Piwik_Plugin($pluginName);
+ return new Plugin($pluginName);
}
require_once $path;
if (!class_exists($pluginClassName, false)) {
- throw new Exception("The class $pluginClassName couldn't be found in the file '$path'");
+ throw new \Exception("The class $pluginClassName couldn't be found in the file '$path'");
}
$newPlugin = new $pluginClassName();
- var_dump(get_class($newPlugin));
- if (!($newPlugin instanceof Piwik_Plugin)) {
- throw new \Exception("The plugin $pluginClassName in the file $path must inherit from Piwik_Plugin.");
+ if (!($newPlugin instanceof Plugin)) {
+ throw new \Exception("The plugin $pluginClassName in the file $path must inherit from Plugin.");
}
return $newPlugin;
}
@@ -570,10 +572,10 @@ class PluginsManager
/**
* Install a specific plugin
*
- * @param Piwik_Plugin $plugin
+ * @param Plugin $plugin
* @throws Piwik_PluginsManager_PluginException if installation fails
*/
- private function installPlugin(Piwik_Plugin $plugin)
+ private function installPlugin(Plugin $plugin)
{
try {
$plugin->install();
@@ -586,9 +588,9 @@ class PluginsManager
* Add a plugin in the loaded plugins array
*
* @param string $pluginName plugin name without prefix (eg. 'UserCountry')
- * @param Piwik_Plugin $newPlugin
+ * @param Plugin $newPlugin
*/
- private function addLoadedPlugin($pluginName, Piwik_Plugin $newPlugin)
+ private function addLoadedPlugin($pluginName, Plugin $newPlugin)
{
$this->loadedPlugins[$pluginName] = $newPlugin;
}
@@ -596,15 +598,15 @@ class PluginsManager
/**
* Load translation
*
- * @param Piwik_Plugin $plugin
+ * @param Plugin $plugin
* @param string $langCode
* @throws Exception
* @return bool whether the translation was found and loaded
*/
private function loadTranslation($plugin, $langCode)
{
- // we are in Tracker mode if Piwik_Loader is not (yet) loaded
- if (!class_exists('Piwik_Loader', false)) {
+ // we are in Tracker mode if Loader is not (yet) loaded
+ if (!class_exists('Piwik\Loader', false)) {
return;
}
@@ -624,7 +626,7 @@ class PluginsManager
} else {
return false;
}
- Piwik_Translate::getInstance()->mergeTranslationArray($translations);
+ Translate::getInstance()->mergeTranslationArray($translations);
return true;
}
@@ -652,7 +654,7 @@ class PluginsManager
$plugins = Config::getInstance()->Plugins['Plugins'];
foreach ($plugins as $pluginName) {
// if a plugin is listed in the config, but is not loaded, it does not exist in the folder
- if (!PluginsManager::getInstance()->isPluginLoaded($pluginName)) {
+ if (!\Piwik\PluginsManager::getInstance()->isPluginLoaded($pluginName)) {
$missingPlugins[] = $pluginName;
}
}
@@ -663,9 +665,9 @@ class PluginsManager
/**
* Install a plugin, if necessary
*
- * @param Piwik_Plugin $plugin
+ * @param Plugin $plugin
*/
- private function installPluginIfNecessary(Piwik_Plugin $plugin)
+ private function installPluginIfNecessary(Plugin $plugin)
{
$pluginName = $plugin->getPluginName();
@@ -697,7 +699,7 @@ class PluginsManager
}
}
- protected function isTrackerPlugin(Piwik_Plugin $plugin)
+ protected function isTrackerPlugin(Plugin $plugin)
{
$hooks = $plugin->getListHooksRegistered();
$hookNames = array_keys($hooks);
@@ -713,7 +715,7 @@ class PluginsManager
{
$name = basename($path);
return file_exists($path . "/" . $name . ".php")
- || file_exists($path . "/" . Piwik_Plugin_MetadataLoader::PLUGIN_JSON_FILENAME);
+ || file_exists($path . "/" . MetadataLoader::PLUGIN_JSON_FILENAME);
}
}
diff --git a/core/ReportRenderer.php b/core/ReportRenderer.php
index e4125cf18f..7d43bf4856 100644
--- a/core/ReportRenderer.php
+++ b/core/ReportRenderer.php
@@ -8,7 +8,11 @@
* @category Piwik
* @package Piwik
*/
+use Piwik\DataTable\Simple;
+use Piwik\DataTable\Row;
use Piwik\Piwik;
+use Piwik\DataTable;
+use Piwik\Loader;
/**
* A Report Renderer produces user friendly renderings of any given Piwik report.
@@ -48,7 +52,7 @@ abstract class Piwik_ReportRenderer
$className = 'Piwik_ReportRenderer_' . $name;
try {
- Piwik_Loader::loadClass($className);
+ Loader::loadClass($className);
return new $className;
} catch (Exception $e) {
@@ -186,9 +190,9 @@ abstract class Piwik_ReportRenderer
*
* @static
* @param $reportMetadata array
- * @param $report Piwik_DataTable
+ * @param $report DataTable
* @param $reportColumns array
- * @return array Piwik_DataTable $report & array $columns
+ * @return array DataTable $report & array $columns
*/
protected static function processTableFormat($reportMetadata, $report, $reportColumns)
{
@@ -196,9 +200,9 @@ abstract class Piwik_ReportRenderer
if (empty($reportMetadata['dimension'])) {
$simpleReportMetrics = $report->getFirstRow();
if ($simpleReportMetrics) {
- $finalReport = new Piwik_DataTable_Simple();
+ $finalReport = new Simple();
foreach ($simpleReportMetrics->getColumns() as $metricId => $metric) {
- $newRow = new Piwik_DataTable_Row();
+ $newRow = new Row();
$newRow->addColumn("label", $reportColumns[$metricId]);
$newRow->addColumn("value", $metric);
$finalReport->addRow($newRow);
diff --git a/core/Site.php b/core/Site.php
index da655b9a74..b0824e77ee 100644
--- a/core/Site.php
+++ b/core/Site.php
@@ -11,7 +11,7 @@
namespace Piwik;
use Exception;
-use Piwik_Date;
+use Piwik\Date;
use Piwik_SitesManager_API;
/**
@@ -127,12 +127,12 @@ class Site
/**
* Returns the creation date of the site
*
- * @return Piwik_Date
+ * @return Date
*/
function getCreationDate()
{
$date = $this->get('ts_created');
- return Piwik_Date::factory($date);
+ return Date::factory($date);
}
/**
diff --git a/core/Tracker.php b/core/Tracker.php
index a5d9bc0186..a5fb093b95 100644
--- a/core/Tracker.php
+++ b/core/Tracker.php
@@ -12,6 +12,7 @@ use Piwik\Config;
use Piwik\Piwik;
use Piwik\Common;
use Piwik\Access;
+use Piwik\Translate;
/**
* Class used by the logging script piwik.php called by the javascript tag.
@@ -313,7 +314,7 @@ class Piwik_Tracker
// While each plugins should ensure that necessary languages are loaded,
// we ensure English translations at least are loaded
- Piwik_Translate::getInstance()->loadEnglishTranslation();
+ Translate::getInstance()->loadEnglishTranslation();
$resultTasks = Piwik_TaskScheduler::runTasks();
@@ -352,7 +353,7 @@ class Piwik_Tracker
Piwik::createDatabaseObject();
}
- $pluginsManager = PluginsManager::getInstance();
+ $pluginsManager = \Piwik\PluginsManager::getInstance();
$pluginsToLoad = Config::getInstance()->Plugins['Plugins'];
$pluginsForcedNotToLoad = Piwik_Tracker::getPluginsNotToLoad();
$pluginsToLoad = array_diff($pluginsToLoad, $pluginsForcedNotToLoad);
@@ -603,9 +604,9 @@ class Piwik_Tracker
$pluginsTracker = Config::getInstance()->Plugins_Tracker['Plugins_Tracker'];
if (count($pluginsTracker) > 0) {
$pluginsTracker = array_diff($pluginsTracker, self::getPluginsNotToLoad());
- PluginsManager::getInstance()->doNotLoadAlwaysActivatedPlugins();
+ \Piwik\PluginsManager::getInstance()->doNotLoadAlwaysActivatedPlugins();
- PluginsManager::getInstance()->loadPlugins($pluginsTracker);
+ \Piwik\PluginsManager::getInstance()->loadPlugins($pluginsTracker);
Common::printDebug("Loading plugins: { " . implode(",", $pluginsTracker) . " }");
}
diff --git a/core/Tracker/Cache.php b/core/Tracker/Cache.php
index 4f7e5809f3..72910c11e0 100644
--- a/core/Tracker/Cache.php
+++ b/core/Tracker/Cache.php
@@ -8,6 +8,7 @@
* @category Piwik
* @package Piwik
*/
+use Piwik\ArchiveProcessor\Rules;
use Piwik\Config;
use Piwik\Piwik;
@@ -96,7 +97,7 @@ class Piwik_Tracker_Cache
Piwik_Tracker::initCorePiwikInTrackerMode();
$cacheContent = array(
- 'isBrowserTriggerEnabled' => Piwik_ArchiveProcessor_Rules::isBrowserTriggerEnabled(),
+ 'isBrowserTriggerEnabled' => Rules::isBrowserTriggerEnabled(),
'lastTrackerCronRun' => Piwik_GetOption('lastTrackerCronRun'),
'currentLocationProviderId' => Piwik_UserCountry_LocationProvider::getCurrentProviderId(),
);
diff --git a/core/Translate.php b/core/Translate.php
index fb2759b289..23b1e26371 100644
--- a/core/Translate.php
+++ b/core/Translate.php
@@ -8,20 +8,22 @@
* @category Piwik
* @package Piwik
*/
+namespace Piwik;
+use Exception;
use Piwik\Config;
use Piwik\Common;
/**
* @package Piwik
*/
-class Piwik_Translate
+class Translate
{
static private $instance = null;
static private $languageToLoad = null;
private $loadedLanguage = false;
/**
- * @return Piwik_Translate
+ * @return \Piwik\Translate
*/
static public function getInstance()
{
@@ -49,7 +51,7 @@ class Piwik_Translate
$this->unloadEnglishTranslation();
$this->loadEnglishTranslation();
$this->loadCoreTranslation($language);
- PluginsManager::getInstance()->loadPluginTranslations($language);
+ \Piwik\PluginsManager::getInstance()->loadPluginTranslations($language);
}
/**
@@ -180,40 +182,3 @@ class Piwik_Translate
}
}
-/**
- * Returns translated string or given message if translation is not found.
- *
- * @param string $string Translation string index
- * @param array|string|int $args sprintf arguments
- * @return string
- */
-function Piwik_Translate($string, $args = array())
-{
- if (!is_array($args)) {
- $args = array($args);
- }
- if (isset($GLOBALS['Piwik_translations'][$string])) {
- $string = $GLOBALS['Piwik_translations'][$string];
- }
- if (count($args) == 0) {
- return $string;
- }
- return vsprintf($string, $args);
-}
-
-/**
- * Returns translated string or given message if translation is not found.
- * This function does not throw any exception. Use it to translate exceptions.
- *
- * @param string $message Translation string index
- * @param array $args sprintf arguments
- * @return string
- */
-function Piwik_TranslateException($message, $args = array())
-{
- try {
- return Piwik_Translate($message, $args);
- } catch (Exception $e) {
- return $message;
- }
-}
diff --git a/core/Twig.php b/core/Twig.php
index 58b1e0cef1..124f018fb5 100644
--- a/core/Twig.php
+++ b/core/Twig.php
@@ -10,7 +10,7 @@
*/
use Piwik\Piwik;
use Piwik\Common;
-
+use Piwik\Translate;
/**
* Twig class
@@ -108,7 +108,7 @@ class Piwik_Twig
return;
}
$pluginTranslationsAlreadyLoaded[] = $plugins;
- $jsTranslations = Piwik_Translate::getInstance()->getJavascriptTranslations($plugins);
+ $jsTranslations = Translate::getInstance()->getJavascriptTranslations($plugins);
$jsCode = '';
if ($disableScriptTag) {
$jsCode .= $jsTranslations;
@@ -136,7 +136,7 @@ class Piwik_Twig
private function getDefaultThemeLoader()
{
$themeLoader = new Twig_Loader_Filesystem(array(
- sprintf("%s/plugins/%s/templates/", PIWIK_INCLUDE_PATH, PluginsManager::DEFAULT_THEME)
+ sprintf("%s/plugins/%s/templates/", PIWIK_INCLUDE_PATH, \Piwik\PluginsManager::DEFAULT_THEME)
));
return $themeLoader;
@@ -213,7 +213,7 @@ class Piwik_Twig
private function addPluginNamespaces(Twig_Loader_Filesystem $loader)
{
- $plugins = PluginsManager::getInstance()->getLoadedPluginsName();
+ $plugins = \Piwik\PluginsManager::getInstance()->getLoadedPluginsName();
foreach($plugins as $name) {
$name = Common::unprefixClass($name);
$path = sprintf("%s/plugins/%s/templates/", PIWIK_INCLUDE_PATH, $name);
diff --git a/core/Updates/0.6-rc1.php b/core/Updates/0.6-rc1.php
index 9f63064eac..f383115ae1 100644
--- a/core/Updates/0.6-rc1.php
+++ b/core/Updates/0.6-rc1.php
@@ -45,8 +45,8 @@ class Piwik_Updates_0_6_rc1 extends Piwik_Updates
);
$disabledPlugins = array();
foreach ($pluginsToDisableMessage as $pluginToDisable => $warningMessage) {
- if (PluginsManager::getInstance()->isPluginActivated($pluginToDisable)) {
- PluginsManager::getInstance()->deactivatePlugin($pluginToDisable);
+ if (\Piwik\PluginsManager::getInstance()->isPluginActivated($pluginToDisable)) {
+ \Piwik\PluginsManager::getInstance()->deactivatePlugin($pluginToDisable);
$disabledPlugins[] = $warningMessage;
}
}
diff --git a/core/Updates/1.10-b4.php b/core/Updates/1.10-b4.php
index 5460b7f540..59ae4cda68 100755
--- a/core/Updates/1.10-b4.php
+++ b/core/Updates/1.10-b4.php
@@ -22,7 +22,7 @@ class Piwik_Updates_1_10_b4 extends Piwik_Updates
static function update()
{
try {
- PluginsManager::getInstance()->activatePlugin('MobileMessaging');
+ \Piwik\PluginsManager::getInstance()->activatePlugin('MobileMessaging');
} catch (Exception $e) {
// pass
}
diff --git a/core/Updates/1.10.1.php b/core/Updates/1.10.1.php
index 879a20de02..38a2b53e7f 100755
--- a/core/Updates/1.10.1.php
+++ b/core/Updates/1.10.1.php
@@ -22,7 +22,7 @@ class Piwik_Updates_1_10_1 extends Piwik_Updates
static function update()
{
try {
- PluginsManager::getInstance()->activatePlugin('Overlay');
+ \Piwik\PluginsManager::getInstance()->activatePlugin('Overlay');
} catch (Exception $e) {
// pass
}
diff --git a/core/Updates/1.11-b1.php b/core/Updates/1.11-b1.php
index 9acfb359fa..3f7a31904e 100644
--- a/core/Updates/1.11-b1.php
+++ b/core/Updates/1.11-b1.php
@@ -22,7 +22,7 @@ class Piwik_Updates_1_11_b1 extends Piwik_Updates
static function update()
{
try {
- PluginsManager::getInstance()->activatePlugin('UserCountryMap');
+ \Piwik\PluginsManager::getInstance()->activatePlugin('UserCountryMap');
} catch (Exception $e) {
// pass
}
diff --git a/core/Updates/1.12-b15.php b/core/Updates/1.12-b15.php
index 49d72e2199..ea66360caf 100644
--- a/core/Updates/1.12-b15.php
+++ b/core/Updates/1.12-b15.php
@@ -17,7 +17,7 @@ class Piwik_Updates_1_12_b15 extends Piwik_Updates
static function update()
{
try {
- PluginsManager::getInstance()->activatePlugin('SegmentEditor');
+ \Piwik\PluginsManager::getInstance()->activatePlugin('SegmentEditor');
} catch (Exception $e) {
// pass
}
diff --git a/core/Updates/1.2-rc1.php b/core/Updates/1.2-rc1.php
index b7636a1225..36c9e42899 100644
--- a/core/Updates/1.2-rc1.php
+++ b/core/Updates/1.2-rc1.php
@@ -122,8 +122,8 @@ class Piwik_Updates_1_2_rc1 extends Piwik_Updates
);
$disabledPlugins = array();
foreach ($pluginsToDisableMessage as $pluginToDisable => $warningMessage) {
- if (PluginsManager::getInstance()->isPluginActivated($pluginToDisable)) {
- PluginsManager::getInstance()->deactivatePlugin($pluginToDisable);
+ if (\Piwik\PluginsManager::getInstance()->isPluginActivated($pluginToDisable)) {
+ \Piwik\PluginsManager::getInstance()->deactivatePlugin($pluginToDisable);
$disabledPlugins[] = $warningMessage;
}
}
diff --git a/core/Updates/1.2-rc2.php b/core/Updates/1.2-rc2.php
index 7f086ef56e..0ab9c30bdc 100644
--- a/core/Updates/1.2-rc2.php
+++ b/core/Updates/1.2-rc2.php
@@ -17,7 +17,7 @@ class Piwik_Updates_1_2_rc2 extends Piwik_Updates
static function update()
{
try {
- PluginsManager::getInstance()->activatePlugin('CustomVariables');
+ \Piwik\PluginsManager::getInstance()->activatePlugin('CustomVariables');
} catch (Exception $e) {
}
}
diff --git a/core/Updates/1.5-rc6.php b/core/Updates/1.5-rc6.php
index 289f44b32b..1015ef63db 100644
--- a/core/Updates/1.5-rc6.php
+++ b/core/Updates/1.5-rc6.php
@@ -17,7 +17,7 @@ class Piwik_Updates_1_5_rc6 extends Piwik_Updates
static function update()
{
try {
- PluginsManager::getInstance()->activatePlugin('PrivacyManager');
+ \Piwik\PluginsManager::getInstance()->activatePlugin('PrivacyManager');
} catch (Exception $e) {
}
}
diff --git a/core/Updates/1.6-rc1.php b/core/Updates/1.6-rc1.php
index 91909b980e..b838a03727 100644
--- a/core/Updates/1.6-rc1.php
+++ b/core/Updates/1.6-rc1.php
@@ -17,7 +17,7 @@ class Piwik_Updates_1_6_rc1 extends Piwik_Updates
static function update()
{
try {
- PluginsManager::getInstance()->activatePlugin('ImageGraph');
+ \Piwik\PluginsManager::getInstance()->activatePlugin('ImageGraph');
} catch (Exception $e) {
}
}
diff --git a/core/Updates/1.8.3-b1.php b/core/Updates/1.8.3-b1.php
index 334d1b9a07..99084a2814 100644
--- a/core/Updates/1.8.3-b1.php
+++ b/core/Updates/1.8.3-b1.php
@@ -43,7 +43,7 @@ class Piwik_Updates_1_8_3_b1 extends Piwik_Updates
static function update()
{
Piwik_Updater::updateDatabase(__FILE__, self::getSql());
- if (!PluginsManager::getInstance()->isPluginLoaded('PDFReports')) {
+ if (!\Piwik\PluginsManager::getInstance()->isPluginLoaded('PDFReports')) {
return;
}
diff --git a/core/Updates/1.9-b19.php b/core/Updates/1.9-b19.php
index 771459b999..03f142de0d 100755
--- a/core/Updates/1.9-b19.php
+++ b/core/Updates/1.9-b19.php
@@ -33,7 +33,7 @@ class Piwik_Updates_1_9_b19 extends Piwik_Updates
try {
- PluginsManager::getInstance()->activatePlugin('Transitions');
+ \Piwik\PluginsManager::getInstance()->activatePlugin('Transitions');
} catch (Exception $e) {
}
}
diff --git a/core/Updates/1.9.3-b10.php b/core/Updates/1.9.3-b10.php
index 0bdff3f713..97e2cd5d5e 100755
--- a/core/Updates/1.9.3-b10.php
+++ b/core/Updates/1.9.3-b10.php
@@ -22,7 +22,7 @@ class Piwik_Updates_1_9_3_b10 extends Piwik_Updates
static function update()
{
try {
- PluginsManager::getInstance()->activatePlugin('Annotations');
+ \Piwik\PluginsManager::getInstance()->activatePlugin('Annotations');
} catch (Exception $e) {
// pass
}
diff --git a/core/Updates/1.9.3-b3.php b/core/Updates/1.9.3-b3.php
index 67e84c6351..60257c6884 100644
--- a/core/Updates/1.9.3-b3.php
+++ b/core/Updates/1.9.3-b3.php
@@ -19,9 +19,9 @@ class Piwik_Updates_1_9_3_b3 extends Piwik_Updates
// Insight was a temporary code name for Overlay
$pluginToDelete = 'Insight';
self::deletePluginFromConfigFile($pluginToDelete);
- PluginsManager::getInstance()->deletePluginFromFilesystem($pluginToDelete);
+ \Piwik\PluginsManager::getInstance()->deletePluginFromFilesystem($pluginToDelete);
// We also clean up 1.9.1 and delete Feedburner plugin
- PluginsManager::getInstance()->deletePluginFromFilesystem('Feedburner');
+ \Piwik\PluginsManager::getInstance()->deletePluginFromFilesystem('Feedburner');
}
}
diff --git a/core/ViewDataTable.php b/core/ViewDataTable.php
index 5ad12b1aae..decc8a0cd0 100644
--- a/core/ViewDataTable.php
+++ b/core/ViewDataTable.php
@@ -11,9 +11,11 @@
use Piwik\Config;
use Piwik\Metrics;
use Piwik\Period;
-use Piwik\Period_Range;
+use Piwik\Period\Range;
use Piwik\Piwik;
use Piwik\Common;
+use Piwik\Date;
+use Piwik\DataTable;
use Piwik\Site;
/**
@@ -82,7 +84,7 @@ abstract class Piwik_ViewDataTable
/**
* DataTable loaded from the API for this ViewDataTable.
*
- * @var Piwik_DataTable
+ * @var DataTable
*/
protected $dataTable = null;
@@ -377,7 +379,7 @@ abstract class Piwik_ViewDataTable
$this->viewProperties['report_id'] = $currentControllerName . '.' . $currentControllerAction;
$this->viewProperties['self_url'] = $this->getBaseReportUrl($currentControllerName, $currentControllerAction);
- if (!PluginsManager::getInstance()->isPluginActivated('Goals')) {
+ if (!\Piwik\PluginsManager::getInstance()->isPluginActivated('Goals')) {
$this->viewProperties['show_goals'] = false;
}
@@ -444,7 +446,7 @@ abstract class Piwik_ViewDataTable
/**
* Returns the DataTable loaded from the API
*
- * @return Piwik_DataTable
+ * @return DataTable
* @throws exception if not yet defined
*/
public function getDataTable()
@@ -460,7 +462,7 @@ abstract class Piwik_ViewDataTable
* It won't be loaded again from the API in this case
*
* @param $dataTable
- * @return void $dataTable Piwik_DataTable
+ * @return void $dataTable DataTable
*/
public function setDataTable($dataTable)
{
@@ -522,7 +524,7 @@ abstract class Piwik_ViewDataTable
* Function called by the ViewDataTable objects in order to fetch data from the API.
* The function init() must have been called before, so that the object knows which API module and action to call.
* It builds the API request string and uses Piwik_API_Request to call the API.
- * The requested Piwik_DataTable object is stored in $this->dataTable.
+ * The requested DataTable object is stored in $this->dataTable.
*/
protected function loadDataTableFromAPI()
{
@@ -551,7 +553,7 @@ abstract class Piwik_ViewDataTable
*/
protected function checkStandardDataTable()
{
- Piwik::checkObjectTypeIs($this->dataTable, array('Piwik_DataTable'));
+ Piwik::checkObjectTypeIs($this->dataTable, array('\Piwik\DataTable'));
}
/**
@@ -567,11 +569,11 @@ abstract class Piwik_ViewDataTable
}
// deal w/ table metadata
- if ($this->dataTable instanceof Piwik_DataTable) {
+ if ($this->dataTable instanceof DataTable) {
$this->viewProperties['metadata'] = $this->dataTable->getAllTableMetadata();
- if (isset($this->viewProperties['metadata'][Piwik_DataTable::ARCHIVED_DATE_METADATA_NAME])) {
- $this->viewProperties['metadata'][Piwik_DataTable::ARCHIVED_DATE_METADATA_NAME] =
+ if (isset($this->viewProperties['metadata'][DataTable::ARCHIVED_DATE_METADATA_NAME])) {
+ $this->viewProperties['metadata'][DataTable::ARCHIVED_DATE_METADATA_NAME] =
$this->makePrettyArchivedOnText();
}
}
@@ -608,7 +610,7 @@ abstract class Piwik_ViewDataTable
// default columns_to_display to label, nb_uniq_visitors/nb_visits if those columns exist in the
// dataset
- if ($this->dataTable instanceof Piwik_DataTable) {
+ if ($this->dataTable instanceof DataTable) {
$columns = $this->dataTable->getColumns();
if (empty($this->viewProperties['columns_to_display'])
&& $this->dataTableColumnsContains($columns, array('nb_visits', 'nb_uniq_visitors'))
@@ -669,8 +671,8 @@ abstract class Piwik_ViewDataTable
*/
private function makePrettyArchivedOnText()
{
- $dateText = $this->viewProperties['metadata'][Piwik_DataTable::ARCHIVED_DATE_METADATA_NAME];
- $date = Piwik_Date::factory($dateText);
+ $dateText = $this->viewProperties['metadata'][DataTable::ARCHIVED_DATE_METADATA_NAME];
+ $date = Date::factory($dateText);
$today = mktime(0, 0, 0);
if ($date->getTimestamp() > $today) {
$elapsedSeconds = time() - $date->getTimestamp();
@@ -835,7 +837,7 @@ abstract class Piwik_ViewDataTable
}
}
- if ($this->dataTable instanceof Piwik_DataTable) {
+ if ($this->dataTable instanceof DataTable) {
// we override the filter_sort_column with the column used for sorting,
// which can be different from the one specified (eg. if the column doesn't exist)
$javascriptVariablesToSet['filter_sort_column'] = $this->dataTable->getSortedByColumnName();
@@ -853,8 +855,8 @@ abstract class Piwik_ViewDataTable
$javascriptVariablesToSet['controllerActionCalledWhenRequestSubTable'] = $this->controllerActionCalledWhenRequestSubTable;
if ($this->dataTable &&
- // Piwik_DataTable_Array doesn't have the method
- !($this->dataTable instanceof Piwik_DataTable_Array)
+ // Set doesn't have the method
+ !($this->dataTable instanceof DataTable\Map)
&& empty($javascriptVariablesToSet['totalRows'])
) {
$javascriptVariablesToSet['totalRows'] = $this->dataTable->getRowsCountBeforeLimitFilter();
@@ -1061,7 +1063,7 @@ abstract class Piwik_ViewDataTable
*/
public function showAnnotationsView()
{
- if (!PluginsManager::getInstance()->isPluginLoaded('Annotations')) {
+ if (!\Piwik\PluginsManager::getInstance()->isPluginLoaded('Annotations')) {
return;
}
@@ -1113,7 +1115,7 @@ abstract class Piwik_ViewDataTable
*/
public function enableShowGoals()
{
- if (PluginsManager::getInstance()->isPluginActivated('Goals')) {
+ if (\Piwik\PluginsManager::getInstance()->isPluginActivated('Goals')) {
$this->viewProperties['show_goals'] = true;
}
}
@@ -1360,10 +1362,10 @@ abstract class Piwik_ViewDataTable
if(empty($this->dataTable)) {
return;
}
- if ($this->dataTable instanceof Piwik_DataTable_Array) {
- $emptyColumns = $this->dataTable->getMetadataIntersectArray(Piwik_DataTable::EMPTY_COLUMNS_METADATA_NAME);
+ if ($this->dataTable instanceof DataTable\Map) {
+ $emptyColumns = $this->dataTable->getMetadataIntersectArray(DataTable::EMPTY_COLUMNS_METADATA_NAME);
} else {
- $emptyColumns = $this->dataTable->getMetadata(Piwik_DataTable::EMPTY_COLUMNS_METADATA_NAME);
+ $emptyColumns = $this->dataTable->getMetadata(DataTable::EMPTY_COLUMNS_METADATA_NAME);
}
if (is_array($emptyColumns)) {
foreach ($emptyColumns as $emptyColumn) {
@@ -1537,14 +1539,14 @@ abstract class Piwik_ViewDataTable
$timezone = 'UTC';
}
- $period = new Period_Range('range', $strDate, $timezone);
+ $period = new Range('range', $strDate, $timezone);
$reportDate = $period->getDateStart();
} // if a multiple period, this function is irrelevant
else if (Period::isMultiplePeriod($strDate, $strPeriod)) {
return false;
} // otherwise, use the date as given
else {
- $reportDate = Piwik_Date::factory($strDate);
+ $reportDate = Date::factory($strDate);
}
$reportYear = $reportDate->toString('Y');
@@ -1619,7 +1621,7 @@ abstract class Piwik_ViewDataTable
* Returns true if the first array contains one or more of the specified
* column names or their associated integer INDEX_ value.
*
- * @param array $columns Piwik_DataTable_Row columns.
+ * @param array $columns Row columns.
* @param array|string $columnsToCheckFor eg, array('nb_visits', 'nb_uniq_visitors')
* @return bool
*/
diff --git a/core/ViewDataTable/GenerateGraphHTML/ChartEvolution.php b/core/ViewDataTable/GenerateGraphHTML/ChartEvolution.php
index 38392bf71a..4ee089abd8 100644
--- a/core/ViewDataTable/GenerateGraphHTML/ChartEvolution.php
+++ b/core/ViewDataTable/GenerateGraphHTML/ChartEvolution.php
@@ -10,7 +10,7 @@
*/
use Piwik\Common;
-use Piwik\Period_Range;
+use Piwik\Period\Range;
use Piwik\Site;
/**
@@ -99,10 +99,10 @@ class Piwik_ViewDataTable_GenerateGraphHTML_ChartEvolution extends Piwik_ViewDat
$this->alwaysShowLimitDropdown();
// set the evolution_{$period}_last_n query param
- if (Period_Range::parseDateRange($this->originalDate)) // if a multiple period
+ if (Range::parseDateRange($this->originalDate)) // if a multiple period
{
// overwrite last_n param using the date range
- $oPeriod = new Period_Range($period, $this->originalDate);
+ $oPeriod = new Range($period, $this->originalDate);
$lastN = count($oPeriod->getSubperiods());
} else // if not a multiple period
{
diff --git a/core/ViewDataTable/HtmlTable.php b/core/ViewDataTable/HtmlTable.php
index dc23e95d2b..05b99543fa 100644
--- a/core/ViewDataTable/HtmlTable.php
+++ b/core/ViewDataTable/HtmlTable.php
@@ -9,6 +9,7 @@
* @package Piwik
*/
use Piwik\Config;
+use Piwik\DataTable\Renderer;
use Piwik\Piwik;
use Piwik\Common;
@@ -23,7 +24,7 @@ use Piwik\Common;
class Piwik_ViewDataTable_HtmlTable extends Piwik_ViewDataTable
{
/**
- * PHP array conversion of the Piwik_DataTable
+ * PHP array conversion of the DataTable
*
* @var array
*/
@@ -168,13 +169,13 @@ class Piwik_ViewDataTable_HtmlTable extends Piwik_ViewDataTable
}
/**
- * Returns friendly php array from the Piwik_DataTable
+ * Returns friendly php array from the DataTable
* @see Piwik_DataTable_Renderer_Php
* @return array
*/
protected function getPHPArrayFromDataTable()
{
- $renderer = Piwik_DataTable_Renderer::factory('php');
+ $renderer = Renderer::factory('php');
$renderer->setTable($this->dataTable);
$renderer->setSerialize(false);
// we get the php array from the datatable but conserving the original datatable format,
diff --git a/core/ViewDataTable/HtmlTable/AllColumns.php b/core/ViewDataTable/HtmlTable/AllColumns.php
index 9b1a1f77d3..6b88cfeeb3 100644
--- a/core/ViewDataTable/HtmlTable/AllColumns.php
+++ b/core/ViewDataTable/HtmlTable/AllColumns.php
@@ -59,7 +59,8 @@ class Piwik_ViewDataTable_HtmlTable_AllColumns extends Piwik_ViewDataTable_HtmlT
'bounce_rate',
$columnConversionRate
));
- $this->dataTable->filter('ColumnCallbackReplace', array('avg_time_on_site', create_function('$averageTimeOnSite', 'return Piwik::getPrettyTimeFromSeconds($averageTimeOnSite);')));
+ $this->dataTable->filter('ColumnCallbackReplace', array('avg_time_on_site', create_function('$averageTimeOnSite',
+ 'return \Piwik\Piwik::getPrettyTimeFromSeconds($averageTimeOnSite);')));
return true;
}
diff --git a/core/ViewDataTable/HtmlTable/Goals.php b/core/ViewDataTable/HtmlTable/Goals.php
index 4fa4980d72..7714e7fd06 100644
--- a/core/ViewDataTable/HtmlTable/Goals.php
+++ b/core/ViewDataTable/HtmlTable/Goals.php
@@ -8,6 +8,7 @@
* @category Piwik
* @package Piwik
*/
+use Piwik\DataTable\Filter\AddColumnsProcessedMetricsGoal;
use Piwik\Piwik;
use Piwik\Common;
use Piwik\Site;
@@ -26,7 +27,7 @@ class Piwik_ViewDataTable_HtmlTable_Goals extends Piwik_ViewDataTable_HtmlTable
public function main()
{
$this->idSite = Common::getRequestVar('idSite', null, 'int');
- $this->processOnlyIdGoal = Common::getRequestVar('idGoal', Piwik_DataTable_Filter_AddColumnsProcessedMetricsGoal::GOALS_OVERVIEW, 'string');
+ $this->processOnlyIdGoal = Common::getRequestVar('idGoal', AddColumnsProcessedMetricsGoal::GOALS_OVERVIEW, 'string');
$this->isEcommerce = $this->processOnlyIdGoal == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER;
$this->viewProperties['show_exclude_low_population'] = true;
$this->viewProperties['show_goals'] = true;
@@ -143,7 +144,7 @@ class Piwik_ViewDataTable_HtmlTable_Goals extends Piwik_ViewDataTable_HtmlTable
$goal['name'] = Common::unsanitizeInputValue($goal['name']);
- if ($this->processOnlyIdGoal > Piwik_DataTable_Filter_AddColumnsProcessedMetricsGoal::GOALS_FULL_TABLE
+ if ($this->processOnlyIdGoal > AddColumnsProcessedMetricsGoal::GOALS_FULL_TABLE
&& $this->processOnlyIdGoal != $idgoal
&& !$this->isEcommerce
) {
@@ -155,7 +156,7 @@ class Piwik_ViewDataTable_HtmlTable_Goals extends Piwik_ViewDataTable_HtmlTable
$this->setDynamicMetricDocumentation($columnName, $columnNameGoal, $goal['name'], $goal['idgoal']);
if (strpos($columnNameGoal, '_rate') === false
// For the goal table (when the flag icon is clicked), we only display the per Goal Conversion rate
- && $this->processOnlyIdGoal == Piwik_DataTable_Filter_AddColumnsProcessedMetricsGoal::GOALS_OVERVIEW
+ && $this->processOnlyIdGoal == AddColumnsProcessedMetricsGoal::GOALS_OVERVIEW
) {
continue;
}
@@ -220,7 +221,7 @@ class Piwik_ViewDataTable_HtmlTable_Goals extends Piwik_ViewDataTable_HtmlTable
protected function getRequestArray()
{
$requestArray = parent::getRequestArray();
- if ($this->processOnlyIdGoal > Piwik_DataTable_Filter_AddColumnsProcessedMetricsGoal::GOALS_FULL_TABLE
+ if ($this->processOnlyIdGoal > AddColumnsProcessedMetricsGoal::GOALS_FULL_TABLE
|| $this->isEcommerce
) {
$requestArray["idGoal"] = $this->processOnlyIdGoal;
@@ -251,7 +252,7 @@ class Piwik_ViewDataTable_HtmlTable_Goals extends Piwik_ViewDataTable_HtmlTable
$this->columnsToRevenueFilter[] = 'revenue_per_visit';
foreach ($this->columnsToRevenueFilter as $columnName) {
$this->dataTable->filter('ColumnCallbackReplace', array($columnName, create_function('$value', 'return sprintf("%.1f",$value);')));
- $this->dataTable->filter('ColumnCallbackReplace', array($columnName, array("Piwik", "getPrettyMoney"), array($this->getIdSite())));
+ $this->dataTable->filter('ColumnCallbackReplace', array($columnName, '\Piwik\Piwik::getPrettyMoney', array($this->getIdSite())));
}
foreach ($this->columnsToConversionFilter as $columnName) {
diff --git a/core/ViewDataTable/Sparkline.php b/core/ViewDataTable/Sparkline.php
index ae85101a78..74e72f03c9 100644
--- a/core/ViewDataTable/Sparkline.php
+++ b/core/ViewDataTable/Sparkline.php
@@ -9,6 +9,7 @@
* @package Piwik
*/
use Piwik\Common;
+use Piwik\DataTable;
/**
* Reads the requested DataTable from the API and prepare data for the Sparkline view.
@@ -101,11 +102,11 @@ class Piwik_ViewDataTable_Sparkline extends Piwik_ViewDataTable
$columnToPlot = $columns[0];
}
$values = false;
- // a Piwik_DataTable_Array is returned when using the normal code path to request data from Archives, in all core plugins
+ // a Set is returned when using the normal code path to request data from Archives, in all core plugins
// however plugins can also return simple datatable, hence why the sparkline can accept both data types
- if ($this->dataTable instanceof Piwik_DataTable_Array) {
+ if ($this->dataTable instanceof DataTable\Map) {
$values = $this->getValuesFromDataTableArray($dataTable, $columnToPlot);
- } elseif ($this->dataTable instanceof Piwik_DataTable) {
+ } elseif ($this->dataTable instanceof DataTable) {
$values = $this->dataTable->getColumn($columnToPlot);
}
return $values;