about.php 7.8 KB

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