| Conditions | 64 |
| Paths | > 20000 |
| Total Lines | 372 |
| Code Lines | 231 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 35 | public function indexAction(Request $request) |
||
| 36 | { |
||
| 37 | $course = $this->getCourse(); |
||
| 38 | $result = $this->autoLaunch(); |
||
| 39 | $js = '<script>'.api_get_language_translate_html().'</script>'; |
||
| 40 | $htmlHeadXtra[] = $js; |
||
|
|
|||
| 41 | |||
| 42 | $user_id = api_get_user_id(); |
||
| 43 | $courseCode = $course->getCode(); |
||
| 44 | $courseId = $course->getId(); |
||
| 45 | $sessionId = $this->getSessionId(); |
||
| 46 | $show_message = ''; |
||
| 47 | |||
| 48 | if (api_is_invitee()) { |
||
| 49 | $isInASession = $sessionId > 0; |
||
| 50 | $isSubscribed = CourseManager::is_user_subscribed_in_course( |
||
| 51 | $user_id, |
||
| 52 | $courseCode, |
||
| 53 | $isInASession, |
||
| 54 | $sessionId |
||
| 55 | ); |
||
| 56 | |||
| 57 | if (!$isSubscribed) { |
||
| 58 | api_not_allowed(true); |
||
| 59 | } |
||
| 60 | } |
||
| 61 | |||
| 62 | // Deleting group session |
||
| 63 | Session::erase('toolgroup'); |
||
| 64 | Session::erase('_gid'); |
||
| 65 | |||
| 66 | $isSpecialCourse = CourseManager::isSpecialCourse($courseId); |
||
| 67 | |||
| 68 | if ($isSpecialCourse) { |
||
| 69 | if (isset($_GET['autoreg']) && $_GET['autoreg'] == 1) { |
||
| 70 | if (CourseManager::subscribeUser($user_id, $courseCode, STUDENT)) { |
||
| 71 | Session::write('is_allowed_in_course', true); |
||
| 72 | } |
||
| 73 | } |
||
| 74 | } |
||
| 75 | |||
| 76 | $action = !empty($_GET['action']) ? Security::remove_XSS($_GET['action']) : ''; |
||
| 77 | |||
| 78 | if ($action == 'subscribe') { |
||
| 79 | if (Security::check_token('get')) { |
||
| 80 | Security::clear_token(); |
||
| 81 | $result = CourseManager::autoSubscribeToCourse($courseCode); |
||
| 82 | if ($result) { |
||
| 83 | if (CourseManager::is_user_subscribed_in_course($user_id, $courseCode)) { |
||
| 84 | Session::write('is_allowed_in_course', true); |
||
| 85 | } |
||
| 86 | } |
||
| 87 | header('Location: '.api_get_self()); |
||
| 88 | exit; |
||
| 89 | } |
||
| 90 | } |
||
| 91 | |||
| 92 | /* Is the user allowed here? */ |
||
| 93 | api_protect_course_script(true); |
||
| 94 | |||
| 95 | /* STATISTICS */ |
||
| 96 | if (!isset($coursesAlreadyVisited[$courseCode])) { |
||
| 97 | Event::accessCourse(); |
||
| 98 | $coursesAlreadyVisited[$courseCode] = 1; |
||
| 99 | Session::write('coursesAlreadyVisited', $coursesAlreadyVisited); |
||
| 100 | } |
||
| 101 | |||
| 102 | $logInfo = [ |
||
| 103 | 'tool' => 'course-main', |
||
| 104 | 'action' => $action, |
||
| 105 | ]; |
||
| 106 | Event::registerLog($logInfo); |
||
| 107 | |||
| 108 | /* Auto launch code */ |
||
| 109 | $autoLaunchWarning = ''; |
||
| 110 | $showAutoLaunchLpWarning = false; |
||
| 111 | $course_id = api_get_course_int_id(); |
||
| 112 | $lpAutoLaunch = api_get_course_setting('enable_lp_auto_launch'); |
||
| 113 | $session_id = api_get_session_id(); |
||
| 114 | $allowAutoLaunchForCourseAdmins = api_is_platform_admin() || api_is_allowed_to_edit(true, true) || api_is_coach(); |
||
| 115 | |||
| 116 | if (!empty($lpAutoLaunch)) { |
||
| 117 | if ($lpAutoLaunch == 2) { |
||
| 118 | // LP list |
||
| 119 | if ($allowAutoLaunchForCourseAdmins) { |
||
| 120 | $showAutoLaunchLpWarning = true; |
||
| 121 | } else { |
||
| 122 | $session_key = 'lp_autolaunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id(); |
||
| 123 | if (!isset($_SESSION[$session_key])) { |
||
| 124 | // Redirecting to the LP |
||
| 125 | $url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq(); |
||
| 126 | $_SESSION[$session_key] = true; |
||
| 127 | header("Location: $url"); |
||
| 128 | exit; |
||
| 129 | } |
||
| 130 | } |
||
| 131 | } else { |
||
| 132 | $lp_table = Database::get_course_table(TABLE_LP_MAIN); |
||
| 133 | $condition = ''; |
||
| 134 | if (!empty($session_id)) { |
||
| 135 | $condition = api_get_session_condition($session_id); |
||
| 136 | $sql = "SELECT id FROM $lp_table |
||
| 137 | WHERE c_id = $course_id AND autolaunch = 1 $condition |
||
| 138 | LIMIT 1"; |
||
| 139 | $result = Database::query($sql); |
||
| 140 | // If we found nothing in the session we just called the session_id = 0 autolaunch |
||
| 141 | if (Database::num_rows($result) == 0) { |
||
| 142 | $condition = ''; |
||
| 143 | } |
||
| 144 | } |
||
| 145 | |||
| 146 | $sql = "SELECT id FROM $lp_table |
||
| 147 | WHERE c_id = $course_id AND autolaunch = 1 $condition |
||
| 148 | LIMIT 1"; |
||
| 149 | $result = Database::query($sql); |
||
| 150 | if (Database::num_rows($result) > 0) { |
||
| 151 | $lp_data = Database::fetch_array($result, 'ASSOC'); |
||
| 152 | if (!empty($lp_data['id'])) { |
||
| 153 | if ($allowAutoLaunchForCourseAdmins) { |
||
| 154 | $showAutoLaunchLpWarning = true; |
||
| 155 | } else { |
||
| 156 | $session_key = 'lp_autolaunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id(); |
||
| 157 | if (!isset($_SESSION[$session_key])) { |
||
| 158 | // Redirecting to the LP |
||
| 159 | $url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$lp_data['id']; |
||
| 160 | |||
| 161 | $_SESSION[$session_key] = true; |
||
| 162 | header("Location: $url"); |
||
| 163 | exit; |
||
| 164 | } |
||
| 165 | } |
||
| 166 | } |
||
| 167 | } |
||
| 168 | } |
||
| 169 | } |
||
| 170 | |||
| 171 | if ($showAutoLaunchLpWarning) { |
||
| 172 | $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.'); |
||
| 173 | } |
||
| 174 | |||
| 175 | $forumAutoLaunch = api_get_course_setting('enable_forum_auto_launch'); |
||
| 176 | if ($forumAutoLaunch == 1) { |
||
| 177 | if ($allowAutoLaunchForCourseAdmins) { |
||
| 178 | if (empty($autoLaunchWarning)) { |
||
| 179 | $autoLaunchWarning = get_lang('The forum\'s auto-launch setting is on. Students will be redirected to the forum tool when entering this course.'); |
||
| 180 | } |
||
| 181 | } else { |
||
| 182 | $url = api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq(); |
||
| 183 | header("Location: $url"); |
||
| 184 | exit; |
||
| 185 | } |
||
| 186 | } |
||
| 187 | |||
| 188 | if (api_get_configuration_value('allow_exercise_auto_launch')) { |
||
| 189 | $exerciseAutoLaunch = (int) api_get_course_setting('enable_exercise_auto_launch'); |
||
| 190 | if ($exerciseAutoLaunch == 2) { |
||
| 191 | if ($allowAutoLaunchForCourseAdmins) { |
||
| 192 | if (empty($autoLaunchWarning)) { |
||
| 193 | $autoLaunchWarning = get_lang( |
||
| 194 | 'TheExerciseAutoLaunchSettingIsONStudentsWillBeRedirectToTheExerciseList' |
||
| 195 | ); |
||
| 196 | } |
||
| 197 | } else { |
||
| 198 | // Redirecting to the document |
||
| 199 | $url = api_get_path(WEB_CODE_PATH).'exercise/exercise.php?'.api_get_cidreq(); |
||
| 200 | header("Location: $url"); |
||
| 201 | exit; |
||
| 202 | } |
||
| 203 | } elseif ($exerciseAutoLaunch == 1) { |
||
| 204 | if ($allowAutoLaunchForCourseAdmins) { |
||
| 205 | if (empty($autoLaunchWarning)) { |
||
| 206 | $autoLaunchWarning = get_lang( |
||
| 207 | 'TheExerciseAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificExercise' |
||
| 208 | ); |
||
| 209 | } |
||
| 210 | } else { |
||
| 211 | // Redirecting to an exercise |
||
| 212 | $table = Database::get_course_table(TABLE_QUIZ_TEST); |
||
| 213 | $condition = ''; |
||
| 214 | if (!empty($session_id)) { |
||
| 215 | $condition = api_get_session_condition($session_id); |
||
| 216 | $sql = "SELECT iid FROM $table |
||
| 217 | WHERE c_id = $course_id AND autolaunch = 1 $condition |
||
| 218 | LIMIT 1"; |
||
| 219 | $result = Database::query($sql); |
||
| 220 | // If we found nothing in the session we just called the session_id = 0 autolaunch |
||
| 221 | if (Database::num_rows($result) == 0) { |
||
| 222 | $condition = ''; |
||
| 223 | } |
||
| 224 | } |
||
| 225 | |||
| 226 | $sql = "SELECT iid FROM $table |
||
| 227 | WHERE c_id = $course_id AND autolaunch = 1 $condition |
||
| 228 | LIMIT 1"; |
||
| 229 | $result = Database::query($sql); |
||
| 230 | if (Database::num_rows($result) > 0) { |
||
| 231 | $row = Database::fetch_array($result, 'ASSOC'); |
||
| 232 | $exerciseId = $row['iid']; |
||
| 233 | $url = api_get_path(WEB_CODE_PATH). |
||
| 234 | 'exercise/overview.php?exerciseId='.$exerciseId.'&'.api_get_cidreq(); |
||
| 235 | header("Location: $url"); |
||
| 236 | exit; |
||
| 237 | } |
||
| 238 | } |
||
| 239 | } |
||
| 240 | } |
||
| 241 | |||
| 242 | $documentAutoLaunch = api_get_course_setting('enable_document_auto_launch'); |
||
| 243 | if ($documentAutoLaunch == 1) { |
||
| 244 | if ($allowAutoLaunchForCourseAdmins) { |
||
| 245 | if (empty($autoLaunchWarning)) { |
||
| 246 | $autoLaunchWarning = get_lang('The document auto-launch feature configuration is enabled. Learners will be automatically redirected to document tool.'); |
||
| 247 | } |
||
| 248 | } else { |
||
| 249 | // Redirecting to the document |
||
| 250 | $url = api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq(); |
||
| 251 | header("Location: $url"); |
||
| 252 | exit; |
||
| 253 | } |
||
| 254 | } |
||
| 255 | |||
| 256 | // Used in different pages |
||
| 257 | $tool_table = Database::get_course_table(TABLE_TOOL_LIST); |
||
| 258 | |||
| 259 | /* Introduction section (editable by course admins) */ |
||
| 260 | $content = Display::return_introduction_section( |
||
| 261 | TOOL_COURSE_HOMEPAGE, |
||
| 262 | [ |
||
| 263 | 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/', |
||
| 264 | 'CreateDocumentDir' => 'document/', |
||
| 265 | 'BaseHref' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/', |
||
| 266 | ] |
||
| 267 | ); |
||
| 268 | |||
| 269 | /* SWITCH TO A DIFFERENT HOMEPAGE VIEW |
||
| 270 | the setting homepage_view is adjustable through |
||
| 271 | the platform administration section */ |
||
| 272 | if (!empty($autoLaunchWarning)) { |
||
| 273 | $show_message .= Display::return_message( |
||
| 274 | $autoLaunchWarning, |
||
| 275 | 'warning' |
||
| 276 | ); |
||
| 277 | } |
||
| 278 | |||
| 279 | //require 'activity.php'; |
||
| 280 | // Activity start |
||
| 281 | $id = isset($_GET['id']) ? (int) $_GET['id'] : null; |
||
| 282 | $course_id = api_get_course_int_id(); |
||
| 283 | $session_id = api_get_session_id(); |
||
| 284 | |||
| 285 | // Work with data post askable by admin of course |
||
| 286 | if (api_is_platform_admin()) { |
||
| 287 | // Show message to confirm that a tool it to be hidden from available tools |
||
| 288 | // visibility 0,1->2 |
||
| 289 | if (!empty($_GET['askDelete'])) { |
||
| 290 | $content .= '<div id="toolhide">'.get_lang('Do you really want to delete this link?').'<br /> |
||
| 291 | <a href="'.api_get_self().'">'.get_lang('No').'</a> | |
||
| 292 | <a href="'.api_get_self().'?delete=yes&id='.$id.'">'.get_lang('Yes').'</a> |
||
| 293 | </div>'; |
||
| 294 | } elseif (isset($_GET['delete']) && $_GET['delete']) { |
||
| 295 | /* |
||
| 296 | * Process hiding a tools from available tools. |
||
| 297 | */ |
||
| 298 | Database::query("DELETE FROM $tool_table WHERE c_id = $course_id AND id='$id' AND added_tool=1"); |
||
| 299 | } |
||
| 300 | } |
||
| 301 | |||
| 302 | // Course legal |
||
| 303 | $enabled = api_get_plugin_setting('courselegal', 'tool_enable'); |
||
| 304 | $pluginExtra = null; |
||
| 305 | if ($enabled === 'true') { |
||
| 306 | require_once api_get_path(SYS_PLUGIN_PATH).'courselegal/config.php'; |
||
| 307 | $plugin = \CourseLegalPlugin::create(); |
||
| 308 | $pluginExtra = $plugin->getTeacherLink(); |
||
| 309 | } |
||
| 310 | |||
| 311 | // Start of tools for CourseAdmins (teachers/tutors) |
||
| 312 | if ($session_id === 0 && api_is_course_admin() && api_is_allowed_to_edit(null, true)) { |
||
| 313 | $content .= '<div class="alert alert-success" style="border:0px; margin-top: 0px;padding:0px;"> |
||
| 314 | <div class="normal-message" id="id_normal_message" style="display:none">'; |
||
| 315 | $content .= '<img src="'.api_get_path(WEB_PATH).'main/inc/lib/javascript/indicator.gif"/> '; |
||
| 316 | $content .= get_lang('Please stand by...'); |
||
| 317 | $content .= '</div> |
||
| 318 | <div class="alert alert-success" id="id_confirmation_message" style="display:none"></div> |
||
| 319 | </div>'; |
||
| 320 | $content .= $pluginExtra; |
||
| 321 | } elseif (api_is_coach()) { |
||
| 322 | $content .= $pluginExtra; |
||
| 323 | if (api_get_setting('show_session_data') === 'true' && $session_id > 0) { |
||
| 324 | $content .= '<div class="row"> |
||
| 325 | <div class="col-xs-12 col-md-12"> |
||
| 326 | <span class="viewcaption">'.get_lang('Session\'s data').'</span> |
||
| 327 | <table class="course_activity_home">'; |
||
| 328 | $content .= CourseHome::show_session_data($session_id); |
||
| 329 | $content .= '</table></div></div>'; |
||
| 330 | } |
||
| 331 | } |
||
| 332 | |||
| 333 | $blocks = CourseHome::getUserBlocks(); |
||
| 334 | // Activity end |
||
| 335 | |||
| 336 | // Get session-career diagram |
||
| 337 | $diagram = ''; |
||
| 338 | $allow = api_get_configuration_value('allow_career_diagram'); |
||
| 339 | if ($allow === true) { |
||
| 340 | $htmlHeadXtra[] = api_get_js('jsplumb2.js'); |
||
| 341 | $extra = new ExtraFieldValue('session'); |
||
| 342 | $value = $extra->get_values_by_handler_and_field_variable( |
||
| 343 | api_get_session_id(), |
||
| 344 | 'external_career_id' |
||
| 345 | ); |
||
| 346 | |||
| 347 | if (!empty($value) && isset($value['value'])) { |
||
| 348 | $careerId = $value['value']; |
||
| 349 | $extraFieldValue = new ExtraFieldValue('career'); |
||
| 350 | $item = $extraFieldValue->get_item_id_from_field_variable_and_field_value( |
||
| 351 | 'external_career_id', |
||
| 352 | $careerId, |
||
| 353 | false, |
||
| 354 | false, |
||
| 355 | false |
||
| 356 | ); |
||
| 357 | |||
| 358 | if (!empty($item) && isset($item['item_id'])) { |
||
| 359 | $careerId = $item['item_id']; |
||
| 360 | $career = new Career(); |
||
| 361 | $careerInfo = $career->get($careerId); |
||
| 362 | if (!empty($careerInfo)) { |
||
| 363 | $extraFieldValue = new ExtraFieldValue('career'); |
||
| 364 | $item = $extraFieldValue->get_values_by_handler_and_field_variable( |
||
| 365 | $careerId, |
||
| 366 | 'career_diagram', |
||
| 367 | false, |
||
| 368 | false, |
||
| 369 | false |
||
| 370 | ); |
||
| 371 | |||
| 372 | if (!empty($item) && isset($item['value']) && !empty($item['value'])) { |
||
| 373 | /** @var Graph $graph */ |
||
| 374 | $graph = UnserializeApi::unserialize( |
||
| 375 | 'career', |
||
| 376 | $item['value'] |
||
| 377 | ); |
||
| 378 | $diagram = Career::renderDiagram($careerInfo, $graph); |
||
| 379 | } |
||
| 380 | } |
||
| 381 | } |
||
| 382 | } |
||
| 383 | } |
||
| 384 | |||
| 385 | $content = '<div id="course_tools">'.$diagram.$content.'</div>'; |
||
| 386 | |||
| 387 | // Deleting the objects |
||
| 388 | Session::erase('_gid'); |
||
| 389 | Session::erase('oLP'); |
||
| 390 | Session::erase('lpobject'); |
||
| 391 | api_remove_in_gradebook(); |
||
| 392 | \Exercise::cleanSessionVariables(); |
||
| 393 | \DocumentManager::removeGeneratedAudioTempFile(); |
||
| 394 | |||
| 395 | return $this->render( |
||
| 396 | '@ChamiloTheme/Course/home.html.twig', |
||
| 397 | [ |
||
| 398 | 'course' => $course, |
||
| 399 | 'diagram' => $diagram, |
||
| 400 | // 'session_info' => $sessionInfo, |
||
| 401 | 'icons' => $result['content'], |
||
| 402 | 'blocks' => $blocks, |
||
| 403 | //'edit_icons' => $editIcons, |
||
| 404 | //'introduction_text' => $introduction, |
||
| 405 | 'exercise_warning' => null, |
||
| 406 | 'lp_warning' => null, |
||
| 407 | ] |
||
| 983 |