php Piwik-Plugin-Report类(方法)实例源码

下面列出了php Piwik-Plugin-Report 类(方法)源码代码实例,从而了解它的用法。

作者:bossrabbi    项目:piwi   
public function renderReportWidget(Report $report)
 {
     Piwik::checkUserHasSomeViewAccess();
     $this->checkSitePermission();
     $report->checkIsEnabled();
     return $report->render();
 }

作者:piwi    项目:piwi   
/**
  * Creates a new container widget based on the specified report in {@link construct()}.
  *
  * It will automatically use the report's categoryId, subcategoryId (if specified) and order in order to
  * create the container.
  *
  * @param string $containerId eg 'Products' or 'Contents' see {Piwik\Widget\WidgetContainerConfig::setId()}.
  *                            Other reports or widgets will be able to add more widgets to this container.
  *                            This is useful when you want to show for example multiple related widgets
  *                            together.
  * @return WidgetContainerConfig
  */
 public function createContainerWidget($containerId)
 {
     $widget = new WidgetContainerConfig();
     $widget->setCategoryId($this->report->getCategoryId());
     $widget->setId($containerId);
     if ($this->report->getSubcategoryId()) {
         $widget->setSubcategoryId($this->report->getSubcategoryId());
     }
     $orderThatListsReportsAtTheEndOfEachCategory = 100 + $this->report->getOrder();
     $widget->setOrder($orderThatListsReportsAtTheEndOfEachCategory);
     return $widget;
 }

作者:piwi    项目:piwi   
protected function init()
 {
     parent::init();
     $this->reportsToMerge = $this->getReportsToMerge();
     $this->module = 'API';
     $this->action = 'get';
     $this->categoryId = 'API';
     $this->name = Piwik::translate('General_MainMetrics');
     $this->documentation = '';
     $this->processedMetrics = array();
     foreach ($this->reportsToMerge as $report) {
         if (!is_array($report->processedMetrics)) {
             continue;
         }
         $this->processedMetrics = array_merge($this->processedMetrics, $report->processedMetrics);
     }
     $this->metrics = array();
     foreach ($this->reportsToMerge as $report) {
         if (!is_array($report->metrics)) {
             continue;
         }
         $this->metrics = array_merge($this->metrics, $report->metrics);
     }
     $this->order = 6;
 }

作者:pombredann    项目:ArcherSy   
public function renderReportWidget($reportModule = null, $reportAction = null)
 {
     Piwik::checkUserHasSomeViewAccess();
     $this->checkSitePermission();
     $report = Report::factory($reportModule, $reportAction);
     if (empty($report)) {
         throw new Exception(Piwik::translate('General_ExceptionReportNotFound'));
     }
     $report->checkIsEnabled();
     return $report->render();
 }

作者:FluentDevelopmen    项目:piwi   
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 = Report::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;
 }

作者:FluentDevelopmen    项目:piwi   
public function indexSiteSearch()
 {
     $view = new View('@Actions/indexSiteSearch');
     $keyword = Report::factory($this->pluginName, 'getSiteSearchKeywords');
     $noResult = Report::factory($this->pluginName, 'getSiteSearchNoResultKeywords');
     $pageUrls = Report::factory($this->pluginName, 'getPageUrlsFollowingSiteSearch');
     $view->keywords = $keyword->render();
     $view->noResultKeywords = $noResult->render();
     $view->pagesUrlsFollowingSiteSearch = $pageUrls->render();
     $categoryTrackingEnabled = Actions::isCustomVariablesPluginsEnabled();
     if ($categoryTrackingEnabled) {
         $categories = Report::factory($this->pluginName, 'getSiteSearchCategories');
         $view->categories = $categories->render();
     }
     return $view->render();
 }

作者:dorelljame    项目:piwi   
public function software()
 {
     $view = new View('@DevicesDetection/software');
     $view->osReport = $this->renderReport('getOsVersions');
     $view->browserReport = $this->renderReport('getBrowsers');
     $view->browserEngineReport = $this->renderReport('getBrowserEngines');
     $isResolutionEnabled = PluginManager::getInstance()->isPluginActivated('Resolution');
     if ($isResolutionEnabled) {
         $view->configurations = $this->renderReport(Report::factory('Resolution', 'getConfiguration'));
     }
     $isDevicePluginsEnabled = PluginManager::getInstance()->isPluginActivated('DevicePlugins');
     if ($isDevicePluginsEnabled) {
         $view->browserPlugins = $this->renderReport(Report::factory('DevicePlugins', 'getPlugin'));
     }
     return $view->render();
 }

