Code Duplication    Length = 56-60 lines in 2 locations

src/Chamilo/CourseBundle/Controller/Home/HomeController.php 2 locations

@@ 233-292 (lines=60) @@
230
        // Exercise auto-launch
231
        $auto_launch = api_get_course_setting('enable_exercise_auto_launch');
232
233
        if (!empty($auto_launch)) {
234
            $session_id = api_get_session_id();
235
            //Exercise list
236
            if ($auto_launch == 2) {
237
                if (api_is_platform_admin() || api_is_allowed_to_edit()) {
238
                    $showAutoLaunchExerciseWarning = true;
239
                } else {
240
                    $session_key = 'exercise_autolunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
241
                    $sessionData = Session::read($session_key);
242
                    if (!isset($sessionData)) {
243
                        //redirecting to the Exercise
244
                        $url = api_get_path(WEB_CODE_PATH).'exercice/exercice.php?'.api_get_cidreq().'&id_session='.$session_id;
245
                        $_SESSION[$session_key] = true;
246
247
                        header("Location: $url");
248
                        exit;
249
                    }
250
                }
251
            } else {
252
                $table = \Database::get_course_table(TABLE_QUIZ_TEST);
253
                $course_id = api_get_course_int_id();
254
                $condition = '';
255
                if (!empty($session_id)) {
256
                    $condition =  api_get_session_condition($session_id);
257
                    $sql = "SELECT iid FROM $table
258
                            WHERE c_id = $course_id AND autolaunch = 1 $condition
259
                            LIMIT 1";
260
                    $result = \Database::query($sql);
261
                    //If we found nothing in the session we just called the session_id =  0 autolaunch
262
                    if (\Database::num_rows($result) ==  0) {
263
                        $condition = '';
264
                    } else {
265
                        //great, there is an specific auto lunch for this session we leave the $condition
266
                    }
267
                }
268
269
                $sql = "SELECT iid FROM $table
270
                        WHERE c_id = $course_id AND autolaunch = 1 $condition
271
                        LIMIT 1";
272
                $result = \Database::query($sql);
273
                if (\Database::num_rows($result) >  0) {
274
                    $data = \Database::fetch_array($result, 'ASSOC');
275
                    if (!empty($data['iid'])) {
276
                        if (api_is_platform_admin() || api_is_allowed_to_edit()) {
277
                            $showAutoLaunchExerciseWarning = true;
278
                        } else {
279
                            $session_key = 'exercise_autolunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
280
                            if (!isset($_SESSION[$session_key])) {
281
                                //redirecting to the LP
282
                                $url = api_get_path(WEB_CODE_PATH).'exercice/overview.php?'.api_get_cidreq().'&exerciseId='.$data['iid'];
283
284
                                $_SESSION[$session_key] = true;
285
                                header("Location: $url");
286
                                exit;
287
                            }
288
                        }
289
                    }
290
                }
291
            }
292
        }
293
294
        /* Auto launch code */
295
        $showAutoLaunchLpWarning = false;
@@ 297-352 (lines=56) @@
294
        /* Auto launch code */
295
        $showAutoLaunchLpWarning = false;
296
        $auto_launch = api_get_course_setting('enable_lp_auto_launch');
297
        if (!empty($auto_launch)) {
298
            $session_id = api_get_session_id();
299
            //LP list
300
            if ($auto_launch == 2) {
301
                if (api_is_platform_admin() || api_is_allowed_to_edit()) {
302
                    $showAutoLaunchLpWarning = true;
303
                } else {
304
                    $session_key = 'lp_autolunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
305
                    if (!isset($_SESSION[$session_key])) {
306
                        //redirecting to the LP
307
                        $url = api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?'.api_get_cidreq().'&id_session='.$session_id;
308
                        $_SESSION[$session_key] = true;
309
                        header("Location: $url");
310
                        exit;
311
                    }
312
                }
313
            } else {
314
                $lp_table = \Database::get_course_table(TABLE_LP_MAIN);
315
                $course_id = api_get_course_int_id();
316
                $condition = '';
317
                if (!empty($session_id)) {
318
                    $condition =  api_get_session_condition($session_id);
319
                    $sql = "SELECT id FROM $lp_table WHERE c_id = $course_id AND autolunch = 1 $condition LIMIT 1";
320
                    $result = \Database::query($sql);
321
                    //If we found nothing in the session we just called the session_id =  0 autolunch
322
                    if (\Database::num_rows($result) ==  0) {
323
                        $condition = '';
324
                    } else {
325
                        //great, there is an specific auto lunch for this session we leave the $condition
326
                    }
327
                }
328
329
                $sql = "SELECT id FROM $lp_table
330
                        WHERE c_id = $course_id AND autolunch = 1 $condition
331
                        LIMIT 1";
332
                $result = \Database::query($sql);
333
                if (\Database::num_rows($result) >  0) {
334
                    $lp_data = \Database::fetch_array($result, 'ASSOC');
335
                    if (!empty($lp_data['id'])) {
336
                        if (api_is_platform_admin() || api_is_allowed_to_edit()) {
337
                            $showAutoLaunchLpWarning = true;
338
                        } else {
339
                            $session_key = 'lp_autolunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
340
                            if (!isset($_SESSION[$session_key])) {
341
                                //redirecting to the LP
342
                                $url = api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$lp_data['id'];
343
344
                                $_SESSION[$session_key] = true;
345
                                header("Location: $url");
346
                                exit;
347
                            }
348
                        }
349
                    }
350
                }
351
            }
352
        }
353
354
        return array(
355
            'show_autolaunch_exercise_warning' => $showAutoLaunchExerciseWarning,