| Conditions | 19 |
| Paths | 216 |
| Total Lines | 220 |
| Code Lines | 129 |
| 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 |
||
| 41 | #[Route(path: '/{sid}/about', name: 'chamilo_core_session_about')] |
||
| 42 | public function about( |
||
| 43 | Request $request, |
||
| 44 | Session $session, |
||
| 45 | IllustrationRepository $illustrationRepo, |
||
| 46 | UserRepository $userRepo, |
||
| 47 | EntityManagerInterface $em |
||
| 48 | ): Response { |
||
| 49 | $requestSession = $request->getSession(); |
||
| 50 | $htmlHeadXtra[] = api_get_asset('readmore-js/readmore.js'); |
||
|
|
|||
| 51 | |||
| 52 | $sessionId = $session->getId(); |
||
| 53 | $courses = []; |
||
| 54 | $sessionCourses = $session->getCourses(); |
||
| 55 | |||
| 56 | /** @var EntityRepository $fieldsRepo */ |
||
| 57 | $fieldsRepo = $em->getRepository(ExtraField::class); |
||
| 58 | |||
| 59 | /** @var TagRepository $tagRepo */ |
||
| 60 | $tagRepo = $em->getRepository(Tag::class); |
||
| 61 | |||
| 62 | /** @var SequenceRepository $sequenceResourceRepo */ |
||
| 63 | $sequenceResourceRepo = $em->getRepository(SequenceResource::class); |
||
| 64 | |||
| 65 | /** @var ExtraField $tagField */ |
||
| 66 | $tagField = $fieldsRepo->findOneBy([ |
||
| 67 | 'itemType' => ExtraField::COURSE_FIELD_TYPE, |
||
| 68 | 'variable' => 'tags', |
||
| 69 | ]); |
||
| 70 | |||
| 71 | $courseValues = new ExtraFieldValue('course'); |
||
| 72 | $userValues = new ExtraFieldValue('user'); |
||
| 73 | $sessionValues = new ExtraFieldValue('session'); |
||
| 74 | |||
| 75 | /** @var SessionRelCourse $sessionRelCourse */ |
||
| 76 | foreach ($sessionCourses as $sessionRelCourse) { |
||
| 77 | $sessionCourse = $sessionRelCourse->getCourse(); |
||
| 78 | $courseTags = []; |
||
| 79 | |||
| 80 | if (null !== $tagField) { |
||
| 81 | $courseTags = $tagRepo->getTagsByItem($tagField, $sessionCourse->getId()); |
||
| 82 | } |
||
| 83 | |||
| 84 | $courseCoaches = $userRepo->getCoachesForSessionCourse($session, $sessionCourse); |
||
| 85 | $coachesData = []; |
||
| 86 | |||
| 87 | /** @var User $courseCoach */ |
||
| 88 | foreach ($courseCoaches as $courseCoach) { |
||
| 89 | $coachData = [ |
||
| 90 | 'complete_name' => UserManager::formatUserFullName($courseCoach), |
||
| 91 | 'image' => $illustrationRepo->getIllustrationUrl($courseCoach), |
||
| 92 | 'diploma' => $courseCoach->getDiplomas(), |
||
| 93 | 'openarea' => $courseCoach->getOpenarea(), |
||
| 94 | 'extra_fields' => $userValues->getAllValuesForAnItem( |
||
| 95 | $courseCoach->getId(), |
||
| 96 | null, |
||
| 97 | true |
||
| 98 | ), |
||
| 99 | ]; |
||
| 100 | |||
| 101 | $coachesData[] = $coachData; |
||
| 102 | } |
||
| 103 | |||
| 104 | $cd = new CourseDescription(); |
||
| 105 | $cd->set_course_id($sessionCourse->getId()); |
||
| 106 | $cd->set_session_id($session->getId()); |
||
| 107 | $descriptionsData = $cd->get_description_data(); |
||
| 108 | |||
| 109 | $courseDescription = []; |
||
| 110 | $courseObjectives = []; |
||
| 111 | $courseTopics = []; |
||
| 112 | $courseMethodology = []; |
||
| 113 | $courseMaterial = []; |
||
| 114 | $courseResources = []; |
||
| 115 | $courseAssessment = []; |
||
| 116 | $courseCustom = []; |
||
| 117 | |||
| 118 | if (!empty($descriptionsData)) { |
||
| 119 | foreach ($descriptionsData as $descriptionInfo) { |
||
| 120 | $type = $descriptionInfo->getDescriptionType(); |
||
| 121 | |||
| 122 | switch ($type) { |
||
| 123 | case CCourseDescription::TYPE_DESCRIPTION: |
||
| 124 | $courseDescription[] = $descriptionInfo; |
||
| 125 | |||
| 126 | break; |
||
| 127 | |||
| 128 | case CCourseDescription::TYPE_OBJECTIVES: |
||
| 129 | $courseObjectives[] = $descriptionInfo; |
||
| 130 | |||
| 131 | break; |
||
| 132 | |||
| 133 | case CCourseDescription::TYPE_TOPICS: |
||
| 134 | $courseTopics[] = $descriptionInfo; |
||
| 135 | |||
| 136 | break; |
||
| 137 | |||
| 138 | case CCourseDescription::TYPE_METHODOLOGY: |
||
| 139 | $courseMethodology[] = $descriptionInfo; |
||
| 140 | |||
| 141 | break; |
||
| 142 | |||
| 143 | case CCourseDescription::TYPE_COURSE_MATERIAL: |
||
| 144 | $courseMaterial[] = $descriptionInfo; |
||
| 145 | |||
| 146 | break; |
||
| 147 | |||
| 148 | case CCourseDescription::TYPE_RESOURCES: |
||
| 149 | $courseResources[] = $descriptionInfo; |
||
| 150 | |||
| 151 | break; |
||
| 152 | |||
| 153 | case CCourseDescription::TYPE_ASSESSMENT: |
||
| 154 | $courseAssessment[] = $descriptionInfo; |
||
| 155 | |||
| 156 | break; |
||
| 157 | |||
| 158 | case CCourseDescription::TYPE_CUSTOM: |
||
| 159 | $courseCustom[] = $descriptionInfo; |
||
| 160 | |||
| 161 | break; |
||
| 162 | } |
||
| 163 | } |
||
| 164 | } |
||
| 165 | |||
| 166 | $courses[] = [ |
||
| 167 | 'course' => $sessionCourse, |
||
| 168 | 'description' => $courseDescription, |
||
| 169 | 'image' => Container::getIllustrationRepository()->getIllustrationUrl($sessionCourse), |
||
| 170 | 'tags' => $courseTags, |
||
| 171 | 'objectives' => $courseObjectives, |
||
| 172 | 'topics' => $courseTopics, |
||
| 173 | 'methodology' => $courseMethodology, |
||
| 174 | 'material' => $courseMaterial, |
||
| 175 | 'resources' => $courseResources, |
||
| 176 | 'assessment' => $courseAssessment, |
||
| 177 | 'custom' => array_reverse($courseCustom), |
||
| 178 | 'coaches' => $coachesData, |
||
| 179 | 'extra_fields' => $courseValues->getAllValuesForAnItem( |
||
| 180 | $sessionCourse->getId(), |
||
| 181 | null, |
||
| 182 | true |
||
| 183 | ), |
||
| 184 | ]; |
||
| 185 | } |
||
| 186 | |||
| 187 | $sessionDates = SessionManager::parseSessionDates($session, true); |
||
| 188 | |||
| 189 | $hasRequirements = false; |
||
| 190 | /*$sessionRequirements = $sequenceResourceRepo->getRequirements( |
||
| 191 | $session->getId(), |
||
| 192 | SequenceResource::SESSION_TYPE |
||
| 193 | ); |
||
| 194 | |||
| 195 | foreach ($sessionRequirements as $sequence) { |
||
| 196 | if (!empty($sequence['requirements'])) { |
||
| 197 | $hasRequirements = true; |
||
| 198 | |||
| 199 | break; |
||
| 200 | } |
||
| 201 | }*/ |
||
| 202 | |||
| 203 | $plugin = BuyCoursesPlugin::create(); |
||
| 204 | $checker = $plugin->isEnabled(); |
||
| 205 | $sessionIsPremium = null; |
||
| 206 | if ($checker) { |
||
| 207 | $sessionIsPremium = $plugin->getItemByProduct( |
||
| 208 | $sessionId, |
||
| 209 | BuyCoursesPlugin::PRODUCT_TYPE_SESSION |
||
| 210 | ); |
||
| 211 | if ([] !== $sessionIsPremium) { |
||
| 212 | $requestSession->set('SessionIsPremium', true); |
||
| 213 | $requestSession->set('sessionId', $sessionId); |
||
| 214 | } |
||
| 215 | } |
||
| 216 | |||
| 217 | $redirectToSession = ('true' === Container::getSettingsManager()->getSetting('session.allow_redirect_to_session_after_inscription_about')); |
||
| 218 | $redirectToSession = $redirectToSession ? '?s='.$sessionId : false; |
||
| 219 | |||
| 220 | $coursesInThisSession = SessionManager::get_course_list_by_session_id($sessionId); |
||
| 221 | $coursesCount = \count($coursesInThisSession); |
||
| 222 | $redirectToSession = 1 === $coursesCount && $redirectToSession |
||
| 223 | ? ($redirectToSession.'&cr='.array_values($coursesInThisSession)[0]['directory']) |
||
| 224 | : $redirectToSession; |
||
| 225 | |||
| 226 | $essence = new Essence(); |
||
| 227 | |||
| 228 | $params = [ |
||
| 229 | 'session' => $session, |
||
| 230 | 'redirect_to_session' => $redirectToSession, |
||
| 231 | 'courses' => $courses, |
||
| 232 | 'essence' => $essence, |
||
| 233 | 'session_extra_fields' => $sessionValues->getAllValuesForAnItem($session->getId(), null, true), |
||
| 234 | 'has_requirements' => $hasRequirements, |
||
| 235 | // 'sequences' => $sessionRequirements, |
||
| 236 | 'is_premium' => $sessionIsPremium, |
||
| 237 | 'show_tutor' => 'true' === api_get_setting('show_session_coach'), |
||
| 238 | 'page_url' => api_get_path(WEB_PATH).sprintf('sessions/%s/about/', $session->getId()), |
||
| 239 | 'session_date' => $sessionDates, |
||
| 240 | 'is_subscribed' => SessionManager::isUserSubscribedAsStudent( |
||
| 241 | $session->getId(), |
||
| 242 | api_get_user_id() |
||
| 243 | ), |
||
| 244 | /*'subscribe_button' => \CoursesAndSessionsCatalog::getRegisteredInSessionButton( |
||
| 245 | $session->getId(), |
||
| 246 | $session->getName(), |
||
| 247 | $hasRequirements, |
||
| 248 | true, |
||
| 249 | true |
||
| 250 | ),*/ |
||
| 251 | 'user_session_time' => SessionManager::getDayLeftInSession( |
||
| 252 | [ |
||
| 253 | 'id' => $session->getId(), |
||
| 254 | 'duration' => $session->getDuration(), |
||
| 255 | ], |
||
| 256 | api_get_user_id() |
||
| 257 | ), |
||
| 258 | ]; |
||
| 259 | |||
| 260 | return $this->render('@ChamiloCore/Session/about.html.twig', $params); |
||
| 261 | } |
||
| 263 |