Code Duplication    Length = 15-18 lines in 3 locations

src/Chamilo/CourseBundle/Component/CourseCopy/CourseRestorer.php 3 locations

@@ 2293-2307 (lines=15) @@
2290
2291
                            $params['code'] = $survey_code;
2292
                            $new_id = Database::insert($table_sur, $params);
2293
                            if ($new_id) {
2294
                                $sql = "UPDATE $table_sur SET survey_id = iid WHERE iid = $new_id";
2295
                                Database::query($sql);
2296
2297
                                $this->course->resources[RESOURCE_SURVEY][$id]->destination_id = $new_id;
2298
                                foreach ($survey->question_ids as $index => $question_id) {
2299
                                    $qid = $this->restore_survey_question($question_id, $new_id);
2300
                                    $sql = "UPDATE $table_que SET survey_id = $new_id
2301
                                            WHERE c_id = ".$this->destination_course_id." AND question_id = $qid";
2302
                                    Database::query($sql);
2303
                                    $sql = "UPDATE $table_ans SET survey_id = $new_id
2304
                                            WHERE  c_id = ".$this->destination_course_id." AND  question_id = $qid";
2305
                                    Database::query($sql);
2306
                                }
2307
                            }
2308
                            break;
2309
                        case FILE_OVERWRITE:
2310
                            // Delete the existing survey with the same code and language and import the one of the source course
@@ 2329-2346 (lines=18) @@
2326
                            // Insert the new source survey
2327
                            $new_id = Database::insert($table_sur, $params);
2328
2329
                            if ($new_id) {
2330
                                $sql = "UPDATE $table_sur SET survey_id = iid WHERE iid = $new_id";
2331
                                Database::query($sql);
2332
2333
                                $this->course->resources[RESOURCE_SURVEY][$id]->destination_id = $new_id;
2334
                                foreach ($survey->question_ids as $index => $question_id) {
2335
                                    $qid = $this->restore_survey_question(
2336
                                        $question_id,
2337
                                        $new_id
2338
                                    );
2339
                                    $sql = "UPDATE $table_que SET survey_id = $new_id
2340
                                            WHERE c_id = ".$this->destination_course_id." AND question_id = $qid";
2341
                                    Database::query($sql);
2342
                                    $sql = "UPDATE $table_ans SET survey_id = $new_id
2343
                                            WHERE c_id = ".$this->destination_course_id." AND question_id = $qid";
2344
                                    Database::query($sql);
2345
                                }
2346
                            }
2347
                            break;
2348
                        default:
2349
                            break;
@@ 2355-2372 (lines=18) @@
2352
                    // No existing survey with the same language and the same code, we just copy the survey
2353
                    $new_id = Database::insert($table_sur, $params);
2354
2355
                    if ($new_id) {
2356
                        $sql = "UPDATE $table_sur SET survey_id = iid WHERE iid = $new_id";
2357
                        Database::query($sql);
2358
2359
                        $this->course->resources[RESOURCE_SURVEY][$id]->destination_id = $new_id;
2360
                        foreach ($survey->question_ids as $index => $question_id) {
2361
                            $qid = $this->restore_survey_question(
2362
                                $question_id,
2363
                                $new_id
2364
                            );
2365
                            $sql = "UPDATE $table_que SET survey_id = $new_id
2366
                                    WHERE c_id = ".$this->destination_course_id." AND question_id = $qid";
2367
                            Database::query($sql);
2368
                            $sql = "UPDATE $table_ans SET survey_id = $new_id
2369
                                    WHERE c_id = ".$this->destination_course_id." AND question_id = $qid";
2370
                            Database::query($sql);
2371
                        }
2372
                    }
2373
                }
2374
            }
2375
        }