Save lp_item_id and attempt id, new tracking system can check LP item spend.

See BT#15768

$_configuration['use_new_tracking_in_lp_item'] = false;
pull/2958/head
Julio Montoya 7 years ago
parent 9bc8f47b22
commit 01a2af6085
  1. 138
      main/inc/lib/tracking.lib.php
  2. 3
      main/install/configuration.dist.php
  3. 30
      main/lp/lp_ajax_save_item.php
  4. 58
      main/lp/lp_controller.php
  5. 14
      main/lp/lp_view.php

@ -158,6 +158,8 @@ class Tracking
}
$hideTime = api_get_configuration_value('hide_lp_time');
$allowNewTracking = api_get_configuration_value('use_new_tracking_in_lp_item');
$lp_id = (int) $lp_id;
$lp_item_id = (int) $lp_item_id;
$user_id = (int) $user_id;
@ -197,7 +199,7 @@ class Tracking
}
$actionColumn = null;
if ($type == 'classic') {
if ($type === 'classic') {
$actionColumn = ' <th>'.get_lang('Actions').'</th>';
}
@ -245,10 +247,10 @@ class Tracking
user_id = $user_id
$session_condition";
$res = Database::query($sql);
$view = '';
$view = 0;
if (Database::num_rows($res) > 0) {
$myrow = Database::fetch_array($res);
$view = $myrow[0];
$view = (int) $myrow[0];
}
$counter = 0;
@ -272,6 +274,14 @@ class Tracking
$result_disabled_ext_all = true;
$chapterTypes = learnpath::getChapterTypes();
$accessToPdfExport = api_is_allowed_to_edit(false, false, true);
$minimunAvailable = self::minimunTimeAvailable($session_id, $course_id);
$timeCourse = [];
if ($minimunAvailable) {
$timeCourse = self::getCalculateTime($user_id, $course_id, $session_id);
Session::write('trackTimeCourse', $timeCourse);
}
// Show lp items
if (is_array($list) && count($list) > 0) {
foreach ($list as $my_item_id) {
@ -321,6 +331,33 @@ class Tracking
$num = Database::num_rows($result);
$time_for_total = 0;
if ($allowNewTracking && $timeCourse) {
$attemptResult = 0;
if (isset($timeCourse['learnpath_detailed']) &&
isset($timeCourse['learnpath_detailed'][$lp_id]) &&
isset($timeCourse['learnpath_detailed'][$lp_id][$my_item_id])
) {
$attemptResult = $timeCourse['learnpath_detailed'][$lp_id][$my_item_id][$view];
}
/*$sql = " SELECT MIN(date_reg) min, MAX(date_reg) max, TIMESTAMPDIFF(SECOND, MIN(date_reg), MAX(date_reg)) diff_sec
FROM track_e_access_complete
WHERE
tool_id = $lp_id AND
user_id = $user_id AND
tool_id_detail = $my_item_id AND
c_id = $course_id AND
session_id = $session_id AND
login_as = 0 AND
current_id <> 0 AND
action_details = $view
LIMIT 1
";
$attemptResult = Database::query($sql);
$attemptResult = Database::fetch_array($attemptResult, 'ASSOC');
*/
}
// Extend all
if (($extend_this || $extend_all) && $num > 0) {
$row = Database::fetch_array($result);
@ -345,7 +382,7 @@ class Tracking
// If there are several attempts, and the link to extend has been clicked, show each attempt...
$oddclass = 'row_even';
if (($counter % 2) == 0) {
if (($counter % 2) === 0) {
$oddclass = 'row_odd';
}
$extend_link = '';
@ -405,6 +442,15 @@ class Tracking
$extend_attempt_link = '';
$extend_this_attempt = 0;
if ($allowNewTracking && $timeCourse) {
//$attemptResult = 0;
if (isset($timeCourse['learnpath_detailed']) &&
isset($timeCourse['learnpath_detailed'][$lp_id]) &&
isset($timeCourse['learnpath_detailed'][$lp_id][$my_item_id])
) {
$attemptResult = $timeCourse['learnpath_detailed'][$lp_id][$my_item_id][$row['iv_view_count']];
}
}
if ((
learnpath::get_interactions_count_from_db($row['iv_id'], $course_id) > 0 ||
learnpath::get_objectives_count_from_db($row['iv_id'], $course_id) > 0
@ -451,16 +497,24 @@ class Tracking
$lesson_status = $row['mystatus'];
$score = $row['myscore'];
$time_for_total = $row['mytime'];
$attemptTime = $row['mytime'];
if (self::minimunTimeAvailable($session_id, $course_id)) {
$timeCourse = self::getCalculateTime($user_id, $course_id, $session_id);
Session::write('trackTimeCourse', $timeCourse);
if ($minimunAvailable) {
$lp_time = $timeCourse[TOOL_LEARNPATH];
$lpTime = (int) $lp_time[$lp_id];
$lpTime = null;
if (isset($lp_time[$lp_id])) {
$lpTime = (int) $lp_time[$lp_id];
}
$time_for_total = $lpTime;
if ($allowNewTracking) {
$time_for_total = (int) $attemptResult;
$attemptTime = (int) $attemptResult;
}
}
$time = learnpathItem::getScormTimeFromParameter('js', $row['mytime']);
//$time = learnpathItem::getScormTimeFromParameter('js', $attemptTime).' - '.learnpathItem::getScormTimeFromParameter('js',$attemptResult);
$time = learnpathItem::getScormTimeFromParameter('js', $attemptTime);
if ($score == 0) {
$maxscore = $row['mymaxscore'];
@ -481,7 +535,7 @@ class Tracking
// Remove "NaN" if any (@todo: locate the source of these NaN)
$time = str_replace('NaN', '00'.$h.'00\'00"', $time);
if ($row['item_type'] != 'dir') {
if ($row['item_type'] !== 'dir') {
if (!$is_allowed_to_edit && $result_disabled_ext_all) {
$view_score = Display::return_icon(
'invisible.png',
@ -557,7 +611,7 @@ class Tracking
$counter++;
$action = null;
if ($type == 'classic') {
if ($type === 'classic') {
$action = '<td></td>';
}
@ -592,10 +646,9 @@ class Tracking
}
$list2 = learnpath::get_iv_objectives_array($row['iv_id'], $course_id);
foreach ($list2 as $id => $interaction) {
if (($counter % 2) == 0) {
$oddclass = 'row_even';
if (($counter % 2) === 0) {
$oddclass = 'row_odd';
} else {
$oddclass = 'row_even';
}
$output .= '<tr class="'.$oddclass.'">
<td></td>
@ -626,7 +679,7 @@ class Tracking
$my_path = Database::escape_string($my_path);
$sql = "SELECT results_disabled
FROM $TBL_QUIZ
WHERE c_id = $course_id AND id ='".$my_path."'";
WHERE c_id = $course_id AND id = '$my_path' ";
$res_result_disabled = Database::query($sql);
$row_result_disabled = Database::fetch_row($res_result_disabled);
@ -676,11 +729,14 @@ class Tracking
$lesson_status = $row['mystatus'];
$score = $row['myscore'];
$subtotal_time = $row['mytime'];
while ($tmp_row = Database::fetch_array($result)) {
$subtotal_time += $tmp_row['mytime'];
}
if ($allowNewTracking) {
$subtotal_time = $attemptResult;
}
$title = $row['mytitle'];
// Selecting the exe_id from stats attempts tables in order to look the max score value.
$sql = 'SELECT * FROM '.$tbl_stats_exercices.'
@ -760,7 +816,7 @@ class Tracking
$maxscore = $row_max_score['maxscore'];
// Get duration time from track_e_exercises.exe_duration instead of lp_view_item.total_time
$sql = 'SELECT SUM(exe_duration) exe_duration
$sql = 'SELECT SUM(exe_duration) exe_duration
FROM '.$tbl_stats_exercices.'
WHERE
exe_exo_id="'.$row['path'].'" AND
@ -822,7 +878,7 @@ class Tracking
} else {
$correct_test_link = '-';
$showRowspan = false;
if ($row['item_type'] == 'quiz') {
if ($row['item_type'] === 'quiz') {
$my_url_suffix = '&course='.$courseCode.'&student_id='.$user_id.'&lp_id='.intval($row['mylpid']).'&origin='.$origin;
$sql = 'SELECT * FROM '.$tbl_stats_exercices.'
WHERE
@ -870,7 +926,7 @@ class Tracking
$title = Security::remove_XSS($title);
$action = null;
if ($type == 'classic') {
if ($type === 'classic') {
$action = '<td '.($showRowspan ? 'rowspan="2"' : '').'>'.$correct_test_link.'</td>';
}
@ -925,8 +981,7 @@ class Tracking
$temp = [];
$temp[] = api_html_entity_decode($title, ENT_QUOTES);
$temp[] = api_html_entity_decode($lesson_status, ENT_QUOTES);
if ($row['item_type'] == 'quiz') {
if ($row['item_type'] === 'quiz') {
if (!$is_allowed_to_edit && $result_disabled_ext_all) {
$temp[] = '/';
} else {
@ -945,7 +1000,7 @@ class Tracking
$counter++;
$action = null;
if ($type == 'classic') {
if ($type === 'classic') {
$action = '<td></td>';
}
@ -1187,7 +1242,7 @@ class Tracking
}
$action = null;
if ($type == 'classic') {
if ($type === 'classic') {
$action = '<td></td>';
}
@ -2858,13 +2913,6 @@ class Tracking
$use_max_score[$row_lp['id']] = $row_lp['use_max_score'];
}
if ($debug) {
echo '$lp_list: ';
var_dump($lp_list);
echo 'Use max score or not list: ';
var_dump($use_max_score);
}
// prepare filter on users
if (is_array($student_id)) {
array_walk($student_id, 'intval');
@ -2913,10 +2961,6 @@ class Tracking
lp_view_id = $lp_view_id
ORDER BY lp_item_id";
$res_lp_item = Database::query($sql);
if ($debug) {
echo 'Getting lp_items done by the user<br />';
var_dump($sql);
}
while ($row_lp_item = Database::fetch_array($res_lp_item, 'ASSOC')) {
$my_lp_item_id = $row_lp_item['lp_item_id'];
@ -3049,9 +3093,6 @@ class Tracking
LIMIT 1";
$result_last_attempt = Database::query($sql);
if ($debug) {
var_dump($sql);
}
$num = Database::num_rows($result_last_attempt);
if ($num > 0) {
$attemptResult = Database::fetch_array($result_last_attempt, 'ASSOC');
@ -3137,10 +3178,7 @@ class Tracking
c_id = $course_id AND
(item_type = 'quiz' OR item_type = 'sco') AND
lp_id = ".$lp_id;
if ($debug) {
var_dump($sql);
}
$result_have_quiz = Database::query($sql);
$result_have_quiz = Database::query($sql);
if (Database::num_rows($result_have_quiz) > 0) {
$row = Database::fetch_array($result_have_quiz, 'ASSOC');
if (is_numeric($row['count']) && $row['count'] != 0) {
@ -6758,7 +6796,6 @@ class Tracking
return [];
}
$lpTime = [];
$sql = "SELECT MIN(date_reg) min, MAX(date_reg) max
FROM track_e_access_complete
WHERE
@ -6800,7 +6837,8 @@ class Tracking
$quizTime = 0;
$result = [];
$totalTime = 0;
$lpTime = [];
$lpDetailTime = [];
foreach ($sessions as $listPerTool) {
$min = 0;
$max = 0;
@ -6853,14 +6891,23 @@ class Tracking
if (!isset($lpTime[$item['tool_id']])) {
$lpTime[$item['tool_id']] = 0;
}
$lpTime[$item['tool_id']] += $partialTime;
// Saving the attempt id "action_details"
if (!empty($item['tool_id'])) {
if (!empty($item['tool_id_detail'])) {
if (!isset($lpDetailTime[$item['tool_id']][$item['tool_id_detail']][$item['action_details']])) {
$lpDetailTime[$item['tool_id']][$item['tool_id_detail']][$item['action_details']] = 0;
}
$lpDetailTime[$item['tool_id']][$item['tool_id_detail']][$item['action_details']] += $partialTime;
}
$lpTime[$item['tool_id']] += $partialTime;
}
break;
case TOOL_QUIZ:
if (!isset($lpTime[$item['action_details']])) {
$lpTime[$item['action_details']] = 0;
}
if ($beforeItem['action'] == 'learnpath_id') {
if ($beforeItem['action'] === 'learnpath_id') {
$lpTime[$item['action_details']] += $partialTime;
} else {
$quizTime += $partialTime;
@ -6882,6 +6929,7 @@ class Tracking
$totalLp += $value;
}
$result['learnpath_detailed'] = $lpDetailTime;
$result[TOOL_LEARNPATH] = $lpTime;
$result[TOOL_QUIZ] = $quizTime;
$result['total_learnpath'] = $totalLp;

@ -1092,6 +1092,9 @@ $_configuration['profile_fields_visibility'] = [
// Only applied for courses with extra field "new_tracking_system" to "1"
//$_configuration['lp_minimum_time'] = false;
// Track LP attempts using the new tracking system.
//$_configuration['use_new_tracking_in_lp_item'] = false;
// Add collapsable option for user course categories
// ALTER TABLE user_course_category ADD collapsed TINYINT(1) DEFAULT NULL;
// $_configuration['allow_user_course_category_collapsable'] = false;

@ -121,6 +121,15 @@ function save_item(
error_log('Prerequisites are OK');
}
$logInfo = [
'tool' => TOOL_LEARNPATH,
'tool_id' => $lp_id,
'tool_id_detail' => $item_id,
'action' => 'view',
'action_details' => $myLP->getCurrentAttempt(),
];
Event::registerLog($logInfo);
if (isset($max) && $max != -1) {
$myLPI->max_score = $max;
$myLPI->set_max_score($max);
@ -490,18 +499,9 @@ function save_item(
}
if ($myLP->get_type() == 2) {
$return .= "update_stats();";
$return .= 'update_stats();';
}
$logInfo = [
'tool' => TOOL_LEARNPATH,
'tool_id' => $myLP->get_id(),
'tool_id_detail' => $myLP->get_current_item_id(),
'action' => 'save_item',
'info' => '',
];
Event::registerLog($logInfo);
// To be sure progress is updated.
$myLP->save_last();
@ -512,6 +512,16 @@ function save_item(
error_log('---------------- lp_ajax_save_item.php : save_item end ----- ');
}
$logInfo = [
'tool' => TOOL_LEARNPATH,
'tool_id' => $myLP->get_id(),
'action_details' => $myLP->getCurrentAttempt(),
'tool_id_detail' => $myLP->get_current_item_id(),
'action' => 'save_item',
];
Event::registerLog($logInfo);
return $return;
}

@ -170,10 +170,6 @@ if ($debug > 0) {
error_log(' $myrefresh: '.$myrefresh);
}
if (!empty($_REQUEST['dialog_box'])) {
$dialog_box = stripslashes(urldecode($_REQUEST['dialog_box']));
}
$lp_controller_touched = 1;
$lp_found = false;
$lpObject = Session::read('lpobject');
@ -324,6 +320,7 @@ if (empty($lp_id)) {
}
$lp_detail_id = 0;
$attemptId = 0;
switch ($action) {
case '':
case 'list':
@ -331,7 +328,8 @@ switch ($action) {
break;
case 'view':
case 'content':
$lp_detail_id = $_SESSION['oLP']->get_current_item_id();
$lp_detail_id = $oLP->get_current_item_id();
$attemptId = $oLP->getCurrentAttempt();
break;
default:
$lp_detail_id = (!empty($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0);
@ -342,6 +340,7 @@ $logInfo = [
'tool' => TOOL_LEARNPATH,
'tool_id' => $eventLpId,
'tool_id_detail' => $lp_detail_id,
'action_details' => $attemptId,
'action' => !empty($action) ? $action : 'list',
];
Event::registerLog($logInfo);
@ -362,50 +361,44 @@ if (isset($_POST['title'])) {
$redirectTo = '';
if ($debug > 0) {
error_log('action "'.$action.'" triggered');
if (!$lp_found) {
//check if the learnpath ID was defined, otherwise send back to list
error_log('No learnpath given');
}
}
switch ($action) {
case 'send_notify_teacher':
// Enviar correo al profesor
// Send notification to the teacher
$studentInfo = api_get_user_info();
$course_info = api_get_course_info();
$sessionId = api_get_session_id();
global $_configuration;
$root_web = $_configuration['root_web'];
if (api_get_session_id() > 0) {
$session_info = api_get_session_info(api_get_session_id());
$course_name = $session_info['name'];
$course_url = $root_web.'courses/'.$course_info['code'].'/index.php?id_session='.api_get_session_id();
} else {
$course_name = $course_info['title'];
$course_url = $root_web.'courses/'.$course_info['code'].'/index.php?';
$courseName = $course_info['title'];
$courseUrl = $course_info['course_public_url'];
if (!empty($sessionId)) {
$sessionInfo = api_get_session_info($sessionId);
$courseName = $sessionInfo['name'];
$courseUrl .= '?id_session='.$sessionId;
}
$url = Display::url($course_name, $course_url, ['title' => get_lang('GoToCourse')]);
$coachList = CourseManager::get_coachs_from_course(api_get_session_id(), api_get_course_int_id());
foreach ($coachList as $coach_course) {
$recipient_name = $coach_course['full_name'];
$url = Display::url($courseName, $courseUrl, ['title' => get_lang('GoToCourse')]);
$coachList = CourseManager::get_coachs_from_course($sessionId, api_get_course_int_id());
foreach ($coachList as $coach_course) {
$recipientName = $coach_course['full_name'];
$coachInfo = api_get_user_info($coach_course['user_id']);
if (empty($coachInfo)) {
continue;
}
$email = $coachInfo['email'];
$tplContent = new Template(null, false, false, false, false, false);
// variables for the default template
$tplContent->assign('name_teacher', $recipient_name);
$tplContent->assign('name_teacher', $recipientName);
$tplContent->assign('name_student', $studentInfo['complete_name']);
$tplContent->assign('course_name', $course_name);
$tplContent->assign('course_name', $courseName);
$tplContent->assign('course_url', $url);
//$tplContent->assign('telefono', $telefono);
//$tplContent->assign('prefix', $prefix);
$layoutContent = $tplContent->get_template('mail/content_ending_learnpath.tpl');
$emailBody = $tplContent->fetch($layoutContent);
api_mail_html(
$recipient_name,
$recipientName,
$email,
sprintf(get_lang('StudentXFinishedLp'), $studentInfo['complete_name']),
$emailBody,
@ -415,7 +408,9 @@ switch ($action) {
);
}
Display::addFlash(Display::return_message(get_lang('MessageSent')));
require 'lp_list.php';
$url = api_get_self().'?action=list&'.api_get_cidreq();
header('Location: '.$url);
exit;
break;
case 'add_item':
if (!$is_allowed_to_edit) {
@ -704,7 +699,6 @@ switch ($action) {
require 'lp_list.php';
} else {
Session::write('refresh', 1);
//require 'lp_build.php';
$url = api_get_self().'?action=add_item&type=step&lp_id='.intval($_SESSION['oLP']->lp_id).'&'.api_get_cidreq();
header('Location: '.$url);
exit;

@ -26,15 +26,14 @@ if ($lp_controller_touched != 1) {
require_once __DIR__.'/../inc/global.inc.php';
api_protect_course_script();
if (isset($_REQUEST['origin']) && $_REQUEST['origin'] === 'learnpath') {
$_REQUEST['origin'] = '';
}
//To prevent the template class
// To prevent the template class
$show_learnpath = true;
api_protect_course_script();
$lp_id = !empty($_GET['lp_id']) ? (int) $_GET['lp_id'] : 0;
$sessionId = api_get_session_id();
$course_code = api_get_course_id();
@ -250,7 +249,6 @@ if (!isset($src)) {
}
$src = $lp->fixBlockedLinks($src);
$lp->start_current_item(); // starts time counter manually if asset
} else {
$src = 'blank.php?error=prerequisites';
@ -313,9 +311,7 @@ if (!empty($_REQUEST['exeId']) &&
$safe_id = $lp_id;
$safe_exe_id = (int) $_REQUEST['exeId'];
if ($safe_id == strval(intval($safe_id)) &&
$safe_item_id == strval(intval($safe_item_id))
) {
if (!empty($safe_id) && !empty($safe_item_id)) {
$sql = 'SELECT start_date, exe_date, exe_result, exe_weighting, exe_exo_id, exe_duration
FROM '.$TBL_TRACK_EXERCICES.'
WHERE exe_id = '.$safe_exe_id;
@ -335,7 +331,7 @@ if (!empty($_REQUEST['exeId']) &&
WHERE
c_id = $course_id AND
lp_item_id = $safe_item_id AND
lp_view_id = ".$lp->lp_view_id."
lp_view_id = ".$lp->get_view_id()."
ORDER BY id DESC
LIMIT 1";
$res_last_attempt = Database::query($sql);

Loading…
Cancel
Save