| Conditions | 31 |
| Paths | 18192 |
| Total Lines | 158 |
| Code Lines | 103 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 228 | private function autoLaunch() |
||
| 229 | { |
||
| 230 | /* Auto launch code */ |
||
| 231 | $autoLaunchWarning = ''; |
||
| 232 | $showAutoLaunchLpWarning = false; |
||
| 233 | $course_id = api_get_course_int_id(); |
||
| 234 | $lpAutoLaunch = api_get_course_setting('enable_lp_auto_launch'); |
||
| 235 | $session_id = api_get_session_id(); |
||
| 236 | $allowAutoLaunchForCourseAdmins = api_is_platform_admin() || api_is_allowed_to_edit(true, true) || api_is_coach(); |
||
| 237 | |||
| 238 | if (!empty($lpAutoLaunch)) { |
||
| 239 | if ($lpAutoLaunch == 2) { |
||
| 240 | // LP list |
||
| 241 | if ($allowAutoLaunchForCourseAdmins) { |
||
| 242 | $showAutoLaunchLpWarning = true; |
||
| 243 | } else { |
||
| 244 | $session_key = 'lp_autolaunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id(); |
||
| 245 | if (!isset($_SESSION[$session_key])) { |
||
| 246 | // Redirecting to the LP |
||
| 247 | $url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq(); |
||
| 248 | $_SESSION[$session_key] = true; |
||
| 249 | header("Location: $url"); |
||
| 250 | exit; |
||
| 251 | } |
||
| 252 | } |
||
| 253 | } else { |
||
| 254 | $lp_table = Database::get_course_table(TABLE_LP_MAIN); |
||
| 255 | $condition = ''; |
||
| 256 | if (!empty($session_id)) { |
||
| 257 | $condition = api_get_session_condition($session_id); |
||
| 258 | $sql = "SELECT id FROM $lp_table |
||
| 259 | WHERE c_id = $course_id AND autolaunch = 1 $condition |
||
| 260 | LIMIT 1"; |
||
| 261 | $result = Database::query($sql); |
||
| 262 | // If we found nothing in the session we just called the session_id = 0 autolaunch |
||
| 263 | if (Database::num_rows($result) == 0) { |
||
| 264 | $condition = ''; |
||
| 265 | } |
||
| 266 | } |
||
| 267 | |||
| 268 | $sql = "SELECT id FROM $lp_table |
||
| 269 | WHERE c_id = $course_id AND autolaunch = 1 $condition |
||
| 270 | LIMIT 1"; |
||
| 271 | $result = Database::query($sql); |
||
| 272 | if (Database::num_rows($result) > 0) { |
||
| 273 | $lp_data = Database::fetch_array($result, 'ASSOC'); |
||
| 274 | if (!empty($lp_data['id'])) { |
||
| 275 | if ($allowAutoLaunchForCourseAdmins) { |
||
| 276 | $showAutoLaunchLpWarning = true; |
||
| 277 | } else { |
||
| 278 | $session_key = 'lp_autolaunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id(); |
||
| 279 | if (!isset($_SESSION[$session_key])) { |
||
| 280 | // Redirecting to the LP |
||
| 281 | $url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$lp_data['id']; |
||
| 282 | |||
| 283 | $_SESSION[$session_key] = true; |
||
| 284 | header("Location: $url"); |
||
| 285 | exit; |
||
| 286 | } |
||
| 287 | } |
||
| 288 | } |
||
| 289 | } |
||
| 290 | } |
||
| 291 | } |
||
| 292 | |||
| 293 | if ($showAutoLaunchLpWarning) { |
||
| 294 | $autoLaunchWarning = get_lang('The learning path auto-launch setting is ON. When learners enter this course, they will be automatically redirected to the learning path marked as auto-launch.'); |
||
| 295 | } |
||
| 296 | |||
| 297 | $forumAutoLaunch = api_get_course_setting('enable_forum_auto_launch'); |
||
| 298 | if ($forumAutoLaunch == 1) { |
||
| 299 | if ($allowAutoLaunchForCourseAdmins) { |
||
| 300 | if (empty($autoLaunchWarning)) { |
||
| 301 | $autoLaunchWarning = get_lang('The forum\'s auto-launch setting is on. Students will be redirected to the forum tool when entering this course.'); |
||
| 302 | } |
||
| 303 | } else { |
||
| 304 | $url = api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq(); |
||
| 305 | header("Location: $url"); |
||
| 306 | exit; |
||
| 307 | } |
||
| 308 | } |
||
| 309 | |||
| 310 | if (api_get_configuration_value('allow_exercise_auto_launch')) { |
||
| 311 | $exerciseAutoLaunch = (int) api_get_course_setting('enable_exercise_auto_launch'); |
||
| 312 | if ($exerciseAutoLaunch == 2) { |
||
| 313 | if ($allowAutoLaunchForCourseAdmins) { |
||
| 314 | if (empty($autoLaunchWarning)) { |
||
| 315 | $autoLaunchWarning = get_lang( |
||
| 316 | 'TheExerciseAutoLaunchSettingIsONStudentsWillBeRedirectToTheExerciseList' |
||
| 317 | ); |
||
| 318 | } |
||
| 319 | } else { |
||
| 320 | // Redirecting to the document |
||
| 321 | $url = api_get_path(WEB_CODE_PATH).'exercise/exercise.php?'.api_get_cidreq(); |
||
| 322 | header("Location: $url"); |
||
| 323 | exit; |
||
| 324 | } |
||
| 325 | } elseif ($exerciseAutoLaunch == 1) { |
||
| 326 | if ($allowAutoLaunchForCourseAdmins) { |
||
| 327 | if (empty($autoLaunchWarning)) { |
||
| 328 | $autoLaunchWarning = get_lang( |
||
| 329 | 'TheExerciseAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificExercise' |
||
| 330 | ); |
||
| 331 | } |
||
| 332 | } else { |
||
| 333 | // Redirecting to an exercise |
||
| 334 | $table = Database::get_course_table(TABLE_QUIZ_TEST); |
||
| 335 | $condition = ''; |
||
| 336 | if (!empty($session_id)) { |
||
| 337 | $condition = api_get_session_condition($session_id); |
||
| 338 | $sql = "SELECT iid FROM $table |
||
| 339 | WHERE c_id = $course_id AND autolaunch = 1 $condition |
||
| 340 | LIMIT 1"; |
||
| 341 | $result = Database::query($sql); |
||
| 342 | // If we found nothing in the session we just called the session_id = 0 autolaunch |
||
| 343 | if (Database::num_rows($result) == 0) { |
||
| 344 | $condition = ''; |
||
| 345 | } |
||
| 346 | } |
||
| 347 | |||
| 348 | $sql = "SELECT iid FROM $table |
||
| 349 | WHERE c_id = $course_id AND autolaunch = 1 $condition |
||
| 350 | LIMIT 1"; |
||
| 351 | $result = Database::query($sql); |
||
| 352 | if (Database::num_rows($result) > 0) { |
||
| 353 | $row = Database::fetch_array($result, 'ASSOC'); |
||
| 354 | $exerciseId = $row['iid']; |
||
| 355 | $url = api_get_path(WEB_CODE_PATH). |
||
| 356 | 'exercise/overview.php?exerciseId='.$exerciseId.'&'.api_get_cidreq(); |
||
| 357 | header("Location: $url"); |
||
| 358 | exit; |
||
| 359 | } |
||
| 360 | } |
||
| 361 | } |
||
| 362 | } |
||
| 363 | |||
| 364 | $documentAutoLaunch = api_get_course_setting('enable_document_auto_launch'); |
||
| 365 | if ($documentAutoLaunch == 1) { |
||
| 366 | if ($allowAutoLaunchForCourseAdmins) { |
||
| 367 | if (empty($autoLaunchWarning)) { |
||
| 368 | $autoLaunchWarning = get_lang('The document auto-launch feature configuration is enabled. Learners will be automatically redirected to document tool.'); |
||
| 369 | } |
||
| 370 | } else { |
||
| 371 | // Redirecting to the document |
||
| 372 | $url = api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq(); |
||
| 373 | header("Location: $url"); |
||
| 374 | exit; |
||
| 375 | } |
||
| 376 | } |
||
| 377 | |||
| 378 | /* SWITCH TO A DIFFERENT HOMEPAGE VIEW |
||
| 379 | the setting homepage_view is adjustable through |
||
| 380 | the platform administration section */ |
||
| 381 | if (!empty($autoLaunchWarning)) { |
||
| 382 | $this->addFlash( |
||
| 383 | Display::return_message( |
||
| 384 | $autoLaunchWarning, |
||
| 385 | 'warning' |
||
| 386 | )); |
||
| 456 |