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

Html.php « Renderer « DataTable « modules - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2ef404653c82d961cbe55fdb17ac07619c0e77eb (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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?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$
 * 
 * @package Piwik_DataTable
 */

/**
 * Simple HTML output
 * Works with recursive DataTable (when a row can be associated with a subDataTable).
 * 
 * @package Piwik_DataTable
 * @subpackage Piwik_DataTable_Renderer
 */
class Piwik_DataTable_Renderer_Html extends Piwik_DataTable_Renderer
{
	protected $prefixRows;
	function __construct($table = null)
	{
		parent::__construct($table);
	}
	
	function render()
	{
		return $this->renderTable($this->table);
	}
	
	protected function renderTable($table)
	{
		if($table instanceof Piwik_DataTable_Array)
		{
			$columnPrefixToAdd = $table->getNameKey();
			$out = "<table border=1>";
			foreach($table->getArray() as $date => $subtable )
			{
				$out .= "<tr><td><h2>$columnPrefixToAdd = $date</h2>";
				$out .= $this->renderDataTable($subtable);
				$out .= "</td></tr>";
			}
			$out .= "</table>";
		}
		else
		{
			$out = $this->renderDataTable($table);
		}
		
		return $out;
	}	
	
	protected function renderDataTable($table)
	{
	
		if($table->getRowsCount() == 0)
		{
			return "<b><i>Empty table</i></b> <br>\n";
		}
		if($table instanceof Piwik_DataTable_Simple 
			&& $table->getRowsCount() ==1)
		{
			$table->deleteColumn('label');
		}
		
		static $depth=0;
		$i = 1;
		$someDetails = false;
		$someIdSubTable = false;
		
		$tableStructure = array();
		
		/*
		 * table = array
		 * ROW1 = col1 | col2 | col3 | details | idSubTable
		 * ROW2 = col1 | col2 (no value but appears) | col3 | details | idSubTable
		 * 		subtable here
		 */
		$allColumns = array();
//		echo $table;
		foreach($table->getRows() as $row)
		{
			foreach($row->getColumns() as $column => $value)
			{
				$allColumns[$column] = true;
				$tableStructure[$i][$column] = $value;
			}

			$details=array();
			foreach($row->getDetails() as $detail => $value)
			{
				if(is_string($value)) $value = "'$value'";
				$details[] = "'$detail' => $value";
			}
			
			if(count($details) != 0)
			{
				$someDetails = true;
				$details = implode("<br>", $details);
				$tableStructure[$i]['_details'] = $details;
			}
			
			$idSubtable = $row->getIdSubDataTable();
			if(!is_null($idSubtable))
			{
				$someIdSubTable = true;
				$tableStructure[$i]['_idSubtable'] = $idSubtable;
			}
			
			if($row->getIdSubDataTable() !== null)
			{
				$depth++;
				try{
					$tableStructure[$i]['_subtable']['html'] =  $this->renderTable( Piwik_DataTable_Manager::getInstance()->getTable($row->getIdSubDataTable()));
				} catch(Exception $e) {
					$tableStructure[$i]['_subtable']['html'] = "-- Sub DataTable not loaded";
				}
				$tableStructure[$i]['_subtable']['depth'] = $depth;
				$depth--;
			}
			$i++;
		}
		
		/*
		// to keep the same columns order as the columns labelled with strings
		ksort($allColumns);
		//replace the label first
		if(isset($allColumns['label']))
		{
			$allColumns = array_merge(array('label'=>true),$allColumns);
		}
		*/
		$allColumns['_details'] = $someDetails;
		$allColumns['_idSubtable'] = $someIdSubTable;
		$html = "\n";
		$html .= "<table border=1 width=70%>";
		$html .= "\n<tr>";
		foreach($allColumns as $name => $toDisplay)
		{
			if($toDisplay !== false)
			{
				$html .= "\n\t<td><b>$name</b></td>";
			}
		}
		$colspan = count($allColumns);
		
		foreach($tableStructure as $row)
		{
			$html .= "\n\n<tr>";
			foreach($allColumns as $name => $toDisplay)
			{
				if($toDisplay !== false)
				{
					$value = "-";
					if(isset($row[$name]))
					{
						$value = $row[$name];
					}
					
					$html .= "\n\t<td>$value</td>";
				}
			}
			$html .= "</tr>";
			
			if(isset($row['_subtable']))
			{
//				echo ".".$row['_subtable'];exit;
				$html .= "<tr>
						<td class=l{$row['_subtable']['depth']} colspan=$colspan>{$row['_subtable']['html']}</td></tr>";
			}
		}
		$html .= "\n\n</table>";
		
		// display styles if there is a subtable displayed
		if($someIdSubTable)
		{
			$styles="\n\n<style>\n";
			for($i=0;$i<11;$i++)
			{
				$padding=$i*2;
				$styles.= "\t TD.l$i { padding-left:{$padding}em; } \n";
			}
			$styles.="</style>\n\n";
			if($depth == 0)
			{
				$html = $styles . $html;
			}
		}
		return $html;
	}
}