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

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@googlemail.com>2014-07-01 05:52:28 +0400
committerThomas Steur <thomas.steur@googlemail.com>2014-07-01 05:52:28 +0400
commit625d6e9a5dd5ed673e3ffc322549aa51acb495fd (patch)
treefcfe4dd36aa92a31afe664ca9aa0d7d4178e9c91 /core/Plugin/Dimension
parentfd565cd7131c2733716402166c0d6a552474e5a8 (diff)
started to add possiblity to add conversion columns
Diffstat (limited to 'core/Plugin/Dimension')
-rw-r--r--core/Plugin/Dimension/Conversion.php158
1 files changed, 158 insertions, 0 deletions
diff --git a/core/Plugin/Dimension/Conversion.php b/core/Plugin/Dimension/Conversion.php
new file mode 100644
index 0000000000..7ce8775715
--- /dev/null
+++ b/core/Plugin/Dimension/Conversion.php
@@ -0,0 +1,158 @@
+<?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\Plugin\Dimension;
+
+use Piwik\Cache\PluginAwareStaticCache;
+use Piwik\Columns\Dimension;
+use Piwik\Plugin\Manager as PluginManager;
+use Piwik\Common;
+use Piwik\Db;
+use Piwik\Tracker\Action;
+use Piwik\Tracker\GoalManager;
+use Piwik\Tracker\Request;
+use Piwik\Tracker\Visitor;
+use Piwik\Translate;
+use Piwik\Plugin\Segment;
+
+/**
+ * @api
+ * @since 2.5.0
+ */
+abstract class Conversion extends Dimension
+{
+ private $tableName = 'log_conversion';
+
+ public function install()
+ {
+ if (empty($this->columnName) || empty($this->columnType)) {
+ return array();
+ }
+
+ return array(
+ $this->tableName => array("ADD COLUMN `$this->columnName` $this->columnType")
+ );
+ }
+
+ public function update()
+ {
+ if (empty($this->columnName) || empty($this->columnType)) {
+ return array();
+ }
+
+ return array(
+ $this->tableName => array("MODIFY COLUMN `$this->columnName` $this->columnType")
+ );
+ }
+
+ public function uninstall()
+ {
+ if (empty($this->columnName) || empty($this->columnType)) {
+ return;
+ }
+
+ try {
+ $sql = "ALTER TABLE `" . Common::prefixTable($this->tableName) . "` DROP COLUMN `$this->columnName`";
+ Db::exec($sql);
+ } catch (\Exception $e) {
+ if (!Db::get()->isErrNo($e, '1091')) {
+ throw $e;
+ }
+ }
+ }
+
+ public function getVersion()
+ {
+ return $this->columnType;
+ }
+
+ protected function addSegment(Segment $segment)
+ {
+ $sqlSegment = $segment->getSqlSegment();
+ if (!empty($this->columnName) && empty($sqlSegment)) {
+ $segment->setSqlSegment($this->tableName . '.' . $this->columnName);
+ }
+
+ parent::addSegment($segment);
+ }
+
+ /** @return \Piwik\Plugin\Dimension\Conversion[] */
+ public static function getAllDimensions()
+ {
+ $cache = new PluginAwareStaticCache('ConversionDimensions');
+
+ if (!$cache->has()) {
+
+ $plugins = PluginManager::getInstance()->getLoadedPlugins();
+ $instances = array();
+
+ foreach ($plugins as $plugin) {
+ foreach (self::getDimensions($plugin) as $instance) {
+ $instances[] = $instance;
+ }
+ }
+
+ $cache->set($instances);
+ }
+
+ return $cache->get();
+ }
+
+ /** @return \Piwik\Plugin\ActionDimension[] */
+ public static function getDimensions(\Piwik\Plugin $plugin)
+ {
+ $dimensions = $plugin->findMultipleComponents('Columns', '\\Piwik\\Plugin\\Dimension\\Conversion');
+ $instances = array();
+
+ foreach ($dimensions as $dimension) {
+ $instances[] = new $dimension();
+ }
+
+ return $instances;
+ }
+
+ /**
+ * @param Request $request
+ * @param Visitor $visitor
+ * @param Action|null $action
+ * @param GoalManager $goalManager
+ *
+ * @return mixed|false
+ */
+ public function onEcommerceOrderConversion(Request $request, Visitor $visitor, $action, GoalManager $goalManager)
+ {
+ return false;
+ }
+
+ /**
+ * @param Request $request
+ * @param Visitor $visitor
+ * @param Action|null $action
+ * @param GoalManager $goalManager
+ *
+ * @return mixed|false
+ */
+ public function onEcommerceCartUpdateConversion(Request $request, Visitor $visitor, $action, GoalManager $goalManager)
+ {
+ return false;
+ }
+
+ /**
+ * @param Request $request
+ * @param Visitor $visitor
+ * @param Action|null $action
+ * @param GoalManager $goalManager
+ *
+ * @return mixed|false
+ */
+ public function onGoalConversion(Request $request, Visitor $visitor, $action, GoalManager $goalManager)
+ {
+ return false;
+ }
+
+}