chamilo /
chamilo-lms
| 1 | <?php |
||
| 2 | |||
| 3 | /* For licensing terms, see /license.txt */ |
||
| 4 | |||
| 5 | use Chamilo\CoreBundle\Entity\CourseRelUser; |
||
| 6 | use Chamilo\CoreBundle\Entity\ExtraField; |
||
|
0 ignored issues
–
show
|
|||
| 7 | use Chamilo\CoreBundle\Entity\Repository\SequenceResourceRepository; |
||
| 8 | use Chamilo\CoreBundle\Entity\SequenceResource; |
||
| 9 | use Chamilo\CourseBundle\Entity\CCourseDescription; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * Course about page |
||
| 13 | * Show information about a course. |
||
| 14 | * |
||
| 15 | * @author Alex Aragon Calixto <[email protected]> |
||
| 16 | */ |
||
| 17 | $cidReset = true; |
||
| 18 | |||
| 19 | require_once __DIR__.'/../inc/global.inc.php'; |
||
| 20 | |||
| 21 | if ((api_get_setting('course_catalog_published') != 'true' && api_is_anonymous()) || api_get_configuration_value('course_about_block_all_access') == 'true') { |
||
| 22 | api_not_allowed(true); |
||
| 23 | } |
||
| 24 | |||
| 25 | $courseId = isset($_GET['course_id']) ? (int) $_GET['course_id'] : 0; |
||
| 26 | |||
| 27 | if (empty($courseId)) { |
||
| 28 | api_not_allowed(true); |
||
| 29 | } |
||
| 30 | |||
| 31 | $token = Security::get_existing_token(); |
||
| 32 | $em = Database::getManager(); |
||
| 33 | |||
| 34 | $userId = api_get_user_id(); |
||
| 35 | $course = api_get_course_entity($courseId); |
||
| 36 | |||
| 37 | if (!$course) { |
||
|
0 ignored issues
–
show
|
|||
| 38 | api_not_allowed(true); |
||
| 39 | } |
||
| 40 | |||
| 41 | $userRepo = UserManager::getRepository(); |
||
| 42 | $fieldsRepo = $em->getRepository('ChamiloCoreBundle:ExtraField'); |
||
| 43 | $fieldTagsRepo = $em->getRepository('ChamiloCoreBundle:ExtraFieldRelTag'); |
||
| 44 | |||
| 45 | /** @var CCourseDescription $courseDescription */ |
||
| 46 | $courseDescriptionTools = $em->getRepository('ChamiloCourseBundle:CCourseDescription') |
||
| 47 | ->findBy( |
||
| 48 | [ |
||
| 49 | 'cId' => $course->getId(), |
||
| 50 | 'sessionId' => 0, |
||
| 51 | ], |
||
| 52 | [ |
||
| 53 | 'id' => 'DESC', |
||
| 54 | 'descriptionType' => 'ASC', |
||
| 55 | ] |
||
| 56 | ); |
||
| 57 | |||
| 58 | $courseValues = new ExtraFieldValue('course'); |
||
| 59 | $userValues = new ExtraFieldValue('user'); |
||
| 60 | |||
| 61 | $urlCourse = api_get_path(WEB_PATH)."course/$courseId/about"; |
||
| 62 | $courseTeachers = $course->getTeachers(); |
||
| 63 | $teachersData = []; |
||
| 64 | |||
| 65 | /** @var CourseRelUser $teacherSubscription */ |
||
| 66 | foreach ($courseTeachers as $teacherSubscription) { |
||
| 67 | $teacher = $teacherSubscription->getUser(); |
||
| 68 | $userData = [ |
||
| 69 | 'complete_name' => UserManager::formatUserFullName($teacher), |
||
| 70 | 'image' => UserManager::getUserPicture( |
||
| 71 | $teacher->getId(), |
||
| 72 | USER_IMAGE_SIZE_ORIGINAL |
||
| 73 | ), |
||
| 74 | 'diploma' => $teacher->getDiplomas(), |
||
| 75 | 'openarea' => $teacher->getOpenarea(), |
||
| 76 | ]; |
||
| 77 | |||
| 78 | $teachersData[] = $userData; |
||
| 79 | } |
||
| 80 | |||
| 81 | $tagField = $fieldsRepo->findOneBy([ |
||
| 82 | 'extraFieldType' => ExtraField::COURSE_FIELD_TYPE, |
||
| 83 | 'variable' => 'tags', |
||
| 84 | ]); |
||
| 85 | |||
| 86 | $courseTags = []; |
||
| 87 | |||
| 88 | if (!is_null($tagField)) { |
||
| 89 | $courseTags = $fieldTagsRepo->getTags($tagField, $courseId); |
||
| 90 | } |
||
| 91 | |||
| 92 | $courseDescription = $courseObjectives = $courseTopics = $courseMethodology = $courseMaterial = $courseResources = $courseAssessment = ''; |
||
| 93 | $courseCustom = []; |
||
| 94 | foreach ($courseDescriptionTools as $descriptionTool) { |
||
| 95 | switch ($descriptionTool->getDescriptionType()) { |
||
| 96 | case CCourseDescription::TYPE_DESCRIPTION: |
||
| 97 | $courseDescription = Security::remove_XSS($descriptionTool->getContent()); |
||
| 98 | break; |
||
| 99 | case CCourseDescription::TYPE_OBJECTIVES: |
||
| 100 | $courseObjectives = $descriptionTool; |
||
| 101 | break; |
||
| 102 | case CCourseDescription::TYPE_TOPICS: |
||
| 103 | $courseTopics = $descriptionTool; |
||
| 104 | break; |
||
| 105 | case CCourseDescription::TYPE_METHODOLOGY: |
||
| 106 | $courseMethodology = $descriptionTool; |
||
| 107 | break; |
||
| 108 | case CCourseDescription::TYPE_COURSE_MATERIAL: |
||
| 109 | $courseMaterial = $descriptionTool; |
||
| 110 | break; |
||
| 111 | case CCourseDescription::TYPE_RESOURCES: |
||
| 112 | $courseResources = $descriptionTool; |
||
| 113 | break; |
||
| 114 | case CCourseDescription::TYPE_ASSESSMENT: |
||
| 115 | $courseAssessment = $descriptionTool; |
||
| 116 | break; |
||
| 117 | case CCourseDescription::TYPE_CUSTOM: |
||
| 118 | $courseCustom[] = $descriptionTool; |
||
| 119 | break; |
||
| 120 | } |
||
| 121 | } |
||
| 122 | |||
| 123 | $topics = [ |
||
| 124 | 'objectives' => $courseObjectives, |
||
| 125 | 'topics' => $courseTopics, |
||
| 126 | 'methodology' => $courseMethodology, |
||
| 127 | 'material' => $courseMaterial, |
||
| 128 | 'resources' => $courseResources, |
||
| 129 | 'assessment' => $courseAssessment, |
||
| 130 | 'custom' => array_reverse($courseCustom), |
||
| 131 | ]; |
||
| 132 | |||
| 133 | $subscriptionUser = CourseManager::is_user_subscribed_in_course($userId, $course->getCode()); |
||
| 134 | |||
| 135 | $allowSubscribe = false; |
||
| 136 | if ($course->getSubscribe() || api_is_platform_admin()) { |
||
| 137 | $allowSubscribe = true; |
||
| 138 | } |
||
| 139 | $plugin = BuyCoursesPlugin::create(); |
||
| 140 | $checker = $plugin->isEnabled(); |
||
| 141 | $courseIsPremium = null; |
||
| 142 | if ($checker) { |
||
| 143 | $courseIsPremium = $plugin->getItemByProduct( |
||
| 144 | $courseId, |
||
| 145 | BuyCoursesPlugin::PRODUCT_TYPE_COURSE |
||
| 146 | ); |
||
| 147 | } |
||
| 148 | |||
| 149 | $courseItem = [ |
||
| 150 | 'code' => $course->getCode(), |
||
| 151 | 'visibility' => $course->getVisibility(), |
||
| 152 | 'title' => $course->getTitle(), |
||
| 153 | 'description' => $courseDescription, |
||
| 154 | 'image' => CourseManager::getPicturePath($course, true), |
||
| 155 | 'syllabus' => $topics, |
||
| 156 | 'tags' => $courseTags, |
||
| 157 | 'teachers' => $teachersData, |
||
| 158 | 'extra_fields' => $courseValues->getAllValuesForAnItem( |
||
| 159 | $course->getId(), |
||
| 160 | null, |
||
| 161 | true |
||
| 162 | ), |
||
| 163 | 'subscription' => $subscriptionUser, |
||
| 164 | ]; |
||
| 165 | |||
| 166 | $metaInfo = '<meta property="og:url" content="'.$urlCourse.'" />'; |
||
| 167 | $metaInfo .= '<meta property="og:type" content="website" />'; |
||
| 168 | $metaInfo .= '<meta property="og:title" content="'.$courseItem['title'].'" />'; |
||
| 169 | $metaInfo .= '<meta property="og:description" content="'.strip_tags($courseDescription).'" />'; |
||
| 170 | $metaInfo .= '<meta property="og:image" content="'.$courseItem['image'].'" />'; |
||
| 171 | |||
| 172 | $htmlHeadXtra[] = $metaInfo; |
||
| 173 | $htmlHeadXtra[] = api_get_asset('readmore-js/readmore.js'); |
||
| 174 | |||
| 175 | /** @var SequenceResourceRepository $sequenceResourceRepo */ |
||
| 176 | $sequenceResourceRepo = $em->getRepository('ChamiloCoreBundle:SequenceResource'); |
||
| 177 | $requirements = $sequenceResourceRepo->getRequirements( |
||
| 178 | $course->getId(), |
||
| 179 | SequenceResource::COURSE_TYPE |
||
| 180 | ); |
||
| 181 | |||
| 182 | $hasRequirements = false; |
||
| 183 | foreach ($requirements as $sequence) { |
||
| 184 | if (!empty($sequence['requirements'])) { |
||
| 185 | $hasRequirements = true; |
||
| 186 | break; |
||
| 187 | } |
||
| 188 | } |
||
| 189 | |||
| 190 | if ($hasRequirements) { |
||
| 191 | $sequenceList = $sequenceResourceRepo->checkRequirementsForUser($requirements, SequenceResource::COURSE_TYPE, $userId); |
||
| 192 | $allowSubscribe = $sequenceResourceRepo->checkSequenceAreCompleted($sequenceList); |
||
| 193 | } |
||
| 194 | |||
| 195 | $template = new Template($course->getTitle(), true, true, false, true, false); |
||
| 196 | |||
| 197 | $template->assign('course', $courseItem); |
||
| 198 | $essence = Essence\Essence::instance(); |
||
| 199 | $template->assign('essence', $essence); |
||
| 200 | $template->assign('is_premium', $courseIsPremium); |
||
| 201 | $template->assign('allow_subscribe', $allowSubscribe); |
||
| 202 | $template->assign('token', $token); |
||
| 203 | $template->assign('url', $urlCourse); |
||
| 204 | $template->assign( |
||
| 205 | 'subscribe_button', |
||
| 206 | CoursesAndSessionsCatalog::getRequirements( |
||
| 207 | $course->getId(), |
||
| 208 | SequenceResource::COURSE_TYPE, |
||
| 209 | true, |
||
| 210 | true |
||
| 211 | ) |
||
| 212 | ); |
||
| 213 | $template->assign('has_requirements', $hasRequirements); |
||
| 214 | $template->assign('sequences', $requirements); |
||
| 215 | |||
| 216 | $layout = $template->get_template('course_home/about.tpl'); |
||
| 217 | $content = $template->fetch($layout); |
||
| 218 | $template->assign('content', $content); |
||
| 219 | $template->display_one_col_template(); |
||
| 220 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: