/**
  * Prints the session and course list (user_portal.php)
  * @param int $user_id
  * @return string
  */
 public function returnCoursesAndSessions($user_id)
 {
     global $_configuration;
     $gamificationModeIsActive = api_get_setting('platform.gamification_mode');
     $load_history = isset($_GET['history']) && intval($_GET['history']) == 1 ? true : false;
     if ($load_history) {
         // Load sessions in category in *history*
         $session_categories = UserManager::get_sessions_by_category($user_id, true);
     } else {
         // Load sessions in category
         $session_categories = UserManager::get_sessions_by_category($user_id, false);
     }
     $html = '';
     // Showing history title
     if ($load_history) {
         $html .= Display::page_subheader(get_lang('HistoryTrainingSession'));
         if (empty($session_categories)) {
             $html .= get_lang('YouDoNotHaveAnySessionInItsHistory');
         }
     }
     $courses_html = '';
     $special_courses = '';
     $sessionCount = 0;
     $courseCount = 0;
     // If we're not in the history view...
     if (!isset($_GET['history'])) {
         // Display special courses.
         $specialCourses = CourseManager::display_special_courses($user_id, $this->load_directories_preview);
         $special_courses = $specialCourses['html'];
         // Display courses.
         $courses = CourseManager::display_courses($user_id, $this->load_directories_preview);
         $courses_html .= $courses['html'];
         $courseCount = $specialCourses['course_count'] + $courses['course_count'];
     }
     $sessions_with_category = '';
     $sessions_with_no_category = '';
     $sessionTitleLink = api_get_configuration_value('courses_list_session_title_link');
     $sessionTitleLink = $sessionTitleLink === false ? 1 : $sessionTitleLink;
     if (is_array($session_categories)) {
         foreach ($session_categories as $session_category) {
             $session_category_id = $session_category['session_category']['id'];
             // Sessions and courses that are not in a session category
             if (empty($session_category_id) && isset($session_category['sessions'])) {
                 // Independent sessions
                 foreach ($session_category['sessions'] as $session) {
                     $session_id = $session['session_id'];
                     // Don't show empty sessions.
                     if (count($session['courses']) < 1) {
                         continue;
                     }
                     // Courses inside the current session.
                     $date_session_start = $session['access_start_date'];
                     $date_session_end = $session['access_end_date'];
                     $coachAccessStartDate = $session['coach_access_start_date'];
                     $coachAccessEndDate = $session['coach_access_end_date'];
                     $session_now = time();
                     $count_courses_session = 0;
                     // Loop course content
                     $html_courses_session = [];
                     $atLeastOneCourseIsVisible = false;
                     foreach ($session['courses'] as $course) {
                         $is_coach_course = api_is_coach($session_id, $course['real_id']);
                         $allowed_time = 0;
                         $dif_time_after = 0;
                         if (!empty($date_session_start) && $date_session_start != '0000-00-00 00:00:00') {
                             if ($is_coach_course) {
                                 $allowed_time = api_strtotime($coachAccessStartDate);
                             } else {
                                 $allowed_time = api_strtotime($date_session_start);
                             }
                             if (!isset($_GET['history'])) {
                                 if (!empty($date_session_end) && $date_session_end != '0000-00-00 00:00:00') {
                                     $endSessionToTms = api_strtotime($date_session_end);
                                     if ($session_now > $endSessionToTms) {
                                         $dif_time_after = $session_now - $endSessionToTms;
                                         $dif_time_after = round($dif_time_after / 86400);
                                     }
                                 }
                             }
                         }
                         if ($session_now > $allowed_time) {
                             // Read only and accessible.
                             $atLeastOneCourseIsVisible = true;
                             if (api_get_setting('session.hide_courses_in_sessions') == 'false') {
                                 $courseUserHtml = CourseManager::get_logged_user_course_html($course, $session_id, 'session_course_item', true, $this->load_directories_preview);
                                 if (isset($courseUserHtml[1])) {
                                     $course_session = $courseUserHtml[1];
                                     $course_session['skill'] = isset($courseUserHtml['skill']) ? $courseUserHtml['skill'] : '';
                                     $html_courses_session[] = $course_session;
                                 }
                             }
                             $count_courses_session++;
                         }
                     }
                     // No courses to show.
                     if ($atLeastOneCourseIsVisible == false) {
                         if (empty($html_courses_session)) {
                             continue;
                         }
                     }
                     if ($count_courses_session > 0) {
                         $params = array('id' => $session_id);
                         $session_box = Display::get_session_title_box($session_id);
                         $extra_info = !empty($session_box['coach']) ? $session_box['coach'] : null;
                         $extra_info .= !empty($session_box['coach']) ? ' - ' . $session_box['dates'] : $session_box['dates'];
                         $extra_info .= isset($session_box['duration']) ? ' ' . $session_box['duration'] : null;
                         $params['extra_fields'] = $session_box['extra_fields'];
                         $params['show_link_to_session'] = !api_is_drh() && $sessionTitleLink;
                         $params['title'] = $session_box['title'];
                         $params['subtitle'] = $extra_info;
                         $params['show_actions'] = api_is_platform_admin() ? true : false;
                         if (api_get_setting('session.hide_courses_in_sessions') == 'false') {
                             // $params['extra'] .=  $html_courses_session;
                         }
                         $params['description'] = $session_box['description'];
                         $params['show_description'] = $session_box['show_description'];
                         $params['courses'] = $html_courses_session;
                         $params['show_simple_session_info'] = false;
                         if (isset($_configuration['show_simple_session_info']) && $_configuration['show_simple_session_info']) {
                             $params['show_simple_session_info'] = true;
                         }
                         if ($gamificationModeIsActive) {
                             $params['stars'] = GamificationUtils::getSessionStars($params['id'], $this->user_id);
                             $params['progress'] = GamificationUtils::getSessionProgress($params['id'], $this->user_id);
                             $params['points'] = GamificationUtils::getSessionPoints($params['id'], $this->user_id);
                         }
                         $this->tpl->assign('session', $params);
                         $this->tpl->assign('gamification_mode', $gamificationModeIsActive);
                         $sessions_with_no_category .= $this->tpl->fetch($this->tpl->get_template('/user_portal/session.tpl'));
                         $sessionCount++;
                     }
                 }
             } else {
                 // All sessions included in
                 $count_courses_session = 0;
                 $html_sessions = '';
                 if (isset($session_category['sessions'])) {
                     foreach ($session_category['sessions'] as $session) {
                         $session_id = $session['session_id'];
                         // Don't show empty sessions.
                         if (count($session['courses']) < 1) {
                             continue;
                         }
                         $date_session_start = $session['access_start_date'];
                         $date_session_end = $session['access_end_date'];
                         $coachAccessStartDate = $session['coach_access_start_date'];
                         $coachAccessEndDate = $session['coach_access_end_date'];
                         $session_now = time();
                         $html_courses_session = [];
                         $count = 0;
                         foreach ($session['courses'] as $course) {
                             $is_coach_course = api_is_coach($session_id, $course['real_id']);
                             $dif_time_after = 0;
                             $allowed_time = 0;
                             if ($is_coach_course) {
                                 // 24 hours = 86400
                                 if ($date_session_start != '0000-00-00 00:00:00') {
                                     $allowed_time = api_strtotime($coachAccessStartDate);
                                 }
                                 if (!isset($_GET['history'])) {
                                     if ($date_session_end != '0000-00-00 00:00:00') {
                                         $endSessionToTms = api_strtotime($date_session_end);
                                         if ($session_now > $endSessionToTms) {
                                             $dif_time_after = $session_now - $endSessionToTms;
                                             $dif_time_after = round($dif_time_after / 86400);
                                         }
                                     }
                                 }
                             } else {
                                 $allowed_time = api_strtotime($date_session_start);
                             }
                             if ($session_now > $allowed_time) {
                                 if (api_get_setting('session.hide_courses_in_sessions') == 'false') {
                                     $c = CourseManager::get_logged_user_course_html($course, $session_id, 'session_course_item');
                                     $html_courses_session[] = $c[1];
                                 }
                                 $count_courses_session++;
                                 $count++;
                             }
                         }
                         $sessionParams = array();
                         //Category
                         if ($count > 0) {
                             $session_box = Display::get_session_title_box($session_id);
                             $sessionParams['id'] = $session_id;
                             $sessionParams['show_link_to_session'] = !api_is_drh() && $sessionTitleLink;
                             $sessionParams['title'] = $session_box['title'];
                             $sessionParams['subtitle'] = (!empty($session_box['coach']) ? $session_box['coach'] . ' | ' : '') . $session_box['dates'];
                             $sessionParams['show_actions'] = api_is_platform_admin();
                             $sessionParams['courses'] = $html_courses_session;
                             $sessionParams['show_simple_session_info'] = false;
                             if (isset($_configuration['show_simple_session_info']) && $_configuration['show_simple_session_info']) {
                                 $sessionParams['show_simple_session_info'] = true;
                             }
                             $this->tpl->assign('session', $sessionParams);
                             $html_sessions .= $this->tpl->fetch($this->tpl->get_template('user_portal/session.tpl'));
                             $sessionCount++;
                         }
                     }
                 }
                 if ($count_courses_session > 0) {
                     $categoryParams = array('id' => $session_category['session_category']['id'], 'title' => $session_category['session_category']['name'], 'show_actions' => api_is_platform_admin(), 'subtitle' => null, 'sessions' => $html_sessions);
                     $session_category_start_date = $session_category['session_category']['date_start'];
                     $session_category_end_date = $session_category['session_category']['date_end'];
                     if (!empty($session_category_start_date) && $session_category_start_date != '0000-00-00' && !empty($session_category_end_date) && $session_category_end_date != '0000-00-00') {
                         $categoryParams['subtitle'] = sprintf(get_lang('FromDateXToDateY'), $session_category['session_category']['date_start'], $session_category['session_category']['date_end']);
                     } else {
                         if (!empty($session_category_start_date) && $session_category_start_date != '0000-00-00') {
                             $categoryParams['subtitle'] = get_lang('From') . ' ' . $session_category_start_date;
                         }
                         if (!empty($session_category_end_date) && $session_category_end_date != '0000-00-00') {
                             $categoryParams['subtitle'] = get_lang('Until') . ' ' . $session_category_end_date;
                         }
                     }
                     $this->tpl->assign('session_category', $categoryParams);
                     $sessions_with_category .= $this->tpl->fetch("{$this->tpl->templateFolder}/user_portal/session_category.tpl");
                 }
             }
         }
     }
     return ['html' => $sessions_with_category . $sessions_with_no_category . $courses_html . $special_courses, 'session_count' => $sessionCount, 'course_count' => $courseCount];
 }
Example #2
0
 /**
  * Generate the social block for a user
  * @param Template $template
  * @param int $userId The user id
  * @param string $groupBlock Optional. Highlight link possible values:
  * group_add, home, messages, messages_inbox, messages_compose,
  * messages_outbox, invitations, shared_profile, friends, groups, search
  * @param int $groupId Optional. Group ID
  * @return string The HTML code with the social block
  */
 public static function setSocialUserBlock(Template $template, $userId, $groupBlock = '', $groupId = 0)
 {
     if (api_get_setting('allow_social_tool') != 'true') {
         return '';
     }
     $socialAvatarBlock = SocialManager::show_social_avatar_block($groupBlock, $groupId, $userId);
     $profileEditionLink = null;
     if (api_get_user_id() == $userId) {
         $profileEditionLink = Display::getProfileEditionLink($userId);
     }
     $vCardUserLink = Display::getVCardUserLink($userId);
     $userInfo = api_get_user_info($userId, true, false, true);
     $template->assign('user', $userInfo);
     $template->assign('social_avatar_block', $socialAvatarBlock);
     $template->assign('profile_edition_link', $profileEditionLink);
     //Added the link to export the vCard to the Template
     $template->assign('vcard_user_link', $vCardUserLink);
     if (api_get_setting('gamification_mode') === '1') {
         $gamificationPoints = GamificationUtils::getTotalUserPoints($userId, $userInfo['status']);
         $template->assign('gamification_points', $gamificationPoints);
     }
     $chatEnabled = api_is_global_chat_enabled();
     $template->assign('chat_enabled', $chatEnabled);
     $templateName = $template->get_template('social/user_block.tpl');
     if (in_array($groupBlock, ['groups', 'group_edit', 'member_list'])) {
         $templateName = $template->get_template('social/group_block.tpl');
     }
     $template->assign('social_avatar_block', $template->fetch($templateName));
 }
Example #3
0
 /**
  * Generate the social block for a user
  * @param Template $template
  * @param int $userId The user id
  * @param string $groupBlock Optional. Highlight link possible values:
  * group_add, home, messages, messages_inbox, messages_compose,
  * messages_outbox, invitations, shared_profile, friends, groups, search
  * @param int $groupId Optional. Group ID
  * @param boolean $show_full_profile - Optional. Shows the Full Profile or Not
  * @return string The HTML code with the social block
  */
 public static function setSocialUserBlock($template, $userId, $groupBlock = '', $groupId = 0, $show_full_profile = true)
 {
     if (api_get_setting('social.allow_social_tool') != 'true') {
         return '';
     }
     $socialAvatarBlock = SocialManager::show_social_avatar_block($groupBlock, $groupId, $userId);
     $profileEditionLink = null;
     if (api_get_user_id() == $userId) {
         $profileEditionLink = Display::getProfileEditionLink($userId);
     }
     $vCardUserLink = Display::getVCardUserLink($userId);
     $userInfo = api_get_user_info($userId, true, false, true, true);
     $template->addGlobal('user', $userInfo);
     $template->addGlobal('social_avatar_block', $socialAvatarBlock);
     $template->addGlobal('profile_edition_link', $profileEditionLink);
     //If not friend $show_full_profile is False and the user can't see Email Address and Vcard Download Link
     if ($show_full_profile) {
         //Added the link to export the vCard to the Template
         $template->addGlobal('vcard_user_link', $vCardUserLink);
     }
     if (api_get_setting('platform.gamification_mode') === '1') {
         $gamificationPoints = GamificationUtils::getTotalUserPoints($userId, $userInfo['status']);
         $template->addGlobal('gamification_points', $gamificationPoints);
     }
     $chatEnabled = api_is_global_chat_enabled();
     $template->addGlobal('chat_enabled', $chatEnabled);
     $templateName = $template->render('@template_style/social/user_block.html.twig');
     if (in_array($groupBlock, ['groups', 'group_edit', 'member_list'])) {
         $templateName = $template->render('@template_style/social/group_block.html.twig');
     }
     $template->addGlobal('social_avatar_block', $templateName);
 }
