/** * Constructor. */ public function __construct($apiModule, $apiMethod, $request) { $this->apiModule = $apiModule; $this->apiMethod = $apiMethod; $this->setRequest($request); $this->report = ReportsProvider::factory($apiModule, $apiMethod); $this->apiInconsistencies = new Inconsistencies(); $this->setFormatter(new Formatter()); }
private function createReportController($module, $action, array &$parameters) { $report = ReportsProvider::factory($module, $action); if (!$report) { return null; } $parameters['report'] = $report; return array($this->createCoreHomeController(), 'renderReportWidget'); }
public function getWidgetConfigs() { $report = ReportsProvider::factory('VisitsSummary', 'get'); $factory = new ReportWidgetFactory($report); $widgets = array(); $list = new WidgetsList(); $report->configureWidgets($list, $factory); foreach ($list->getWidgetConfigs() as $config) { $config->setIsNotWidgetizable(); $widgets[] = $config; } return $widgets; }
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; }
/** * 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 = ReportsProvider::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; }
/** * Convenience method that creates and renders a ViewDataTable for a API method. * * @param string|\Piwik\Plugin\Report $apiAction The name of the API action (eg, `'getResolution'`) or * an instance of an report. * @param bool $controllerAction The name of the Controller action name that is rendering the report. Defaults * to the `$apiAction`. * @param bool $fetch If `true`, the rendered string is returned, if `false` it is `echo`'d. * @throws \Exception if `$pluginName` is not an existing plugin or if `$apiAction` is not an * existing method of the plugin's API. * @return string|void See `$fetch`. * @api */ protected function renderReport($apiAction, $controllerAction = false) { if (empty($controllerAction) && is_string($apiAction)) { $report = ReportsProvider::factory($this->pluginName, $apiAction); if (!empty($report)) { $apiAction = $report; } } if ($apiAction instanceof Report) { $this->checkSitePermission(); $apiAction->checkIsEnabled(); return $apiAction->render(); } $pluginName = $this->pluginName; /** @var Proxy $apiProxy */ $apiProxy = Proxy::getInstance(); if (!$apiProxy->isExistingApiAction($pluginName, $apiAction)) { throw new \Exception("Invalid action name '{$apiAction}' for '{$pluginName}' plugin."); } $apiAction = $apiProxy->buildApiActionName($pluginName, $apiAction); if ($controllerAction !== false) { $controllerAction = $pluginName . '.' . $controllerAction; } $view = ViewDataTableFactory::build(null, $apiAction, $controllerAction); $rendered = $view->render(); return $rendered; }
private function setThisReportMetadata($report) { list($module, $method) = explode('.', $report); $this->thisReport = ReportsProvider::factory($module, $method); if (empty($this->thisReport)) { throw new Exception("Unable to find report '{$report}'."); } $this->subtableDimension = $this->thisReport->getSubtableDimension(); $thisReportDimension = $this->thisReport->getDimension(); if ($thisReportDimension !== null) { $segments = $thisReportDimension->getSegments(); $this->thisReportDimensionSegment = reset($segments); } }
public function getRelatedReports() { return array(ReportsProvider::factory('Actions', 'getExitPageTitles')); }
/** * Return the report object for the given apiAction * @param $apiAction * @return null|Report */ private static function getReport($apiAction) { if (strpos($apiAction, '.') === false) { return; } list($module, $action) = explode('.', $apiAction); $report = ReportsProvider::factory($module, $action); return $report; }
/** * Returns the Dimension instance of this report's subtable report. * * @return Dimension|null The subtable report's dimension or null if there is subtable report or * no dimension for the subtable report. * @api */ public function getSubtableDimension() { if (empty($this->actionToLoadSubTables)) { return null; } list($subtableReportModule, $subtableReportAction) = $this->getSubtableApiMethod(); $subtableReport = ReportsProvider::factory($subtableReportModule, $subtableReportAction); if (empty($subtableReport)) { return null; } return $subtableReport->getDimension(); }
public function getRelatedReports() { return array(ReportsProvider::factory('DevicesDetection', 'getBrowserVersions')); }
public function getRelatedReports() { return array(ReportsProvider::factory('UserLanguage', 'getLanguage')); }
private function checkisValidCallable($module, $action) { if (!Development::isEnabled()) { return; } $prefix = 'Menu item added in ' . get_class($this) . ' will fail when being selected. '; if (!is_string($action)) { Development::error($prefix . 'No valid action is specified. Make sure the defined action that should be executed is a string.'); } $reportAction = lcfirst(substr($action, 4)); if (ReportsProvider::factory($module, $reportAction)) { return; } $controllerClass = '\\Piwik\\Plugins\\' . $module . '\\Controller'; if (!Development::methodExists($controllerClass, $action)) { Development::error($prefix . 'The defined action "' . $action . '" does not exist in ' . $controllerClass . '". Make sure to define such a method.'); } if (!Development::isCallableMethod($controllerClass, $action)) { Development::error($prefix . 'The defined action "' . $action . '" is not callable on "' . $controllerClass . '". Make sure the method is public.'); } }
public function getRelatedReports() { return array(ReportsProvider::factory('Resolution', 'getResolution')); }
/** * Constructor. Initializes display and request properties to their default values. * Posts the {@hook ViewDataTable.configure} event which plugins can use to configure the * way reports are displayed. */ public function __construct($controllerAction, $apiMethodToRequestDataTable, $overrideParams = array()) { if (strpos($controllerAction, '.') === false) { $controllerName = ''; $controllerAction = ''; } else { list($controllerName, $controllerAction) = explode('.', $controllerAction); } $this->requestConfig = static::getDefaultRequestConfig(); $this->config = static::getDefaultConfig(); $this->config->subtable_controller_action = $controllerAction; $this->config->setController($controllerName, $controllerAction); $this->request = new ViewDataTableRequest($this->requestConfig); $this->requestConfig->idSubtable = Common::getRequestVar('idSubtable', false, 'int'); $this->config->self_url = Request::getBaseReportUrl($controllerName, $controllerAction); $this->requestConfig->apiMethodToRequestDataTable = $apiMethodToRequestDataTable; $report = ReportsProvider::factory($this->requestConfig->getApiModuleToRequest(), $this->requestConfig->getApiMethodToRequest()); if (!empty($report)) { /** @var Report $report */ $subtable = $report->getActionToLoadSubTables(); if (!empty($subtable)) { $this->config->subtable_controller_action = $subtable; } $this->config->show_goals = $report->hasGoalMetrics(); $relatedReports = $report->getRelatedReports(); if (!empty($relatedReports)) { foreach ($relatedReports as $relatedReport) { $relatedReportName = $relatedReport->getName(); $this->config->addRelatedReport($relatedReport->getModule() . '.' . $relatedReport->getAction(), $relatedReportName); } } $metrics = $report->getMetrics(); if (!empty($metrics)) { $this->config->addTranslations($metrics); } $processedMetrics = $report->getProcessedMetrics(); if (!empty($processedMetrics)) { $this->config->addTranslations($processedMetrics); } $this->config->title = $report->getName(); $report->configureView($this); } /** * Triggered during {@link ViewDataTable} construction. Subscribers should customize * the view based on the report that is being displayed. * * Plugins that define their own reports must subscribe to this event in order to * specify how the Piwik UI should display the report. * * **Example** * * // event handler * public function configureViewDataTable(ViewDataTable $view) * { * switch ($view->requestConfig->apiMethodToRequestDataTable) { * case 'VisitTime.getVisitInformationPerServerTime': * $view->config->enable_sort = true; * $view->requestConfig->filter_limit = 10; * break; * } * } * * @param ViewDataTable $view The instance to configure. */ Piwik::postEvent('ViewDataTable.configure', array($this)); $this->assignRelatedReportsTitle(); $this->config->show_footer_icons = false == $this->requestConfig->idSubtable; // the exclude low population threshold value is sometimes obtained by requesting data. // to avoid issuing unnecessary requests when display properties are determined by metadata, // we allow it to be a closure. if (isset($this->requestConfig->filter_excludelowpop_value) && $this->requestConfig->filter_excludelowpop_value instanceof \Closure) { $function = $this->requestConfig->filter_excludelowpop_value; $this->requestConfig->filter_excludelowpop_value = $function(); } $this->overrideViewPropertiesWithParams($overrideParams); $this->overrideViewPropertiesWithQueryParams(); }
private function setShouldShowPivotBySubtable() { $report = ReportsProvider::factory($this->controllerName, $this->controllerAction); if (empty($report)) { $this->show_pivot_by_subtable = false; $this->pivot_by_dimension = false; } else { $this->show_pivot_by_subtable = PivotByDimension::isPivotingReportBySubtableSupported($report); $subtableDimension = $report->getSubtableDimension(); if (!empty($subtableDimension)) { $this->pivot_by_dimension = $subtableDimension->getId(); $this->pivot_dimension_name = $subtableDimension->getName(); } } }
public function getRelatedReports() { return array(ReportsProvider::factory('DevicesDetection', 'getOsFamilies')); }
public function configureViewDataTable(ViewDataTable $view) { if ($view->requestConfig->getApiModuleToRequest() != 'Events') { return; } // eg. 'Events.getCategory' $apiMethod = $view->requestConfig->getApiMethodToRequest(); $secondaryDimension = $this->getSecondaryDimensionFromRequest(); $view->config->subtable_controller_action = API::getInstance()->getActionToLoadSubtables($apiMethod, $secondaryDimension); $pivotBy = Common::getRequestVar('pivotBy', false); if (empty($pivotBy)) { $view->config->columns_to_display = array('label', 'nb_events', 'sum_event_value'); } $view->config->show_flatten_table = true; $view->requestConfig->filter_sort_column = 'nb_events'; if ($view->isViewDataTableId(AllColumns::ID)) { $view->config->filters[] = function (DataTable $table) use($view) { $columsToDisplay = array('label'); $columns = $table->getColumns(); if (in_array('nb_visits', $columns)) { $columsToDisplay[] = 'nb_visits'; } if (in_array('nb_uniq_visitors', $columns)) { $columsToDisplay[] = 'nb_uniq_visitors'; } $view->config->columns_to_display = array_merge($columsToDisplay, array('nb_events', 'sum_event_value', 'avg_event_value', 'min_event_value', 'max_event_value')); if (!in_array($view->requestConfig->filter_sort_column, $view->config->columns_to_display)) { $view->requestConfig->filter_sort_column = 'nb_events'; } }; $view->config->show_pivot_by_subtable = false; } $labelTranslation = $this->getColumnTranslation($apiMethod); $view->config->addTranslation('label', $labelTranslation); $view->config->addTranslations($this->getMetricTranslations()); $this->addRelatedReports($view, $secondaryDimension); $this->addTooltipEventValue($view); $subtableReport = ReportsProvider::factory('Events', $view->config->subtable_controller_action); $view->config->pivot_by_dimension = $subtableReport->getDimension()->getId(); $view->config->pivot_by_column = 'nb_events'; }
public function getRelatedReports() { return array(ReportsProvider::factory('VisitTime', 'getByDayOfWeek')); }
public function getRelatedReports() { return array(ReportsProvider::factory('Actions', 'getPageUrlsFollowingSiteSearch')); }
private function createWidgetForReport($module, $action) { $report = ReportsProvider::factory($module, $action); $factory = new ReportWidgetFactory($report); return $factory->createWidget(); }
public function getRelatedReports() { return array(ReportsProvider::factory('DBStats', 'getMetricDataSummaryByYear')); }
public final function __construct($controllerAction, $apiMethodToRequestDataTable, $params = array()) { $templateFile = static::TEMPLATE_FILE; if (empty($templateFile)) { throw new \Exception('You have not defined a constant named TEMPLATE_FILE in your visualization class.'); } $this->metricsFormatter = new HtmlFormatter(); parent::__construct($controllerAction, $apiMethodToRequestDataTable, $params); $this->report = ReportsProvider::factory($this->requestConfig->getApiModuleToRequest(), $this->requestConfig->getApiMethodToRequest()); }
public function getRelatedReports() { return array(ReportsProvider::factory('VisitTime', 'getVisitInformationPerLocalTime')); }
/** * Similar to {@link get()} but does not return any metrics for new and returning visitors. It won't apply * any segment by default. This method is deprecated from the API as it is only there to make the implementation of * the actual {@link get()} method easy. * * @deprecated * @internal */ public function getMetrics($idSite, $period, $date, $segment = false, $idGoal = false, $columns = array()) { Piwik::checkUserHasViewAccess($idSite); $archive = Archive::build($idSite, $period, $date, $segment); // Mapping string idGoal to internal ID $idGoal = self::convertSpecialGoalIds($idGoal); $isEcommerceGoal = $idGoal === GoalManager::IDGOAL_ORDER || $idGoal === GoalManager::IDGOAL_CART; $allMetrics = Goals::getGoalColumns($idGoal); $columnsToShow = Piwik::getArrayFromApiParameter($columns); $requestedColumns = $columnsToShow; $shouldAddAverageOrderRevenue = (in_array('avg_order_revenue', $requestedColumns) || empty($requestedColumns)) && $isEcommerceGoal; if ($shouldAddAverageOrderRevenue && !empty($requestedColumns)) { $avgOrder = new AverageOrderRevenue(); $metricsToAdd = $avgOrder->getDependentMetrics(); $requestedColumns = array_unique(array_merge($requestedColumns, $metricsToAdd)); } $report = ReportsProvider::factory('Goals', 'getMetrics'); $columnsToGet = $report->getMetricsRequiredForReport($allMetrics, $requestedColumns); $inDbMetricNames = array_map(function ($name) use($idGoal) { return $name == 'nb_visits' ? $name : Archiver::getRecordName($name, $idGoal); }, $columnsToGet); $dataTable = $archive->getDataTableFromNumeric($inDbMetricNames); if (count($columnsToGet) > 0) { $newNameMapping = array_combine($inDbMetricNames, $columnsToGet); } else { $newNameMapping = array(); } $dataTable->filter('ReplaceColumnNames', array($newNameMapping)); // TODO: this should be in Goals/Get.php but it depends on idGoal parameter which isn't always in _GET (ie, // it's not in ProcessedReport.php). more refactoring must be done to report class before this can be // corrected. if ($shouldAddAverageOrderRevenue) { $dataTable->filter(function (DataTable $table) { $extraProcessedMetrics = $table->getMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME); if (empty($extraProcessedMetrics)) { $extraProcessedMetrics = array(); } $extraProcessedMetrics[] = new AverageOrderRevenue(); $table->setMetadata(DataTable::EXTRA_PROCESSED_METRICS_METADATA_NAME, $extraProcessedMetrics); }); } // remove temporary metrics that were not explicitly requested if (empty($columnsToShow)) { $columnsToShow = $allMetrics; $columnsToShow[] = 'conversion_rate'; if ($isEcommerceGoal) { $columnsToShow[] = 'avg_order_revenue'; } } $dataTable->queueFilter('ColumnDelete', array($columnsToRemove = array(), $columnsToShow)); return $dataTable; }