| Conditions | 12 |
| Paths | 40 |
| Total Lines | 146 |
| Code Lines | 89 |
| 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 |
||
| 51 | public function aboutAction(Course $course): Response |
||
| 52 | { |
||
| 53 | $courseId = $course->getId(); |
||
| 54 | $userId = $this->getUser()->getId(); |
||
| 55 | |||
| 56 | $em = $this->getDoctrine()->getManager(); |
||
| 57 | |||
| 58 | $fieldsRepo = $em->getRepository('ChamiloCoreBundle:ExtraField'); |
||
| 59 | $fieldTagsRepo = $em->getRepository('ChamiloCoreBundle:ExtraFieldRelTag'); |
||
| 60 | |||
| 61 | /** @var CCourseDescription $courseDescription */ |
||
| 62 | $courseDescriptionTools = $em->getRepository('ChamiloCourseBundle:CCourseDescription') |
||
| 63 | ->findBy( |
||
| 64 | [ |
||
| 65 | 'cId' => $course->getId(), |
||
| 66 | 'sessionId' => 0, |
||
| 67 | ], |
||
| 68 | [ |
||
| 69 | 'id' => 'DESC', |
||
| 70 | 'descriptionType' => 'ASC', |
||
| 71 | ] |
||
| 72 | ); |
||
| 73 | |||
| 74 | $courseValues = new \ExtraFieldValue('course'); |
||
| 75 | |||
| 76 | $urlCourse = api_get_path(WEB_PATH)."course/$courseId/about"; |
||
| 77 | $courseTeachers = $course->getTeachers(); |
||
| 78 | $teachersData = []; |
||
| 79 | |||
| 80 | foreach ($courseTeachers as $teacherSubscription) { |
||
| 81 | $teacher = $teacherSubscription->getUser(); |
||
| 82 | $userData = [ |
||
| 83 | 'complete_name' => UserManager::formatUserFullName($teacher), |
||
| 84 | 'image' => UserManager::getUserPicture( |
||
| 85 | $teacher->getId(), |
||
| 86 | USER_IMAGE_SIZE_ORIGINAL |
||
| 87 | ), |
||
| 88 | 'diploma' => $teacher->getDiplomas(), |
||
| 89 | 'openarea' => $teacher->getOpenarea(), |
||
| 90 | ]; |
||
| 91 | |||
| 92 | $teachersData[] = $userData; |
||
| 93 | } |
||
| 94 | |||
| 95 | $tagField = $fieldsRepo->findOneBy([ |
||
| 96 | 'extraFieldType' => ExtraField::COURSE_FIELD_TYPE, |
||
| 97 | 'variable' => 'tags', |
||
| 98 | ]); |
||
| 99 | |||
| 100 | $courseTags = []; |
||
| 101 | |||
| 102 | if (!is_null($tagField)) { |
||
| 103 | $courseTags = $fieldTagsRepo->getTags($tagField, $courseId); |
||
| 104 | } |
||
| 105 | |||
| 106 | $courseDescription = $courseObjectives = $courseTopics = $courseMethodology = $courseMaterial = $courseResources = $courseAssessment = ''; |
||
| 107 | $courseCustom = []; |
||
| 108 | foreach ($courseDescriptionTools as $descriptionTool) { |
||
| 109 | switch ($descriptionTool->getDescriptionType()) { |
||
| 110 | case CCourseDescription::TYPE_DESCRIPTION: |
||
| 111 | $courseDescription = $descriptionTool->getContent(); |
||
| 112 | |||
| 113 | break; |
||
| 114 | case CCourseDescription::TYPE_OBJECTIVES: |
||
| 115 | $courseObjectives = $descriptionTool; |
||
| 116 | |||
| 117 | break; |
||
| 118 | case CCourseDescription::TYPE_TOPICS: |
||
| 119 | $courseTopics = $descriptionTool; |
||
| 120 | |||
| 121 | break; |
||
| 122 | case CCourseDescription::TYPE_METHODOLOGY: |
||
| 123 | $courseMethodology = $descriptionTool; |
||
| 124 | |||
| 125 | break; |
||
| 126 | case CCourseDescription::TYPE_COURSE_MATERIAL: |
||
| 127 | $courseMaterial = $descriptionTool; |
||
| 128 | |||
| 129 | break; |
||
| 130 | case CCourseDescription::TYPE_RESOURCES: |
||
| 131 | $courseResources = $descriptionTool; |
||
| 132 | |||
| 133 | break; |
||
| 134 | case CCourseDescription::TYPE_ASSESSMENT: |
||
| 135 | $courseAssessment = $descriptionTool; |
||
| 136 | |||
| 137 | break; |
||
| 138 | case CCourseDescription::TYPE_CUSTOM: |
||
| 139 | $courseCustom[] = $descriptionTool; |
||
| 140 | |||
| 141 | break; |
||
| 142 | } |
||
| 143 | } |
||
| 144 | |||
| 145 | $topics = [ |
||
| 146 | 'objectives' => $courseObjectives, |
||
| 147 | 'topics' => $courseTopics, |
||
| 148 | 'methodology' => $courseMethodology, |
||
| 149 | 'material' => $courseMaterial, |
||
| 150 | 'resources' => $courseResources, |
||
| 151 | 'assessment' => $courseAssessment, |
||
| 152 | 'custom' => array_reverse($courseCustom), |
||
| 153 | ]; |
||
| 154 | |||
| 155 | $subscriptionUser = \CourseManager::is_user_subscribed_in_course($userId, $course->getCode()); |
||
| 156 | |||
| 157 | /*$allowSubscribe = false; |
||
| 158 | if ($course->getSubscribe() || api_is_platform_admin()) { |
||
| 159 | $allowSubscribe = true; |
||
| 160 | } |
||
| 161 | $plugin = \BuyCoursesPlugin::create(); |
||
| 162 | $checker = $plugin->isEnabled(); |
||
| 163 | $courseIsPremium = null; |
||
| 164 | if ($checker) { |
||
| 165 | $courseIsPremium = $plugin->getItemByProduct( |
||
| 166 | $courseId, |
||
| 167 | \BuyCoursesPlugin::PRODUCT_TYPE_COURSE |
||
| 168 | ); |
||
| 169 | }*/ |
||
| 170 | |||
| 171 | $image = Container::getIllustrationRepository()->getIllustrationUrl($course, 'course_picture_medium'); |
||
| 172 | $params = [ |
||
| 173 | 'course' => $course, |
||
| 174 | 'description' => $courseDescription, |
||
| 175 | 'image' => $image, |
||
| 176 | 'syllabus' => $topics, |
||
| 177 | 'tags' => $courseTags, |
||
| 178 | 'teachers' => $teachersData, |
||
| 179 | 'extra_fields' => $courseValues->getAllValuesForAnItem( |
||
| 180 | $course->getId(), |
||
| 181 | null, |
||
| 182 | true |
||
| 183 | ), |
||
| 184 | 'subscription' => $subscriptionUser, |
||
| 185 | ]; |
||
| 186 | |||
| 187 | $metaInfo = '<meta property="og:url" content="'.$urlCourse.'" />'; |
||
| 188 | $metaInfo .= '<meta property="og:type" content="website" />'; |
||
| 189 | $metaInfo .= '<meta property="og:title" content="'.$course->getTitle().'" />'; |
||
| 190 | $metaInfo .= '<meta property="og:description" content="'.strip_tags($courseDescription).'" />'; |
||
| 191 | $metaInfo .= '<meta property="og:image" content="'.$image.'" />'; |
||
| 192 | |||
| 193 | $htmlHeadXtra[] = $metaInfo; |
||
|
|
|||
| 194 | $htmlHeadXtra[] = api_get_asset('readmore-js/readmore.js'); |
||
| 195 | |||
| 196 | return $this->render('@ChamiloTheme/Course/about.html.twig', [$params]); |
||
| 197 | } |
||
| 199 |