本文整理汇总了PHP中Piwik\Piwik::getArrayFromApiParameter方法的典型用法代码示例。如果您正苦于以下问题:PHP Piwik::getArrayFromApiParameter方法的具体用法?PHP Piwik::getArrayFromApiParameter怎么用?PHP Piwik::getArrayFromApiParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piwik\Piwik
的用法示例。
在下文中一共展示了Piwik::getArrayFromApiParameter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: unprefixColumns
protected function unprefixColumns(&$columns)
{
$columns = Piwik::getArrayFromApiParameter($columns);
foreach ($columns as &$column) {
$column = str_replace(self::COLUMN_SUFFIX, "", $column);
}
}
示例2: getRowEvolution
public function getRowEvolution($idSite, $period, $date, $apiModule, $apiAction, $label = false, $segment = false, $column = false, $language = false, $idGoal = false, $legendAppendMetric = true, $labelUseAbsoluteUrl = true)
{
// validation of requested $period & $date
if ($period == 'range') {
// load days in the range
$period = 'day';
}
if (!Period::isMultiplePeriod($date, $period)) {
throw new Exception("Row evolutions can not be processed with this combination of \\'date\\' and \\'period\\' parameters.");
}
$label = ResponseBuilder::unsanitizeLabelParameter($label);
$labels = Piwik::getArrayFromApiParameter($label);
$metadata = $this->getRowEvolutionMetaData($idSite, $period, $date, $apiModule, $apiAction, $language, $idGoal);
$dataTable = $this->loadRowEvolutionDataFromAPI($metadata, $idSite, $period, $date, $apiModule, $apiAction, $labels, $segment, $idGoal);
if (empty($labels)) {
$labels = $this->getLabelsFromDataTable($dataTable, $labels);
$dataTable = $this->enrichRowAddMetadataLabelIndex($labels, $dataTable);
}
if (count($labels) != 1) {
$data = $this->getMultiRowEvolution($dataTable, $metadata, $apiModule, $apiAction, $labels, $column, $legendAppendMetric, $labelUseAbsoluteUrl);
} else {
$data = $this->getSingleRowEvolution($idSite, $dataTable, $metadata, $apiModule, $apiAction, $labels[0], $labelUseAbsoluteUrl);
}
return $data;
}
示例3: configureView
/**
* Here you can configure how your report should be displayed. For instance whether your report supports a search
* etc. You can also change the default request config. For instance change how many rows are displayed by default.
*
* @param ViewDataTable $view
*/
public function configureView(ViewDataTable $view)
{
if ($view->isViewDataTableId(Sparklines::ID)) {
/** @var Sparklines $view */
$view->config->addSparklineMetric(array('server1'));
$view->config->addSparklineMetric(array('server2'));
$view->config->addTranslations(array('server1' => 'Evolution of temperature for server piwik.org'));
$view->config->addTranslations(array('server2' => 'Evolution of temperature for server dev.piwik.org'));
} elseif ($view->isViewDataTableId(Evolution::ID)) {
/** @var Evolution $view */
$selectableColumns = array('server1', 'server2');
$columns = Common::getRequestVar('columns', false);
if (!empty($columns)) {
$columns = Piwik::getArrayFromApiParameter($columns);
}
$columns = array_merge($columns ? $columns : array(), $selectableColumns);
$view->config->columns_to_display = $columns;
$view->config->addTranslations(array_combine($columns, $columns));
$view->config->selectable_columns = $selectableColumns;
$view->requestConfig->filter_sort_column = 'label';
$view->requestConfig->filter_sort_order = 'asc';
$view->config->documentation = 'My documentation';
$view->config->show_goals = false;
}
}
示例4: get
public function get($idSite, $period, $date, $segment = false, $columns = false)
{
Piwik::checkUserHasViewAccess($idSite);
$archive = Archive::build($idSite, $period, $date, $segment);
// array values are comma separated
$columns = Piwik::getArrayFromApiParameter($columns);
$tempColumns = array();
$bounceRateRequested = $actionsPerVisitRequested = $averageVisitDurationRequested = false;
if (!empty($columns)) {
// make sure base metrics are there for processed metrics
if (false !== ($bounceRateRequested = array_search('bounce_rate', $columns))) {
if (!in_array('nb_visits', $columns)) {
$tempColumns[] = 'nb_visits';
}
if (!in_array('bounce_count', $columns)) {
$tempColumns[] = 'bounce_count';
}
unset($columns[$bounceRateRequested]);
}
if (false !== ($actionsPerVisitRequested = array_search('nb_actions_per_visit', $columns))) {
if (!in_array('nb_visits', $columns)) {
$tempColumns[] = 'nb_visits';
}
if (!in_array('nb_actions', $columns)) {
$tempColumns[] = 'nb_actions';
}
unset($columns[$actionsPerVisitRequested]);
}
if (false !== ($averageVisitDurationRequested = array_search('avg_time_on_site', $columns))) {
if (!in_array('nb_visits', $columns)) {
$tempColumns[] = 'nb_visits';
}
if (!in_array('sum_visit_length', $columns)) {
$tempColumns[] = 'sum_visit_length';
}
unset($columns[$averageVisitDurationRequested]);
}
$tempColumns = array_unique($tempColumns);
rsort($tempColumns);
$columns = array_merge($columns, $tempColumns);
} else {
$bounceRateRequested = $actionsPerVisitRequested = $averageVisitDurationRequested = true;
$columns = $this->getCoreColumns($period);
}
$dataTable = $archive->getDataTableFromNumeric($columns);
// Process ratio metrics from base metrics, when requested
if ($bounceRateRequested !== false) {
$dataTable->filter('ColumnCallbackAddColumnPercentage', array('bounce_rate', 'bounce_count', 'nb_visits', 0));
}
if ($actionsPerVisitRequested !== false) {
$dataTable->filter('ColumnCallbackAddColumnQuotient', array('nb_actions_per_visit', 'nb_actions', 'nb_visits', 1));
}
if ($averageVisitDurationRequested !== false) {
$dataTable->filter('ColumnCallbackAddColumnQuotient', array('avg_time_on_site', 'sum_visit_length', 'nb_visits', 0));
}
// remove temp metrics that were used to compute processed metrics
$dataTable->deleteColumns($tempColumns);
return $dataTable;
}
示例5: getEvolutionGraph
public function getEvolutionGraph($fetch = false, array $columns = array())
{
if (empty($columns)) {
$columns = Common::getRequestVar('columns');
$columns = Piwik::getArrayFromApiParameter($columns);
}
$view = $this->getLastUnitGraphAcrossPlugins($this->pluginName, __FUNCTION__, $columns, $selectableColumns = array('server1', 'server2'), 'My documentation', 'ExampleUI.getTemperaturesEvolution');
$view->requestConfig->filter_sort_column = 'label';
return $this->renderView($view);
}
示例6: get
public function get($idSite, $period, $date, $segment = false, $columns = false)
{
Piwik::checkUserHasViewAccess($idSite);
$archive = Archive::build($idSite, $period, $date, $segment);
$requestedColumns = Piwik::getArrayFromApiParameter($columns);
$report = ReportsProvider::factory("VisitsSummary", "get");
$columns = $report->getMetricsRequiredForReport($this->getCoreColumns($period), $requestedColumns);
$dataTable = $archive->getDataTableFromNumeric($columns);
if (!empty($requestedColumns)) {
$columnsToShow = $requestedColumns ?: $report->getAllMetrics();
$dataTable->queueFilter('ColumnDelete', array($columnsToRemove = array(), $columnsToShow));
}
return $dataTable;
}
示例7: get
/**
* Returns the list of metrics (pages, downloads, outlinks)
*
* @param int $idSite
* @param string $period
* @param string $date
* @param bool|string $segment
* @param bool|array $columns
* @return DataTable
*/
public function get($idSite, $period, $date, $segment = false, $columns = false)
{
Piwik::checkUserHasViewAccess($idSite);
$archive = Archive::build($idSite, $period, $date, $segment);
$metrics = Archiver::$actionsAggregateMetrics;
$metrics['Actions_avg_time_generation'] = 'avg_time_generation';
// get requested columns
$columns = Piwik::getArrayFromApiParameter($columns);
if (!empty($columns)) {
// get the columns that are available and requested
$columns = array_intersect($columns, array_values($metrics));
$columns = array_values($columns);
// make sure indexes are right
$nameReplace = array();
foreach ($columns as $i => $column) {
$fullColumn = array_search($column, $metrics);
$columns[$i] = $fullColumn;
$nameReplace[$fullColumn] = $column;
}
if (false !== ($avgGenerationTimeRequested = array_search('Actions_avg_time_generation', $columns))) {
unset($columns[$avgGenerationTimeRequested]);
$avgGenerationTimeRequested = true;
}
} else {
// get all columns
unset($metrics['Actions_avg_time_generation']);
$columns = array_keys($metrics);
$nameReplace =& $metrics;
$avgGenerationTimeRequested = true;
}
if ($avgGenerationTimeRequested) {
$tempColumns[] = Archiver::METRIC_SUM_TIME_RECORD_NAME;
$tempColumns[] = Archiver::METRIC_HITS_TIMED_RECORD_NAME;
$columns = array_merge($columns, $tempColumns);
$columns = array_unique($columns);
$nameReplace[Archiver::METRIC_SUM_TIME_RECORD_NAME] = 'sum_time_generation';
$nameReplace[Archiver::METRIC_HITS_TIMED_RECORD_NAME] = 'nb_hits_with_time_generation';
}
$table = $archive->getDataTableFromNumeric($columns);
// replace labels (remove Actions_)
$table->filter('ReplaceColumnNames', array($nameReplace));
// compute avg generation time
if ($avgGenerationTimeRequested) {
$table->filter('ColumnCallbackAddColumnQuotient', array('avg_time_generation', 'sum_time_generation', 'nb_hits_with_time_generation', 3));
$table->deleteColumns(array('sum_time_generation', 'nb_hits_with_time_generation'));
}
return $table;
}
示例8: getEvolutionGraph
public function getEvolutionGraph(array $columns = array(), array $defaultColumns = array())
{
if (empty($columns)) {
$columns = Common::getRequestVar('columns', false);
if (false !== $columns) {
$columns = Piwik::getArrayFromApiParameter($columns);
}
}
$view = $this->getLastUnitGraphAcrossPlugins($this->pluginName, __FUNCTION__, $columns, $selectableColumns = array('server1', 'server2'), 'My documentation', 'ExampleUI.getTemperaturesEvolution');
$view->requestConfig->filter_sort_column = 'label';
$view->requestConfig->filter_sort_order = 'asc';
if (empty($view->config->columns_to_display) && !empty($defaultColumns)) {
$view->config->columns_to_display = $defaultColumns;
}
return $this->renderView($view);
}
示例9: get
/**
* Returns the list of metrics (pages, downloads, outlinks)
*
* @param int $idSite
* @param string $period
* @param string $date
* @param bool|string $segment
* @param bool|array $columns
* @return DataTable
*/
public function get($idSite, $period, $date, $segment = false, $columns = false)
{
Piwik::checkUserHasViewAccess($idSite);
$report = Report::factory("Actions", "get");
$archive = Archive::build($idSite, $period, $date, $segment);
$requestedColumns = Piwik::getArrayFromApiParameter($columns);
$columns = $report->getMetricsRequiredForReport($allColumns = null, $requestedColumns);
$inDbColumnNames = array_map(function ($value) {
return 'Actions_' . $value;
}, $columns);
$dataTable = $archive->getDataTableFromNumeric($inDbColumnNames);
$dataTable->deleteColumns(array_diff($requestedColumns, $columns));
$newNameMapping = array_combine($inDbColumnNames, $columns);
$dataTable->filter('ReplaceColumnNames', array($newNameMapping));
$columnsToShow = $requestedColumns ?: $report->getAllMetrics();
$dataTable->queueFilter('ColumnDelete', array($columnsToRemove = array(), $columnsToShow));
return $dataTable;
}
示例10: getEvolutionGraph
public function getEvolutionGraph(array $columns = array(), array $defaultColumns = array())
{
if (empty($columns)) {
$columns = Common::getRequestVar('columns', false);
if (false !== $columns) {
$columns = Piwik::getArrayFromApiParameter($columns);
}
}
$documentation = Piwik::translate('VisitsSummary_VisitsSummaryDocumentation') . '<br />' . Piwik::translate('General_BrokenDownReportDocumentation') . '<br /><br />' . '<b>' . Piwik::translate('General_ColumnNbVisits') . ':</b> ' . Piwik::translate('General_ColumnNbVisitsDocumentation') . '<br />' . '<b>' . Piwik::translate('General_ColumnNbUniqVisitors') . ':</b> ' . Piwik::translate('General_ColumnNbUniqVisitorsDocumentation') . '<br />' . '<b>' . Piwik::translate('General_ColumnNbActions') . ':</b> ' . Piwik::translate('General_ColumnNbActionsDocumentation') . '<br />' . '<b>' . Piwik::translate('General_ColumnNbUsers') . ':</b> ' . Piwik::translate('General_ColumnNbUsersDocumentation') . ' (<a target="_blank" href="http://piwik.org/docs/user-id/">User ID</a>)<br />' . '<b>' . Piwik::translate('General_ColumnActionsPerVisit') . ':</b> ' . Piwik::translate('General_ColumnActionsPerVisitDocumentation');
$selectableColumns = array('nb_visits', 'nb_uniq_visitors', 'nb_users', 'avg_time_on_site', 'bounce_rate', 'nb_actions_per_visit', 'max_actions', 'nb_visits_converted', 'nb_pageviews', 'nb_uniq_pageviews', 'nb_downloads', 'nb_uniq_downloads', 'nb_outlinks', 'nb_uniq_outlinks', 'avg_time_generation');
$idSite = Common::getRequestVar('idSite');
$displaySiteSearch = Site::isSiteSearchEnabledFor($idSite);
if ($displaySiteSearch) {
$selectableColumns[] = 'nb_searches';
$selectableColumns[] = 'nb_keywords';
}
$view = $this->getLastUnitGraphAcrossPlugins($this->pluginName, __FUNCTION__, $columns, $selectableColumns, $documentation);
if (empty($view->config->columns_to_display) && !empty($defaultColumns)) {
$view->config->columns_to_display = $defaultColumns;
}
return $this->renderView($view);
}
示例11: overrideViewPropertiesWithQueryParams
private function overrideViewPropertiesWithQueryParams()
{
$properties = $this->getOverridableProperties();
foreach ($properties as $name) {
if (property_exists($this->requestConfig, $name)) {
$this->requestConfig->{$name} = $this->getPropertyFromQueryParam($name, $this->requestConfig->{$name});
} elseif (property_exists($this->config, $name)) {
$this->config->{$name} = $this->getPropertyFromQueryParam($name, $this->config->{$name});
}
}
// handle special 'columns' query parameter
$columns = Common::getRequestVar('columns', false);
if (false !== $columns) {
$this->config->columns_to_display = Piwik::getArrayFromApiParameter($columns);
array_unshift($this->config->columns_to_display, 'label');
}
}
示例12: getSitesIdFromTimezones
/**
* Returns all websites with a timezone matching one the specified timezones
*
* @param array $timezones
* @return array
* @ignore
*/
public function getSitesIdFromTimezones($timezones)
{
Piwik::checkUserHasSuperUserAccess();
$timezones = Piwik::getArrayFromApiParameter($timezones);
$timezones = array_unique($timezones);
$ids = Db::get()->fetchAll('SELECT idsite
FROM ' . Common::prefixTable('site') . '
WHERE timezone IN (' . Common::getSqlStringFieldsArray($timezones) . ')
ORDER BY idsite ASC', $timezones);
$return = array();
foreach ($ids as $id) {
$return[] = $id['idsite'];
}
return $return;
}
示例13: get
/**
* Returns Goals data
*
* @param int $idSite
* @param string $period
* @param string $date
* @param bool $segment
* @param bool|int $idGoal
* @param array $columns Array of metrics to fetch: nb_conversions, conversion_rate, revenue
* @return DataTable
*/
public function get($idSite, $period, $date, $segment = false, $idGoal = false, $columns = array())
{
Piwik::checkUserHasViewAccess($idSite);
$archive = Archive::build($idSite, $period, $date, $segment);
$columns = Piwik::getArrayFromApiParameter($columns);
// Mapping string idGoal to internal ID
$idGoal = self::convertSpecialGoalIds($idGoal);
if (empty($columns)) {
$columns = Goals::getGoalColumns($idGoal);
if ($idGoal == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER) {
$columns[] = 'avg_order_revenue';
}
}
if (in_array('avg_order_revenue', $columns) && $idGoal == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER) {
$columns[] = 'nb_conversions';
$columns[] = 'revenue';
$columns = array_values(array_unique($columns));
}
$columnsToSelect = array();
foreach ($columns as &$columnName) {
$columnsToSelect[] = Archiver::getRecordName($columnName, $idGoal);
}
$dataTable = $archive->getDataTableFromNumeric($columnsToSelect);
// Rewrite column names as we expect them
foreach ($columnsToSelect as $id => $oldName) {
$dataTable->renameColumn($oldName, $columns[$id]);
}
if ($idGoal == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER) {
if ($dataTable instanceof DataTable\Map) {
foreach ($dataTable->getDataTables() as $row) {
$this->enrichTable($row);
}
} else {
$this->enrichTable($dataTable);
}
}
return $dataTable;
}
示例14: get
/**
* Get a combined report of the *.get API methods.
*/
public function get($idSite, $period, $date, $segment = false, $columns = false)
{
$columns = Piwik::getArrayFromApiParameter($columns);
// build columns map for faster checks later on
$columnsMap = array();
foreach ($columns as $column) {
$columnsMap[$column] = true;
}
// find out which columns belong to which plugin
$columnsByPlugin = array();
$meta = \Piwik\Plugins\API\API::getInstance()->getReportMetadata($idSite, $period, $date);
foreach ($meta as $reportMeta) {
// scan all *.get reports
if ($reportMeta['action'] == 'get' && !isset($reportMeta['parameters']) && $reportMeta['module'] != 'API' && !empty($reportMeta['metrics'])) {
$plugin = $reportMeta['module'];
foreach ($reportMeta['metrics'] as $column => $columnTranslation) {
// a metric from this report has been requested
if (isset($columnsMap[$column]) || empty($columnsMap)) {
$columnsByPlugin[$plugin][] = $column;
}
}
}
}
krsort($columnsByPlugin);
$mergedDataTable = false;
$params = compact('idSite', 'period', 'date', 'segment', 'idGoal');
foreach ($columnsByPlugin as $plugin => $columns) {
// load the data
$className = Request::getClassNameAPI($plugin);
$params['columns'] = implode(',', $columns);
$dataTable = Proxy::getInstance()->call($className, 'get', $params);
// make sure the table has all columns
$array = $dataTable instanceof DataTable\Map ? $dataTable->getDataTables() : array($dataTable);
foreach ($array as $table) {
// we don't support idSites=all&date=DATE1,DATE2
if ($table instanceof DataTable) {
$firstRow = $table->getFirstRow();
if (!$firstRow) {
$firstRow = new Row();
$table->addRow($firstRow);
}
foreach ($columns as $column) {
if ($firstRow->getColumn($column) === false) {
$firstRow->setColumn($column, 0);
}
}
}
}
// merge reports
if ($mergedDataTable === false) {
$mergedDataTable = $dataTable;
} else {
$this->mergeDataTables($mergedDataTable, $dataTable);
}
}
return $mergedDataTable;
}
示例15: get
/**
* Get a combined report of the *.get API methods.
*/
public function get($idSite, $period, $date, $segment = false, $columns = false)
{
Piwik::checkUserHasViewAccess($idSite);
$columns = Piwik::getArrayFromApiParameter($columns);
// build columns map for faster checks later on
$columnsMap = array();
foreach ($columns as $column) {
$columnsMap[$column] = true;
}
// find out which columns belong to which plugin
$columnsByPlugin = array();
$meta = \Piwik\Plugins\API\API::getInstance()->getReportMetadata($idSite, $period, $date);
foreach ($meta as $reportMeta) {
// scan all *.get reports
if ($reportMeta['action'] == 'get' && !isset($reportMeta['parameters']) && $reportMeta['module'] != 'API' && !empty($reportMeta['metrics'])) {
$plugin = $reportMeta['module'];
$allMetrics = array_merge($reportMeta['metrics'], @$reportMeta['processedMetrics'] ?: array());
foreach ($allMetrics as $column => $columnTranslation) {
// a metric from this report has been requested
if (isset($columnsMap[$column]) || empty($columnsMap)) {
$columnsByPlugin[$plugin][] = $column;
}
}
}
}
krsort($columnsByPlugin);
$mergedDataTable = false;
$params = compact('idSite', 'period', 'date', 'segment', 'idGoal');
foreach ($columnsByPlugin as $plugin => $columns) {
// load the data
$className = Request::getClassNameAPI($plugin);
$params['columns'] = implode(',', $columns);
$dataTable = Proxy::getInstance()->call($className, 'get', $params);
$dataTable->filter(function (DataTable $table) {
$table->clearQueuedFilters();
});
// merge reports
if ($mergedDataTable === false) {
$mergedDataTable = $dataTable;
} else {
$merger = new MergeDataTables();
$merger->mergeDataTables($mergedDataTable, $dataTable);
}
}
if (!empty($columnsMap) && !empty($mergedDataTable)) {
$mergedDataTable->queueFilter('ColumnDelete', array(false, array_keys($columnsMap)));
}
return $mergedDataTable;
}