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

ReportsByDimension.php « View « core - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 014b8f39ad378d112da6b9b7363687d3d1c32d50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/**
 * Piwik - Open source web analytics
 * 
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 * @version $Id$
 * 
 * @category Piwik
 * @package SmartyPlugins
 */

/**
 * A facade that makes it easier to use the 'reports_by_dimension.tpl' template.
 * 
 * This view will output HTML that displays a list of report names by category and
 * loads them by AJAX when clicked. The loaded report is displayed to the right
 * of the report listing.
 */
class Piwik_View_ReportsByDimension extends Piwik_View
{
	/**
	 * Constructor.
	 */
	public function __construct()
	{
		parent::__construct(PIWIK_INCLUDE_PATH.'/plugins/CoreHome/templates/reports_by_dimension.tpl');
		$this->dimensionCategories = array();
	}
	
	/**
	 * Adds a report to the list of reports to display.
	 * 
	 * @param string $category The report's category. Can be a i18n token.
	 * @param string $title The report's title. Can be a i18n token.
	 * @param string $action The controller action used to load the report, ie, Referrers.getAll
	 * @param array $params The list of query parameters to use when loading the report.
	 *                      This list overrides query parameters currently in use. For example,
	 *                        array('idSite' => 2, 'viewDataTable' => 'goalsTable')
	 *                      would mean the goals report for site w/ ID=2 will always be loaded.
	 */
	public function addReport( $category, $title, $action, $params = array() )
	{
		list($module, $action) = explode('.', $action);
		$params = array('module' => $module, 'action' => $action) + $params;
		
		$categories = $this->dimensionCategories;
		$categories[$category][] = array(
			'title' => $title,
			'params' => $params,
			'url' => Piwik_Url::getCurrentQueryStringWithParametersModified($params)
		);
		$this->dimensionCategories = $categories;
	}
	
	/**
	 * Adds a set of reports to the list of reports to display.
	 * 
	 * @param array $reports An array containing report information. The array requires
	 *                       the 'category', 'title', 'action' and 'params' elements.
	 *                       For information on what they should contain, @see addReport.
	 */
	public function addReports( $reports )
	{
		foreach ($reports as $report)
		{
			$this->addReport($report['category'], $report['title'], $report['action'], $report['params']);
		}
	}
	
	/**
	 * Renders this view.
	 * 
	 * @return string The rendered view.
	 */
	public function render()
	{
		$this->firstReport = "";
		
		// if there are reports & report categories added, render the first one so we can
		// display it initially
		$categories = $this->dimensionCategories;
		if (!empty($categories))
		{
			$firstReportInfo = reset(reset($categories));
			
			$oldGet = $_GET;
			$oldPost = $_POST;
			
			foreach ($firstReportInfo['params'] as $key => $value)
			{
				$_GET[$key] = $value;
			}
		
			$_POST = array();
			
			$module = $firstReportInfo['params']['module'];
			$action = $firstReportInfo['params']['action'];
			$this->firstReport = Piwik_FrontController::getInstance()->fetchDispatch($module, $action);
		
			$_GET = $oldGet;
			$_POST = $oldPost;
		}
		
		return parent::render();
	}
}