about.php 8.2 KB

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