Newer
Older
* Do not sort this table, leave it as it comes out of the API
*/
public function disableSort()
{
$this->viewProperties['enable_sort'] = false;
}
/**
* Do not show the footer icons (show all columns icon, "plus" icon)
*/
public function disableFooterIcons()
{
$this->viewProperties['show_footer_icons'] = false;
}
/**
* When this method is called, the output will not include the template datatable_footer
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
*/
public function disableFooter()
{
$this->viewProperties['show_footer'] = false;
}
/**
* The "Include low population" link won't be displayed under this table
*/
public function disableExcludeLowPopulation()
{
$this->viewProperties['show_exclude_low_population'] = false;
}
/**
* Whether or not to show the "View table" icon
*/
public function disableShowTable()
{
$this->viewProperties['show_table'] = false;
}
/**
* Whether or not to show the "View more data" icon
*/
public function disableShowAllColumns()
{
$this->viewProperties['show_table_all_columns'] = false;
}
/**
* Whether or not to show the tag cloud, pie charts, bar chart icons
*/
public function disableShowAllViewsIcons()
{
$this->viewProperties['show_all_views_icons'] = false;
}
/**
* Whether or not to hide view icons altogether.
* The difference to disableShowAllViewsIcons is that not even the single icon
* will be shown. This icon might cause trouble because it reloads the graph on click.
*/
public function hideAllViewsIcons()
{
$this->viewProperties['show_all_views_icons'] = false;
$this->viewProperties['hide_all_views_icons'] = true;
}
/**
* Whether or not to show the annotations view. This method has no effect if
* the Annotations plugin is not loaded.
*/
public function showAnnotationsView()
{
if (!Piwik_PluginsManager::getInstance()->isPluginLoaded('Annotations')) {
return;
}
$this->viewProperties['hide_annotations_view'] = false;
}
/**
* Whether or not to show the bar chart icon.
*/
public function disableShowBarChart()
{
$this->viewProperties['show_bar_chart'] = false;
}
/**
* Whether or not to show the pie chart icon.
*/
public function disableShowPieChart()
{
$this->viewProperties['show_pie_chart'] = false;
}
/**
* Whether or not to show the tag cloud icon.
*/
public function disableTagCloud()
{
$this->viewProperties['show_tag_cloud'] = false;
}
/**
* Whether or not to show related reports in the footer
*/
public function disableShowRelatedReports()
{
$this->viewProperties['show_related_reports'] = false;
}
/**
* Whether or not to show the export to RSS feed icon
*/
public function disableShowExportAsRssFeed()
{
$this->viewProperties['show_export_as_rss_feed'] = false;
}
/**
* Whether or not to show the "goal" icon
*/
public function enableShowGoals()
{
if (Piwik_PluginsManager::getInstance()->isPluginActivated('Goals')) {
$this->viewProperties['show_goals'] = true;
}
}
/**
* Whether or not to show the "Ecommerce orders/cart" icons
*/
public function enableShowEcommerce()
{
$this->viewProperties['show_ecommerce'] = true;
}
/**
* Whether or not to show the summary row on every page of results. The default behavior
* is to treat the summary row like any other row.
*/
public function alwaysShowSummaryRow()
{
Benaka Moorthi
a validé
$this->viewProperties['keep_summary_row'] = true;
}
/**
* Sets the value to use for the Exclude low population filter.
*
* @param int|float If a row value is less than this value, it will be removed from the dataTable
* @param string The name of the column for which we compare the value to $minValue
*/
public function setExcludeLowPopulation($columnName = null, $minValue = null)
{
if (is_null($columnName)) {
$columnName = 'nb_visits';
}
Benaka Moorthi
a validé
$this->viewProperties['filter_excludelowpop'] = $columnName;
$this->viewProperties['filter_excludelowpop_value'] = $minValue;
}
/**
* Sets the pattern to look for in the table (only rows matching the pattern will be kept)
*
* @param string $pattern to look for
* @param string $column to compare the pattern to
*/
public function setSearchPattern($pattern, $column)
{
Benaka Moorthi
a validé
$this->viewProperties['filter_pattern'] = $pattern;
$this->viewProperties['filter_column'] = $column;
}
/**
* Sets the maximum number of rows of the table
*
* @param int $limit
*/
public function setLimit($limit)
{
if ($limit !== 0) {
Benaka Moorthi
a validé
$this->viewProperties['filter_limit'] = $limit;
}
}
/**
* Will display a message in the DataTable footer.
*
* @param string $message Message
*/
public function setFooterMessage($message)
{
$this->viewProperties['show_footer_message'] = $message;
}
/**
* Sets the dataTable column to sort by. This sorting will be applied before applying the (offset, limit) filter.
*
mattab
a validé
* @param int|string $columnId eg. 'nb_visits' for some tables, or Piwik_Metrics::INDEX_NB_VISITS for others
* @param string $order desc or asc
*/
public function setSortedColumn($columnId, $order = 'desc')
{
Benaka Moorthi
a validé
$this->viewProperties['filter_sort_column'] = $columnId;
$this->viewProperties['filter_sort_order'] = $order;
}
/**
* Returns the column name on which the table will be sorted
*
* @return string
*/
public function getSortedColumn()
{
Benaka Moorthi
a validé
return isset($this->viewProperties['filter_sort_column']) ? $this->viewProperties['filter_sort_column'] : false;
}
/**
* Sets translation string for given column
*
* @param string $columnName column name
* @param string $columnTranslation column name translation
* @throws Exception
*/
public function setColumnTranslation($columnName, $columnTranslation)
{
Benaka Moorthi
a validé
$this->viewProperties['translations'][$columnName] = $columnTranslation;
}
/**
* Returns column translation if available, in other case given column name
*
* @param string $columnName column name
* @return string
*/
public function getColumnTranslation($columnName)
{
Benaka Moorthi
a validé
if (isset($this->viewProperties['translations'][$columnName])) {
return $this->viewProperties['translations'][$columnName];
}
return $columnName;
}
/**
* Set the documentation of a metric used in the report.
* Please note, that the default way of doing this is by using
* getReportMetadata. Only use this method, if you have a good
* reason to do so.
*
* @param string $metricIdentifier The idenentifier string of
* the metric
* @param string $documentation The metric documentation as a
* translated string
*/
public function setMetricDocumentation($metricIdentifier, $documentation)
{
Benaka Moorthi
a validé
$this->viewProperties['metrics_documentation'][$metricIdentifier] = $documentation;
}
/**
* Returns metric documentation, or false
*
* @param string $columnName column name
* @return bool
*/
public function getMetricDocumentation($columnName)
{
Benaka Moorthi
a validé
if (empty($this->viewProperties['metrics_documentation'])) {
$this->loadDocumentation();
}
Benaka Moorthi
a validé
if (!empty($this->viewProperties['metrics_documentation'][$columnName])) {
return $this->viewProperties['metrics_documentation'][$columnName];
}
return false;
}
/**
* Set the documentation of the report.
* Please note, that the default way of doing this is by using
* getReportMetadata. Only use this method, if you have a good
* reason to do so.
*
* @param string $documentation The report documentation as a
* translated string
*/
public function setReportDocumentation($documentation)
{
Benaka Moorthi
a validé
$this->viewProperties['documentation'] = $documentation;
}
/**
* Returns report documentation, or false
* @return array|bool
*/
public function getReportDocumentation()
{
Benaka Moorthi
a validé
return $this->viewProperties['documentation'];
}
/** Load documentation from the API */
private function loadDocumentation()
{
Benaka Moorthi
a validé
$this->viewProperties['metrics_documentation'] = array();
$report = Piwik_API_API::getInstance()->getMetadata(0, $this->currentControllerName, $this->currentControllerAction);
$report = $report[0];
if (isset($report['metricsDocumentation'])) {
Benaka Moorthi
a validé
$this->viewProperties['metrics_documentation'] = $report['metricsDocumentation'];
}
if (isset($report['documentation'])) {
Benaka Moorthi
a validé
$this->viewProperties['documentation'] = $report['documentation'];
}
}
/**
* Sets the columns that will be displayed in the HTML output
* By default all columns are displayed ($columnsNames = array() will display all columns)
*
* @param array $columnsNames Array of column names eg. array('nb_visits','nb_hits')
*/
public function setColumnsToDisplay($columnsNames)
{
if (!is_array($columnsNames)) {
if (strpos($columnsNames, ',') !== false) {
// array values are comma separated
$columnsNames = explode(',', $columnsNames);
} else {
$columnsNames = array($columnsNames);
}
}
Benaka Moorthi
a validé
$this->viewProperties['columns_to_display'] = array_filter($columnsNames);
}
/**
* Returns columns names to display, in order.
* If no columns were specified to be displayed, return all columns found in the first row.
* If the data table has empty_columns meta data set, those columns will be removed.
* @param array PHP array conversion of the data table
* @return array
*/
public function getColumnsToDisplay()
{
Benaka Moorthi
a validé
if (empty($this->viewProperties['columns_to_display'])) {
$row = $this->dataTable->getFirstRow();
if (empty($row)) {
return array();
}
return array_keys($row->getColumns());
}
Benaka Moorthi
a validé
$this->viewProperties['columns_to_display'] = array_filter($this->viewProperties['columns_to_display']);
$this->removeEmptyColumnsFromDisplay();
Benaka Moorthi
a validé
return $this->viewProperties['columns_to_display'];
}
private function removeEmptyColumnsFromDisplay()
{
if ($this->dataTable instanceof Piwik_DataTable_Array) {
$emptyColumns = $this->dataTable->getMetadataIntersectArray(Piwik_DataTable::EMPTY_COLUMNS_METADATA_NAME);
} else {
$emptyColumns = $this->dataTable->getMetadata(Piwik_DataTable::EMPTY_COLUMNS_METADATA_NAME);
}
if (is_array($emptyColumns)) {
foreach ($emptyColumns as $emptyColumn) {
Benaka Moorthi
a validé
$key = array_search($emptyColumn, $this->viewProperties['columns_to_display']);
if ($key !== false) {
Benaka Moorthi
a validé
unset($this->viewProperties['columns_to_display'][$key]);
}
}
Benaka Moorthi
a validé
$this->viewProperties['columns_to_display'] = array_values($this->viewProperties['columns_to_display']);
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
}
}
/**
* Set whether to highlight the summary row or not. If not highlighted, it will
* look like every other row.
*/
public function setHighlightSummaryRow($highlightSummaryRow)
{
$this->viewProperties['highlight_summary_row'] = $highlightSummaryRow;
}
/**
* Sets the name of the metadata to use for a custom tooltip.
*/
public function setTooltipMetadataName($metadataName)
{
$this->viewProperties['tooltip_metadata_name'] = $metadataName;
}
/**
* Sets columns translations array.
*
* @param array $columnsTranslations An associative array indexed by column names, eg. array('nb_visit'=>"Numer of visits")
*/
public function setColumnsTranslations($columnsTranslations)
{
Benaka Moorthi
a validé
$this->viewProperties['translations'] += $columnsTranslations;
}
/**
* Sets a custom parameter, that will be printed in the javascript array associated with each datatable
*
* @param string $parameter name
* @param mixed $value
* @throws Exception
*/
public function setCustomParameter($parameter, $value)
{
Benaka Moorthi
a validé
if (isset($this->viewProperties['custom_parameters'][$parameter])) {
throw new Exception("$parameter is already defined for this DataTable.");
}
Benaka Moorthi
a validé
$this->viewProperties['custom_parameters'][$parameter] = $value;
}
/**
* Queues a Datatable filter, that will be applied once the datatable is loaded from the API.
* Useful when the controller needs to add columns, or decorate existing columns, when these filters don't
* necessarily make sense directly in the API.
*
* @param string $filterName
* @param mixed $parameters
* @param bool $runBeforeGenericFilters Set to true if the filter will delete rows from the table,
* and should therefore be ran before Sort, Limit, etc.
* @return void
*/
public function queueFilter($filterName, $parameters = array(), $runBeforeGenericFilters = false)
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
{
if ($runBeforeGenericFilters) {
$this->queuedFiltersPriority[] = array($filterName, $parameters);
} else {
$this->queuedFilters[] = array($filterName, $parameters);
}
}
/**
* Adds one report to the set of reports that are related to this one. Related reports
* are displayed in the footer as links. When they are clicked, the report will change to
* the related report.
*
* Make sure to call setReportTitle so this report will be displayed correctly.
*
* @param string $module The report's controller name, ie, 'UserSettings'.
* @param string $action The report's controller action, ie, 'getBrowser'.
* @param string $title The text used to describe the related report.
* @param array $queryParams Any specific query params to use when loading the report.
* This can be used to, for example, make a goal report a related
* report (by adding an idGoal parameter).
*/
public function addRelatedReport($module, $action, $title, $queryParams = array())
{
// don't add the related report if it references this report
if ($this->currentControllerName == $module && $this->currentControllerAction == $action) {
return;
}
$url = $this->getBaseReportUrl($module, $action, $queryParams);
$this->viewProperties['relatedReports'][$url] = $title;
}
/**
* Adds a set of reports that are related to this one. Related reports are displayed in
* the footer as links. When they are clicked, the report will change to the related report.
*
* If you need to associate specific query params with a report, use the addRelatedReport
* method instead of this one.
*
* @param string $thisReportTitle The title of this report.
* @param array $relatedReports An array mapping report IDs ('Controller.methodName') with
* display text.
*/
public function addRelatedReports($thisReportTitle, $relatedReports)
{
Benaka Moorthi
a validé
if (!empty($thisReportTitle)) {
$this->setReportTitle($thisReportTitle);
}
foreach ($relatedReports as $report => $title) {
list($module, $action) = explode('.', $report);
$this->addRelatedReport($module, $action, $title);
}
}
/**
* Sets the title of this report.
*
* @param string $title
*/
public function setReportTitle($title)
{
$this->viewProperties['title'] = $title;
}
/**
* Sets a custom URL to use to reference this report.
*
* @param string $module
* @param string $action
* @param array $queryParams
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
*/
public function setReportUrl($module, $action, $queryParams = array())
{
$this->viewProperties['self_url'] = $this->getBaseReportUrl($module, $action, $queryParams);
}
/**
* Returns true if it is likely that the data for this report has been purged and if the
* user should be told about that.
*
* In order for this function to return true, the following must also be true:
* - The data table for this report must either be empty or not have been fetched.
* - The period of this report is not a multiple period.
* - The date of this report must be older than the delete_reports_older_than config option.
* @return bool
*/
public function hasReportBeenPurged()
{
$strPeriod = Piwik_Common::getRequestVar('period', false);
$strDate = Piwik_Common::getRequestVar('date', false);
if ($strPeriod !== false
&& $strDate !== false
&& (is_null($this->dataTable) || $this->dataTable->getRowsCount() == 0)
) {
// if range, only look at the first date
if ($strPeriod == 'range') {
$idSite = Piwik_Common::getRequestVar('idSite', '');
if (intval($idSite) != 0) {
$site = new Piwik_Site($idSite);
$timezone = $site->getTimezone();
} else {
$timezone = 'UTC';
}
$period = new Piwik_Period_Range('range', $strDate, $timezone);
$reportDate = $period->getDateStart();
} // if a multiple period, this function is irrelevant
else if (Piwik_Period::isMultiplePeriod($strDate, $strPeriod)) {
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
return false;
} // otherwise, use the date as given
else {
$reportDate = Piwik_Date::factory($strDate);
}
$reportYear = $reportDate->toString('Y');
$reportMonth = $reportDate->toString('m');
if (class_exists('Piwik_PrivacyManager')
&& Piwik_PrivacyManager::shouldReportBePurged($reportYear, $reportMonth)
) {
return true;
}
}
return false;
}
/**
* Returns URL for this report w/o any filter parameters.
*
* @param string $module
* @param string $action
* @param array $queryParams
*/
private function getBaseReportUrl($module, $action, $queryParams = array())
{
$params = array_merge($queryParams, array('module' => $module, 'action' => $action));
Benaka Moorthi
a validé
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
return Piwik_API_Request::getCurrentUrlWithoutGenericFilters($params);
}
/**
* Convenience method that creates and renders a ViewDataTable for a API method.
*
* @param string $pluginName The name of the plugin (eg, UserSettings).
* @param string $apiAction The name of the API action (eg, getResolution).
* @param bool $fetch If true, the result is returned, if false it is echo'd.
* @return string|null See $fetch.
*/
static public function render($pluginName, $apiAction, $fetch = true)
{
$apiClassName = 'Piwik_'.$pluginName.'_API';
if (!method_exists($apiClassName::getInstance(), $apiAction)) {
throw new Exception("Invalid action name '$apiAction' for '$pluginName' plugin.");
}
$view = self::factory(null, $pluginName.'.'.$apiAction);
$view->main();
$rendered = $view->getView()->render();
if ($fetch) {
return $rendered;
} else {
echo $rendered;
}
}
/**
* Returns whether the DataTable result will have to be expanded for the
* current request before rendering.
*
* @return bool
*/
public static function shouldLoadExpanded()
{
// if filter_column_recursive & filter_pattern_recursive are supplied, and flat isn't supplied
// we have to load all the child subtables.
return Piwik_Common::getRequestVar('filter_column_recursive', false) !== false
&& Piwik_Common::getRequestVar('filter_pattern_recursive', false) !== false
&& Piwik_Common::getRequestVar('flat', false) === false;
}
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
/**
* Returns true if the first array contains one or more of the specified
* column names or their associated integer INDEX_ value.
*
* @param array $columns Piwik_DataTable_Row columns.
* @param array|string $columnsToCheckFor eg, array('nb_visits', 'nb_uniq_visitors')
* @return bool
*/
private function dataTableColumnsContains($columns, $columnsToCheckFor)
{
if (!is_array($columnsToCheckFor)) {
$columnsToCheckFor = array($columnsToCheckFor);
}
foreach ($columnsToCheckFor as $columnToCheckFor) {
foreach ($columns as $column) {
// check for the column name and its associated integer INDEX_ value
if ($column == $columnToCheckFor
|| (isset(Piwik_Metrics::$mappingFromNameToId[$columnToCheckFor])
&& $column == Piwik_Metrics::$mappingFromNameToId[$columnToCheckFor])
) {
return true;
}
}
}
return false;
}
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
protected function buildView($visualization, $template = false)
{
if ($template === false) {
$template = $this->dataTableTemplate;
}
$view = new Piwik_View($template);
if (!empty($this->loadingError)) {
$view->error = $this->loadingError;
}
$view->visualization = $visualization;
if (!$this->isDataAvailable) {
$view->dataTable = null;
} else {
$view->dataTable = $this->dataTable;
// if it's likely that the report data for this data table has been purged,
// set whether we should display a message to that effect.
$view->showReportDataWasPurgedMessage = $this->hasReportBeenPurged();
$view->deleteReportsOlderThan = Piwik_GetOption('delete_reports_older_than');
}
$view->javascriptVariablesToSet = $this->getJavascriptVariablesToSet();
$view->properties = $this->getViewProperties();
return $view;
}
public function getDefaultDataTableCssClass()
{
return false;
}