Issues (17)

src/actions/ViewAction.php (1 issue)

Severity
1
<?php
2
/**
3
 * @copyright Copyright(c) 2016 Webtools Ltd
4
 * @copyright Copyright(c) 2018 Thamtech, LLC
5
 * @link https://github.com/thamtech/yii2-scheduler
6
 * @license https://opensource.org/licenses/MIT
7
**/
8
9
namespace thamtech\scheduler\actions;
10
11
use thamtech\scheduler\models\SchedulerLog;
12
use Yii;
13
use yii\base\Action;
14
use thamtech\scheduler\models\SchedulerTask;
15
16
/**
17
 * View a task instance.
18
 */
19
class ViewAction extends Action
20
{
21
    /**
22
     * @var string the view file to be rendered. If not set, it will take the value of [[id]].
23
     * That means, if you name the action as "index" in "SchedulerController", then the view name
24
     * would be "index", and the corresponding view file would be "views/scheduler/index.php".
25
     */
26
    public $view;
27
28
    /**
29
     * Runs the action
30
     *
31
     * @return string result content
32
     */
33
    public function run($id)
34
    {
35
        $model = SchedulerTask::findOne($id);
36
        $request = Yii::$app->getRequest();
37
38
        if (!$model) {
0 ignored issues
show
$model is of type yii\db\ActiveRecord, thus it always evaluated to true.
Loading history...
39
            throw new \yii\web\HttpException(404, 'The requested page does not exist.');
40
        }
41
42
        if ($model->load($request->post())) {
43
            $model->save();
44
        }
45
46
        $logModel = new SchedulerLog();
47
        $logModel->scheduler_task_id = $model->id;
48
        $logDataProvider = $logModel->search($_GET);
49
50
        return $this->controller->render($this->view ?: $this->id, [
51
            'model' => $model,
52
            'logModel' => $logModel,
53
            'logDataProvider' => $logDataProvider,
54
        ]);
55
    }
56
}
57