Piwik\Plugin\Controller::renderReport PHP Method

renderReport() protected method

Convenience method that creates and renders a ViewDataTable for a API method.
protected renderReport ( string | Report $apiAction, boolean $controllerAction = false ) : string | void
$apiAction string | Report The name of the API action (eg, `'getResolution'`) or an instance of an report.
$controllerAction boolean The name of the Controller action name that is rendering the report. Defaults to the `$apiAction`.
return string | void See `$fetch`.
    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;
    }