| Conditions | 12 |
| Paths | 40 |
| Total Lines | 137 |
| Code Lines | 86 |
| 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 |
||
| 60 | if (null !== $document && $document->getResourceNode()->hasResourceFile()) { |
||
| 61 | return $this->redirectToRoute('chamilo_core_resource_view', [ |
||
| 62 | 'tool' => 'document', |
||
| 63 | 'type' => 'file', |
||
| 64 | 'id' => $document->getResourceNode()->getId(), |
||
| 65 | ]); |
||
| 66 | } |
||
| 67 | |||
| 68 | throw new AccessDeniedException('File not found'); |
||
| 69 | } |
||
| 70 | |||
| 71 | #[Route('/{id}/welcome', name: 'chamilo_core_course_welcome')] |
||
| 72 | public function welcome(Course $course): Response |
||
| 73 | { |
||
| 74 | return $this->render('@ChamiloCore/Course/welcome.html.twig', [ |
||
| 75 | 'course' => $course, |
||
| 76 | ]); |
||
| 77 | } |
||
| 78 | |||
| 79 | #[Route('/{id}/about', name: 'chamilo_core_course_about')] |
||
| 80 | public function about(Course $course, IllustrationRepository $illustrationRepository, CCourseDescriptionRepository $courseDescriptionRepository): Response |
||
| 81 | { |
||
| 82 | $courseId = $course->getId(); |
||
| 83 | $userId = $this->getUser()->getId(); |
||
| 84 | $em = $this->getDoctrine()->getManager(); |
||
| 85 | |||
| 86 | /** @var EntityRepository $fieldsRepo */ |
||
| 87 | $fieldsRepo = $em->getRepository(ExtraField::class); |
||
| 88 | /** @var ExtraFieldRelTagRepository $fieldTagsRepo */ |
||
| 89 | $fieldTagsRepo = $em->getRepository(ExtraFieldRelTag::class); |
||
| 90 | |||
| 91 | $courseDescriptions = $courseDescriptionRepository->getResourcesByCourse($course)->getQuery()->getResult(); |
||
| 92 | |||
| 93 | $courseValues = new ExtraFieldValue('course'); |
||
| 94 | |||
| 95 | $urlCourse = api_get_path(WEB_PATH).sprintf('course/%s/about', $courseId); |
||
| 96 | $courseTeachers = $course->getTeachers(); |
||
| 97 | $teachersData = []; |
||
| 98 | |||
| 99 | foreach ($courseTeachers as $teacherSubscription) { |
||
| 100 | $teacher = $teacherSubscription->getUser(); |
||
| 101 | $userData = [ |
||
| 102 | 'complete_name' => UserManager::formatUserFullName($teacher), |
||
| 103 | 'image' => $illustrationRepository->getIllustrationUrl($teacher), |
||
| 104 | 'diploma' => $teacher->getDiplomas(), |
||
| 105 | 'openarea' => $teacher->getOpenarea(), |
||
| 106 | ]; |
||
| 107 | |||
| 108 | $teachersData[] = $userData; |
||
| 109 | } |
||
| 110 | /** @var ExtraField $tagField */ |
||
| 111 | $tagField = $fieldsRepo->findOneBy([ |
||
| 112 | 'extraFieldType' => ExtraField::COURSE_FIELD_TYPE, |
||
| 113 | 'variable' => 'tags', |
||
| 114 | ]); |
||
| 115 | |||
| 116 | $courseTags = []; |
||
| 117 | if (null !== $tagField) { |
||
| 118 | $courseTags = $fieldTagsRepo->getTags($tagField, $courseId); |
||
| 119 | } |
||
| 120 | |||
| 121 | $courseDescription = $courseObjectives = $courseTopics = $courseMethodology = ''; |
||
| 122 | $courseMaterial = $courseResources = $courseAssessment = ''; |
||
| 123 | $courseCustom = []; |
||
| 124 | foreach ($courseDescriptions as $descriptionTool) { |
||
| 125 | switch ($descriptionTool->getDescriptionType()) { |
||
| 126 | case CCourseDescription::TYPE_DESCRIPTION: |
||
| 127 | $courseDescription = $descriptionTool->getContent(); |
||
| 128 | |||
| 129 | break; |
||
| 130 | case CCourseDescription::TYPE_OBJECTIVES: |
||
| 131 | $courseObjectives = $descriptionTool; |
||
| 132 | |||
| 133 | break; |
||
| 134 | case CCourseDescription::TYPE_TOPICS: |
||
| 135 | $courseTopics = $descriptionTool; |
||
| 136 | |||
| 137 | break; |
||
| 138 | case CCourseDescription::TYPE_METHODOLOGY: |
||
| 139 | $courseMethodology = $descriptionTool; |
||
| 140 | |||
| 141 | break; |
||
| 142 | case CCourseDescription::TYPE_COURSE_MATERIAL: |
||
| 143 | $courseMaterial = $descriptionTool; |
||
| 144 | |||
| 145 | break; |
||
| 146 | case CCourseDescription::TYPE_RESOURCES: |
||
| 147 | $courseResources = $descriptionTool; |
||
| 148 | |||
| 149 | break; |
||
| 150 | case CCourseDescription::TYPE_ASSESSMENT: |
||
| 151 | $courseAssessment = $descriptionTool; |
||
| 152 | |||
| 153 | break; |
||
| 154 | case CCourseDescription::TYPE_CUSTOM: |
||
| 155 | $courseCustom[] = $descriptionTool; |
||
| 156 | |||
| 157 | break; |
||
| 158 | } |
||
| 159 | } |
||
| 160 | |||
| 161 | $topics = [ |
||
| 162 | 'objectives' => $courseObjectives, |
||
| 163 | 'topics' => $courseTopics, |
||
| 164 | 'methodology' => $courseMethodology, |
||
| 165 | 'material' => $courseMaterial, |
||
| 166 | 'resources' => $courseResources, |
||
| 167 | 'assessment' => $courseAssessment, |
||
| 168 | 'custom' => array_reverse($courseCustom), |
||
| 169 | ]; |
||
| 170 | |||
| 171 | $subscriptionUser = CourseManager::is_user_subscribed_in_course($userId, $course->getCode()); |
||
| 172 | |||
| 173 | /*$allowSubscribe = false; |
||
| 174 | if ($course->getSubscribe() || api_is_platform_admin()) { |
||
| 175 | $allowSubscribe = true; |
||
| 176 | } |
||
| 177 | $plugin = \BuyCoursesPlugin::create(); |
||
| 178 | $checker = $plugin->isEnabled(); |
||
| 179 | $courseIsPremium = null; |
||
| 180 | if ($checker) { |
||
| 181 | $courseIsPremium = $plugin->getItemByProduct( |
||
| 182 | $courseId, |
||
| 183 | \BuyCoursesPlugin::PRODUCT_TYPE_COURSE |
||
| 184 | ); |
||
| 185 | }*/ |
||
| 186 | |||
| 187 | $image = Container::getIllustrationRepository()->getIllustrationUrl($course, 'course_picture_medium'); |
||
| 188 | |||
| 189 | $params = [ |
||
| 190 | 'course' => $course, |
||
| 191 | 'description' => $courseDescription, |
||
| 192 | 'image' => $image, |
||
| 193 | 'syllabus' => $topics, |
||
| 194 | 'tags' => $courseTags, |
||
| 195 | 'teachers' => $teachersData, |
||
| 196 | 'extra_fields' => $courseValues->getAllValuesForAnItem( |
||
| 197 | $course->getId(), |
||
| 219 |