Don't register the invited users' progress in learning paths - refs BT#9070

1.10.x
Angel Fernando Quiroz Campos 11 years ago
parent 900d92f5a2
commit 41e2bfb831
  1. 57
      main/newscorm/learnpath.class.php
  2. 228
      main/newscorm/learnpathItem.class.php
  3. 2
      main/newscorm/lp_view.php

@ -204,7 +204,7 @@ class learnpath
$this->last_item_seen = $row['last_item'];
$this->progress_db = $row['progress'];
$this->lp_view_session_id = $row['session_id'];
} else {
} else if (!api_is_invited_user()) {
if ($this->debug > 2) {
error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - NOT Found previous view', 0);
}
@ -350,16 +350,18 @@ class learnpath
}
}
} else {
if (is_object($this->items[$item_id])) {
$this->items[$item_id]->set_status($this->default_status);
}
// Add that row to the lp_item_view table so that we have something to show in the stats page.
$sql_ins = "INSERT INTO $lp_item_view_table (c_id, lp_item_id, lp_view_id, view_count, status)
VALUES ($course_id, ".$item_id . "," . $this->lp_view_id . ", 1, 'not attempted')";
if ($this->debug > 2) {
error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - Inserting blank item_view : ' . $sql_ins, 0);
if (!api_is_invited_user()) {
if (is_object($this->items[$item_id])) {
$this->items[$item_id]->set_status($this->default_status);
}
// Add that row to the lp_item_view table so that we have something to show in the stats page.
$sql_ins = "INSERT INTO $lp_item_view_table (c_id, lp_item_id, lp_view_id, view_count, status)
VALUES ($course_id, ".$item_id . "," . $this->lp_view_id . ", 1, 'not attempted')";
if ($this->debug > 2) {
error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - Inserting blank item_view : ' . $sql_ins, 0);
}
Database::query($sql_ins);
}
Database::query($sql_ins);
}
}
}
@ -3619,7 +3621,7 @@ class learnpath
if (Database :: num_rows($res) > 0) {
$row = Database :: fetch_array($res);
$this->lp_view_id = $row['id'];
} else {
} else if (!api_is_invited_user()) {
// There is no database record, create one.
$sql = "INSERT INTO $lp_view_table (c_id, lp_id,user_id, view_count, session_id) VALUES
($course_id, " . $this->get_id() . "," . $this->get_user_id() . ", 1, $sessionId)";
@ -4186,6 +4188,9 @@ class learnpath
// TODO
// Call autosave method to save the current progress.
//$this->index = 0;
if (api_is_invited_user()) {
return false;
}
$session_id = api_get_session_id();
$course_id = api_get_course_int_id();
$lp_view_table = Database :: get_course_table(TABLE_LP_VIEW);
@ -4303,7 +4308,7 @@ class learnpath
$session_condition = api_get_session_condition(api_get_session_id(), true, false);
$table = Database :: get_course_table(TABLE_LP_VIEW);
if (isset($this->current)) {
if (isset($this->current) && !api_is_invited_user()) {
if ($this->debug > 2) {
error_log('New LP - Saving current item (' . $this->current . ') for later review', 0);
}
@ -4320,19 +4325,21 @@ class learnpath
Database::query($sql);
}
// Save progress.
list($progress, $text) = $this->get_progress_bar_text('%');
if ($progress >= 0 && $progress <= 100) {
$progress = (int) $progress;
$sql = "UPDATE $table SET
progress = $progress
WHERE
c_id = ".$course_id." AND
lp_id = " . $this->get_id() . " AND
user_id = " . $this->get_user_id()." ".$session_condition;
// Ignore errors as some tables might not have the progress field just yet.
Database::query($sql);
$this->progress_db = $progress;
if (!api_is_invited_user()) {
// Save progress.
list($progress, $text) = $this->get_progress_bar_text('%');
if ($progress >= 0 && $progress <= 100) {
$progress = (int) $progress;
$sql = "UPDATE $table SET
progress = $progress
WHERE
c_id = ".$course_id." AND
lp_id = " . $this->get_id() . " AND
user_id = " . $this->get_user_id()." ".$session_condition;
// Ignore errors as some tables might not have the progress field just yet.
Database::query($sql);
$this->progress_db = $progress;
}
}
}

@ -3815,42 +3815,44 @@ class learnpathItem
if ($this->type == 'quiz' && $this->get_prevent_reinit() == 0 &&
$this->get_status() == 'completed'
) {
// We force the item to be restarted.
$this->restart();
$sql = "INSERT INTO $item_view_table " .
"(c_id, total_time, " .
"start_time, " .
"score, " .
"status, " .
"max_score, " .
"lp_item_id, " .
"lp_view_id, " .
"view_count, " .
"suspend_data, " .
//"max_time_allowed," .
"lesson_location)" .
"VALUES" .
"($course_id, " . $this->get_total_time() . "," .
"" . $this->current_start_time . "," .
"" . $this->get_score() . "," .
"'" . $this->get_status(false) . "'," .
"'" . $this->get_max() . "'," .
"" . $this->db_id . "," .
"" . $this->view_id . "," .
"" . $this->get_attempt_id() . "," .
"'" . Database::escape_string($this->current_data) . "'," .
//"'".$this->get_max_time_allowed()."'," .
"'" . $this->lesson_location . "')";
if (self::debug > 2) {
error_log(
'learnpathItem::write_to_db() - Inserting into item_view forced: ' . $sql,
0
);
if (!api_is_invited_user()) {
// We force the item to be restarted.
$this->restart();
$sql = "INSERT INTO $item_view_table " .
"(c_id, total_time, " .
"start_time, " .
"score, " .
"status, " .
"max_score, " .
"lp_item_id, " .
"lp_view_id, " .
"view_count, " .
"suspend_data, " .
//"max_time_allowed," .
"lesson_location)" .
"VALUES" .
"($course_id, " . $this->get_total_time() . "," .
"" . $this->current_start_time . "," .
"" . $this->get_score() . "," .
"'" . $this->get_status(false) . "'," .
"'" . $this->get_max() . "'," .
"" . $this->db_id . "," .
"" . $this->view_id . "," .
"" . $this->get_attempt_id() . "," .
"'" . Database::escape_string($this->current_data) . "'," .
//"'".$this->get_max_time_allowed()."'," .
"'" . $this->lesson_location . "')";
if (self::debug > 2) {
error_log(
'learnpathItem::write_to_db() - Inserting into item_view forced: ' . $sql,
0
);
}
Database::query($sql);
$this->db_item_view_id = Database::insert_id();
$inserted = true;
}
Database::query($sql);
$this->db_item_view_id = Database::insert_id();
$inserted = true;
}
$item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
@ -3870,54 +3872,58 @@ class learnpathItem
// Depending on what we want (really), we'll update or insert a new row
// now save into DB.
if (!$inserted && Database::num_rows($check_res) < 1) {
$sql = "INSERT INTO $item_view_table " .
"(c_id, total_time, " .
"start_time, " .
"score, " .
"status, " .
"max_score, " .
"lp_item_id, " .
"lp_view_id, " .
"view_count, " .
"suspend_data, " .
//"max_time_allowed," .
"lesson_location)" .
"VALUES" .
"($course_id, " . $this->get_total_time() . "," .
"" . $this->current_start_time . "," .
"" . $this->get_score() . "," .
"'" . $this->get_status(false) . "'," .
"'" . $this->get_max() . "'," .
"" . $this->db_id . "," .
"" . $this->view_id . "," .
"" . $this->get_attempt_id() . "," .
"'" . Database::escape_string($this->current_data) . "'," .
//"'".$this->get_max_time_allowed()."'," .
"'" . $this->lesson_location . "')";
if (self::debug > 2) {
error_log(
'learnpathItem::write_to_db() - Inserting into item_view: ' . $sql,
0
);
if (!api_is_invited_user()) {
$sql = "INSERT INTO $item_view_table " .
"(c_id, total_time, " .
"start_time, " .
"score, " .
"status, " .
"max_score, " .
"lp_item_id, " .
"lp_view_id, " .
"view_count, " .
"suspend_data, " .
//"max_time_allowed," .
"lesson_location)" .
"VALUES" .
"($course_id, " . $this->get_total_time() . "," .
"" . $this->current_start_time . "," .
"" . $this->get_score() . "," .
"'" . $this->get_status(false) . "'," .
"'" . $this->get_max() . "'," .
"" . $this->db_id . "," .
"" . $this->view_id . "," .
"" . $this->get_attempt_id() . "," .
"'" . Database::escape_string($this->current_data) . "'," .
//"'".$this->get_max_time_allowed()."'," .
"'" . $this->lesson_location . "')";
if (self::debug > 2) {
error_log(
'learnpathItem::write_to_db() - Inserting into item_view: ' . $sql,
0
);
}
Database::query($sql);
$this->db_item_view_id = Database::insert_id();
}
Database::query($sql);
$this->db_item_view_id = Database::insert_id();
} else {
$sql = '';
if ($this->type == 'hotpotatoes') {
$sql = "UPDATE $item_view_table SET
total_time = " . $this->get_total_time() . ",
start_time = " . $this->get_current_start_time() . ",
score = " . $this->get_score() . ",
status = '" . $this->get_status(false) . "',
max_score = '" . $this->get_max() . "',
suspend_data = '" . Database::escape_string($this->current_data) . "',
lesson_location = '" . $this->lesson_location . "'
WHERE
c_id = $course_id AND
lp_item_id = " . $this->db_id . " AND
lp_view_id = " . $this->view_id . " AND
view_count = " . $this->get_attempt_id();
if (!api_is_invited_user()) {
$sql = "UPDATE $item_view_table SET
total_time = " . $this->get_total_time() . ",
start_time = " . $this->get_current_start_time() . ",
score = " . $this->get_score() . ",
status = '" . $this->get_status(false) . "',
max_score = '" . $this->get_max() . "',
suspend_data = '" . Database::escape_string($this->current_data) . "',
lesson_location = '" . $this->lesson_location . "'
WHERE
c_id = $course_id AND
lp_item_id = " . $this->db_id . " AND
lp_view_id = " . $this->view_id . " AND
view_count = " . $this->get_attempt_id();
}
} else {
// For all other content types...
if ($this->type == 'quiz') {
@ -4041,36 +4047,40 @@ class learnpathItem
}
if ($this->type == 'sco') {
//IF scorm scorm_update_time has already updated total_time in db
//" . //start_time = ".$this->get_current_start_time().", " . //scorm_init_time does it
////" max_time_allowed = '".$this->get_max_time_allowed()."'," .
$sql = "UPDATE $item_view_table SET
score = " . $this->get_score() . ",
$my_status
max_score = '" . $this->get_max() . "',
suspend_data = '" . Database::escape_string($this->current_data) . "',
lesson_location = '" . $this->lesson_location . "'
WHERE
c_id = $course_id AND
lp_item_id = " . $this->db_id . "AND
lp_view_id = " . $this->view_id . " AND
view_count = " . $this->get_attempt_id();
if (!api_is_invited_user()) {
//IF scorm scorm_update_time has already updated total_time in db
//" . //start_time = ".$this->get_current_start_time().", " . //scorm_init_time does it
////" max_time_allowed = '".$this->get_max_time_allowed()."'," .
$sql = "UPDATE $item_view_table SET
score = " . $this->get_score() . ",
$my_status
max_score = '" . $this->get_max() . "',
suspend_data = '" . Database::escape_string($this->current_data) . "',
lesson_location = '" . $this->lesson_location . "'
WHERE
c_id = $course_id AND
lp_item_id = " . $this->db_id . "AND
lp_view_id = " . $this->view_id . " AND
view_count = " . $this->get_attempt_id();
}
} else {
//" max_time_allowed = '".$this->get_max_time_allowed()."'," .
$sql = "UPDATE $item_view_table SET
$total_time
start_time = " . $this->get_current_start_time() . ",
score = " . $this->get_score() . ",
$my_status
max_score = '" . $this->get_max() . "',
suspend_data = '" . Database::escape_string($this->current_data) . "',
lesson_location = '" . $this->lesson_location . "'
WHERE
c_id = $course_id AND
lp_item_id = " . $this->db_id . " AND
lp_view_id = " . $this->view_id . " AND
view_count = " . $this->get_attempt_id();
if (!api_is_invited_user()) {
//" max_time_allowed = '".$this->get_max_time_allowed()."'," .
$sql = "UPDATE $item_view_table SET
$total_time
start_time = " . $this->get_current_start_time() . ",
score = " . $this->get_score() . ",
$my_status
max_score = '" . $this->get_max() . "',
suspend_data = '" . Database::escape_string($this->current_data) . "',
lesson_location = '" . $this->lesson_location . "'
WHERE
c_id = $course_id AND
lp_item_id = " . $this->db_id . " AND
lp_view_id = " . $this->view_id . " AND
view_count = " . $this->get_attempt_id();
}
}
$this->current_start_time = time();
}
@ -4080,7 +4090,9 @@ class learnpathItem
0
);
}
Database::query($sql);
if (!empty($sql)) {
Database::query($sql);
}
}
if (is_array($this->interactions) && count($this->interactions) > 0) {

@ -255,7 +255,7 @@ if (!empty($_REQUEST['exeId']) &&
LIMIT 1";
$res_last_attempt = Database::query($sql);
if (Database::num_rows($res_last_attempt)) {
if (Database::num_rows($res_last_attempt) && !api_is_invited_user()) {
$row_last_attempt = Database::fetch_row($res_last_attempt);
$lp_item_view_id = $row_last_attempt[0];
$sql = "UPDATE $TBL_LP_ITEM_VIEW SET

Loading…
Cancel
Save