about.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Entity\Course;
  4. use Chamilo\CoreBundle\Entity\CourseRelUser;
  5. use Chamilo\CoreBundle\Entity\ExtraField;
  6. use Chamilo\CourseBundle\Entity\CCourseDescription;
  7. /**
  8. * Course about page
  9. * Show information about a course.
  10. *
  11. * @author Alex Aragon Calixto <alex.aragon@beeznest.com>
  12. *
  13. * @package chamilo.course
  14. */
  15. $cidReset = true;
  16. require_once __DIR__.'/../inc/global.inc.php';
  17. $courseId = isset($_GET['course_id']) ? (int) $_GET['course_id'] : 0;
  18. if (empty($courseId)) {
  19. api_not_allowed(true);
  20. }
  21. $token = Security::get_existing_token();
  22. $em = Database::getManager();
  23. //userID
  24. $userId = api_get_user_id();
  25. /** @var Course $course */
  26. $course = $em->find('ChamiloCoreBundle:Course', $courseId);
  27. if (!$course) {
  28. api_not_allowed(true);
  29. }
  30. $userRepo = UserManager::getRepository();
  31. $fieldsRepo = $em->getRepository('ChamiloCoreBundle:ExtraField');
  32. $fieldTagsRepo = $em->getRepository('ChamiloCoreBundle:ExtraFieldRelTag');
  33. /** @var CCourseDescription $courseDescription */
  34. $courseDescriptionTools = $em->getRepository('ChamiloCourseBundle:CCourseDescription')
  35. ->findBy(
  36. [
  37. 'cId' => $course->getId(),
  38. 'sessionId' => 0,
  39. ],
  40. [
  41. 'id' => 'DESC',
  42. 'descriptionType' => 'ASC',
  43. ]
  44. );
  45. $courseValues = new ExtraFieldValue('course');
  46. $userValues = new ExtraFieldValue('user');
  47. $urlCourse = api_get_path(WEB_PATH)."course/$courseId/about";
  48. $courseTeachers = $course->getTeachers();
  49. $teachersData = [];
  50. /** @var CourseRelUser $teacherSubscription */
  51. foreach ($courseTeachers as $teacherSubscription) {
  52. $teacher = $teacherSubscription->getUser();
  53. $userData = [
  54. 'complete_name' => $teacher->getCompleteName(),
  55. 'image' => UserManager::getUserPicture(
  56. $teacher->getId(),
  57. USER_IMAGE_SIZE_ORIGINAL
  58. ),
  59. 'diploma' => $teacher->getDiplomas(),
  60. 'openarea' => $teacher->getOpenarea(),
  61. ];
  62. $teachersData[] = $userData;
  63. }
  64. $tagField = $fieldsRepo->findOneBy([
  65. 'extraFieldType' => ExtraField::COURSE_FIELD_TYPE,
  66. 'variable' => 'tags',
  67. ]);
  68. $courseTags = [];
  69. if (!is_null($tagField)) {
  70. $courseTags = $fieldTagsRepo->getTags($tagField, $courseId);
  71. }
  72. $courseDescription = $courseObjectives = $courseTopics = $courseMethodology = $courseMaterial = $courseResources = $courseAssessment = '';
  73. $courseCustom = [];
  74. foreach ($courseDescriptionTools as $descriptionTool) {
  75. switch ($descriptionTool->getDescriptionType()) {
  76. case CCourseDescription::TYPE_DESCRIPTION:
  77. $courseDescription = $descriptionTool->getContent();
  78. break;
  79. case CCourseDescription::TYPE_OBJECTIVES:
  80. $courseObjectives = $descriptionTool;
  81. break;
  82. case CCourseDescription::TYPE_TOPICS:
  83. $courseTopics = $descriptionTool;
  84. break;
  85. case CCourseDescription::TYPE_METHODOLOGY:
  86. $courseMethodology = $descriptionTool;
  87. break;
  88. case CCourseDescription::TYPE_COURSE_MATERIAL:
  89. $courseMaterial = $descriptionTool;
  90. break;
  91. case CCourseDescription::TYPE_RESOURCES:
  92. $courseResources = $descriptionTool;
  93. break;
  94. case CCourseDescription::TYPE_ASSESSMENT:
  95. $courseAssessment = $descriptionTool;
  96. break;
  97. case CCourseDescription::TYPE_CUSTOM:
  98. $courseCustom[] = $descriptionTool;
  99. break;
  100. }
  101. }
  102. $topics = [
  103. 'objectives' => $courseObjectives,
  104. 'topics' => $courseTopics,
  105. 'methodology' => $courseMethodology,
  106. 'material' => $courseMaterial,
  107. 'resources' => $courseResources,
  108. 'assessment' => $courseAssessment,
  109. 'custom' => array_reverse($courseCustom),
  110. ];
  111. $subscriptionUser = CourseManager::is_user_subscribed_in_course($userId, $course->getCode());
  112. $allowSubscribe = false;
  113. if ($course->getSubscribe() || api_is_platform_admin()) {
  114. $allowSubscribe = true;
  115. }
  116. $plugin = BuyCoursesPlugin::create();
  117. $checker = $plugin->isEnabled();
  118. $courseIsPremium = null;
  119. if ($checker) {
  120. $courseIsPremium = $plugin->getItemByProduct(
  121. $courseId,
  122. BuyCoursesPlugin::PRODUCT_TYPE_COURSE
  123. );
  124. }
  125. $courseItem = [
  126. 'code' => $course->getCode(),
  127. 'title' => $course->getTitle(),
  128. 'description' => $courseDescription,
  129. 'image' => CourseManager::getPicturePath($course, true),
  130. 'syllabus' => $topics,
  131. 'tags' => $courseTags,
  132. 'teachers' => $teachersData,
  133. 'extra_fields' => $courseValues->getAllValuesForAnItem(
  134. $course->getId(),
  135. null,
  136. true
  137. ),
  138. 'subscription' => $subscriptionUser,
  139. ];
  140. $metaInfo = '<meta property="og:url" content="'.$urlCourse.'" />';
  141. $metaInfo .= '<meta property="og:type" content="website" />';
  142. $metaInfo .= '<meta property="og:title" content="'.$courseItem['title'].'" />';
  143. $metaInfo .= '<meta property="og:description" content="'.strip_tags($courseDescription).'" />';
  144. $metaInfo .= '<meta property="og:image" content="'.$courseItem['image'].'" />';
  145. $htmlHeadXtra[] = $metaInfo;
  146. $htmlHeadXtra[] = api_get_asset('readmore-js/readmore.js');
  147. $template = new Template($course->getTitle(), true, true, false, true, false);
  148. $template->assign('course', $courseItem);
  149. $essence = Essence\Essence::instance();
  150. $template->assign('essence', $essence);
  151. $template->assign('is_premium', $courseIsPremium);
  152. $template->assign('allow_subscribe', $allowSubscribe);
  153. $template->assign('token', $token);
  154. $template->assign('url', $urlCourse);
  155. $layout = $template->get_template('course_home/about.tpl');
  156. $content = $template->fetch($layout);
  157. $template->assign('content', $content);
  158. $template->display_one_col_template();