Minor - format code

remotes/angel/1.11.x
jmontoyaa 8 years ago
parent 980cb956f5
commit 73a2b8bf8e
  1. 138
      main/inc/lib/tracking.lib.php
  2. 110
      main/session/index.php

@ -17,6 +17,19 @@ use Chamilo\CoreBundle\Entity\Session;
*/
class Tracking
{
/**
* Get group reporting
* @param int $course_id
* @param int $sessionId
* @param int $group_id
* @param string $type
* @param int $start
* @param int $limit
* @param int $sidx
* @param string $sord
* @param array $where_condition
* @return array|null
*/
public static function get_group_reporting(
$course_id,
$sessionId = null,
@ -65,7 +78,6 @@ class Tracking
if (!empty($result)) {
foreach ($result as $group) {
$users = GroupManager::get_users($group['id'], true);
$time = 0;
$avg_student_score = 0;
$avg_student_progress = 0;
@ -141,7 +153,6 @@ class Tracking
$session_id = intval($session_id);
$origin = Security::remove_XSS($origin);
$list = learnpath :: get_flat_ordered_items_list($lp_id, 0, $courseInfo['real_id']);
$is_allowed_to_edit = api_is_allowed_to_edit(null, true);
$course_id = $courseInfo['real_id'];
$courseCode = $courseInfo['code'];
@ -162,7 +173,6 @@ class Tracking
Display::return_icon('view_less_stats.gif', get_lang('HideAllAttempts')),
api_get_self() . '?action=stats' . $url_suffix
);
$extend_all = 1;
} else {
$extend_all_link = Display::url(
@ -207,7 +217,6 @@ class Tracking
// Going through the items using the $items[] array instead of the database order ensures
// we get them in the same order as in the imsmanifest file, which is rather random when using
// the database table.
$TBL_LP_ITEM = Database :: get_course_table(TABLE_LP_ITEM);
$TBL_LP_ITEM_VIEW = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
$TBL_LP_VIEW = Database :: get_course_table(TABLE_LP_VIEW);
@ -1232,7 +1241,6 @@ class Tracking
}
$sessions = SessionManager::get_sessions_followed_by_drh($userId);
} else {
$studentList = UserManager::getUsersFollowedByUser(
$userId,
STUDENT,
@ -1357,10 +1365,11 @@ class Tracking
/**
* Calculates the time spent on the platform by a user
* @param int|array User id
* @param string type of time filter: 'last_week' or 'custom'
* @param string start date date('Y-m-d H:i:s')
* @param string end date date('Y-m-d H:i:s')
* @return timestamp $nb_seconds
* @param string $timeFilter type of time filter: 'last_week' or 'custom'
* @param string $start_date start date date('Y-m-d H:i:s')
* @param string $end_date end date date('Y-m-d H:i:s')
*
* @return int $nb_seconds
*/
public static function get_time_spent_on_the_platform(
$userId,
@ -1394,7 +1403,7 @@ class Tracking
$newDate = new DateTime('-30 days', new DateTimeZone('UTC'));
$condition_time = " AND (login_date >= '{$newDate->format('Y-m-d H:i:s')}'";
$condition_time .= "AND logout_date <= '{$today->format('Y-m-d H:i:s')}') ";
break;
break;
case 'custom':
if (!empty($start_date) && !empty($end_date)) {
$start_date = Database::escape_string($start_date);
@ -1404,10 +1413,10 @@ class Tracking
break;
}
$sql = 'SELECT SUM(TIMESTAMPDIFF(SECOND, login_date, logout_date)) diff
$sql = 'SELECT SUM(TIMESTAMPDIFF(SECOND, login_date, logout_date)) diff
FROM '.$tbl_track_login.'
WHERE '.$userCondition.$condition_time;
$rs = Database::query($sql);
$rs = Database::query($sql);
$row = Database::fetch_array($rs, 'ASSOC');
$diff = $row['diff'];
@ -1429,19 +1438,18 @@ class Tracking
public static function get_time_spent_on_the_course($user_id, $courseId, $session_id = 0)
{
$courseId = intval($courseId);
$session_id = intval($session_id);
$tbl_track_course = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
if (is_array($user_id)) {
$user_id = array_map('intval', $user_id);
$condition_user = " AND user_id IN (".implode(',',$user_id).") ";
} else {
$user_id = intval($user_id);
$condition_user = " AND user_id = $user_id ";
}
$session_id = intval($session_id);
$tbl_track_course = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
if (is_array($user_id)) {
$user_id = array_map('intval', $user_id);
$condition_user = " AND user_id IN (".implode(',',$user_id).") ";
} else {
$user_id = intval($user_id);
$condition_user = " AND user_id = $user_id ";
}
$sql = "SELECT
SUM(UNIX_TIMESTAMP(logout_course_date) - UNIX_TIMESTAMP(login_course_date)) as nb_seconds
$sql = "SELECT
SUM(UNIX_TIMESTAMP(logout_course_date) - UNIX_TIMESTAMP(login_course_date)) as nb_seconds
FROM $tbl_track_course
WHERE UNIX_TIMESTAMP(logout_course_date) > UNIX_TIMESTAMP(login_course_date) ";
@ -1455,9 +1463,9 @@ class Tracking
$sql .= $condition_user;
$rs = Database::query($sql);
$row = Database::fetch_array($rs);
$row = Database::fetch_array($rs);
return $row['nb_seconds'];
return $row['nb_seconds'];
}
/**
@ -1468,25 +1476,25 @@ class Tracking
*/
public static function get_first_connection_date($student_id)
{
$tbl_track_login = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$sql = 'SELECT login_date
FROM ' . $tbl_track_login . '
$tbl_track_login = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$sql = 'SELECT login_date
FROM ' . $tbl_track_login . '
WHERE login_user_id = ' . intval($student_id) . '
ORDER BY login_date ASC
LIMIT 0,1';
$rs = Database::query($sql);
if (Database::num_rows($rs)>0) {
if ($first_login_date = Database::result($rs, 0, 0)) {
$rs = Database::query($sql);
if (Database::num_rows($rs)>0) {
if ($first_login_date = Database::result($rs, 0, 0)) {
return api_convert_and_format_date(
$first_login_date,
DATE_FORMAT_SHORT,
date_default_timezone_get()
);
}
}
}
}
return false;
return false;
}
/**
@ -1499,37 +1507,37 @@ class Tracking
*/
public static function get_last_connection_date($student_id, $warning_message = false, $return_timestamp = false)
{
$table = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$sql = 'SELECT login_date
FROM ' . $table . '
$table = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$sql = 'SELECT login_date
FROM ' . $table . '
WHERE login_user_id = ' . intval($student_id) . '
ORDER BY login_date
DESC LIMIT 0,1';
$rs = Database::query($sql);
if (Database::num_rows($rs) > 0) {
if ($last_login_date = Database::result($rs, 0, 0)) {
$last_login_date = api_get_local_time($last_login_date);
if ($return_timestamp) {
return api_strtotime($last_login_date,'UTC');
} else {
if (!$warning_message) {
return api_format_date($last_login_date, DATE_FORMAT_SHORT);
} else {
$timestamp = api_strtotime($last_login_date,'UTC');
$currentTimestamp = time();
$rs = Database::query($sql);
if (Database::num_rows($rs) > 0) {
if ($last_login_date = Database::result($rs, 0, 0)) {
$last_login_date = api_get_local_time($last_login_date);
if ($return_timestamp) {
return api_strtotime($last_login_date,'UTC');
} else {
if (!$warning_message) {
return api_format_date($last_login_date, DATE_FORMAT_SHORT);
} else {
$timestamp = api_strtotime($last_login_date,'UTC');
$currentTimestamp = time();
//If the last connection is > than 7 days, the text is red
//345600 = 7 days in seconds
if ($currentTimestamp - $timestamp > 604800) {
return '<span style="color: #F00;">' . api_format_date($last_login_date, DATE_FORMAT_SHORT) . '</span>';
} else {
return api_format_date($last_login_date, DATE_FORMAT_SHORT);
}
}
}
}
}
//If the last connection is > than 7 days, the text is red
//345600 = 7 days in seconds
if ($currentTimestamp - $timestamp > 604800) {
return '<span style="color: #F00;">' . api_format_date($last_login_date, DATE_FORMAT_SHORT) . '</span>';
} else {
return api_format_date($last_login_date, DATE_FORMAT_SHORT);
}
}
}
}
}
return false;
}
@ -1812,7 +1820,7 @@ class Tracking
}
// Compose a filter based on optional session id given
$condition_session = "";
$condition_session = '';
if (isset($session_id)) {
$session_id = intval($session_id);
$condition_session = " AND session_id = $session_id ";
@ -1866,7 +1874,6 @@ class Tracking
}
$count_quiz = Database::fetch_row(Database::query($sql));
$sql = "SELECT
SUM(exe_result/exe_weighting*100) as avg_score,
COUNT(*) as num_attempts
@ -4378,7 +4385,6 @@ class Tracking
$html = '';
// Course list
if ($show_courses) {
if (!empty($courses)) {
$html .= Display::page_subheader(
@ -4472,11 +4478,9 @@ class Tracking
$main_session_graph = '';
//Load graphics only when calling to an specific session
$session_graph = array();
$all_exercise_graph_name_list = array();
$my_results = array();
$all_exercise_graph_list = array();
$all_exercise_start_time = array();
foreach ($course_in_session as $my_session_id => $session_data) {
@ -4501,9 +4505,7 @@ class Tracking
$exercise_obj->read($exercise_data['id']);
//Exercise is not necessary to be visible to show results check the result_disable configuration instead
//$visible_return = $exercise_obj->is_visible();
if ($exercise_data['results_disabled'] == 0 || $exercise_data['results_disabled'] == 2) {
$best_average = intval(
ExerciseLib::get_best_average_score_by_exercise(
$exercise_data['id'],

@ -42,16 +42,6 @@ $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();
@ -71,60 +61,7 @@ if (empty($user_course_list)) {
}
$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;
}
}*/
$final_array = array();
$new_course_list = array();
if (!empty($course_list)) {
@ -283,7 +220,7 @@ $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) {
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']) {
@ -325,7 +262,9 @@ foreach ($final_array as $session_data) {
$exercise_result['exe_weighting']
);
$my_score = 0;
if(!empty($exercise_result['exe_weighting']) && intval($exercise_result['exe_weighting']) != 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(
@ -435,9 +374,10 @@ if ($session_info['show_description'] == 1) {
}
// All Learnpaths grid settings (First tab, first subtab)
$columns_courses = array(
get_lang('Title'), get_lang('NumberOfPublishedExercises'), get_lang('NumberOfPublishedLps')
get_lang('Title'),
get_lang('NumberOfPublishedExercises'),
get_lang('NumberOfPublishedLps'),
);
$column_model_courses = array(
array('name'=>'title', 'index'=>'title', 'width'=>'400px', 'align'=>'left', 'sortable'=>'true'),
@ -624,15 +564,16 @@ if (!api_is_anonymous()) {
false,
false
);
if (!empty($reportingTab)) {
$reportingTab .= '<br />'.Tracking::show_course_detail(
api_get_user_id(),
$courseCode,
$session_id
);
if (!empty($reportingTab)) {
$reportingTab .= '<br />';
$reportingTab .= Tracking::show_course_detail(
api_get_user_id(),
$courseCode,
$session_id
);
}
if (empty($reportingTab)) {
$reportingTab = Display::return_message(get_lang('NoDataAvailable'), 'warning');
$reportingTab = Display::return_message(get_lang('NoDataAvailable'), 'warning');
}
}
@ -648,24 +589,6 @@ if (!api_is_anonymous()) {
$headers[] = get_lang('MyStatistics');
}
// Sub headers
/*$sub_header = array(
get_lang('AllLearningPaths'),
get_lang('PerWeek'),
get_lang('ByCourse')
);
// Sub headers data
$lpTab = Display::tabs(
$sub_header,
array(
//Display::grid_html('list_default'),
Display::grid_html('list_week'),
//Display::grid_html('list_course')
),
'sub_tab'
);*/
$coursesTab = Display::grid_html('courses');
$starTab = Display::grid_html('list_default');
@ -696,7 +619,6 @@ echo Display::tabs(
Session::erase('_gid');
Session::erase('oLP');
Session::erase('lpobject');
api_remove_in_gradebook();
Display::display_footer();

Loading…
Cancel
Save