execut /
yii2-actions
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Created by PhpStorm. |
||
| 4 | * User: execut |
||
| 5 | * Date: 2/21/18 |
||
| 6 | * Time: 2:44 PM |
||
| 7 | */ |
||
| 8 | |||
| 9 | namespace execut\actions\widgets; |
||
| 10 | |||
| 11 | |||
| 12 | use kartik\alert\Alert; |
||
| 13 | use yii\helpers\Html; |
||
| 14 | use yii\helpers\Inflector; |
||
| 15 | use yii\helpers\Json; |
||
| 16 | use yii\helpers\Url; |
||
| 17 | use kartik\base\Config; |
||
| 18 | |||
| 19 | class GridView extends \kartik\grid\GridView |
||
| 20 | { |
||
| 21 | public $addButtonUrl = null; |
||
| 22 | public $title = null; |
||
| 23 | public $isAjaxCrud = false; |
||
| 24 | public $formModel = null; |
||
| 25 | public $uniqueId = null; |
||
| 26 | public function init() |
||
| 27 | { |
||
| 28 | $this->toolbar = $this->getToolbarConfig(); |
||
| 29 | $this->rowOptions = function ($row) { |
||
| 30 | return [ |
||
| 31 | 'attributes' => Json::encode($row->attributes), |
||
| 32 | ]; |
||
| 33 | }; |
||
| 34 | |||
| 35 | return parent::init(); |
||
| 36 | } |
||
| 37 | |||
| 38 | public function run() |
||
| 39 | { |
||
| 40 | $this->initToggleData(); |
||
| 41 | $this->initExport(); |
||
| 42 | if ($this->export !== false && isset($this->exportConfig[self::PDF])) { |
||
| 43 | Config::checkDependency( |
||
| 44 | 'mpdf\Pdf', |
||
| 45 | 'yii2-mpdf', |
||
| 46 | 'for PDF export functionality. To include PDF export, follow the install steps below. If you do not ' . |
||
| 47 | "need PDF export functionality, do not include 'PDF' as a format in the 'export' property. You can " . |
||
| 48 | "otherwise set 'export' to 'false' to disable all export functionality" |
||
| 49 | ); |
||
| 50 | } |
||
| 51 | $this->initHeader(); |
||
| 52 | $this->initBootstrapStyle(); |
||
| 53 | $this->containerOptions['id'] = $this->options['id'] . '-container'; |
||
| 54 | Html::addCssClass($this->containerOptions, 'kv-grid-container'); |
||
| 55 | $this->registerAssets(); |
||
| 56 | $this->renderPanel(); |
||
| 57 | $this->beginPjax(); |
||
| 58 | $this->initLayout(); |
||
| 59 | parent::run(); |
||
| 60 | $this->endPjax(); |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @param $refreshUrlParams |
||
| 65 | * @return array |
||
| 66 | */ |
||
| 67 | public function getToolbarConfig(): array |
||
| 68 | { |
||
| 69 | // $refreshUrlParams = [ |
||
|
0 ignored issues
–
show
|
|||
| 70 | // $this->adapter->uniqueId, |
||
| 71 | // ]; |
||
| 72 | // |
||
| 73 | // foreach ($this->refreshAttributes as $key) { |
||
| 74 | // if (!empty($this->adapter->actionParams->get[$key])) { |
||
| 75 | // $refreshUrlParams[$key] = $this->adapter->actionParams->get[$key]; |
||
| 76 | // } |
||
| 77 | // } |
||
| 78 | |||
| 79 | return [ |
||
| 80 | // 'massEdit' => ['content' => $this->renderMassEditButton()], |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
63% 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...
|
|||
| 81 | // 'massVisible' => ['content' => $this->renderVisibleButtons()], |
||
| 82 | 'add' => ['content' => $this->renderAddButton()], |
||
| 83 | 'alert' => ['content' => $this->renderAlertBlock()], |
||
| 84 | // 'refresh' => [ |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
56% 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...
|
|||
| 85 | // 'content' => Html::a('<i class="glyphicon glyphicon-repeat"></i>', $refreshUrlParams, ['data-pjax' => 0, 'class' => 'btn btn-default', 'title' => 'Reset Grid']), |
||
| 86 | // ], |
||
| 87 | // 'dynaParams' => ['content' => '{dynagridFilter}{dynagridSort}{dynagrid}'], |
||
| 88 | // 'toggleData' => '{toggleData}', |
||
| 89 | // 'export' => '{export}', |
||
| 90 | ]; |
||
| 91 | } |
||
| 92 | |||
| 93 | public function beginPjax() { |
||
| 94 | parent::beginPjax(); |
||
| 95 | if ($this->isAjaxCrud) { |
||
| 96 | $model = $this->formModel; |
||
| 97 | if (is_callable($model)) { |
||
| 98 | $model = $model(); |
||
| 99 | } |
||
| 100 | |||
| 101 | if ($this->pjax) { |
||
| 102 | $gridId = $this->id . '-pjax'; |
||
| 103 | } else { |
||
| 104 | $gridId = null; |
||
| 105 | } |
||
| 106 | |||
| 107 | echo EditDialog::widget([ |
||
| 108 | 'id' => $this->id . '-edit', |
||
| 109 | 'model' => $model, |
||
| 110 | 'uniqueId' => $this->uniqueId, |
||
| 111 | 'alertId' => $this->id . '-alert', |
||
| 112 | 'clientOptions' => [ |
||
| 113 | 'inputsPrefix' => str_replace('-', '', Inflector::camel2id($model->formName())), |
||
| 114 | 'attributesElement' => 'tr:first', |
||
| 115 | 'editButtons' => '.btn.update', |
||
| 116 | 'gridId' => $gridId, |
||
| 117 | ], |
||
| 118 | 'toggleButtonOptions' => false, |
||
| 119 | ]); |
||
| 120 | } |
||
| 121 | } |
||
| 122 | |||
| 123 | public function renderAlertBlock() { |
||
| 124 | $alertWidgetOptions = [ |
||
| 125 | 'id' => $this->id . '-alert', |
||
| 126 | ]; |
||
| 127 | |||
| 128 | $alertWidgetOptions['body'] = '<span></span>'; |
||
| 129 | $alertWidgetOptions['options'] = [ |
||
| 130 | 'class' => ['alert', 'alert-success'], |
||
| 131 | 'style' => 'padding-left:10px;padding-right:10px;' |
||
| 132 | ]; |
||
| 133 | |||
| 134 | return Alert::widget($alertWidgetOptions); |
||
| 135 | } |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @return string |
||
| 139 | */ |
||
| 140 | protected function renderAddButton() |
||
| 141 | { |
||
| 142 | $title = \yii::t('execut.actions', 'Add') . ' ' . $this->title; |
||
| 143 | return Html::a($title, Url::to($this->addButtonUrl), [ |
||
| 144 | 'id' => $this->id . '-edit-add-button', |
||
| 145 | 'type' => 'button', |
||
| 146 | 'data-pjax' => 0, |
||
| 147 | 'title' => $title, |
||
| 148 | 'class' => 'btn btn-success' |
||
| 149 | ]); |
||
| 150 | } |
||
| 151 | } |
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.