| Conditions | 26 |
| Paths | 2376 |
| Total Lines | 165 |
| Code Lines | 99 |
| 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 |
||
| 36 | public function indexAction(Request $request, CToolRepository $toolRepository, ToolChain $toolChain) |
||
| 37 | { |
||
| 38 | $this->autoLaunch(); |
||
| 39 | $course = $this->getCourse(); |
||
| 40 | |||
| 41 | $js = '<script>'.api_get_language_translate_html().'</script>'; |
||
| 42 | $htmlHeadXtra[] = $js; |
||
|
|
|||
| 43 | |||
| 44 | $userId = $this->getUser()->getId(); |
||
| 45 | $courseCode = $course->getCode(); |
||
| 46 | $courseId = $course->getId(); |
||
| 47 | $sessionId = $this->getSessionId(); |
||
| 48 | |||
| 49 | if (api_is_invitee()) { |
||
| 50 | $isInASession = $sessionId > 0; |
||
| 51 | $isSubscribed = CourseManager::is_user_subscribed_in_course( |
||
| 52 | $userId, |
||
| 53 | $courseCode, |
||
| 54 | $isInASession, |
||
| 55 | $sessionId |
||
| 56 | ); |
||
| 57 | |||
| 58 | if (!$isSubscribed) { |
||
| 59 | api_not_allowed(true); |
||
| 60 | } |
||
| 61 | } |
||
| 62 | |||
| 63 | // Deleting group session |
||
| 64 | Session::erase('toolgroup'); |
||
| 65 | Session::erase('_gid'); |
||
| 66 | |||
| 67 | $isSpecialCourse = CourseManager::isSpecialCourse($courseId); |
||
| 68 | |||
| 69 | if ($isSpecialCourse) { |
||
| 70 | if (isset($_GET['autoreg']) && $_GET['autoreg'] == 1) { |
||
| 71 | if (CourseManager::subscribeUser($userId, $courseCode, STUDENT)) { |
||
| 72 | Session::write('is_allowed_in_course', true); |
||
| 73 | } |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | $action = !empty($_GET['action']) ? Security::remove_XSS($_GET['action']) : ''; |
||
| 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($userId, $courseCode)) { |
||
| 84 | Session::write('is_allowed_in_course', true); |
||
| 85 | } |
||
| 86 | } |
||
| 87 | header('Location: '.api_get_self()); |
||
| 88 | exit; |
||
| 89 | } |
||
| 90 | } |
||
| 91 | |||
| 92 | /* STATISTICS */ |
||
| 93 | if (!isset($coursesAlreadyVisited[$courseCode])) { |
||
| 94 | Event::accessCourse(); |
||
| 95 | $coursesAlreadyVisited[$courseCode] = 1; |
||
| 96 | Session::write('coursesAlreadyVisited', $coursesAlreadyVisited); |
||
| 97 | } |
||
| 98 | |||
| 99 | $logInfo = [ |
||
| 100 | 'tool' => 'course-main', |
||
| 101 | 'action' => $action, |
||
| 102 | ]; |
||
| 103 | Event::registerLog($logInfo); |
||
| 104 | |||
| 105 | /* Introduction section (editable by course admins) */ |
||
| 106 | /*$introduction = Display::return_introduction_section( |
||
| 107 | TOOL_COURSE_HOMEPAGE, |
||
| 108 | [ |
||
| 109 | 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/', |
||
| 110 | 'CreateDocumentDir' => 'document/', |
||
| 111 | 'BaseHref' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/', |
||
| 112 | ] |
||
| 113 | );*/ |
||
| 114 | |||
| 115 | $qb = $toolRepository->getResourcesByCourse($course, $this->getSession()); |
||
| 116 | $result = $qb->getQuery()->getResult(); |
||
| 117 | |||
| 118 | $tools = []; |
||
| 119 | /** @var CTool $item */ |
||
| 120 | foreach ($result as $item) { |
||
| 121 | $toolModel = $toolChain->getToolFromName($item->getTool()->getName()); |
||
| 122 | // Dont show admin links. |
||
| 123 | if ($toolModel->getAdmin()) { |
||
| 124 | continue; |
||
| 125 | } |
||
| 126 | |||
| 127 | if ($toolModel->getCategory() === 'admin' && !$this->isGranted('ROLE_CURRENT_COURSE_TEACHER')) { |
||
| 128 | continue; |
||
| 129 | } |
||
| 130 | $tools[$item->getCategory()][] = $item; |
||
| 131 | } |
||
| 132 | |||
| 133 | // Get session-career diagram |
||
| 134 | $diagram = ''; |
||
| 135 | $allow = api_get_configuration_value('allow_career_diagram'); |
||
| 136 | if ($allow === true) { |
||
| 137 | $htmlHeadXtra[] = api_get_js('jsplumb2.js'); |
||
| 138 | $extra = new ExtraFieldValue('session'); |
||
| 139 | $value = $extra->get_values_by_handler_and_field_variable( |
||
| 140 | api_get_session_id(), |
||
| 141 | 'external_career_id' |
||
| 142 | ); |
||
| 143 | |||
| 144 | if (!empty($value) && isset($value['value'])) { |
||
| 145 | $careerId = $value['value']; |
||
| 146 | $extraFieldValue = new ExtraFieldValue('career'); |
||
| 147 | $item = $extraFieldValue->get_item_id_from_field_variable_and_field_value( |
||
| 148 | 'external_career_id', |
||
| 149 | $careerId, |
||
| 150 | false, |
||
| 151 | false, |
||
| 152 | false |
||
| 153 | ); |
||
| 154 | |||
| 155 | if (!empty($item) && isset($item['item_id'])) { |
||
| 156 | $careerId = $item['item_id']; |
||
| 157 | $career = new Career(); |
||
| 158 | $careerInfo = $career->get($careerId); |
||
| 159 | if (!empty($careerInfo)) { |
||
| 160 | $extraFieldValue = new ExtraFieldValue('career'); |
||
| 161 | $item = $extraFieldValue->get_values_by_handler_and_field_variable( |
||
| 162 | $careerId, |
||
| 163 | 'career_diagram', |
||
| 164 | false, |
||
| 165 | false, |
||
| 166 | false |
||
| 167 | ); |
||
| 168 | |||
| 169 | if (!empty($item) && isset($item['value']) && !empty($item['value'])) { |
||
| 170 | /** @var Graph $graph */ |
||
| 171 | $graph = UnserializeApi::unserialize( |
||
| 172 | 'career', |
||
| 173 | $item['value'] |
||
| 174 | ); |
||
| 175 | $diagram = Career::renderDiagram($careerInfo, $graph); |
||
| 176 | } |
||
| 177 | } |
||
| 178 | } |
||
| 179 | } |
||
| 180 | } |
||
| 181 | |||
| 182 | // Deleting the objects |
||
| 183 | Session::erase('_gid'); |
||
| 184 | Session::erase('oLP'); |
||
| 185 | Session::erase('lpobject'); |
||
| 186 | api_remove_in_gradebook(); |
||
| 187 | \Exercise::cleanSessionVariables(); |
||
| 188 | \DocumentManager::removeGeneratedAudioTempFile(); |
||
| 189 | |||
| 190 | return $this->render( |
||
| 191 | '@ChamiloTheme/Course/home.html.twig', |
||
| 192 | [ |
||
| 193 | 'course' => $course, |
||
| 194 | 'diagram' => $diagram, |
||
| 195 | // 'session_info' => $sessionInfo, |
||
| 196 | 'tools' => $tools, |
||
| 197 | //'edit_icons' => $editIcons, |
||
| 198 | //'introduction_text' => $introduction, |
||
| 199 | 'exercise_warning' => null, |
||
| 200 | 'lp_warning' => null, |
||
| 201 | ] |
||
| 389 |