diff options
author | diosmosis <benaka@piwik.pro> | 2015-09-11 03:56:01 +0300 |
---|---|---|
committer | diosmosis <benaka@piwik.pro> | 2015-09-15 02:39:40 +0300 |
commit | 45c929d831a0e0c1c31cd10099f8f399e911b1fa (patch) | |
tree | 99981854cc4e12ccf58fb91474948a21738ba9c1 /plugins/CustomVariables | |
parent | f674f696e5864f6b85af15b915cd0f49e0ea9850 (diff) |
Allow Segments to define multiple SQL columns if the segment value can be matched in any of those fields, and use to define two new segments: customVariableName & customVariableValue.
Diffstat (limited to 'plugins/CustomVariables')
5 files changed, 63 insertions, 6 deletions
diff --git a/plugins/CustomVariables/Columns/Base.php b/plugins/CustomVariables/Columns/Base.php new file mode 100644 index 0000000000..b92f280691 --- /dev/null +++ b/plugins/CustomVariables/Columns/Base.php @@ -0,0 +1,47 @@ +<?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\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()); + $segment->setCategory('CustomVariables_CustomVariables'); + $segment->setSqlSegment($this->getSegmentColumns('log_visit.' . $fieldPrefix, $numCustomVariables)); + $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)); + $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 ba1f79807d..85aa46436f 100644 --- a/plugins/CustomVariables/Columns/CustomVariableName.php +++ b/plugins/CustomVariables/Columns/CustomVariableName.php @@ -9,10 +9,14 @@ namespace Piwik\Plugins\CustomVariables\Columns; use Piwik\Piwik; -use Piwik\Plugin\Dimension\VisitDimension; -class CustomVariableName extends VisitDimension +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 92b0ce62ca..03046758cf 100644 --- a/plugins/CustomVariables/Columns/CustomVariableValue.php +++ b/plugins/CustomVariables/Columns/CustomVariableValue.php @@ -9,10 +9,14 @@ namespace Piwik\Plugins\CustomVariables\Columns; use Piwik\Piwik; -use Piwik\Plugin\Dimension\VisitDimension; -class CustomVariableValue extends VisitDimension +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 79c6f5ec43..fbc9174747 100644 --- a/plugins/CustomVariables/tests/System/CustomVariablesSystemTest.php +++ b/plugins/CustomVariables/tests/System/CustomVariablesSystemTest.php @@ -43,8 +43,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> |