Fix some bug in reports - refs BT#7551

1.9.x
Francis Gonzales 12 years ago
parent afab246248
commit 3d4cd1fb23
  1. 30
      main/inc/ajax/course.ajax.php
  2. 5
      main/inc/ajax/model.ajax.php
  3. 24
      main/inc/ajax/session.ajax.php
  4. 24
      main/inc/lib/course.lib.php
  5. 72
      main/inc/lib/sessionmanager.lib.php
  6. 2
      main/inc/lib/tracking.lib.php
  7. 37
      main/mySpace/index.php
  8. 2
      main/mySpace/myspace.lib.php

@ -126,6 +126,36 @@ switch ($action) {
}
}
break;
case 'search_course_by_session_all':
if (api_is_platform_admin())
{
if ($_GET['session_id'] == 'TODOS' || $_GET['session_id'] == 'T') {
$_GET['session_id'] = '%';
}
$results = SessionManager::get_course_list_by_session_id_like($_GET['session_id'], $_GET['q']);
//$results = SessionManager::get_sessions_list(array('s.name LIKE' => "%".$_REQUEST['q']."%"));
$results2 = array();
if (!empty($results)) {
foreach ($results as $item) {
$item2 = array();
foreach ($item as $id => $internal) {
if ($id == 'id') {
$item2[$id] = $internal;
}
if ($id == 'title') {
$item2['text'] = $internal;
}
}
$results2[] = $item2;
}
echo json_encode($results2);
} else {
echo json_encode(array());
}
}
break;
case 'search_user_by_course':
if (api_is_platform_admin())
{

@ -265,7 +265,7 @@ switch ($action) {
case 'get_session_lp_progress':
case 'get_session_progress':
//@TODO replace this for a more efficient function (not retrieving the whole data)
$course = api_get_course_info_by_id($courseId);
$course = api_get_course_info_by_id($_GET['course_id']);
$users = CourseManager::get_student_list_from_course_code($course['code'], true, $_GET['session_id'], $_GET['date_from'], $_GET['date_to']);
$count = count($users);
break;
@ -656,7 +656,7 @@ switch ($action) {
$sessionId = 0;
if (!empty($_GET['course_id']))
{
$sessionId = intval($_GET['session_id']);
$sessionId = $sessionId == 'T' ? 'T' : intval($_GET['session_id']);
$courseId = intval($_GET['course_id']);
$course = api_get_course_info_by_id($courseId);
$date_from = $_GET['date_from'];
@ -793,6 +793,7 @@ switch ($action) {
'clicks',
'ip',
'timeLoggedIn',
'session'
);
$sessionId = 0;
if (!empty($_GET['course_id']))

@ -47,6 +47,30 @@ switch ($action) {
}
}
break;
case 'search_session_all':
if (api_is_platform_admin()) {
$results = SessionManager::get_sessions_list(array('s.name LIKE' => "%".$_REQUEST['q']."%"));
$results2 = array();
if (!empty($results)) {
foreach ($results as $item) {
$item2 = array();
foreach ($item as $id => $internal) {
if ($id == 'id') {
$item2[$id] = $internal;
}
if ($id == 'name') {
$item2['text'] = $internal;
}
}
$results2[] = $item2;
}
$results2[] = array('T', 'text' => 'TODOS', 'id' => 'T');
echo json_encode($results2);
} else {
echo json_encode(array(array('T', 'text' => 'TODOS', 'id' => 'T')));
}
}
break;
case 'search_session_by_course':
if (api_is_platform_admin()) {
$results = SessionManager::get_sessions_list(array('s.name LIKE' => "%".$_REQUEST['q']."%"));

@ -1558,7 +1558,7 @@ class CourseManager
public static function get_student_list_from_course_code($course_code, $with_session = false, $session_id = 0, $date_from, $date_to) {
$session_id = intval($session_id);
$course_code = Database::escape_string($course_code);
$students = array();
if ($session_id == 0) {
@ -1574,11 +1574,27 @@ class CourseManager
// students subscribed to the course through a session
if ($with_session) {
$sql_query = "SELECT * FROM ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)."
WHERE course_code = '$course_code' AND status <> 2";
$joinSession = "";
//Session creation date
if (!empty($date_from) && !empty($date_to)) {
$joinSession = "INNER JOIN " . Database::get_main_table(TABLE_MAIN_SESSION) . " s";
}
$sql_query = "SELECT * FROM ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)." scu
$joinSession
WHERE scu.course_code = '$course_code' AND scu.status <> 2";
if (!empty($date_from) && !empty($date_to)) {
$date_from = Database::escape_string($date_from);
$date_to = Database::escape_string($date_to);
$sql_query .= " AND s.date_start >= '$date_from' AND s.date_end <= '$date_to'";
}
if ($session_id != 0) {
$sql_query .= ' AND id_session = '.$session_id;
$sql_query .= ' AND scu.id_session = '.$session_id;
}
$rs = Database::query($sql_query);
while($student = Database::fetch_array($rs)) {
$students[$student['id_user']] = $student;

@ -510,7 +510,7 @@ class SessionManager
public static function get_session_lp_progress($sessionId = 0, $courseId = 0, $date_from, $date_to, $options)
{
//escaping vars
$sessionId = intval($sessionId);
$sessionId = $sessionId == 'T' ? 'T' : intval($sessionId);
$courseId = intval($courseId);
$date_from = Database :: escape_string($date_from);
$date_to = Database :: escape_string($date_to);
@ -533,8 +533,14 @@ class SessionManager
// Registered students in session.
$users = CourseManager :: get_student_list_from_course_code($course_code, true, $sessionId);
}*/
$sessionCond = 'and id_session = %s';
if ($sessionId == 'T') {
$sessionCond = "";
}
$where = " WHERE course_code = '%s'
AND s.status <> 2 and id_session = %s";
AND s.status <> 2 $sessionCond";
$limit = null;
if (!empty($options['limit'])) {
@ -554,9 +560,9 @@ class SessionManager
FROM $session_course_user s
INNER JOIN $user u ON u.user_id = s.id_user
$where $order $limit";
$sql_query = sprintf($sql, $course['code'], $sessionId);
$rs = Database::query($sql_query);
while ($user = Database::fetch_array($rs))
{
@ -576,13 +582,19 @@ class SessionManager
'username' => $user[3],
);
$sessionCond = 'AND v.session_id = %d';
if ($sessionId == 'T') {
$sessionCond = "";
}
//Get lessons progress by user
$sql = "SELECT v.lp_id as id, v.progress
FROM $tbl_course_lp_view v
WHERE v.session_id = %d
AND v.c_id = %d
AND v.user_id = %d";
$sql_query = sprintf($sql, $sessionId, $courseId, $user['user_id']);
WHERE v.c_id = %d
AND v.user_id = %d
$sessionCond";
$sql_query = sprintf($sql, $courseId, $user['user_id'], $sessionId);
$result = Database::query($sql_query);
@ -1046,6 +1058,7 @@ class SessionManager
$course = Database :: get_main_table(TABLE_MAIN_COURSE);
$track_e_login = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$track_e_course_access = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
$sessionTable = Database :: get_main_table(TABLE_MAIN_SESSION);
global $export_csv;
if ($export_csv) {
@ -1101,7 +1114,8 @@ class SessionManager
a.counter,
c.title,
c.code,
u.user_id
u.user_id,
a.session_id
FROM $track_e_course_access a
INNER JOIN $user u ON a.user_id = u.user_id
INNER JOIN $course c ON a.course_code = c.code
@ -1116,6 +1130,14 @@ class SessionManager
//foreach
foreach ($data as $key => $info) {
$sql = "SELECT
name
FROM $sessionTable
WHERE
id = {$info['session_id']}";
$result = Database::query($sql);
$session = Database::fetch_assoc($result);
//We are not using this becaouse the range its to small and no other date match the condition of this function
//$clicks = Tracking::get_total_clicks($info['user_id'], $courseId, $sessionId, $info['login_course_date'], $info['logout_course_date']);
@ -1129,7 +1151,7 @@ class SessionManager
'clicks' => $info['counter'], //+ $clicks[$info['user_id']],
'ip' => '',
'timeLoggedIn' => gmdate("H:i:s", strtotime($info['logout_course_date']) - strtotime($info['login_course_date'])),
);
'session' => $session['name']);
}
//Search for ip, we do less querys if we iterate the final array
foreach ($return as $key => $info) {
@ -2481,7 +2503,37 @@ class SessionManager
}
return $courses;
}
/**
* Gets the list of courses by session filtered by access_url
* @param int session id
* @param string course_name
* @return array list of courses
*/
public static function get_course_list_by_session_id_like($session_id, $course_name = '')
{
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
// select the courses
$sql = "SELECT * FROM $tbl_course c INNER JOIN $tbl_session_rel_course src ON c.code = src.course_code
WHERE src.id_session like '$session_id'";
if (!empty($course_name))
{
$course_name = Database::escape_string($course_name);
$sql .= " AND UPPER(c.title) LIKE UPPER('%$course_name%') ";
}
$sql .= "ORDER BY title;";
$result = Database::query($sql);
$num_rows = Database::num_rows($result);
$courses = array();
if ($num_rows > 0) {
while ($row = Database::fetch_array($result,'ASSOC')) {
$courses[$row['id']] = $row;
}
}
return $courses;
}
/**
* Get the session id based on the original id and field name in the extra fields. Returns 0 if session was not found
*

@ -3305,6 +3305,7 @@ class Tracking
//none is empty
$course = api_get_course_info_by_id($courseId);
$courses[$courseId] = array($course['code']);
$courses[$courseId]['code'] = $course['code'];
$sessions[$sessionId] = api_get_session_info($sessionId);
} else {
//both are empty, not enough data, return an empty array
@ -3416,6 +3417,7 @@ class Tracking
$users[$rowUser['user_id']] = $rowUser;
}
foreach ($data as $id => $row) {
$data[$id]['session'] = $sessions[$row['session_id']]['name'];
$data[$id]['firstname'] = $users[$row['user_id']]['firstname'];
$data[$id]['lastname'] = $users[$row['user_id']]['lastname'];
$data[$id]['username'] = $users[$row['user_id']]['username'];

@ -34,7 +34,7 @@ $nameTools = get_lang('MySpace');
$user_id = api_get_user_id();
$is_coach = api_is_coach($_GET['session_id']); // This is used?
$session_id = isset($_GET['session_id']) ? intval($_GET['session_id']) : 0;
$session_id = isset($_GET['session_id']) ? ($_GET['session_id'] == 'T' ? 'T' :intval($_GET['session_id'])) : 0;
$is_platform_admin = api_is_platform_admin();
$is_drh = api_is_drh();
@ -617,7 +617,7 @@ if ($is_platform_admin && in_array($view, array('admin')) && $display != 'yourst
//Session Filter
$sessionFilter = new FormValidator('session_filter', 'get', '', '', array('class'=> 'form-horizontal'), false);
$sessionAjax = "search_session";
switch ($display) {
case 'coaches':
$tool_name = get_lang('DisplayCoaches');
@ -636,6 +636,7 @@ if ($is_platform_admin && in_array($view, array('admin')) && $display != 'yourst
break;
case 'lpprogressoverview':
$tool_name = get_lang('DisplayLpProgressOverview');
$sessionAjax = 'search_session_all';
break;
case 'progressoverview':
$tool_name = get_lang('DisplayProgressOverview');
@ -649,21 +650,31 @@ if ($is_platform_admin && in_array($view, array('admin')) && $display != 'yourst
}
$sessionFilter->addElement('header', '', $tool_name);
$url = $ajax_path . 'session.ajax.php?a=search_session';
$url = $ajax_path . 'session.ajax.php?a=' . $sessionAjax;
$sessionList = array();
$sessionId = isset($_GET['session_id']) ? $_GET['session_id'] : null;
if (!empty($sessionId)) {
$sessionList = array();
$sessionInfo = SessionManager::fetch($sessionId);
$sessionList[] = array('id' => $sessionInfo['id'], 'text' => $sessionInfo['name']);
if ($sessionId == 'T') {
$sessionInfo = SessionManager::fetch($sessionId);
$sessionList[] = array('id' => 'T', 'text' => 'TODOS');
} else {
$sessionInfo = SessionManager::fetch($sessionId);
$sessionList[] = array('id' => $sessionInfo['id'], 'text' => $sessionInfo['name']);
}
}
$sessionFilter->addElement('select_ajax', 'session_name', get_lang('SearchSession'), null, array('url' => $url, 'defaults' => $sessionList, 'width' => '400px'));
//course filter
$a = 'search_course';
if (!empty($_GET['session_id'])) {
$a = 'search_course_by_session';
$a = 'search_course_by_session';
}
if ($display == 'lpprogressoverview') {
$a = 'search_course_by_session_all';
}
$url = $ajax_path . 'course.ajax.php?a='. $a .'&session_id=' . $_GET['session_id'];
$courseList = array();
@ -782,19 +793,25 @@ if ($is_platform_admin && in_array($view, array('admin')) && $display != 'yourst
}*/
//date filter
if (!in_array($display, array('surveyoverview', 'progressoverview', 'lpprogressoverview'))) {
// if (!in_array($display, array('surveyoverview', 'progressoverview', 'lpprogressoverview'))) {
$sessionFilter->addElement('text', 'from', get_lang('From'), array('id' => 'date_from', 'value' => (!empty($_GET['date_from']) ? $_GET['date_from'] : ''), 'style' => 'width:75px' ));
$sessionFilter->addElement('text', 'to', get_lang('Until'), array('id' => 'date_to', 'value' => (!empty($_GET['date_to']) ? $_GET['date_to'] : ''), 'style' => 'width:75px' ));
}
// }
$sessionFilter->addElement('submit', '', get_lang('Generate'), 'id="generateReport"');
echo '<div class="">';
echo $sessionFilter->return_form();
echo '</div>';
$a = 'search_course';
if (!empty($_GET['session_id'])) {
$a = 'search_course_by_session';
}
if ($display == 'lpprogressoverview') {
$a = 'search_course_by_session_all';
}
$url = $ajax_path . 'course.ajax.php?a='. $a .'&session_id=' . $_GET['session_id'];
echo '<script>
$(function() {
@ -832,7 +849,7 @@ if ($is_platform_admin && in_array($view, array('admin')) && $display != 'yourst
$("#session_name").on("change", function() {
var sessionId = $(this).val();
//window.location = "'.$self.'?view=admin&display='.$display.'&session_id="+sessionId;
select2("#course_name", "' . $ajax_path . 'course.ajax.php?a=search_course_by_session&session_id=" + sessionId);
select2("#course_name", "' . $ajax_path . 'course.ajax.php?a=' . $a . '&session_id=" + sessionId);
});
if (display == "lpprogressoverview" || display == "progressoverview" || display == "surveyoverview") {
@ -937,7 +954,7 @@ if ($is_platform_admin && in_array($view, array('admin')) && $display != 'yourst
} else if($display == 'lpprogressoverview') {
if (!empty($_GET['session_id'])) {
if (!empty($_GET['course_id'])) {
echo MySpace::display_tracking_lp_progress_overview(intval($_GET['session_id']), intval($_GET['course_id']), $_GET['date_from'], $_GET['date_to']);
echo MySpace::display_tracking_lp_progress_overview($sessionId, intval($_GET['course_id']), $_GET['date_from'], $_GET['date_to']);
} else {
Display::display_warning_message(get_lang('ChooseCourse'));
}

@ -664,6 +664,7 @@ class MySpace {
get_lang('Clicks'),
get_lang('IP'),
get_lang('TimeLoggedIn'),
get_lang('Session'),
);
$column_model = array(
@ -674,6 +675,7 @@ class MySpace {
array('name'=>'clicks', 'index'=>'clicks', 'align'=>'left', 'search' => 'true'),
array('name'=>'ip', 'index'=>'ip', 'align'=>'left', 'search' => 'true'),
array('name'=>'timeloggedin', 'index'=>'timeLoggedIn', 'align'=>'left', 'search' => 'true'),
array('name'=>'session', 'index'=>'session', 'align'=>'left')
);
$action_links = '';

Loading…
Cancel
Save