Code Duplication    Length = 25-29 lines in 2 locations

main/exercice/exercise.class.php 2 locations

@@ 3378-3406 (lines=29) @@
3375
                    }
3376
                    $totalScore = $questionScore;
3377
                    break;
3378
                case MULTIPLE_ANSWER: //2
3379
                    if ($from_database) {
3380
                        $choice = array();
3381
                        $sql = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT."
3382
                                WHERE exe_id = '".$exeId."' AND question_id= '".$questionId."'";
3383
                        $resultans = Database::query($sql);
3384
                        while ($row = Database::fetch_array($resultans)) {
3385
                            $ind = $row['answer'];
3386
                            $choice[$ind] = 1;
3387
                        }
3388
3389
                        $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
3390
                        $real_answers[$answerId] = (bool)$studentChoice;
3391
3392
                        if ($studentChoice) {
3393
                            $questionScore  +=$answerWeighting;
3394
                        }
3395
                    } else {
3396
                        $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
3397
                        $real_answers[$answerId] = (bool)$studentChoice;
3398
3399
                        if (isset($studentChoice)) {
3400
                            $questionScore  += $answerWeighting;
3401
                        }
3402
                    }
3403
                    $totalScore += $answerWeighting;
3404
3405
                    if ($debug) error_log("studentChoice: $studentChoice");
3406
                    break;
3407
                case GLOBAL_MULTIPLE_ANSWER:
3408
                    if ($from_database) {
3409
                        $choice = array();
@@ 3407-3431 (lines=25) @@
3404
3405
                    if ($debug) error_log("studentChoice: $studentChoice");
3406
                    break;
3407
                case GLOBAL_MULTIPLE_ANSWER:
3408
                    if ($from_database) {
3409
                        $choice = array();
3410
                        $sql = "SELECT answer FROM $TBL_TRACK_ATTEMPT
3411
                                WHERE exe_id = '".$exeId."' AND question_id= '".$questionId."'";
3412
                        $resultans = Database::query($sql);
3413
                        while ($row = Database::fetch_array($resultans)) {
3414
                            $ind = $row['answer'];
3415
                            $choice[$ind] = 1;
3416
                        }
3417
                        $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
3418
                        $real_answers[$answerId] = (bool)$studentChoice;
3419
                        if ($studentChoice) {
3420
                            $questionScore +=$answerWeighting;
3421
                        }
3422
                    } else {
3423
                        $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
3424
                        if (isset($studentChoice)) {
3425
                            $questionScore += $answerWeighting;
3426
                        }
3427
                        $real_answers[$answerId] = (bool)$studentChoice;
3428
                    }
3429
                    $totalScore += $answerWeighting;
3430
                    if ($debug) error_log("studentChoice: $studentChoice");
3431
                    break;
3432
                case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE:
3433
                    if ($from_database) {
3434
                        $sql = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT."