Completed
Push — master ( 0c1c6f...58b419 )
by eXeCUT
32:28
created

DynaGrid::init()   B

Complexity

Conditions 2
Paths 1

Size

Total Lines 55

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 55
rs 8.9818
c 0
b 0
f 0
cc 2
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: execut
5
 * Date: 11/15/17
6
 * Time: 12:14 PM
7
 */
8
9
namespace execut\actions\widgets;
10
11
use execut\actions\action\adapter\viewRenderer\DynaGridRow;
12
use execut\yii\jui\WidgetTrait;
13
use kartik\export\ExportMenu;
14
use yii\helpers\ArrayHelper;
15
use yii\helpers\Html;
16
use \kartik\dynagrid\DynaGrid as KartikDynaGrid;
17
18
class DynaGrid extends KartikDynaGrid
19
{
20
    use WidgetTrait;
21
    public $dataProvider = null;
22
    public $storage = KartikDynaGrid::TYPE_DB;
23
    public $filter = null;
24
25
    public function init()
26
    {
27
        $columns = $this->filter->getGridColumns();
28
//        foreach ($exportColumns as &$column) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
29
//            unset($column['visible']);
30
//        }
31
32
        $fullExportMenu = ExportMenu::widget([
33
            'dataProvider' => $this->dataProvider,
34
            'columns' => $columns,
35
            'showColumnSelector' => true,
36
            'target' => ExportMenu::TARGET_BLANK,
37
            'batchSize' => 1000,
38
            'fontAwesome' => true,
39
            'asDropdown' => false,
40
            'dynagrid' => true,
41
            'dynagridOptions' => [
42
                'options' => ['id' => $this->options['id']],
43
//                'columns' => $columns,
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
44
            ],
45
            'dropdownOptions' => [
46
                'label' => '<i class="glyphicon glyphicon-export"></i> Full'
47
            ],
48
        ]);
49
50
        $this->columns = $columns;
51
52
        $this->gridOptions = ArrayHelper::merge([
53
            'class' => GridView::class,
54
            'responsive' => false,
55
            'responsiveWrap' => false,
56
            'rowOptions' => function ($row) {
57
                if ($row instanceof DynaGridRow) {
58
                    return $row->getRowOptions();
59
                }
60
            },
61
            'panel' => false,
62
            'export' => [
63
                'fontAwesome' => true,
64
                'itemsAfter'=> [
65
                    '<li role="presentation" class="divider"></li>',
66
                    '<li class="dropdown-header">Export All Data</li>',
67
                    $fullExportMenu
68
                ]
69
            ],
70
            'toggleDataOptions' => [
71
                'maxCount' => 100000,
72
            ],
73
            'filterModel' => $this->filter,
74
//            'toolbar' => $this->getToolbarConfig(),
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
75
            'dataProvider' => $this->dataProvider,
76
        ], $this->gridOptions);
77
78
        parent::init(); // TODO: Change the autogenerated stub
79
    }
80
81
    public function getGridId() {
82
        return $this->id . '-grid';
83
    }
84
85
    /**
86
     * @inheritdoc
87
     */
88
    public function run()
89
    {
90
        if (method_exists($this, 'initWidget')) {
91
            $this->initWidget();
92
        }
93
94
        $this->gridOptions['options']['id'] = $this->id;
95
96
        Html::addCssClass($this->options, $this->getDefaultCssClass());
97
        $this->_registerBundle();
98
99
        echo Html::tag('div', GridView::widget($this->gridOptions), $this->options);
100
    }
101
}