PrepareAjaxViewAction::getDefaultRules()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 26
ccs 0
cts 24
cp 0
rs 9.504
cc 2
nc 1
nop 0
crap 6
1
<?php
2
/**
3
 * HiPanel core package
4
 *
5
 * @link      https://hipanel.com/
6
 * @package   hipanel-core
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2014-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\actions;
12
13
/**
14
 * Class PrepareAjaxViewAction.
15
 */
16
class PrepareAjaxViewAction extends ViewAction
17
{
18
    /** {@inheritdoc} */
19
    protected function getDefaultRules()
20
    {
21
        return array_merge(parent::getDefaultRules(), [
22
            'ajax' => [
23
                'save' => true,
24
                'flash' => false,
25
                'success' => [
26
                    'class' => RenderAjaxAction::class,
27
                    'view' => $this->view,
28
                    'data' => function () {
29
                        return $this->prepareData();
30
                    },
31
                    'params' => function () {
32
                        foreach ($this->collection->models as $model) {
33
                            $model->scenario = $this->scenario;
0 ignored issues
show
Bug introduced by
The property scenario does not seem to exist. Did you mean _scenario?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
34
                        }
35
36
                        return [
37
                            'models' => $this->collection->models,
38
                            'model' => $this->collection->first,
39
                        ];
40
                    },
41
                ],
42
            ],
43
        ]);
44
    }
45
}
46