Piwik\Plugin\ViewDataTable::__construct PHP Method

__construct() public method

Posts the {@hook ViewDataTable.configure} event which plugins can use to configure the way reports are displayed.
public __construct ( $controllerAction, $apiMethodToRequestDataTable, $overrideParams = [] )
    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();
    }

Usage Example

Example #1
0
 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 = Report::factory($this->requestConfig->getApiModuleToRequest(), $this->requestConfig->getApiMethodToRequest());
 }
All Usage Examples Of Piwik\Plugin\ViewDataTable::__construct