作者:FluentDevelopmen    项目:piwi   
/**
  * @return Report[]
  */
 private function getReportsToMerge()
 {
     $result = array();
     foreach (Report::getAllReportClasses() as $reportClass) {
         if ($reportClass == 'Piwik\\Plugins\\API\\Reports\\Get') {
             continue;
         }
         /** @var Report $report */
         $report = new $reportClass();
         if ($report->getModule() == 'API' || $report->getAction() != 'get') {
             continue;
         }
         $metrics = $report->getMetrics();
         if (!empty($report->parameters) || empty($metrics)) {
             continue;
         }
         $result[] = $report;
     }
     return $result;
 }

作者:jos    项目:CGE-File-Sharin   
protected function makeController($module, $action, &$parameters)
 {
     $controllerClassName = $this->getClassNameController($module);
     // TRY TO FIND ACTION IN CONTROLLER
     if (class_exists($controllerClassName)) {
         $class = $this->getClassNameController($module);
         /** @var $controller Controller */
         $controller = new $class();
         $controllerAction = $action;
         if ($controllerAction === false) {
             $controllerAction = $controller->getDefaultAction();
         }
         if (is_callable(array($controller, $controllerAction))) {
             return array($controller, $controllerAction);
         }
         if ($action === false) {
             $this->triggerControllerActionNotFoundError($module, $controllerAction);
         }
     }
     // TRY TO FIND ACTION IN WIDGET
     $widget = Widgets::factory($module, $action);
     if (!empty($widget)) {
         $parameters['widgetModule'] = $module;
         $parameters['widgetMethod'] = $action;
         return array(new CoreHomeController(), 'renderWidget');
     }
     // TRY TO FIND ACTION IN REPORT
     $report = Report::factory($module, $action);
     if (!empty($report)) {
         $parameters['reportModule'] = $module;
         $parameters['reportAction'] = $action;
         return array(new CoreHomeController(), 'renderReportWidget');
     }
     if (!empty($action) && 'menu' === substr($action, 0, 4)) {
         $reportAction = lcfirst(substr($action, 4));
         // menuGetPageUrls => getPageUrls
         $report = Report::factory($module, $reportAction);
         if (!empty($report)) {
             $parameters['reportModule'] = $module;
             $parameters['reportAction'] = $reportAction;
             return array(new CoreHomeController(), 'renderReportMenu');
         }
     }
     $this->triggerControllerActionNotFoundError($module, $action);
 }

作者:hichni    项目:piwi   
/**
  * 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())
 {
     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 = Report::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) {
                 $widgetTitle = $relatedReport->getWidgetTitle();
                 if ($widgetTitle && Common::getRequestVar('widget', 0, 'int')) {
                     $relatedReportName = $widgetTitle;
                 } else {
                     $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);
         }
         $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 unecessary 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();
 }

作者:TensorWrenchOS    项目:piwi   
public function test_getForDimension_ShouldReturnNullIfReportPluginNotLoaded()
 {
     PluginManager::getInstance()->loadPlugins(array());
     $report = Report::getForDimension(new Keyword());
     $this->assertNull($report);
 }

作者:emersonmatsumot    项目:piwi   
/**
  * 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 = Report::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;
 }

作者:CaptainShar    项目:SSAD_Projec   
private function isAllMetricsReport()
 {
     return $this->report->getModule() == 'API' && $this->report->getAction() == 'get';
 }

作者:TensorWrenchOS    项目:piwi   
private static function getAllReportsWithGoalMetrics()
 {
     $reportsWithGoals = array();
     foreach (Report::getAllReports() as $report) {
         if ($report->hasGoalMetrics()) {
             $reportsWithGoals[] = array('category' => $report->getCategory(), 'name' => $report->getName(), 'module' => $report->getModule(), 'action' => $report->getAction());
         }
     }
     /**
      * Triggered when gathering all reports that contain Goal metrics. The list of reports
      * will be displayed on the left column of the bottom of every _Goals_ page.
      *
      * If plugins define reports that contain goal metrics (such as **conversions** or **revenue**),
      * they can use this event to make sure their reports can be viewed on Goals pages.
      *
      * **Example**
      *
      *     public function getReportsWithGoalMetrics(&$reports)
      *     {
      *         $reports[] = array(
      *             'category' => Piwik::translate('MyPlugin_myReportCategory'),
      *             'name' => Piwik::translate('MyPlugin_myReportDimension'),
      *             'module' => 'MyPlugin',
      *             'action' => 'getMyReport'
      *         );
      *     }
      *
      * @param array &$reportsWithGoals The list of arrays describing reports that have Goal metrics.
      *                                 Each element of this array must be an array with the following
      *                                 properties:
      *
      *                                 - **category**: The report category. This should be a translated string.
      *                                 - **name**: The report's translated name.
      *                                 - **module**: The plugin the report is in, eg, `'UserCountry'`.
      *                                 - **action**: The API method of the report, eg, `'getCountry'`.
      * @ignore
      * @deprecated since 2.5.0
      */
     Piwik::postEvent('Goals.getReportsWithGoalMetrics', array(&$reportsWithGoals));
     return $reportsWithGoals;
 }

