about.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Entity\Course;
  4. use Chamilo\CoreBundle\Entity\ExtraField;
  5. use Chamilo\CoreBundle\Entity\Repository\SequenceRepository;
  6. use Chamilo\CoreBundle\Entity\SequenceResource;
  7. use Chamilo\CourseBundle\Entity\CCourseDescription;
  8. use Chamilo\UserBundle\Entity\User;
  9. /**
  10. * Session about page
  11. * Show information about a session and its courses.
  12. *
  13. * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
  14. * @author Julio Montoya
  15. *
  16. * @package chamilo.session
  17. */
  18. $cidReset = true;
  19. require_once __DIR__.'/../inc/global.inc.php';
  20. $sessionId = isset($_GET['session_id']) ? (int) $_GET['session_id'] : 0;
  21. $em = Database::getManager();
  22. $session = api_get_session_entity($sessionId);
  23. if (!$session) {
  24. api_not_allowed(true);
  25. }
  26. $htmlHeadXtra[] = api_get_asset('readmore-js/readmore.js');
  27. $courses = [];
  28. $sessionCourses = $em->getRepository('ChamiloCoreBundle:Session')->getCoursesOrderedByPosition($session);
  29. $fieldsRepo = $em->getRepository('ChamiloCoreBundle:ExtraField');
  30. $fieldTagsRepo = $em->getRepository('ChamiloCoreBundle:ExtraFieldRelTag');
  31. $userRepo = UserManager::getRepository();
  32. /** @var SequenceRepository $sequenceResourceRepo */
  33. $sequenceResourceRepo = $em->getRepository('ChamiloCoreBundle:SequenceResource');
  34. $tagField = $fieldsRepo->findOneBy([
  35. 'extraFieldType' => ExtraField::COURSE_FIELD_TYPE,
  36. 'variable' => 'tags',
  37. ]);
  38. $courseValues = new ExtraFieldValue('course');
  39. $userValues = new ExtraFieldValue('user');
  40. $sessionValues = new ExtraFieldValue('session');
  41. /** @var Course $sessionCourse */
  42. foreach ($sessionCourses as $sessionCourse) {
  43. $courseTags = [];
  44. if (!is_null($tagField)) {
  45. $courseTags = $fieldTagsRepo->getTags($tagField, $sessionCourse->getId());
  46. }
  47. $courseCoaches = $userRepo->getCoachesForSessionCourse($session, $sessionCourse);
  48. $coachesData = [];
  49. /** @var User $courseCoach */
  50. foreach ($courseCoaches as $courseCoach) {
  51. $coachData = [
  52. 'complete_name' => UserManager::formatUserFullName($courseCoach),
  53. 'image' => UserManager::getUserPicture(
  54. $courseCoach->getId(),
  55. USER_IMAGE_SIZE_ORIGINAL
  56. ),
  57. 'diploma' => $courseCoach->getDiplomas(),
  58. 'openarea' => $courseCoach->getOpenarea(),
  59. 'extra_fields' => $userValues->getAllValuesForAnItem(
  60. $courseCoach->getId(),
  61. null,
  62. true
  63. ),
  64. ];
  65. $coachesData[] = $coachData;
  66. }
  67. $cd = new CourseDescription();
  68. $cd->set_course_id($sessionCourse->getId());
  69. $cd->set_session_id($session->getId());
  70. $descriptionsData = $cd->get_description_data();
  71. $courseDescription = [];
  72. $courseObjectives = [];
  73. $courseTopics = [];
  74. $courseMethodology = [];
  75. $courseMaterial = [];
  76. $courseResources = [];
  77. $courseAssessment = [];
  78. $courseCustom = [];
  79. if (!empty($descriptionsData['descriptions'])) {
  80. foreach ($descriptionsData['descriptions'] as $descriptionInfo) {
  81. switch ($descriptionInfo['description_type']) {
  82. case CCourseDescription::TYPE_DESCRIPTION:
  83. $courseDescription[] = $descriptionInfo;
  84. break;
  85. case CCourseDescription::TYPE_OBJECTIVES:
  86. $courseObjectives[] = $descriptionInfo;
  87. break;
  88. case CCourseDescription::TYPE_TOPICS:
  89. $courseTopics[] = $descriptionInfo;
  90. break;
  91. case CCourseDescription::TYPE_METHODOLOGY:
  92. $courseMethodology[] = $descriptionInfo;
  93. break;
  94. case CCourseDescription::TYPE_COURSE_MATERIAL:
  95. $courseMaterial[] = $descriptionInfo;
  96. break;
  97. case CCourseDescription::TYPE_RESOURCES:
  98. $courseResources[] = $descriptionInfo;
  99. break;
  100. case CCourseDescription::TYPE_ASSESSMENT:
  101. $courseAssessment[] = $descriptionInfo;
  102. break;
  103. case CCourseDescription::TYPE_CUSTOM:
  104. $courseCustom[] = $descriptionInfo;
  105. break;
  106. }
  107. }
  108. }
  109. $courses[] = [
  110. 'course' => $sessionCourse,
  111. 'description' => $courseDescription,
  112. 'image' => CourseManager::getPicturePath($sessionCourse, true),
  113. 'tags' => $courseTags,
  114. 'objectives' => $courseObjectives,
  115. 'topics' => $courseTopics,
  116. 'methodology' => $courseMethodology,
  117. 'material' => $courseMaterial,
  118. 'resources' => $courseResources,
  119. 'assessment' => $courseAssessment,
  120. 'custom' => array_reverse($courseCustom),
  121. 'coaches' => $coachesData,
  122. 'extra_fields' => $courseValues->getAllValuesForAnItem(
  123. $sessionCourse->getId(),
  124. null,
  125. true
  126. ),
  127. ];
  128. }
  129. $sessionDates = SessionManager::parseSessionDates(
  130. [
  131. 'display_start_date' => $session->getDisplayStartDate(),
  132. 'display_end_date' => $session->getDisplayEndDate(),
  133. 'access_start_date' => $session->getAccessStartDate(),
  134. 'access_end_date' => $session->getAccessEndDate(),
  135. 'coach_access_start_date' => $session->getCoachAccessStartDate(),
  136. 'coach_access_end_date' => $session->getCoachAccessEndDate(),
  137. ],
  138. true
  139. );
  140. $sessionRequirements = $sequenceResourceRepo->getRequirements(
  141. $session->getId(),
  142. SequenceResource::SESSION_TYPE
  143. );
  144. $hasRequirements = false;
  145. foreach ($sessionRequirements as $sequence) {
  146. if (!empty($sequence['requirements'])) {
  147. $hasRequirements = true;
  148. break;
  149. }
  150. }
  151. $courseController = new CoursesController();
  152. /* View */
  153. $template = new Template($session->getName(), true, true, false, true, false);
  154. $template->assign('show_tutor', (api_get_setting('show_session_coach') === 'true' ? true : false));
  155. $template->assign('page_url', api_get_path(WEB_PATH)."session/{$session->getId()}/about/");
  156. $template->assign('session', $session);
  157. $template->assign('session_date', $sessionDates);
  158. $template->assign(
  159. 'is_subscribed',
  160. SessionManager::isUserSubscribedAsStudent(
  161. $session->getId(),
  162. api_get_user_id()
  163. )
  164. );
  165. $template->assign(
  166. 'subscribe_button',
  167. $courseController->getRegisteredInSessionButton(
  168. $session->getId(),
  169. $session->getName(),
  170. $hasRequirements,
  171. true,
  172. true
  173. )
  174. );
  175. $template->assign(
  176. 'user_session_time',
  177. SessionManager::getDayLeftInSession(
  178. ['id' => $session->getId(), 'duration' => $session->getDuration()],
  179. api_get_user_id()
  180. )
  181. );
  182. $plugin = BuyCoursesPlugin::create();
  183. $checker = $plugin->isEnabled();
  184. $sessionIsPremium = null;
  185. if ($checker) {
  186. $sessionIsPremium = $plugin->getItemByProduct(
  187. $sessionId,
  188. BuyCoursesPlugin::PRODUCT_TYPE_SESSION
  189. );
  190. if ($sessionIsPremium) {
  191. ChamiloSession::write('SessionIsPremium', true);
  192. ChamiloSession::write('sessionId', $sessionId);
  193. }
  194. }
  195. $redirectToSession = api_get_configuration_value('allow_redirect_to_session_after_inscription_about');
  196. $redirectToSession = $redirectToSession ? '?s='.$sessionId : false;
  197. $coursesInThisSession = SessionManager::get_course_list_by_session_id($sessionId);
  198. $coursesCount = count($coursesInThisSession);
  199. $redirectToSession = $coursesCount == 1 && $redirectToSession
  200. ? ($redirectToSession.'&cr='.array_values($coursesInThisSession)[0]['directory'])
  201. : $redirectToSession;
  202. $template->assign('redirect_to_session', $redirectToSession);
  203. $template->assign('courses', $courses);
  204. $essence = Essence\Essence::instance();
  205. $template->assign('essence', $essence);
  206. $template->assign(
  207. 'session_extra_fields',
  208. $sessionValues->getAllValuesForAnItem($session->getId(), null, true)
  209. );
  210. $template->assign('has_requirements', $hasRequirements);
  211. $template->assign('sequences', $sessionRequirements);
  212. $template->assign('is_premium', $sessionIsPremium);
  213. $layout = $template->get_template('session/about.tpl');
  214. $content = $template->fetch($layout);
  215. $template->assign('content', $content);
  216. $template->display_one_col_template();