/**
  * Creates a new Rubric model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $subcategories = ArrayHelper::map(Subcategory::find()->with('englishTranslate')->all(), 'id', 'englishTranslate.title');
     $model = new Rubric();
     $enForm = new RubricTranslateForm();
     $enModel = new RubricTranslate();
     $deForm = new RubricTranslateForm();
     $deModel = new RubricTranslate();
     $post = Yii::$app->request->post();
     $translatePost = Yii::$app->request->post('RubricTranslateForm');
     $model->scenario = 'insert';
     if ($model->load($post) && $enForm->load($translatePost, 'en') && $deForm->load($translatePost, 'de')) {
         $model->image = UploadedFile::getInstance($model, 'image');
         if ($model->validate() && $enForm->validate() && $deForm->validate()) {
             $transaction = $model::getDb()->beginTransaction();
             try {
                 if ($model->save()) {
                     $model->upload();
                     $enModel->attributes = ArrayHelper::merge($enForm->attributes, ['lang' => 'en']);
                     $deModel->attributes = ArrayHelper::merge($deForm->attributes, ['lang' => 'de']);
                     $model->link('translates', $enModel);
                     $model->link('translates', $deModel);
                     $transaction->commit();
                     Yii::$app->session->setFlash('success', 'Rubric have been created.');
                 }
             } catch (\Exception $e) {
                 Yii::$app->session->setFlash('error', 'Failed to create Rubric.');
                 $transaction->rollBack();
             }
         }
     } else {
         return $this->render('create', ['model' => $model, 'enForm' => $enForm, 'deForm' => $deForm, 'subcategories' => $subcategories]);
     }
     return $this->redirect('index');
 }