public function addGroup($group_name = '', $after_group) { $group_index = count($this->data['layouts']); $group_data = StyleForm::GenerateRandomLayout($group_index); if (!empty($group_name)) { $group_data['label'] = $group_name; } $i = 0; $newlayouts = []; foreach ($this->data['layouts'] as $key => $group) { $newlayouts[$i] = $group; $i++; if ($key == $after_group) { $newlayouts[$i] = $group_data; $i++; } } $this->data['layouts'] = $newlayouts; if ($this->save()) { /* $current_group= StyleLayoutGroup::widget([ 'group_name'=>$group_data['label'], 'change_group_name_template_url' => Url::toRoute(['styles-api/change-group-name', 'id'=>$this->id, 'group_index'=>$group_index, 'newgroup'=>'newgroupname']), 'upload_files_url'=>Url::toRoute(['styles-api/upload-background', 'id'=>$this->id, 'group_index'=>$group_index]), 'upload_files_template_url'=>Url::toRoute(['styles-api/upload-background', 'id'=>$this->id, 'group_index'=>'groupindex']), 'group_data'=>$group_data, 'style_id'=>$this->id, 'delete_url'=>Url::toRoute(['styles-api/delete-group', 'id'=>$this->id, 'group_index'=>$group_index]), 'change_background_color_url'=>Url::toRoute(['styles-api/change-group-background-color', 'id'=>$this->id, 'group_index'=>$group_index, 'color'=>'newcolor']), 'background_color'=>$group_data['background_color'], 'background_image'=>$group_data['background_image'], 'add_group_url'=>Url::toRoute(['styles-api/add-group', 'id'=>$this->id, 'after_group'=>$group_index]) ]);*/ $groups = []; $i = 0; foreach ($newlayouts as $key => $group_data) { $i = $key; $groups[$i] = StyleLayoutGroup::widget(['group_name' => $group_data['label'], 'change_group_name_template_url' => Url::toRoute(['styles-api/change-group-name', 'id' => $this->id, 'group_index' => $i, 'newgroup' => 'newgroupname']), 'upload_files_url' => Url::toRoute(['styles-api/upload-background', 'id' => $this->id, 'group_index' => $i]), 'upload_files_template_url' => Url::toRoute(['styles-api/upload-background', 'id' => $this->id, 'group_index' => 'groupindex']), 'group_data' => $group_data, 'style_id' => $this->id, 'delete_url' => Url::toRoute(['styles-api/delete-group', 'id' => $this->id, 'group_index' => $i]), 'change_background_color_url' => Url::toRoute(['styles-api/change-group-background-color', 'id' => $this->id, 'group_index' => $i, 'color' => 'newcolor']), 'background_color' => $group_data['background_color'], 'background_image' => $group_data['background_image'], 'add_group_url' => Url::toRoute(['styles-api/add-group', 'id' => $this->id, 'after_group' => $i]), 'group_index' => $i]); $i++; } $result = ['response' => ['status' => true, 'groups' => $groups]]; } else { $result = ['error' => ['msg' => Yii::t('app', 'Не удалось сохранить изменения')]]; } return $result; }