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