Code Duplication    Length = 25-29 lines in 2 locations

main/exercise/exercise.class.php 2 locations

@@ 3352-3380 (lines=29) @@
3349
                    }
3350
                    $totalScore = $questionScore;
3351
                    break;
3352
                case MULTIPLE_ANSWER: //2
3353
                    if ($from_database) {
3354
                        $choice = array();
3355
                        $sql = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT."
3356
                                WHERE exe_id = '".$exeId."' AND question_id= '".$questionId."'";
3357
                        $resultans = Database::query($sql);
3358
                        while ($row = Database::fetch_array($resultans)) {
3359
                            $ind = $row['answer'];
3360
                            $choice[$ind] = 1;
3361
                        }
3362
3363
                        $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
3364
                        $real_answers[$answerId] = (bool)$studentChoice;
3365
3366
                        if ($studentChoice) {
3367
                            $questionScore  +=$answerWeighting;
3368
                        }
3369
                    } else {
3370
                        $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
3371
                        $real_answers[$answerId] = (bool)$studentChoice;
3372
3373
                        if (isset($studentChoice)) {
3374
                            $questionScore  += $answerWeighting;
3375
                        }
3376
                    }
3377
                    $totalScore += $answerWeighting;
3378
3379
                    if ($debug) error_log("studentChoice: $studentChoice");
3380
                    break;
3381
                case GLOBAL_MULTIPLE_ANSWER:
3382
                    if ($from_database) {
3383
                        $choice = array();
@@ 3381-3405 (lines=25) @@
3378
3379
                    if ($debug) error_log("studentChoice: $studentChoice");
3380
                    break;
3381
                case GLOBAL_MULTIPLE_ANSWER:
3382
                    if ($from_database) {
3383
                        $choice = array();
3384
                        $sql = "SELECT answer FROM $TBL_TRACK_ATTEMPT
3385
                                WHERE exe_id = '".$exeId."' AND question_id= '".$questionId."'";
3386
                        $resultans = Database::query($sql);
3387
                        while ($row = Database::fetch_array($resultans)) {
3388
                            $ind = $row['answer'];
3389
                            $choice[$ind] = 1;
3390
                        }
3391
                        $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
3392
                        $real_answers[$answerId] = (bool)$studentChoice;
3393
                        if ($studentChoice) {
3394
                            $questionScore +=$answerWeighting;
3395
                        }
3396
                    } else {
3397
                        $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
3398
                        if (isset($studentChoice)) {
3399
                            $questionScore += $answerWeighting;
3400
                        }
3401
                        $real_answers[$answerId] = (bool)$studentChoice;
3402
                    }
3403
                    $totalScore += $answerWeighting;
3404
                    if ($debug) error_log("studentChoice: $studentChoice");
3405
                    break;
3406
                case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE:
3407
                    if ($from_database) {
3408
                        $sql = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT."