Beeznest
*/
use ChamiloSession as Session;
$cidReset = true;
require_once '../inc/global.inc.php';
if (empty($_GET['session_id'])) {
api_not_allowed();
}
$session_id = isset($_GET['session_id']) ? intval($_GET['session_id']): null;
$sessionField = new ExtraFieldValue('session');
$valueAllowVisitors = $sessionField->get_values_by_handler_and_field_variable($session_id, 'allow_visitors');
$allowVisitors = $valueAllowVisitors != false;
if (!$allowVisitors) {
// Only users who are logged in can proceed.
api_block_anonymous_users();
}
$this_section = SECTION_COURSES;
$htmlHeadXtra[] = api_get_jqgrid_js();
$course_id = isset($_GET['course_id']) ? intval($_GET['course_id']) : null;
$_SESSION['id_session'] = $session_id;
// Clear the exercise session just in case
if (isset($_SESSION['objExercise'])) {
Session::erase('objExercise');
}
$userId = api_get_user_id();
$session_info = SessionManager::fetch($session_id);
$session_list = SessionManager::get_sessions_by_coach(api_get_user_id());
$course_list = SessionManager::get_course_list_by_session_id($session_id);
// Getting all sessions where I'm subscribed
/*$new_session_list = array();
if (!api_is_anonymous()) {
$new_session_list = UserManager::get_personal_session_course_list(api_get_user_id());
}
$user_course_list = array();
foreach ($new_session_list as $session_item) {
$user_course_list[] = $session_item['code'];
}*/
$userIsGeneralCoach = SessionManager::user_is_general_coach($userId, $session_id);
$user_course_list = array();
foreach ($course_list as $course) {
$status = SessionManager::get_user_status_in_course_session(
$userId,
$course['real_id'],
$session_id
);
if ($status !== false || api_is_platform_admin() || $userIsGeneralCoach) {
$user_course_list[] = $course['code'];
}
}
if (empty($user_course_list)) {
api_not_allowed(true);
}
$my_session_list = array();
$final_array = array();
/*
if (!empty($new_session_list)) {
foreach ($new_session_list as $item) {
$my_session_id = isset($item['id_session']) ? $item['id_session'] : null;
if (isset($my_session_id) && !in_array($my_session_id, $my_session_list) && $session_id == $my_session_id) {
$final_array[$my_session_id]['name'] = $item['session_name'];
//Get all courses by session where I'm subscribed
$my_course_list = UserManager::get_courses_list_by_session(api_get_user_id(), $my_session_id);
foreach ($my_course_list as $my_course) {
$course = array();
$course_info = api_get_course_info($my_course['code']);
// Getting all visible exercises from the current course
$exercise_list = ExerciseLib::get_all_exercises(
$course_info,
$my_session_id,
true,
null,
false,
1
);
$course['name'] = $course_info['name'];
$course['id'] = $course_info['real_id'];
if (!empty($exercise_list)) {
foreach ($exercise_list as $exercise_item) {
//Loading the exercise
$exercise = new Exercise($course_info['real_id']);
$exercise->read($exercise_item['id']);
$visible_return = $exercise->is_visible();
if ($visible_return['value'] != false) {
// Reading all Exercise results by user, exercise_id, code, and session.
$user_results = Event::getExerciseResultsByUser(
api_get_user_id(),
$exercise_item['id'],
$my_course['code'],
$my_session_id
);
$course['exercises'][$exercise_item['id']]['data']['exercise_data'] = $exercise;
$course['exercises'][$exercise_item['id']]['data']['results'] = $user_results;
}
}
$final_array[$my_session_id]['data'][$my_course['code']] = $course;
}
}
}
$my_session_list[] = $my_session_id;
}
}*/
$new_course_list = array();
if (!empty($course_list)) {
foreach ($course_list as $course_data) {
if (!api_is_platform_admin()) {
if (in_array(
$course_data['code'],
$user_course_list
) || api_is_anonymous()
) {
$course_data['title'] = Display::url(
$course_data['title'],
api_get_course_url($course_data['code'], $session_id)
);
} else {
continue;
}
}
$list = new LearnpathList(
api_get_user_id(),
$course_data['code'],
$session_id,
'publicated_on ASC',
true
);
$lp_list = $list->get_flat_list();
$lp_count = 0;
if (!empty($lp_list)) {
foreach ($lp_list as $valLp) {
if ($valLp['lp_visibility']) {
$lp_count++;
}
}
}
$course_info = api_get_course_info($course_data['code']);
$exercise_count = count(
ExerciseLib::get_all_exercises(
$course_info,
$session_id,
true,
null,
false,
1
)
);
$max_mutation_date = '';
$last_date = Tracking::get_last_connection_date_on_the_course(
api_get_user_id(),
$course_info,
$session_id,
false
);
$icons = '';
foreach ($lp_list as $item) {
if ($item['modified_on'] == '0000-00-00 00:00:00' || empty($item['modified_on'])) {
$lp_date_original = $item['created_on'];
$image = 'new.gif';
$label = get_lang('LearnpathAdded');
} else {
$lp_date_original = $item['modified_on'];
$image = 'moderator_star.png';
$label = get_lang('LearnpathUpdated');
}
$mutation_date = api_strtotime($item['publicated_on']) > api_strtotime($lp_date_original) ? $item['publicated_on'] : $lp_date_original;
if (api_strtotime($mutation_date) > api_strtotime($max_mutation_date)) {
$max_mutation_date = $mutation_date;
}
if (strtotime($last_date) < strtotime($lp_date_original)) {
if (empty($icons)) {
$icons .= ' '.Display::return_icon(
$image,
get_lang('TitleNotification').': '.$label.' - '.$lp_date_original
).' ';
}
}
}
$new_course_list[] = array(
'title'=> $course_data['title'].$icons,
// 'recent_lps' => $icons,
//'max_mutation_date' => substr(api_get_local_time($max_mutation_date),0,10),
'exercise_count' => $exercise_count,
'lp_count' => $lp_count
);
}
}
// If the requested session does not exist in my list we stop the script
/*if (!api_is_platform_admin()) {
if (!api_is_anonymous() && !in_array($session_id, $my_session_list)) {
api_not_allowed(true);
}
}*/
//If session is not active we stop de script
if (!api_is_allowed_to_session_edit()) {
api_not_allowed();
}
$entityManager = Database::getManager();
$session = $entityManager->find('ChamiloCoreBundle:Session', $session_id);
if (!empty($session)) {
$sessionCourses = $session->getCourses();
if (count($sessionCourses) === 1) {
$sessionCourse = $sessionCourses[0]->getCourse();
$courseUrl = $sessionCourse->getDirectory() . '/index.php?';
$courseUrl .= http_build_query([
'id_session' => $session->getId()
]);
header('Location: ' . api_get_path(WEB_COURSE_PATH) . $courseUrl);
exit;
}
}
Display::display_header(get_lang('Session'));
$session_select = array();
foreach ($session_list as $item) {
$session_select[$item['id']] = $item['name'];
}
// Session list form
if (count($session_select) > 1) {
$form = new FormValidator('exercise_admin', 'get', api_get_self().'?session_id='.$session_id);
$form->addElement('select', 'session_id', get_lang('SessionList'), $session_select, 'onchange="javascript:change_session()"');
$defaults['session_id'] = $session_id;
$form->setDefaults($defaults);
$form->display();
}
if (empty($session_id)) {
$user_list = UserManager::get_user_list();
} else {
$user_list = SessionManager::get_users_by_session($session_id);
}
//Final data to be show
$my_real_array = $new_exercises = array();
$now = time();
foreach ($final_array as $session_data) {
$my_course_list = isset($session_data['data']) ? $session_data['data']: array();
if (!empty($my_course_list)) {
foreach ($my_course_list as $my_course_code=>$course_data) {
$courseInfo = api_get_course_info($my_course_code);
if (isset($course_id) && !empty($course_id)) {
if ($course_id != $course_data['id']) {
continue;
}
}
if (!empty($course_data['exercises'])) {
// Exercises
foreach ($course_data['exercises'] as $my_exercise_id => $exercise_data) {
$best_score_data = ExerciseLib::get_best_attempt_in_course(
$my_exercise_id,
$courseInfo['real_id'],
$session_id
);
$best_score = '';
if (!empty($best_score_data)) {
$best_score = ExerciseLib::show_score($best_score_data['exe_result'], $best_score_data['exe_weighting']);
}
// Exercise results
$counter = 1;
foreach ($exercise_data as $exercise_item) {
$result_list = $exercise_item['results'];
$exercise_info = $exercise_item['exercise_data'];
if ($exercise_info->start_time == '0000-00-00 00:00:00') {
$start_date = '-';
} else {
$start_date = $exercise_info->start_time;
}
if (!empty($result_list)) {
foreach ($result_list as $exercise_result) {
$platform_score = ExerciseLib::show_score($exercise_result['exe_result'], $exercise_result['exe_weighting']);
$my_score = 0;
if(!empty($exercise_result['exe_weighting']) && intval($exercise_result['exe_weighting']) != 0) {
$my_score = $exercise_result['exe_result']/$exercise_result['exe_weighting'];
}
$position = ExerciseLib::get_exercise_result_ranking(
$my_score,
$exercise_result['exe_id'],
$my_exercise_id,
$my_course_code,
$session_id,
$user_list
);
$exercise_info->exercise = Display::url(
$exercise_info->exercise,
api_get_path(WEB_CODE_PATH)."exercice/result.php?cidReq=$my_course_code&id={$exercise_result['exe_id']}&id_session=$session_id&show_headers=1",
array('target'=>SESSION_LINK_TARGET,'class'=>'exercise-result-link')
);
$my_real_array[]= array(
'status' => Display::return_icon('quiz.gif', get_lang('Attempted'),'', ICON_SIZE_SMALL),
'date' => $start_date,
'course' => $course_data['name'],
'exercise' => $exercise_info->exercise,
'attempt' => $counter,
'result' => $platform_score,
'best_result' => $best_score,
'position' => $position
);
$counter++;
}
} else {
// We check the date validation of the exercise if the user can make it
if ($exercise_info->start_time != '0000-00-00 00:00:00') {
$allowed_time = api_strtotime($exercise_info->start_time, 'UTC');
if ($now < $allowed_time) {
continue;
}
}
$exercise_info->exercise = Display::url(
$exercise_info->exercise,
api_get_path(WEB_CODE_PATH)."exercice/overview.php?cidReq=$my_course_code&exerciseId={$exercise_info->id}&id_session=$session_id",
array('target'=>SESSION_LINK_TARGET)
);
$new_exercises[]= array(
'status' => Display::return_icon('star.png', get_lang('New'), array('width'=>ICON_SIZE_SMALL)),
'date' => $start_date,
'course' => $course_data['name'],
'exercise' => $exercise_info->exercise,
'attempt' => '-',
'result' => '-',
'best_result' => '-',
'position' => '-'
);
}
}
}
}
}
}
}
$my_real_array = msort($my_real_array, 'date', 'asc');
if (!empty($new_exercises)) {
$my_real_array = array_merge($new_exercises, $my_real_array);
}
$start = $end = $start_only = $end_only ='';
if (!empty($session_info['access_start_date']) && $session_info['access_start_date'] != '0000-00-00') {
$start = api_convert_and_format_date($session_info['access_start_date'], DATE_FORMAT_SHORT);
$start_only = get_lang('From').' '.$session_info['access_start_date'];
}
if (!empty($session_info['access_start_date']) && $session_info['access_end_date'] != '0000-00-00') {
$end = api_convert_and_format_date($session_info['access_end_date'], DATE_FORMAT_SHORT);
$end_only = get_lang('Until').' '.$session_info['access_end_date'];
}
if (!empty($start) && !empty($end)) {
$dates = Display::tag('i', sprintf(get_lang('FromDateXToDateY'), $start, $end));
} else {
$dates = Display::tag('i', $start_only.' '.$end_only);
}
echo Display::tag('h1', $session_info['name']);
echo $dates.'
';
if ($session_info['show_description'] == 1) {
?>