diff options
author | Matthieu Aubry <matt@piwik.org> | 2015-09-15 03:18:17 +0300 |
---|---|---|
committer | Matthieu Aubry <matt@piwik.org> | 2015-09-15 03:18:17 +0300 |
commit | 1d805fe626807fd648de68ad8d13cd78fd5dbc97 (patch) | |
tree | ddd4aa22a67faeba467d088f68e6c284efe44b9e /plugins/CustomVariables | |
parent | 3a84a8aeb2612fa16926d65554c182b156844642 (diff) | |
parent | ca6b7e77f4d4b886db0d0660db1f0ae6980e3fe4 (diff) |
Merge pull request #8754 from piwik/6031_cvar_unified_segment
Define four segments that search over all custom variable name/value columns instead of one per column
Diffstat (limited to 'plugins/CustomVariables')
5 files changed, 70 insertions, 6 deletions
diff --git a/plugins/CustomVariables/Columns/Base.php b/plugins/CustomVariables/Columns/Base.php new file mode 100644 index 0000000000..1818ca3145 --- /dev/null +++ b/plugins/CustomVariables/Columns/Base.php @@ -0,0 +1,54 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +namespace Piwik\Plugins\CustomVariables\Columns; + +use Piwik\DataTable; +use Piwik\Piwik; +use Piwik\Plugin\Dimension\VisitDimension; +use Piwik\Plugin\Segment; +use Piwik\Plugins\CustomVariables\CustomVariables; + +class Base extends VisitDimension +{ + protected function configureSegmentsFor($fieldPrefix, $segmentNameSuffix) + { + $numCustomVariables = CustomVariables::getNumUsableCustomVariables(); + + $segment = new Segment(); + $segment->setType('dimension'); + $segment->setSegment('customVariable' . $segmentNameSuffix); + $segment->setName($this->getName() . ' (' . Piwik::translate('CustomVariables_ScopeVisit') . ')'); + $segment->setCategory('CustomVariables_CustomVariables'); + $segment->setSqlSegment($this->getSegmentColumns('log_visit.' . $fieldPrefix, $numCustomVariables)); + $segment->setSuggestedValuesCallback(function ($idSite, $ignore, DataTable $table) use ($segmentNameSuffix) { + return $table->getColumnsStartingWith('customVariable' . $segmentNameSuffix); + }); + $this->addSegment($segment); + + $segment = new Segment(); + $segment->setType('dimension'); + $segment->setSegment('customVariablePage' . $segmentNameSuffix); + $segment->setName($this->getName() . ' (' . Piwik::translate('CustomVariables_ScopePage') . ')'); + $segment->setCategory('CustomVariables_CustomVariables'); + $segment->setSqlSegment($this->getSegmentColumns('log_link_visit_action.' . $fieldPrefix, $numCustomVariables)); + $segment->setSuggestedValuesCallback(function ($idSite, $ignore, DataTable $table) use ($segmentNameSuffix) { + return $table->getColumnsStartingWith('customVariablePage' . $segmentNameSuffix); + }); + $this->addSegment($segment); + } + + private function getSegmentColumns($column, $numCustomVariables) + { + $columns = array(); + for ($i = 1; $i <= $numCustomVariables; ++$i) { + $columns[] = $column . $i; + } + return $columns; + } +}
\ No newline at end of file diff --git a/plugins/CustomVariables/Columns/CustomVariableName.php b/plugins/CustomVariables/Columns/CustomVariableName.php index 1ad4d214fa..85aa46436f 100644 --- a/plugins/CustomVariables/Columns/CustomVariableName.php +++ b/plugins/CustomVariables/Columns/CustomVariableName.php @@ -8,11 +8,15 @@ */ namespace Piwik\Plugins\CustomVariables\Columns; -use Piwik\Columns\Dimension; use Piwik\Piwik; -class CustomVariableName extends Dimension +class CustomVariableName extends Base { + protected function configureSegments() + { + $this->configureSegmentsFor('custom_var_k', 'Name'); + } + public function getName() { return Piwik::translate('CustomVariables_ColumnCustomVariableName'); diff --git a/plugins/CustomVariables/Columns/CustomVariableValue.php b/plugins/CustomVariables/Columns/CustomVariableValue.php index ef6908042e..03046758cf 100644 --- a/plugins/CustomVariables/Columns/CustomVariableValue.php +++ b/plugins/CustomVariables/Columns/CustomVariableValue.php @@ -8,11 +8,15 @@ */ namespace Piwik\Plugins\CustomVariables\Columns; -use Piwik\Columns\Dimension; use Piwik\Piwik; -class CustomVariableValue extends Dimension +class CustomVariableValue extends Base { + protected function configureSegments() + { + $this->configureSegmentsFor('custom_var_v', 'Value'); + } + public function getName() { return Piwik::translate('CustomVariables_ColumnCustomVariableValue'); diff --git a/plugins/CustomVariables/tests/System/CustomVariablesSystemTest.php b/plugins/CustomVariables/tests/System/CustomVariablesSystemTest.php index 176221fcff..cce902ef30 100644 --- a/plugins/CustomVariables/tests/System/CustomVariablesSystemTest.php +++ b/plugins/CustomVariables/tests/System/CustomVariablesSystemTest.php @@ -44,8 +44,8 @@ class CustomVariablesSystemTest extends SystemTestCase array($apiToCall, array( 'idSite' => self::$fixture->idSite, 'date' => self::$fixture->dateTime, - 'periods' => array('day')) - ) + 'periods' => array('day'), + )), ); } diff --git a/plugins/CustomVariables/tests/System/expected/test_CustomVariablesSystemTest__Live.getLastVisitsDetails_day.xml b/plugins/CustomVariables/tests/System/expected/test_CustomVariablesSystemTest__Live.getLastVisitsDetails_day.xml index 2f242c53c1..007bd155c3 100644 --- a/plugins/CustomVariables/tests/System/expected/test_CustomVariablesSystemTest__Live.getLastVisitsDetails_day.xml +++ b/plugins/CustomVariables/tests/System/expected/test_CustomVariablesSystemTest__Live.getLastVisitsDetails_day.xml @@ -15,6 +15,7 @@ <url>http://localhost</url> <icon>plugins/Morpheus/images/goal.png</icon> + </row> <row> <type>action</type> @@ -58,6 +59,7 @@ </row> </customVariables> <icon /> + </row> </actionDetails> <goalConversions>1</goalConversions> |