flipboxfactory/craft-reports

View on GitHub
src/controllers/RunController.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace flipbox\craft\reports\controllers;

use Craft;
use craft\web\Controller;
use flipbox\craft\reports\actions\Run;

/**
 * This controller runs a report.  It is not intended to handle any other operation.
 *
 * We accept all 'action' id's (which is actually the report handle) and route them through the same action.
 *
 * Ex: reports/run/users -> runs a report with 'users' as the handle
 * Ex: reports/run/entries -> runs a report with 'entries' as the handle
 */
class RunController extends Controller
{
    /**
     * @return array
     */
    public function actions()
    {
        return [
            'index' => [
                'class' => Run::class
            ]
        ];
    }

    /**
     * Add the report 'identifier' to params.
     *
     * @inheritDoc
     */
    public function runAction($id, $params = [])
    {
        $params['identifier'] = $id;
        return parent::runAction($id, $params);
    }

    /**
     * @param string $id
     * @return object|\yii\base\Action|null
     * @throws \yii\base\InvalidConfigException
     */
    public function createAction($id)
    {
        return Craft::createObject([
            'class' => Run::class
        ], ['index', $this]);
    }
}