/**
  * Copy record
  * If copy is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be copy
  */
 public function actionCopy($id)
 {
     $data = $this->loadModel($id);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['GameEventAnswerModel'])) {
         $model = new GameEventAnswerModel();
         $model->attributes = $_POST['GameEventAnswerModel'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('copy', array('model' => $data));
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new GameEventQuestionModel();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['GameEventQuestionModel'])) {
         $model->attributes = $_POST['GameEventQuestionModel'];
         if ($model->save()) {
             //Create answers
             $answers_name = $_POST['answer'];
         }
         $answers_isTrue = $_POST['answer_chk'];
         $position = array(0 => 'A', 1 => 'B', 2 => 'C', 3 => 'D');
         if ($model->type == 'text') {
             for ($i = 0; $i < 4; $i++) {
                 if ($answers_name[$i]) {
                     $answer = new GameEventAnswerModel();
                     $answer->ask_id = $model->id;
                     $answer->name = $answers_name[$i];
                     $answer->is_true = $answers_isTrue == $i ? 1 : 0;
                     $answer->position = $position[$i];
                     $answer->save();
                 }
             }
         } else {
             $ask_image = array();
             $ask_image[] = $_POST['ask_image_0'];
             $ask_image[] = $_POST['ask_image_1'];
             $ask_image[] = $_POST['ask_image_2'];
             $ask_image[] = $_POST['ask_image_3'];
             for ($i = 0; $i < 4; $i++) {
                 if ($ask_image[$i]) {
                     $answer = new GameEventAnswerModel();
                     $answer->ask_id = $model->id;
                     $answer->name = $ask_image[$i];
                     $answer->is_true = $answers_isTrue == $i ? 1 : 0;
                     $answer->position = $position[$i];
                     $answer->save();
                 }
             }
         }
         $this->redirect(array('view', 'id' => $model->id));
     }
     $this->render('create', array('model' => $model));
 }