1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace app\backend\components; |
4
|
|
|
|
5
|
|
|
use app\backend\BackendModule; |
6
|
|
|
use app\components\BaseModule; |
7
|
|
|
use Yii; |
8
|
|
|
use yii\db\ActiveRecord; |
9
|
|
|
use yii\helpers\Html; |
10
|
|
|
use kartik\icons\Icon; |
11
|
|
|
|
12
|
|
|
class Helper |
13
|
|
|
{ |
14
|
|
|
private static $returnUrl; |
15
|
|
|
public static $returnUrlWithoutHistory = false; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @param int $depth |
|
|
|
|
19
|
|
|
* @return string |
20
|
|
|
*/ |
21
|
|
|
public static function getReturnUrl() |
22
|
|
|
{ |
23
|
|
|
if (is_null(self::$returnUrl)) { |
24
|
|
|
$url = parse_url(Yii::$app->request->url); |
25
|
|
|
$returnUrlParams = []; |
26
|
|
|
if (isset($url['query'])) { |
27
|
|
|
$parts = explode('&', $url['query']); |
28
|
|
|
foreach ($parts as $part) { |
29
|
|
|
$pieces = explode('=', $part); |
30
|
|
|
if (static::$returnUrlWithoutHistory && count($pieces) == 2 && $pieces[0] === 'returnUrl') { |
31
|
|
|
continue; |
32
|
|
|
} |
33
|
|
|
if (count($pieces) == 2 && strlen($pieces[1]) > 0) { |
34
|
|
|
$returnUrlParams[] = $part; |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
if (count($returnUrlParams) > 0) { |
39
|
|
|
self::$returnUrl = $url['path'] . '?' . implode('&', $returnUrlParams); |
40
|
|
|
} else { |
41
|
|
|
self::$returnUrl = $url['path']; |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
return self::$returnUrl; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param ActiveRecord $model Model instance |
49
|
|
|
* @param string $indexAction Route path to index action |
50
|
|
|
* @return string Rendered save buttons with redurectUrl! |
51
|
|
|
*/ |
52
|
|
|
public static function saveButtons(ActiveRecord $model, $indexAction='index', $buttonClass='btn-sm', $onlySaveAndBack=false) |
53
|
|
|
{ |
54
|
|
|
$result = '<div class="form-group no-margin btn-group">'; |
55
|
|
|
if ($onlySaveAndBack === false) { |
56
|
|
|
$result .= |
57
|
|
|
Html::a( |
58
|
|
|
Icon::show('arrow-circle-left') . Yii::t('app', 'Back'), |
59
|
|
|
Yii::$app->request->get('returnUrl', [$indexAction, 'id' => $model->id]), |
60
|
|
|
['class' => 'btn btn-default ' . $buttonClass] |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
View Code Duplication |
if ($model->isNewRecord && $onlySaveAndBack === false) { |
65
|
|
|
$result .= Html::submitButton( |
66
|
|
|
Icon::show('save') . Yii::t('app', 'Save & Go next'), |
67
|
|
|
[ |
68
|
|
|
'class' => 'btn btn-success ' . $buttonClass, |
69
|
|
|
'name' => 'action', |
70
|
|
|
'value' => 'next', |
71
|
|
|
] |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$result .= |
76
|
|
|
Html::submitButton( |
77
|
|
|
Icon::show('save') . Yii::t('app', 'Save & Go back'), |
78
|
|
|
[ |
79
|
|
|
'class' => 'btn btn-warning ' . $buttonClass, |
80
|
|
|
'name' => 'action', |
81
|
|
|
'value' => 'back', |
82
|
|
|
] |
83
|
|
|
); |
84
|
|
View Code Duplication |
if ($onlySaveAndBack === false) { |
85
|
|
|
$result .= |
86
|
|
|
Html::submitButton( |
87
|
|
|
Icon::show('save') . Yii::t('app', 'Save'), |
88
|
|
|
[ |
89
|
|
|
'class' => 'btn btn-primary ' . $buttonClass, |
90
|
|
|
'name' => 'action', |
91
|
|
|
'value' => 'save', |
92
|
|
|
] |
93
|
|
|
); |
94
|
|
|
} |
95
|
|
|
$result .= '</div>'; |
96
|
|
|
|
97
|
|
|
return $result; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public static function toString($value) |
101
|
|
|
{ |
102
|
|
|
return (string) $value; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public static function getBackendGridClass($moduleId, $key, $columnNumber, $defaultClass = '') |
106
|
|
|
{ |
107
|
|
|
/** @var BackendModule $backendModule */ |
108
|
|
|
$backendModule = Yii::$app->getModule('backend'); |
109
|
|
|
if (isset($backendModule->backendEditGrids[$moduleId][$key])) { |
110
|
|
|
$type = $backendModule->backendEditGrids[$moduleId][$key]; |
111
|
|
|
} else { |
112
|
|
|
/** @var BaseModule $module */ |
113
|
|
|
$module = Yii::$app->getModule($moduleId); |
114
|
|
|
if ($module->hasMethod('getBackendGridDefaultValue')) { |
115
|
|
|
$type = $module->getBackendGridDefaultValue($key); |
116
|
|
|
} else { |
117
|
|
|
return $defaultClass; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
switch ($type) { |
121
|
|
|
case BackendModule::BACKEND_GRID_ONE_COLUMN: |
122
|
|
|
return 'backend-edit-grid col-lg-12 col-md-12 col-ms-12 col-xs-12'; |
123
|
|
|
case BackendModule::BACKEND_GRID_ONE_TO_ONE: |
124
|
|
|
return 'backend-edit-grid col-lg-6 col-md-6 col-ms-6 col-xs-12'; |
125
|
|
|
case BackendModule::BACKEND_GRID_TWO_TO_ONE: |
126
|
|
|
return $columnNumber === 1 |
127
|
|
|
? 'backend-edit-grid col-lg-8 col-md-8 col-ms-8 col-xs-12' |
128
|
|
|
: 'backend-edit-grid col-lg-4 col-md-4 col-ms-4 col-xs-12'; |
129
|
|
|
case BackendModule::BACKEND_GRID_ONE_TO_TWO: |
130
|
|
|
return $columnNumber === 1 |
131
|
|
|
? 'backend-edit-grid col-lg-4 col-md-4 col-ms-4 col-xs-12' |
132
|
|
|
: 'backend-edit-grid col-lg-8 col-md-8 col-ms-8 col-xs-12'; |
133
|
|
|
default: |
134
|
|
|
return $defaultClass; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.