/**
  * Creates a new Rule model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Rule();
     // create 10 RuleCondition models
     $modelsRuleCondition[] = new RuleCondition();
     for ($i = 0; $i <= 9; $i++) {
         $modelsRuleCondition[$i] = new RuleCondition();
         // if it is not the first one, there must be always one condition
         if (0 < $i) {
             $modelsRuleCondition[$i]->value_value = Yii::t('app', '- None -');
             $modelsRuleCondition[$i]->weight = $i;
         }
     }
     // create 5 RuleAction models
     $modelsRuleAction[] = new RuleAction();
     for ($i = 0; $i <= 4; $i++) {
         $modelsRuleAction[$i] = new RuleAction();
         // if it is not the first one, there must be always one condition
         if (0 < $i) {
             $modelsRuleAction[$i]->value_value = Yii::t('app', '- None -');
             $modelsRuleAction[$i]->weight = $i;
         }
     }
     if ($model->load(Yii::$app->request->post()) && RuleCondition::loadMultiple($modelsRuleCondition, Yii::$app->request->post()) && RuleAction::loadMultiple($modelsRuleAction, Yii::$app->request->post())) {
         // set rule_id temporary on 0, for validation
         foreach ($modelsRuleCondition as $key => $modelRuleCondition) {
             $modelRuleCondition->rule_id = 0;
             $modelsRuleCondition[$key] = $modelRuleCondition;
         }
         // set rule_id temporary on 0, for validation
         foreach ($modelsRuleAction as $key => $modelRuleAction) {
             $modelRuleAction->rule_id = 0;
             $modelsRuleAction[$key] = $modelRuleAction;
         }
         if ($model->validate() && RuleCondition::validateMultiple($modelsRuleCondition) && RuleAction::validateMultiple($modelsRuleAction)) {
             $model->save(false);
             // change the rule_id, and save
             foreach ($modelsRuleCondition as $modelRuleCondition) {
                 if (Yii::t('app', '- None -') != $modelRuleCondition->value_value) {
                     $modelRuleCondition->rule_id = $model->id;
                     $modelRuleCondition->save(false);
                 }
             }
             // change the rule_id, and save
             foreach ($modelsRuleAction as $modelRuleAction) {
                 //echo('$modelRuleAction: ') . '<br/>' . PHP_EOL;
                 //var_dump($modelRuleAction);
                 if (Yii::t('app', '- None -') != $modelRuleAction->value_value) {
                     $modelRuleAction->rule_id = $model->id;
                     $modelRuleAction->save(false);
                 }
             }
             //exit();
             return $this->redirect(['view', 'id' => $model->id]);
         }
     }
     return $this->render('create', ['model' => $model, 'modelsRuleCondition' => $modelsRuleCondition, 'modelsRuleAction' => $modelsRuleAction]);
 }