Example #4
0
        continue;
    }
    if ($currentSession && $currentSession->getId() === $session->getId()) {
        $allowAccess = true;
    }
    $sessionList[$session->getId()] = $session;
}
if ($currentSession && !$allowAccess) {
    api_not_allowed(true);
}
$template = new Template($nameTools);
$template->assign('user', $user);
$template->assign('user_avatar', SocialManager::show_social_avatar_block('home', 0, $user->getId()));
$template->assign('gamification_stars', GamificationUtils::getTotalUserStars($user->getId(), $user->getStatus()));
$template->assign('gamification_points', GamificationUtils::getTotalUserPoints($user->getId(), $user->getStatus()));
$template->assign('gamification_progress', GamificationUtils::getTotalUserProgress($user->getId(), $user->getStatus()));
$template->assign('sessions', $sessionList);
$template->assign('current_session', $currentSession);
if ($currentSession) {
    $sessionData = [];
    $sessionCourses = $currentSession->getCourses();
    foreach ($sessionCourses as $sessionCourse) {
        $course = $sessionCourse->getCourse();
        $courseData = ['title' => $course->getTitle(), 'stats' => []];
        $learningPathList = new LearnpathList($user->getId(), $course->getCode(), $currentSession->getId());
        foreach ($learningPathList->list as $learningPathId => $learningPath) {
            $courseData['stats'][] = [$learningPath['lp_name'], 'newscorm/lp_controller.php?' . http_build_query(['action' => 'stats', 'cidReq' => $course->getCode(), 'id_session' => $currentSession->getId(), 'gidReq' => 0, 'lp_id' => $learningPathId]) . api_get_cidreq()];
        }
        $sessionData[$course->getId()] = $courseData;
    }
    $template->assign('session_data', $sessionData);