controllers/QuestionBankController.php
/*
    * Function for uploading the figures. The model will have the save
    * command to save into a specified directory.
    */
Function for uploading the figures. The model will have the save
command to save into a specified directory.
Function for uploading the figures . The model will have the save command to save into a specified directory .
public function actionUploadImage($id)
    {
        $model = new StoreImage();
        $questionBankModel = $this->findModel($id);
        $columnModel = new MatchColumn();
        $question = $questionBankModel->question;
        $description = $questionBankModel->description;
        $questionNos = $questionBankModel->nos_option; 
        if (Yii::$app->request->isPost) {
            $model->imageFile = UploadedFile::getInstance($model, 'imageFile'); 
            $model->question_bank_id = $id;
            $imageName = Yii::$app->security->generateRandomString();
            $model->file_name = $imageName . '.' . $model->imageFile->extension;
            $model->nos_question = $questionBankModel->nos_option; 
            $model->file_size = $model->imageFile->size; 
            if ($model->upload()) {
                $score = $questionBankModel->max_mark/$questionBankModel->nos_option; 
                for( $i = 1; $i <= $questionBankModel->nos_option; $i++ ) {
                    $columnModel->match_column_id = NULL; 
                    $columnModel->isNewRecord = true;
                    $columnModel->question_bank_id = $id;
                    $columnModel->image_id = $model->image_id;
                    $columnModel->column = $i . ''; 
                    $columnModel->column_match = $_POST[ $i ]; 
                    $columnModel->score = $score; 
                    $columnModel->save();
                }
            }
            return $this->redirect(['index']); 
       }
        return $this->render('upload-image', [
            'model' => $model,
            'question' => $question,
            'description' => $description,
            'questionNos' => $questionNos,
            ]);
    }
public function actionUploadImage ( $ id ) { $ model = new StoreImage ( ) ; $ questionBankModel = $ this -> findModel ( $ id ) ; $ columnModel = new MatchColumn ( ) ; $ question = $ questionBankModel -> question ; $ description = $ questionBankModel -> description ; $ questionNos = $ questionBankModel -> nos_option ; if ( Yii :: $ app -> request -> isPost ) { $ model -> imageFile = UploadedFile :: getInstance ( $ model , 'imageFile' ) ; $ model -> question_bank_id = $ id ; $ imageName = Yii :: $ app -> security -> generateRandomString ( ) ; $ model -> file_name = $ imageName . '.' . $ model -> imageFile -> extension ; $ model -> nos_question = $ questionBankModel -> nos_option ; $ model -> file_size = $ model -> imageFile -> size ; if ( $ model -> upload ( ) ) { $ score = $ questionBankModel -> max_mark / $ questionBankModel -> nos_option ; for ( $ i = 1 ; $ i <= $ questionBankModel -> nos_option ; $ i ++ ) { $ columnModel -> match_column_id = NULL ; $ columnModel -> isNewRecord = true ; $ columnModel -> question_bank_id = $ id ; $ columnModel -> image_id = $ model -> image_id ; $ columnModel -> column = $ i . '' ; $ columnModel -> column_match = $ _POST [ $ i ] ; $ columnModel -> score = $ score ; $ columnModel -> save ( ) ; } } return $ this -> redirect ( [ 'index' ] ) ; } return $ this -> render ( 'upload-image' , [ 'model' => $ model , 'question' => $ question , 'description' => $ description , 'questionNos' => $ questionNos , ] ) ; }
Function for uploading the figures.
Function for uploading the figures .
//image captured //Image has been submitted // populate the field in image table // file is uploaded and saved // populate the field in match column table //reset the model, needed for saving in loop //primary key(auto increment id) id //save the model // column to be matched // correct column // equal score for each column // Go to theindex view of question bank