about.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Session about page
  5. * Show information about a session and its courses
  6. * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
  7. * @package chamilo.session
  8. */
  9. use Chamilo\CoreBundle\Entity\ExtraField;
  10. use Chamilo\CourseBundle\Entity\CCourseDescription;
  11. use \Chamilo\CoreBundle\Entity\SequenceResource;
  12. $cidReset = true;
  13. require_once '../inc/global.inc.php';
  14. $sessionId = isset($_GET['session_id']) ? intval($_GET['session_id']) : 0;
  15. $entityManager = Database::getManager();
  16. $session = $entityManager->find('ChamiloCoreBundle:Session', $sessionId);
  17. if (!$session) {
  18. api_not_allowed(true);
  19. }
  20. $sessionCourses = $entityManager->getRepository('ChamiloCoreBundle:Session')
  21. ->getCoursesOrderedByPosition($session);
  22. $courses = [];
  23. $entityManager = Database::getManager();
  24. $fieldsRepo = $entityManager->getRepository('ChamiloCoreBundle:ExtraField');
  25. $fieldTagsRepo = $entityManager->getRepository('ChamiloCoreBundle:ExtraFieldRelTag');
  26. $userRepo = $entityManager->getRepository('ChamiloUserBundle:User');
  27. $sequenceResourceRepo = $entityManager->getRepository(
  28. 'ChamiloCoreBundle:SequenceResource'
  29. );
  30. $tagField = $fieldsRepo->findOneBy([
  31. 'extraFieldType' => ExtraField::COURSE_FIELD_TYPE,
  32. 'variable' => 'tags'
  33. ]);
  34. $courseValues = new ExtraFieldValue('course');
  35. $userValues = new ExtraFieldValue('user');
  36. $sessionValues = new ExtraFieldValue('session');
  37. foreach ($sessionCourses as $sessionCourse) {
  38. $courseTags = [];
  39. if (!is_null($tagField)) {
  40. $courseTags = $fieldTagsRepo->getTags($tagField, $sessionCourse->getId());
  41. }
  42. $courseCoaches = $userRepo->getCoachesForSessionCourse($session, $sessionCourse);
  43. $coachesData = [];
  44. foreach ($courseCoaches as $courseCoach) {
  45. $coachData = [
  46. 'complete_name' => $courseCoach->getCompleteName(),
  47. 'image' => UserManager::getUserPicture($courseCoach->getId(), USER_IMAGE_SIZE_ORIGINAL),
  48. 'extra_fields' => $userValues->getAllValuesForAnItem($courseCoach->getId(), true)
  49. ];
  50. $coachesData[] = $coachData;
  51. }
  52. $courseDescriptionTools = $entityManager->getRepository('ChamiloCourseBundle:CCourseDescription')
  53. ->findBy(
  54. [
  55. 'cId' => $sessionCourse->getId(),
  56. 'sessionId' => 0
  57. ],
  58. [
  59. 'id' => 'DESC',
  60. 'descriptionType' => 'ASC'
  61. ]
  62. );
  63. $courseDescription = $courseObjectives = $courseTopics = null;
  64. foreach ($courseDescriptionTools as $descriptionTool) {
  65. switch ($descriptionTool->getDescriptionType()) {
  66. case CCourseDescription::TYPE_DESCRIPTION:
  67. $courseDescription = $descriptionTool;
  68. break;
  69. case CCourseDescription::TYPE_OBJECTIVES:
  70. $courseObjectives = $descriptionTool;
  71. break;
  72. case CCourseDescription::TYPE_TOPICS:
  73. $courseTopics = $descriptionTool;
  74. break;
  75. }
  76. }
  77. $courses[] = [
  78. 'course' => $sessionCourse,
  79. 'description' => $courseDescription,
  80. 'tags' => $courseTags,
  81. 'objectives' => $courseObjectives,
  82. 'topics' => $courseTopics,
  83. 'coaches' => $coachesData,
  84. 'extra_fields' => $courseValues->getAllValuesForAnItem($sessionCourse->getId())
  85. ];
  86. }
  87. $sessionDates = SessionManager::parseSessionDates([
  88. 'display_start_date' => $session->getDisplayStartDate(),
  89. 'display_end_date' => $session->getDisplayEndDate(),
  90. 'access_start_date' => $session->getAccessStartDate(),
  91. 'access_end_date' => $session->getAccessEndDate(),
  92. 'coach_access_start_date' => $session->getCoachAccessStartDate(),
  93. 'coach_access_end_date' => $session->getCoachAccessEndDate()
  94. ]);
  95. $sessionRequirements = $sequenceResourceRepo->getRequirements(
  96. $session->getId(),
  97. SequenceResource::SESSION_TYPE
  98. );
  99. $hasRequirements = false;
  100. foreach ($sessionRequirements as $sequence) {
  101. if (!empty($sequence['requirements'])) {
  102. $hasRequirements = true;
  103. break;
  104. }
  105. }
  106. $courseController = new CoursesController();
  107. /* View */
  108. $template = new Template($session->getName(), true, true, false, true, false);
  109. $template->assign('show_tutor', (api_get_setting('show_session_coach')==='true' ? true : false));
  110. $template->assign('pageUrl', api_get_path(WEB_PATH) . "session/{$session->getId()}/about/");
  111. $template->assign('session', $session);
  112. $template->assign('session_date', $sessionDates);
  113. $template->assign(
  114. 'is_subscribed',
  115. SessionManager::isUserSubscribedAsStudent(
  116. $session->getId(),
  117. api_get_user_id()
  118. )
  119. );
  120. $template->assign(
  121. 'subscribe_button',
  122. $courseController->getRegisteredInSessionButton(
  123. $session->getId(),
  124. $session->getName(),
  125. $hasRequirements
  126. )
  127. );
  128. $template->assign('courses', $courses);
  129. $template->assign('essence', \Essence\Essence::instance());
  130. $template->assign(
  131. 'session_extra_fields',
  132. $sessionValues->getAllValuesForAnItem($session->getId(), true)
  133. );
  134. $template->assign('has_requirements', $hasRequirements);
  135. $template->assign('sequences', $sessionRequirements);
  136. $templateFolder = api_get_configuration_value('default_template');
  137. $layout = $template->get_template('session/about.tpl');
  138. $content = $template->fetch($layout);
  139. $template->assign('header', $session->getName());
  140. $template->assign('content', $content);
  141. $template->display_one_col_template();