controllers/QuestionBankController.php
/*
    * Function for Multiple Question Multiple Ansswers
    */
Function for Multiple Question Multiple Ansswers
Function for Multiple Question Multiple Ansswers
public function actionMultiOption( $id){
        $optionModel = new Option(); 
        $model = $this->findModel($id);
        if(!empty($_POST)){
            $correct = $_POST['correct']; 
            $correctCount = count($correct); 
            $score = $model->max_mark/$correctCount; 
            for( $i = 1; $i <= $model->nos_option; $i++ ) {
                $optionModel->option_id = NULL; 
                $optionModel->isNewRecord = true;
                $optionModel->score = 0; 
                foreach($correct as $val) {
                    if(intval($val) == $i) {
                        $optionModel->score = $score;
                    }
                }
                $optionModel->question_bank_id = $id;
                $optionModel->question_option = $_POST['option_' . $i ];
                $optionModel->save();
            }
            return $this->redirect(['index']); 
        } else { 
            return $this->render('multi-option', [
                'model' => $model,
            ]);
        }
    }
public function actionMultiOption ( $ id ) { $ optionModel = new Option ( ) ; $ model = $ this -> findModel ( $ id ) ; if ( ! empty ( $ _POST ) ) { $ correct = $ _POST [ 'correct' ] ; $ correctCount = count ( $ correct ) ; $ score = $ model -> max_mark / $ correctCount ; for ( $ i = 1 ; $ i <= $ model -> nos_option ; $ i ++ ) { $ optionModel -> option_id = NULL ; $ optionModel -> isNewRecord = true ; $ optionModel -> score = 0 ; foreach ( $ correct as $ val ) { if ( intval ( $ val ) == $ i ) { $ optionModel -> score = $ score ; } } $ optionModel -> question_bank_id = $ id ; $ optionModel -> question_option = $ _POST [ 'option_' . $ i ] ; $ optionModel -> save ( ) ; } return $ this -> redirect ( [ 'index' ] ) ; } else { return $ this -> render ( 'multi-option' , [ 'model' => $ model , ] ) ; } }
Function for Multiple Question Multiple Ansswers
Function for Multiple Question Multiple Ansswers
// get the option model // Sl.no of the correct answer // number of correct answer // fraction marks for each correct answer //reset the model, needed for saving in loop //primary key(auto increment id) id //reset the score // assign score if the answer is correct //save the model // Go to theindex view of question bank // Go to multi option form