about.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. foreach ($sessionCourses as $sessionCourse) {
  40. $courseTags = [];
  41. if (!is_null($tagField)) {
  42. $courseTags = $fieldTagsRepo->getTags($tagField, $sessionCourse->getId());
  43. }
  44. $courseCoaches = $userRepo->getCoachesForSessionCourse($session, $sessionCourse);
  45. $coachesData = [];
  46. /** @var User $courseCoach */
  47. foreach ($courseCoaches as $courseCoach) {
  48. $coachData = [
  49. 'complete_name' => $courseCoach->getCompleteName(),
  50. 'image' => UserManager::getUserPicture(
  51. $courseCoach->getId(),
  52. USER_IMAGE_SIZE_ORIGINAL
  53. ),
  54. 'extra_fields' => $userValues->getAllValuesForAnItem(
  55. $courseCoach->getId(),
  56. null,
  57. true
  58. ),
  59. ];
  60. $coachesData[] = $coachData;
  61. }
  62. $courseDescriptionTools = $em->getRepository('ChamiloCourseBundle:CCourseDescription')
  63. ->findBy(
  64. [
  65. 'cId' => $sessionCourse->getId(),
  66. 'sessionId' => 0
  67. ],
  68. [
  69. 'id' => 'DESC',
  70. 'descriptionType' => 'ASC'
  71. ]
  72. );
  73. $courseDescription = $courseObjectives = $courseTopics = $courseMethodology = $courseMaterial = $courseResources = $courseAssessment = '';
  74. $courseCustom = [];
  75. foreach ($courseDescriptionTools as $descriptionTool) {
  76. switch ($descriptionTool->getDescriptionType()) {
  77. case CCourseDescription::TYPE_DESCRIPTION:
  78. $courseDescription = $descriptionTool;
  79. break;
  80. case CCourseDescription::TYPE_OBJECTIVES:
  81. $courseObjectives = $descriptionTool;
  82. break;
  83. case CCourseDescription::TYPE_TOPICS:
  84. $courseTopics = $descriptionTool;
  85. break;
  86. case CCourseDescription::TYPE_METHODOLOGY:
  87. $courseMethodology = $descriptionTool;
  88. break;
  89. case CCourseDescription::TYPE_COURSE_MATERIAL:
  90. $courseMaterial = $descriptionTool;
  91. break;
  92. case CCourseDescription::TYPE_RESOURCES:
  93. $courseResources = $descriptionTool;
  94. break;
  95. case CCourseDescription::TYPE_ASSESMENT:
  96. $courseAssessment = $descriptionTool;
  97. break;
  98. case CCourseDescription::TYPE_CUSTOM:
  99. $courseCustom[] = $descriptionTool;
  100. break;
  101. }
  102. }
  103. $courses[] = [
  104. 'course' => $sessionCourse,
  105. 'description' => $courseDescription,
  106. 'tags' => $courseTags,
  107. 'objectives' => $courseObjectives,
  108. 'topics' => $courseTopics,
  109. 'methodology' => $courseMethodology,
  110. 'material' => $courseMaterial,
  111. 'resources' => $courseResources,
  112. 'assessment' => $courseAssessment,
  113. 'custom' => array_reverse($courseCustom),
  114. 'coaches' => $coachesData,
  115. 'extra_fields' => $courseValues->getAllValuesForAnItem(
  116. $sessionCourse->getId(),
  117. null,
  118. true
  119. ),
  120. ];
  121. }
  122. $sessionDates = SessionManager::parseSessionDates(
  123. [
  124. 'display_start_date' => $session->getDisplayStartDate(),
  125. 'display_end_date' => $session->getDisplayEndDate(),
  126. 'access_start_date' => $session->getAccessStartDate(),
  127. 'access_end_date' => $session->getAccessEndDate(),
  128. 'coach_access_start_date' => $session->getCoachAccessStartDate(),
  129. 'coach_access_end_date' => $session->getCoachAccessEndDate(),
  130. ],
  131. true
  132. );
  133. $sessionRequirements = $sequenceResourceRepo->getRequirements(
  134. $session->getId(),
  135. SequenceResource::SESSION_TYPE
  136. );
  137. $hasRequirements = false;
  138. foreach ($sessionRequirements as $sequence) {
  139. if (!empty($sequence['requirements'])) {
  140. $hasRequirements = true;
  141. break;
  142. }
  143. }
  144. $courseController = new CoursesController();
  145. /* View */
  146. $template = new Template($session->getName(), true, true, false, true, false);
  147. $template->assign('show_tutor', (api_get_setting('show_session_coach') === 'true' ? true : false));
  148. $template->assign('page_url', api_get_path(WEB_PATH)."session/{$session->getId()}/about/");
  149. $template->assign('session', $session);
  150. $template->assign('session_date', $sessionDates);
  151. $template->assign(
  152. 'is_subscribed',
  153. SessionManager::isUserSubscribedAsStudent(
  154. $session->getId(),
  155. api_get_user_id()
  156. )
  157. );
  158. $template->assign(
  159. 'subscribe_button',
  160. $courseController->getRegisteredInSessionButton(
  161. $session->getId(),
  162. $session->getName(),
  163. $hasRequirements,
  164. true,
  165. true
  166. )
  167. );
  168. $template->assign(
  169. 'user_session_time',
  170. SessionManager::getDayLeftInSession(
  171. ['id' => $session->getId(), 'duration' => $session->getDuration()],
  172. api_get_user_id()
  173. )
  174. );
  175. $plugin = BuyCoursesPlugin::create();
  176. $checker = $plugin->isEnabled();
  177. if ($checker) {
  178. $sessionIsPremium = $plugin->getItemByProduct(
  179. $sessionId,
  180. BuyCoursesPlugin::PRODUCT_TYPE_SESSION
  181. );
  182. if ($sessionIsPremium) {
  183. Session::write('SessionIsPremium', true);
  184. Session::write('sessionId', $sessionId);
  185. }
  186. }
  187. $redirectToSession = api_get_configuration_value('allow_redirect_to_session_after_inscription_about');
  188. $redirectToSession = $redirectToSession ? '?s='.$sessionId : false;
  189. $coursesInThisSession = SessionManager::get_course_list_by_session_id($sessionId);
  190. $coursesCount = count($coursesInThisSession);
  191. $redirectToSession = $coursesCount == 1 && $redirectToSession ? $redirectToSession.'&cr='.array_values($coursesInThisSession)[0]['directory'] : $redirectToSession;
  192. $template->assign('redirect_to_session', $redirectToSession);
  193. $template->assign('courses', $courses);
  194. $essence = Essence\Essence::instance();
  195. $template->assign('essence', $essence);
  196. $template->assign(
  197. 'session_extra_fields',
  198. $sessionValues->getAllValuesForAnItem($session->getId(), null, true)
  199. );
  200. $template->assign('has_requirements', $hasRequirements);
  201. $template->assign('sequences', $sessionRequirements);
  202. $templateFolder = api_get_configuration_value('default_template');
  203. $layout = $template->get_template('session/about.tpl');
  204. $content = $template->fetch($layout);
  205. $template->assign('header', $session->getName());
  206. $template->assign('content', $content);
  207. $template->display_one_col_template();