Fix query allow validation if session id is 0 or null #2251

- Format code
pull/2487/head
jmontoyaa 7 years ago
parent 6aee6eecfa
commit 8d0c2dbf47
  1. 28
      main/inc/lib/tracking.lib.php

@ -76,7 +76,7 @@ class Tracking
return $result[0]['count']; return $result[0]['count'];
} }
$parsed_result = array(); $parsedResult = array();
if (!empty($result)) { if (!empty($result)) {
foreach ($result as $group) { foreach ($result as $group) {
$users = GroupManager::get_users($group['id'], true); $users = GroupManager::get_users($group['id'], true);
@ -120,7 +120,7 @@ class Tracking
$averageProgress = empty($countUsers) ? 0 : round($avg_student_progress / $countUsers, 2); $averageProgress = empty($countUsers) ? 0 : round($avg_student_progress / $countUsers, 2);
$averageScore = empty($countUsers) ? 0 : round($avg_student_score / $countUsers, 2); $averageScore = empty($countUsers) ? 0 : round($avg_student_score / $countUsers, 2);
$group_item = array( $groupItem = array(
'id' => $group['id'], 'id' => $group['id'],
'name' => $group['name'], 'name' => $group['name'],
'time' => api_time_to_hms($time), 'time' => api_time_to_hms($time),
@ -129,11 +129,11 @@ class Tracking
'works' => $work, 'works' => $work,
'messages' => $messages, 'messages' => $messages,
); );
$parsed_result[] = $group_item; $parsedResult[] = $groupItem;
} }
} }
return $parsed_result; return $parsedResult;
} }
/** /**
@ -2559,18 +2559,17 @@ class Tracking
} }
$conditionToString = implode('AND', $conditions); $conditionToString = implode('AND', $conditions);
$sql = " $sql = "SELECT lp_id, view_count, progress
SELECT lp_id, view_count, progress
FROM $lpViewTable lp_view FROM $lpViewTable lp_view
WHERE WHERE
$conditionToString $conditionToString
$groupBy $groupBy
ORDER BY view_count DESC ORDER BY view_count DESC";
";
$result = Database::query($sql); $result = Database::query($sql);
$progress = array(); $progress = [];
$viewCount = array(); $viewCount = [];
while ($row = Database::fetch_array($result, 'ASSOC')) { while ($row = Database::fetch_array($result, 'ASSOC')) {
if (!isset($viewCount[$row['lp_id']])) { if (!isset($viewCount[$row['lp_id']])) {
$progress[$row['lp_id']] = $row['progress']; $progress[$row['lp_id']] = $row['progress'];
@ -3737,14 +3736,12 @@ class Tracking
$student_id = intval($student_id); $student_id = intval($student_id);
$conditions[] = " ip.insert_user_id = '$student_id' "; $conditions[] = " ip.insert_user_id = '$student_id' ";
} }
if (isset($session_id)) {
$session_id = intval($session_id);
$conditions[] = " pub.session_id = $session_id ";
}
$conditions[] = ' pub.active <> 2 '; $conditions[] = ' pub.active <> 2 ';
$conditionToString = implode(' AND ', $conditions);
$conditionToString = implode('AND', $conditions); $sessionCondition = api_get_session_condition($session_id, true, false, 'pub.session_id');
$conditionToString .= $sessionCondition;
$sql = "SELECT count(ip.tool) as count $sql = "SELECT count(ip.tool) as count
FROM $tbl_item_property ip FROM $tbl_item_property ip
@ -3754,6 +3751,7 @@ class Tracking
ip.tool='work' AND ip.tool='work' AND
$conditionToString"; $conditionToString";
$rs = Database::query($sql); $rs = Database::query($sql);
$row = Database::fetch_array($rs, 'ASSOC'); $row = Database::fetch_array($rs, 'ASSOC');
return $row['count']; return $row['count'];

Loading…
Cancel
Save