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:
authormattpiwik <matthieu.aubry@gmail.com>2008-10-31 15:11:43 +0300
committermattpiwik <matthieu.aubry@gmail.com>2008-10-31 15:11:43 +0300
commit3ba202aeb55f42500edf4b07856c47c91d83b8c3 (patch)
treef654420bded11ace4d5869348b9a815d5e9d4484 /core/DataTable/Filter/ColumnCallbackAddColumnPercentage.php
parentde733c413f54b29ba64a907881c50f77a6eb0440 (diff)
- error message to support upgrade type message
- start integration of Updater - adding new filter to add percentage columns easily git-svn-id: http://dev.piwik.org/svn/trunk@667 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'core/DataTable/Filter/ColumnCallbackAddColumnPercentage.php')
-rw-r--r--core/DataTable/Filter/ColumnCallbackAddColumnPercentage.php48
1 files changed, 48 insertions, 0 deletions
diff --git a/core/DataTable/Filter/ColumnCallbackAddColumnPercentage.php b/core/DataTable/Filter/ColumnCallbackAddColumnPercentage.php
new file mode 100644
index 0000000000..7779a14482
--- /dev/null
+++ b/core/DataTable/Filter/ColumnCallbackAddColumnPercentage.php
@@ -0,0 +1,48 @@
+<?php
+/**
+ * Add a new column to the table which is a percentage based on the value resulting
+ * from a callback function with the parameter being another column's value
+ *
+ * For example in the keywords table, we can create a "nb_visits_percentage" column
+ * from the "nb_visits" column that will be nb_visits / $totalValueUsedToComputePercentage
+ * You can also specify the precision of the percentage value to be displayed (defaults to 0, eg "11%")
+ *
+ * Usage:
+ * $nbVisits = Piwik_VisitsSummary_API::getVisits($idSite, $period, $date);
+ * $dataTable->queueFilter('Piwik_DataTable_Filter_ColumnCallbackAddColumnPercentage', array('nb_visits', 'nb_visits_percentage', $nbVisits, 1));
+ *
+ */
+class Piwik_DataTable_Filter_ColumnCallbackAddColumnPercentage extends Piwik_DataTable_Filter
+{
+ private $columnValueToRead;
+ private $columnNamePercentageToAdd;
+ private $totalValueUsedToComputePercentage;
+ private $percentagePrecision;
+
+ /**
+ * @param Piwik_DataTable $table
+ * @param string $columnValueToRead
+ * @param string $columnNamePercentageToAdd
+ * @param double $totalValueUsedToComputePercentage
+ * @param int $percentagePrecision precision 0 means "11", 1 means "11.2"
+ */
+ public function __construct( $table, $columnValueToRead, $columnNamePercentageToAdd, $totalValueUsedToComputePercentage, $percentagePrecision = 0 )
+ {
+ parent::__construct($table);
+ $this->columnValueToRead = $columnValueToRead;
+ $this->columnNamePercentageToAdd = $columnNamePercentageToAdd;
+ $this->totalValueUsedToComputePercentage = $totalValueUsedToComputePercentage;
+ $this->percentagePrecision = $percentagePrecision;
+ $this->filter();
+ }
+
+ protected function filter()
+ {
+ foreach($this->table->getRows() as $key => $row)
+ {
+ $value = $row->getColumn($this->columnValueToRead);
+ $percentage = round( 100 * $value / $this->totalValueUsedToComputePercentage, $this->percentagePrecision);
+ $row->addColumn($this->columnNamePercentageToAdd, $percentage);
+ }
+ }
+} \ No newline at end of file