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:
Diffstat (limited to 'plugins/Goals/Controller.php')
-rw-r--r--plugins/Goals/Controller.php217
1 files changed, 89 insertions, 128 deletions
diff --git a/plugins/Goals/Controller.php b/plugins/Goals/Controller.php
index 032135c111..06d16b93b0 100644
--- a/plugins/Goals/Controller.php
+++ b/plugins/Goals/Controller.php
@@ -18,54 +18,33 @@ class Piwik_Goals_Controller extends Piwik_Controller
{
const CONVERSION_RATE_PRECISION = 1;
- protected $goalColumnNameToLabel = array(
- 'nb_conversions' => 'Goals_ColumnConversions',
- 'conversion_rate'=> 'Goals_ColumnConversionRate',
- 'revenue' => 'Goals_ColumnRevenue',
- );
-
- public function __construct()
+ function __construct()
{
parent::__construct();
$this->idSite = Piwik_Common::getRequestVar('idSite');
- $this->goals = Piwik_Goals_API::getInstance()->getGoals($this->idSite);
+ $this->goals = Piwik_Goals_API::getGoals($this->idSite);
}
- public function widgetGoalReport()
- {
- $view = $this->getGoalReportView();
- $view->displayFullReport = false;
- echo $view->render();
- }
-
- public function goalReport()
- {
- $view = $this->getGoalReportView();
- $view->displayFullReport = true;
- $view->goalSegments = $this->getAvailableGoalSegments();
- echo $view->render();
- }
-
- protected function getGoalReportView()
+ function goalReport()
{
$idGoal = Piwik_Common::getRequestVar('idGoal', null, 'int');
if(!isset($this->goals[$idGoal]))
{
- Piwik::redirectToModule('Goals', 'index', array('idGoal' => null));
+ throw new Exception("idgoal $idGoal not valid.");
}
$goalDefinition = $this->goals[$idGoal];
$view = Piwik_View::factory('single_goal');
- $this->setGeneralVariablesView($view);
+ $view->currency = Piwik::getCurrency();
$goal = $this->getMetricsForGoal($idGoal);
foreach($goal as $name => $value)
{
$view->$name = $value;
}
- $view->idGoal = $idGoal;
- $view->goalName = $goalDefinition['name'];
+ $view->name = $goalDefinition['name'];
+ $view->title = $goalDefinition['name'] . ' - Conversions';
$view->graphEvolution = $this->getEvolutionGraph(true, array(Piwik_Goals::getRecordName('nb_conversions', $idGoal)), $idGoal);
- $view->nameGraphEvolution = 'GoalsgetEvolutionGraph'.$idGoal;
+ $view->nameGraphEvolution = 'GoalsgetEvolutionGraph';
$view->topSegments = $this->getTopSegments($idGoal);
// conversion rate for new and returning visitors
@@ -73,31 +52,75 @@ class Piwik_Goals_Controller extends Piwik_Controller
$view->conversion_rate_returning = round( $request->process(), self::CONVERSION_RATE_PRECISION );
$request = new Piwik_API_Request("method=Goals.getConversionRateNewVisitors&format=original");
$view->conversion_rate_new = round( $request->process(), self::CONVERSION_RATE_PRECISION );
- return $view;
+
+ $verticalSlider = array();
+ // string label
+ // array parameters to ajax call on click (module, action)
+ // specific order
+ // (intermediate labels)
+ // automatically load the first from the list, highlights it
+ $view->tableByConversion = Piwik_FrontController::getInstance()->fetchDispatch('Referers', 'getKeywords', array(false, 'tableGoals'));
+ echo $view->render();
}
- public function index()
+ protected function getTopSegments($idGoal)
{
- $view = $this->getOverviewView();
- $view->goalsJSON = json_encode($this->goals);
- $view->goalSegments = $this->getAvailableGoalSegments();
- $view->userCanEditGoals = Piwik::isUserHasAdminAccess($this->idSite);
- $view->displayFullReport = true;
- echo $view->render();
+ $columnNbConversions = 'goal_'.$idGoal.'_nb_conversions';
+ $columnConversionRate = 'goal_'.$idGoal.'_conversion_rate';
+
+ $topSegmentsToLoad = array(
+ 'country' => 'UserCountry.getCountry',
+ 'keyword' => 'Referers.getKeywords',
+ 'website' => 'Referers.getWebsites',
+ );
+
+ $topSegments = array();
+ foreach($topSegmentsToLoad as $segmentName => $apiMethod)
+ {
+ $request = new Piwik_API_Request("method=$apiMethod
+ &format=original
+ &filter_update_columns_when_show_all_goals=1
+ &filter_sort_order=desc
+ &filter_sort_column=$columnNbConversions
+ &filter_limit=3");
+ $datatable = $request->process();
+ $topSegment = array();
+ foreach($datatable->getRows() as $row)
+ {
+ $topSegment[] = array (
+ 'name' => $row->getColumn('label'),
+ 'nb_conversions' => $row->getColumn($columnNbConversions),
+ 'conversion_rate' => $row->getColumn($columnConversionRate),
+ 'metadata' => $row->getMetadata(),
+ );
+ }
+ $topSegments[$segmentName] = $topSegment;
+ }
+ return $topSegments;
}
- public function widgetGoalsOverview( )
+ protected function getMetricsForGoal($idGoal)
{
- $view = $this->getOverviewView();
- $view->displayFullReport = false;
- echo $view->render();
+ $request = new Piwik_API_Request("method=Goals.get&format=original&idGoal=$idGoal");
+ $datatable = $request->process();
+ $dataRow = $datatable->getFirstRow();
+ return array (
+ 'id' => $idGoal,
+ 'nb_conversions' => $dataRow->getColumn(Piwik_Goals::getRecordName('nb_conversions', $idGoal)),
+ 'conversion_rate' => round($dataRow->getColumn(Piwik_Goals::getRecordName('conversion_rate', $idGoal)), 1),
+ 'revenue' => $dataRow->getColumn(Piwik_Goals::getRecordName('revenue', $idGoal)),
+ 'urlSparklineConversions' => $this->getUrlSparkline('getEvolutionGraph', array('columns' => array(Piwik_Goals::getRecordName('nb_conversions', $idGoal)), 'idGoal' => $idGoal)),
+ 'urlSparklineConversionRate' => $this->getUrlSparkline('getEvolutionGraph', array('columns' => array(Piwik_Goals::getRecordName('conversion_rate', $idGoal)), 'idGoal' => $idGoal)),
+ 'urlSparklineRevenue' => $this->getUrlSparkline('getEvolutionGraph', array('columns' => array(Piwik_Goals::getRecordName('revenue', $idGoal)), 'idGoal' => $idGoal)),
+ );
}
- protected function getOverviewView()
+ function index()
{
$view = Piwik_View::factory('overview');
- $this->setGeneralVariablesView($view);
+ $view->currency = Piwik::getCurrency();
+ $view->title = 'All goals - evolution';
$view->graphEvolution = $this->getEvolutionGraph(true, array(Piwik_Goals::getRecordName('nb_conversions')));
$view->nameGraphEvolution = 'GoalsgetEvolutionGraph';
@@ -106,7 +129,7 @@ class Piwik_Goals_Controller extends Piwik_Controller
$view->urlSparklineConversionRate = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array(Piwik_Goals::getRecordName('conversion_rate'))));
$view->urlSparklineRevenue = $this->getUrlSparkline('getEvolutionGraph', array('columns' => array(Piwik_Goals::getRecordName('revenue'))));
- $request = new Piwik_API_Request("method=Goals.get&format=original&idGoal=0");
+ $request = new Piwik_API_Request("method=Goals.get&format=original");
$datatable = $request->process();
$dataRow = $datatable->getFirstRow();
$view->nb_conversions = $dataRow->getColumn('Goal_nb_conversions');
@@ -122,36 +145,26 @@ class Piwik_Goals_Controller extends Piwik_Controller
$view->goalMetrics = $goalMetrics;
$view->goals = $this->goals;
- return $view;
- }
-
- public function getLastNbConversionsGraph( $fetch = false )
- {
- $view = $this->getLastUnitGraph($this->pluginName, __FUNCTION__, 'Goals.getConversions');
- return $this->renderView($view, $fetch);
- }
-
- public function getLastConversionRateGraph( $fetch = false )
- {
- $view = $this->getLastUnitGraph($this->pluginName, __FUNCTION__, 'Goals.getConversionRate');
- return $this->renderView($view, $fetch);
- }
-
- public function getLastRevenueGraph( $fetch = false )
- {
- $view = $this->getLastUnitGraph($this->pluginName, __FUNCTION__, 'Goals.getRevenue');
- return $this->renderView($view, $fetch);
+ $view->goalsJSON = json_encode($this->goals);
+ $view->userCanEditGoals = Piwik::isUserHasAdminAccess($this->idSite);
+ echo $view->render();
}
- public function addNewGoal()
+ function addNewGoal()
{
$view = Piwik_View::factory('add_new_goal');
- $this->setGeneralVariablesView($view);
$view->userCanEditGoals = Piwik::isUserHasAdminAccess($this->idSite);
+ $view->currency = Piwik::getCurrency();
$view->onlyShowAddNewGoal = true;
echo $view->render();
}
+ protected $goalColumnNameToLabel = array(
+ 'nb_conversions' => 'Goals_ColumnConversions',
+ 'conversion_rate'=> 'Goals_ColumnConversionRate',
+ 'revenue' => 'Goals_ColumnRevenue',
+ );
+
public function getEvolutionGraph( $fetch = false, $columns = false, $idGoal = false)
{
if(empty($columns))
@@ -180,7 +193,7 @@ class Piwik_Goals_Controller extends Piwik_Controller
if(!empty($idGoal) && isset($this->goals[$idGoal]))
{
$goalName = $this->goals[$idGoal]['name'];
- $columnTranslation = "$columnTranslation (".Piwik_Translate('Goals_GoalX', "$goalName").")";
+ $columnTranslation = "$columnTranslation (goal \"$goalName\")";
}
$view->setColumnTranslation($columnName, $columnTranslation);
}
@@ -188,73 +201,21 @@ class Piwik_Goals_Controller extends Piwik_Controller
return $this->renderView($view, $fetch);
}
- protected function getAvailableGoalSegments()
+ function getLastNbConversionsGraph( $fetch = false )
{
- $segments = array();
- Piwik_PostEvent('Goals.getAvailableGoalSegments', $segments);
- $segmentsByGroup = array();
- foreach($segments as $segment)
- {
- $group = $segment['group'];
- unset($segment['group']);
- $segmentsByGroup[$group][] = $segment;
- }
- return $segmentsByGroup;
+ $view = $this->getLastUnitGraph($this->pluginName, __FUNCTION__, 'Goals.getConversions');
+ return $this->renderView($view, $fetch);
}
- protected function getTopSegments($idGoal)
+ function getLastConversionRateGraph( $fetch = false )
{
- $columnNbConversions = 'goal_'.$idGoal.'_nb_conversions';
- $columnConversionRate = 'goal_'.$idGoal.'_conversion_rate';
-
- $topSegmentsToLoad = array(
- 'country' => 'UserCountry.getCountry',
- 'keyword' => 'Referers.getKeywords',
- 'website' => 'Referers.getWebsites',
- );
-
- $topSegments = array();
- foreach($topSegmentsToLoad as $segmentName => $apiMethod)
- {
- $request = new Piwik_API_Request("method=$apiMethod
- &format=original
- &filter_update_columns_when_show_all_goals=1
- &filter_sort_order=desc
- &filter_sort_column=$columnNbConversions
- &filter_limit=3");
- $datatable = $request->process();
- $topSegment = array();
- foreach($datatable->getRows() as $row)
- {
- $conversions = $row->getColumn($columnNbConversions);
- if($conversions > 0)
- {
- $topSegment[] = array (
- 'name' => $row->getColumn('label'),
- 'nb_conversions' => $conversions,
- 'conversion_rate' => $row->getColumn($columnConversionRate),
- 'metadata' => $row->getMetadata(),
- );
- }
- }
- $topSegments[$segmentName] = $topSegment;
- }
- return $topSegments;
+ $view = $this->getLastUnitGraph($this->pluginName, __FUNCTION__, 'Goals.getConversionRate');
+ return $this->renderView($view, $fetch);
}
-
- protected function getMetricsForGoal($idGoal)
+
+ function getLastRevenueGraph( $fetch = false )
{
- $request = new Piwik_API_Request("method=Goals.get&format=original&idGoal=$idGoal");
- $datatable = $request->process();
- $dataRow = $datatable->getFirstRow();
- return array (
- 'id' => $idGoal,
- 'nb_conversions' => $dataRow->getColumn(Piwik_Goals::getRecordName('nb_conversions', $idGoal)),
- 'conversion_rate' => round($dataRow->getColumn(Piwik_Goals::getRecordName('conversion_rate', $idGoal)), 1),
- 'revenue' => $dataRow->getColumn(Piwik_Goals::getRecordName('revenue', $idGoal)),
- 'urlSparklineConversions' => $this->getUrlSparkline('getEvolutionGraph', array('columns' => array(Piwik_Goals::getRecordName('nb_conversions', $idGoal)), 'idGoal' => $idGoal)),
- 'urlSparklineConversionRate' => $this->getUrlSparkline('getEvolutionGraph', array('columns' => array(Piwik_Goals::getRecordName('conversion_rate', $idGoal)), 'idGoal' => $idGoal)),
- 'urlSparklineRevenue' => $this->getUrlSparkline('getEvolutionGraph', array('columns' => array(Piwik_Goals::getRecordName('revenue', $idGoal)), 'idGoal' => $idGoal)),
- );
+ $view = $this->getLastUnitGraph($this->pluginName, __FUNCTION__, 'Goals.getRevenue');
+ return $this->renderView($view, $fetch);
}
}