about.php 5.5 KB

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