예제 #1
0
 public function save()
 {
     $group = new PatternGroup();
     $group->project_id = \Yii::$app->request->get('project_id');
     $group->name = $this->name;
     if (!$group->save()) {
         return false;
     }
     $patterns = Pattern::find()->where(['group_id' => $this->id])->all();
     foreach ($patterns as $pattern) {
         $patternNew = new Pattern();
         $patternNew->attributes = $pattern->attributes;
         $patternNew->group_id = $group->id;
         if (!$patternNew->save()) {
             return false;
         }
         $translations = PatternTranslation::find()->where(['pattern_id' => $pattern->id])->all();
         foreach ($translations as $translation) {
             $translationNew = new PatternTranslation();
             $translationNew->attributes = $translation->attributes;
             $translationNew->pattern_id = $patternNew->id;
             if (!$translationNew->save()) {
                 return false;
             }
         }
     }
     return true;
 }
예제 #2
0
 /**
  * Creates a new Pattern model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Pattern();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index', 'project_id' => Yii::$app->request->get('project_id'), 'group_id' => Yii::$app->request->get('group_id')]);
     } else {
         $model->group_id = Yii::$app->request->get('group_id');
         return $this->render('create', ['model' => $model]);
     }
 }