本文整理匯總了PHP中Piwik\Metrics::getDefaultMetricTranslations方法的典型用法代碼示例。如果您正苦於以下問題:PHP Metrics::getDefaultMetricTranslations方法的具體用法?PHP Metrics::getDefaultMetricTranslations怎麽用?PHP Metrics::getDefaultMetricTranslations使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Piwik\Metrics
的用法示例。
在下文中一共展示了Metrics::getDefaultMetricTranslations方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: renderSidebar
/** Render the area left of the iframe */
public function renderSidebar()
{
$idSite = Common::getRequestVar('idSite');
$period = Common::getRequestVar('period');
$date = Common::getRequestVar('date');
$currentUrl = Common::getRequestVar('currentUrl');
$currentUrl = Common::unsanitizeInputValue($currentUrl);
$normalizedCurrentUrl = PageUrl::excludeQueryParametersFromUrl($currentUrl, $idSite);
$normalizedCurrentUrl = Common::unsanitizeInputValue($normalizedCurrentUrl);
// load the appropriate row of the page urls report using the label filter
ArchivingHelper::reloadConfig();
$path = ArchivingHelper::getActionExplodedNames($normalizedCurrentUrl, Action::TYPE_PAGE_URL);
$path = array_map('urlencode', $path);
$label = implode('>', $path);
$request = new Request('method=Actions.getPageUrls' . '&idSite=' . urlencode($idSite) . '&date=' . urlencode($date) . '&period=' . urlencode($period) . '&label=' . urlencode($label) . '&format=original' . '&format_metrics=0');
$dataTable = $request->process();
$formatter = new Metrics\Formatter\Html();
$data = array();
if ($dataTable->getRowsCount() > 0) {
$row = $dataTable->getFirstRow();
$translations = Metrics::getDefaultMetricTranslations();
$showMetrics = array('nb_hits', 'nb_visits', 'nb_users', 'nb_uniq_visitors', 'bounce_rate', 'exit_rate', 'avg_time_on_page');
foreach ($showMetrics as $metric) {
$value = $row->getColumn($metric);
if ($value === false) {
// skip unique visitors for period != day
continue;
}
if ($metric == 'bounce_rate' || $metric == 'exit_rate') {
$value = $formatter->getPrettyPercentFromQuotient($value);
} else {
if ($metric == 'avg_time_on_page') {
$value = $formatter->getPrettyTimeFromSeconds($value, $displayAsSentence = true);
}
}
$data[] = array('name' => $translations[$metric], 'value' => $value);
}
}
// generate page url string
foreach ($path as &$part) {
$part = preg_replace(';^/;', '', urldecode($part));
}
$page = '/' . implode('/', $path);
$page = preg_replace(';/index$;', '/', $page);
if ($page == '/') {
$page = '/index';
}
// render template
$view = new View('@Overlay/renderSidebar');
$view->data = $data;
$view->location = $page;
$view->normalizedUrl = $normalizedCurrentUrl;
$view->label = $label;
$view->idSite = $idSite;
$view->period = $period;
$view->date = $date;
$this->outputCORSHeaders();
return $view->render();
}
示例2: getMetricTranslations
private function getMetricTranslations($metricsToTranslate)
{
$translations = Metrics::getDefaultMetricTranslations();
$metrics = array();
foreach ($metricsToTranslate as $metric) {
if (!empty($translations[$metric])) {
$metrics[$metric] = $translations[$metric];
} else {
$metrics[$metric] = $metric;
}
}
return $metrics;
}
示例3: translateColumnNames
/**
* Translate column names to the current language.
* Used in subclasses.
*
* @param array $names
* @return array
*/
protected function translateColumnNames($names)
{
if (!$this->apiMethod) {
return $names;
}
// load the translations only once
// when multiple dates are requested (date=...,...&period=day), the meta data would
// be loaded lots of times otherwise
if ($this->columnTranslations === false) {
$meta = $this->getApiMetaData();
if ($meta === false) {
return $names;
}
$t = Metrics::getDefaultMetricTranslations();
foreach (array('metrics', 'processedMetrics', 'metricsGoal', 'processedMetricsGoal') as $index) {
if (isset($meta[$index]) && is_array($meta[$index])) {
$t = array_merge($t, $meta[$index]);
}
}
$this->columnTranslations =& $t;
}
foreach ($names as &$name) {
if (isset($this->columnTranslations[$name])) {
$name = $this->columnTranslations[$name];
}
}
return $names;
}
示例4: getDefaultMetricTranslations
/**
* Default translations for many core metrics.
* This is used for exports with translated labels. The exports contain columns that
* are not visible in the UI and not present in the API meta data. These columns are
* translated here.
* @return array
* @deprecated since Piwik 2.15.1
*/
public function getDefaultMetricTranslations()
{
return Metrics::getDefaultMetricTranslations();
}
示例5: __construct
public function __construct()
{
parent::__construct();
$this->translations = Metrics::getDefaultMetricTranslations();
}
示例6: getMetricTranslations
private function getMetricTranslations($metricsToTranslate)
{
$translations = Metrics::getDefaultMetricTranslations();
$metrics = array();
foreach ($metricsToTranslate as $metric) {
if ($metric instanceof Metric) {
$metricName = $metric->getName();
$translation = $metric->getTranslatedName();
} else {
$metricName = $metric;
$translation = @$translations[$metric];
}
$metrics[$metricName] = $translation ?: $metricName;
}
return $metrics;
}