作者:bossrabbi    项目:piwi   
private function addVisualizationInfoFromMetricMetadata()
 {
     $dataTable = $this->dataTable instanceof DataTable\Map ? $this->dataTable->getFirstRow() : $this->dataTable;
     $metrics = Report::getMetricsForTable($dataTable, $this->report);
     // TODO: instead of iterating & calling translate everywhere, maybe we can get all translated names in one place.
     //       may be difficult, though, since translated metrics are specific to the report.
     foreach ($metrics as $metric) {
         $name = $metric->getName();
         if (empty($this->config->translations[$name])) {
             $this->config->translations[$name] = $metric->getTranslatedName();
         }
         if (empty($this->config->metrics_documentation[$name])) {
             $this->config->metrics_documentation[$name] = $metric->getDocumentation();
         }
     }
 }

作者:Abin    项目:piwi   
public function test_getAllReports_ShouldFindAllAvailableReports()
 {
     $this->loadExampleReportPlugin();
     $this->loadMorePlugins();
     $reports = Report::getAllReports();
     $this->assertGreaterThan(20, count($reports));
     foreach ($reports as $report) {
         $this->assertInstanceOf('Piwik\\Plugin\\Report', $report);
     }
 }

作者:FluentDevelopmen    项目:piwi   
/**
  * Returns if the default viewDataTable ID to use is fixed.
  *
  * @param Report $report
  * @return bool
  */
 private static function isDefaultViewTypeForReportFixed($report)
 {
     if (!empty($report) && $report->isEnabled()) {
         return $report->alwaysUseDefaultViewDataTable();
     }
     return false;
 }

作者:dorelljame    项目:piwi   
/**
  * @param DataTable $dataTable
  * @param Report $report
  * @return Metric[]
  */
 private function getMetricsToFormat(DataTable $dataTable, Report $report = null)
 {
     return Report::getMetricsForTable($dataTable, $report, $baseType = 'Piwik\\Plugin\\Metric');
 }

作者:bossrabbi    项目:piwi   
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);
     if (Common::getRequestVar('pivotBy', false) === false) {
         $view->config->columns_to_display = array('label', 'nb_events', 'sum_event_value');
     }
     $view->config->show_flatten_table = true;
     $view->config->show_table_all_columns = false;
     $view->requestConfig->filter_sort_column = 'nb_events';
     $labelTranslation = $this->getColumnTranslation($apiMethod);
     $view->config->addTranslation('label', $labelTranslation);
     $view->config->addTranslations($this->getMetricTranslations());
     $this->addRelatedReports($view, $secondaryDimension);
     $this->addTooltipEventValue($view);
     $subtableReport = Report::factory('Events', $view->config->subtable_controller_action);
     $view->config->pivot_by_dimension = $subtableReport->getDimension()->getId();
     $view->config->pivot_by_column = 'nb_events';
 }

作者:bossrabbi    项目:piwi   
/**
  * Triggers the Menu.Reporting.addItems hook and returns the menu.
  *
  * @return Array
  */
 public function getMenu()
 {
     if (!$this->menu) {
         /**
          * @ignore
          * @deprecated
          */
         Piwik::postEvent('Menu.Reporting.addItems', array());
         foreach (Report::getAllReports() as $report) {
             if ($report->isEnabled()) {
                 $report->configureReportingMenu($this);
             }
         }
         foreach ($this->getAllMenus() as $menu) {
             $menu->configureReportingMenu($this);
         }
     }
     return parent::getMenu();
 }


问题


面经


文章

微信
公众号

扫码关注公众号