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