@@ -80,13 +80,13 @@ discard block |
||
80 | 80 | { |
81 | 81 | $this->on(self::EVENT_BEFORE_ITEM_SAVE, [$this, 'beforeItemSave']); |
82 | 82 | |
83 | - if(!$this->parent){ |
|
84 | - throw new yii\base\InvalidArgumentException('Parent not defined in '.self::class); |
|
83 | + if (!$this->parent) { |
|
84 | + throw new yii\base\InvalidArgumentException('Parent not defined in ' . self::class); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | $this->setCurrentChildren(); |
88 | 88 | $this->itemsOrder = ""; |
89 | - $this->assignmentClassname = $this->assignment->class; |
|
89 | + $this->assignmentClassname = $this->assignment->class; |
|
90 | 90 | parent::init(); |
91 | 91 | } |
92 | 92 | |
@@ -94,17 +94,17 @@ discard block |
||
94 | 94 | public function rules() |
95 | 95 | { |
96 | 96 | return [ |
97 | - [['parent','child','assignment'], 'required'], |
|
98 | - [['children_ids'], 'each','rule'=>[ 'string','max'=>16]], |
|
99 | - [['itemsOrder'], 'each','rule'=>[ 'integer']] |
|
97 | + [['parent', 'child', 'assignment'], 'required'], |
|
98 | + [['children_ids'], 'each', 'rule'=>['string', 'max'=>16]], |
|
99 | + [['itemsOrder'], 'each', 'rule'=>['integer']] |
|
100 | 100 | ]; |
101 | 101 | |
102 | 102 | } |
103 | 103 | |
104 | 104 | |
105 | - public function assignDefaultValues(){ |
|
106 | - if(!empty($this->defaultValues)){ |
|
107 | - foreach ($this->defaultValues as $attribute =>$value){ |
|
105 | + public function assignDefaultValues() { |
|
106 | + if (!empty($this->defaultValues)) { |
|
107 | + foreach ($this->defaultValues as $attribute =>$value) { |
|
108 | 108 | $this->$attribute = $value; |
109 | 109 | } |
110 | 110 | } |
@@ -118,35 +118,35 @@ discard block |
||
118 | 118 | |
119 | 119 | } |
120 | 120 | |
121 | - public function save(){ |
|
122 | - $i=0; |
|
121 | + public function save() { |
|
122 | + $i = 0; |
|
123 | 123 | $this->cleanChildrenIds(); |
124 | 124 | |
125 | - if(is_array($this->children_ids)){ |
|
126 | - foreach ($this->children_ids as $childId){ |
|
125 | + if (is_array($this->children_ids)) { |
|
126 | + foreach ($this->children_ids as $childId) { |
|
127 | 127 | |
128 | - if(!$this->childExists($childId)){ |
|
128 | + if (!$this->childExists($childId)) { |
|
129 | 129 | $model = new $this->assignmentClassname; |
130 | - }else{ |
|
130 | + } else { |
|
131 | 131 | $model = $this->getCurrentChildById($childId); |
132 | 132 | } |
133 | 133 | |
134 | 134 | |
135 | 135 | $model->{$this->parent_fk_colname} = $this->parent->primaryKey; |
136 | - if($this->hasChildTable){ |
|
136 | + if ($this->hasChildTable) { |
|
137 | 137 | $model->{$this->child_fk_colname} = $childId; |
138 | 138 | } |
139 | 139 | $model->{$this->child_fk_colname} = $childId; |
140 | 140 | |
141 | 141 | |
142 | 142 | // set order if order colname is set |
143 | - if($this->order_colname<>""){ |
|
143 | + if ($this->order_colname <> "") { |
|
144 | 144 | $model->{$this->order_colname} = $i; |
145 | 145 | } |
146 | 146 | |
147 | 147 | // assign default Value |
148 | - if(!empty($this->defaultValues)){ |
|
149 | - foreach ($this->defaultValues as $attribute =>$value){ |
|
148 | + if (!empty($this->defaultValues)) { |
|
149 | + foreach ($this->defaultValues as $attribute =>$value) { |
|
150 | 150 | $model->{$attribute} = $value; |
151 | 151 | } |
152 | 152 | } |
@@ -154,9 +154,9 @@ discard block |
||
154 | 154 | $this->assignmentItem = $model; |
155 | 155 | $event = new MyAssignmentEvent; |
156 | 156 | $event->item = $model; |
157 | - $this->trigger(self::EVENT_BEFORE_ITEM_SAVE,$event); |
|
157 | + $this->trigger(self::EVENT_BEFORE_ITEM_SAVE, $event); |
|
158 | 158 | |
159 | - if(!$this->assignmentItem->save()){ |
|
159 | + if (!$this->assignmentItem->save()) { |
|
160 | 160 | $this->addErrors($this->assignmentItem->errors); |
161 | 161 | return false; |
162 | 162 | } |
@@ -166,10 +166,10 @@ discard block |
||
166 | 166 | } |
167 | 167 | |
168 | 168 | // delete what was unselected |
169 | - if(is_array($this->current_children)){ |
|
170 | - foreach ($this->current_children as $child){ |
|
171 | - if((is_array($this->children_ids) && !in_array($child->{$this->child_fk_colname}, $this->children_ids)) |
|
172 | - or ( !is_array($this->children_ids))){ |
|
169 | + if (is_array($this->current_children)) { |
|
170 | + foreach ($this->current_children as $child) { |
|
171 | + if ((is_array($this->children_ids) && !in_array($child->{$this->child_fk_colname}, $this->children_ids)) |
|
172 | + or (!is_array($this->children_ids))) { |
|
173 | 173 | |
174 | 174 | $child->delete(); |
175 | 175 | } |
@@ -185,24 +185,24 @@ discard block |
||
185 | 185 | |
186 | 186 | public function childExists($childId) { |
187 | 187 | $currentChildrenIds = $this->getCurrentChildrenIds(false); |
188 | - if(is_array($currentChildrenIds)){ |
|
188 | + if (is_array($currentChildrenIds)) { |
|
189 | 189 | return in_array($childId, $currentChildrenIds); |
190 | 190 | } |
191 | 191 | return false; |
192 | 192 | } |
193 | 193 | |
194 | - public function setCurrentChildren(){ |
|
194 | + public function setCurrentChildren() { |
|
195 | 195 | $query = $this->identifyChildrenQuery(); |
196 | 196 | |
197 | 197 | // if order column is set, we order it ascending |
198 | - if($this->order_colname){ |
|
198 | + if ($this->order_colname) { |
|
199 | 199 | $query->orderBy([$this->order_colname=>SORT_ASC]); |
200 | 200 | } |
201 | 201 | |
202 | 202 | $indexCol = $this->child->primaryKey()[0]; |
203 | 203 | $children = $query->indexBy($indexCol)->all(); |
204 | 204 | |
205 | - if ($children){ |
|
205 | + if ($children) { |
|
206 | 206 | $this->current_children = $children; |
207 | 207 | } |
208 | 208 | $this->getCurrentChildrenIds(); |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | |
212 | 212 | |
213 | 213 | |
214 | - public function setLastChild(){ |
|
214 | + public function setLastChild() { |
|
215 | 215 | $query = $this->identifyChildrenQuery(); |
216 | 216 | $query->orderBy([ |
217 | 217 | $this->assignment->timeCreatedCol=>SORT_DESC, |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | /** |
228 | 228 | * @return \yii\db\ActiveQuery |
229 | 229 | */ |
230 | - public function identifyChildrenQuery(){ |
|
230 | + public function identifyChildrenQuery() { |
|
231 | 231 | $query = $this->assignment->find() |
232 | 232 | ->andWhere([$this->parent_fk_colname => $this->parent->primaryKey]); |
233 | 233 | return $query; |
@@ -241,13 +241,13 @@ discard block |
||
241 | 241 | * @return array|bool |
242 | 242 | */ |
243 | 243 | public function getCurrentChildrenIds($set = true) { |
244 | - if(is_array($this->current_children)){ |
|
244 | + if (is_array($this->current_children)) { |
|
245 | 245 | $ids = []; |
246 | - foreach ($this->current_children as $child){ |
|
246 | + foreach ($this->current_children as $child) { |
|
247 | 247 | |
248 | - $ids[]=$child->{$this->child_fk_colname}; |
|
248 | + $ids[] = $child->{$this->child_fk_colname}; |
|
249 | 249 | } |
250 | - if($set){ |
|
250 | + if ($set) { |
|
251 | 251 | $this->children_ids = $ids; |
252 | 252 | } |
253 | 253 | return $ids; |
@@ -256,9 +256,9 @@ discard block |
||
256 | 256 | |
257 | 257 | } |
258 | 258 | private function getCurrentChildById($id) { |
259 | - if(is_array($this->current_children)){ |
|
260 | - foreach ($this->current_children as $child){ |
|
261 | - if($child->{$this->child_fk_colname} == $id){ |
|
259 | + if (is_array($this->current_children)) { |
|
260 | + foreach ($this->current_children as $child) { |
|
261 | + if ($child->{$this->child_fk_colname} == $id) { |
|
262 | 262 | return $child; |
263 | 263 | } |
264 | 264 | } |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | * Clean Ids to be integers |
272 | 272 | */ |
273 | 273 | private function cleanChildrenIds() { |
274 | - if(is_array($this->children_ids) && $this->isChildIdInteger){ |
|
274 | + if (is_array($this->children_ids) && $this->isChildIdInteger) { |
|
275 | 275 | $clean = []; |
276 | 276 | foreach ($this->children_ids as $id) { |
277 | 277 | $clean[] = intval($id); |
@@ -286,8 +286,8 @@ discard block |
||
286 | 286 | * @return MyActiveRecord |
287 | 287 | * @deprecated |
288 | 288 | */ |
289 | - public function getLastChild(){ |
|
290 | - if(!$this->last_child){ |
|
289 | + public function getLastChild() { |
|
290 | + if (!$this->last_child) { |
|
291 | 291 | $this->setLastChild(); |
292 | 292 | } |
293 | 293 | return $this->last_child; |
@@ -127,7 +127,7 @@ |
||
127 | 127 | |
128 | 128 | if(!$this->childExists($childId)){ |
129 | 129 | $model = new $this->assignmentClassname; |
130 | - }else{ |
|
130 | + } else{ |
|
131 | 131 | $model = $this->getCurrentChildById($childId); |
132 | 132 | } |
133 | 133 |
@@ -23,7 +23,7 @@ |
||
23 | 23 | [[$this->parentIdColumnName, $this->childIdColumnName], 'required'], |
24 | 24 | [$this->childIdColumnName, function($attribute) { |
25 | 25 | if ($this->isAlreadyAssigned) { |
26 | - $this->addError($attribute,Yii::t('app',"Can only be used once!")); |
|
26 | + $this->addError($attribute, Yii::t('app', "Can only be used once!")); |
|
27 | 27 | } |
28 | 28 | }], |
29 | 29 | ]); |
@@ -30,7 +30,7 @@ |
||
30 | 30 | |
31 | 31 | <div class="panel panel-default"> |
32 | 32 | <div class="panel-body"> |
33 | - <?php if(!empty($generator->searchModelClass)): ?> |
|
33 | + <?php if (!empty($generator->searchModelClass)): ?> |
|
34 | 34 | <?= " <?php " . ($generator->indexWidgetType === 'grid' ? "// " : "") ?>echo $this->render('_search', ['model' => $searchModel]); ?> |
35 | 35 | <?php endif; ?> |
36 | 36 |
@@ -69,7 +69,8 @@ discard block |
||
69 | 69 | ['class' => 'yii\grid\ActionColumn'], |
70 | 70 | ], |
71 | 71 | ]); ?> |
72 | - <?php else: ?> |
|
72 | + <?php else { |
|
73 | + : ?> |
|
73 | 74 | <?= "<?= " ?>ListView::widget([ |
74 | 75 | 'dataProvider' => $dataProvider, |
75 | 76 | 'itemOptions' => ['class' => 'item'], |
@@ -77,7 +78,9 @@ discard block |
||
77 | 78 | return Html::a(Html::encode($model-><?= $nameAttribute ?>), ['view', <?= $urlParams ?>]); |
78 | 79 | }, |
79 | 80 | ]) ?> |
80 | - <?php endif; ?> |
|
81 | + <?php endif; |
|
82 | +} |
|
83 | +?> |
|
81 | 84 | |
82 | 85 | </div> |
83 | 86 | </div> |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | use <?= ltrim($generator->modelClass, '\\') ?>; |
34 | 34 | <?php if (!empty($generator->searchModelClass)): ?> |
35 | 35 | use <?= ltrim($generator->searchModelClass, '\\') . (isset($searchModelAlias) ? " as $searchModelAlias" : "") ?>; |
36 | -<?php else: ?> |
|
36 | +<?php else : ?> |
|
37 | 37 | use yii\data\ActiveDataProvider; |
38 | 38 | <?php endif; ?> |
39 | 39 | use <?= ltrim($generator->baseControllerClass, '\\') ?>; |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | 'searchModel' => $searchModel, |
98 | 98 | 'dataProvider' => $dataProvider, |
99 | 99 | ]); |
100 | -<?php else: ?> |
|
100 | +<?php else : ?> |
|
101 | 101 | $dataProvider = new ActiveDataProvider([ |
102 | 102 | 'query' => <?= $modelClass ?>::find(), |
103 | 103 | ]); |
@@ -33,9 +33,12 @@ discard block |
||
33 | 33 | use <?= ltrim($generator->modelClass, '\\') ?>; |
34 | 34 | <?php if (!empty($generator->searchModelClass)): ?> |
35 | 35 | use <?= ltrim($generator->searchModelClass, '\\') . (isset($searchModelAlias) ? " as $searchModelAlias" : "") ?>; |
36 | -<?php else: ?> |
|
36 | +<?php else { |
|
37 | + : ?> |
|
37 | 38 | use yii\data\ActiveDataProvider; |
38 | -<?php endif; ?> |
|
39 | +<?php endif; |
|
40 | +} |
|
41 | +?> |
|
39 | 42 | use <?= ltrim($generator->baseControllerClass, '\\') ?>; |
40 | 43 | use yii\web\NotFoundHttpException; |
41 | 44 | use yii\web\ForbiddenHttpException; |
@@ -97,7 +100,8 @@ discard block |
||
97 | 100 | 'searchModel' => $searchModel, |
98 | 101 | 'dataProvider' => $dataProvider, |
99 | 102 | ]); |
100 | -<?php else: ?> |
|
103 | +<?php else { |
|
104 | + : ?> |
|
101 | 105 | $dataProvider = new ActiveDataProvider([ |
102 | 106 | 'query' => <?= $modelClass ?>::find(), |
103 | 107 | ]); |
@@ -105,7 +109,9 @@ discard block |
||
105 | 109 | return $this->render('index', [ |
106 | 110 | 'dataProvider' => $dataProvider, |
107 | 111 | ]); |
108 | -<?php endif; ?> |
|
112 | +<?php endif; |
|
113 | +} |
|
114 | +?> |
|
109 | 115 | } |
110 | 116 | |
111 | 117 | /** |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | public function __construct(array $config = []) |
31 | 31 | { |
32 | 32 | //assign defaultvalues |
33 | - if(!empty($config['defaultValues'])){ |
|
33 | + if (!empty($config['defaultValues'])) { |
|
34 | 34 | $this->defaultValues = $config['defaultValues']; |
35 | 35 | $this->assignDefaultValues(); |
36 | 36 | } |
@@ -90,9 +90,9 @@ discard block |
||
90 | 90 | return $this->{$this->timeClosedCol}; |
91 | 91 | } |
92 | 92 | |
93 | - public function assignDefaultValues(){ |
|
94 | - if(!empty($this->defaultValues)){ |
|
95 | - foreach ($this->defaultValues as $attribute =>$value){ |
|
93 | + public function assignDefaultValues() { |
|
94 | + if (!empty($this->defaultValues)) { |
|
95 | + foreach ($this->defaultValues as $attribute =>$value) { |
|
96 | 96 | $this->$attribute = $value; |
97 | 97 | } |
98 | 98 | } |
@@ -104,9 +104,9 @@ discard block |
||
104 | 104 | * @param array $filters |
105 | 105 | * @return mixed |
106 | 106 | */ |
107 | - public function getRelationCount($className, $idColumn = null,$filters = null){ |
|
108 | - if(!$idColumn){ |
|
109 | - $idColumn = $this->tableName()."_id"; |
|
107 | + public function getRelationCount($className, $idColumn = null, $filters = null) { |
|
108 | + if (!$idColumn) { |
|
109 | + $idColumn = $this->tableName() . "_id"; |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | $config = [ |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | $query = $model->query() |
120 | 120 | ->from($className::tableName()) |
121 | 121 | ->andWhere([$idColumn => $this->primaryKey]); |
122 | - if($filters){ |
|
122 | + if ($filters) { |
|
123 | 123 | $query->andWhere($filters); |
124 | 124 | } |
125 | 125 | return $query->count(); |