Skip to content

Commit

Permalink
Fix weird scorm status update BT#8897
Browse files Browse the repository at this point in the history
Restoring file from previous change
  • Loading branch information
jmontoyaa committed Mar 26, 2015
1 parent dd2df8a commit 8095571
Showing 1 changed file with 85 additions and 97 deletions.
182 changes: 85 additions & 97 deletions main/newscorm/learnpathItem.class.php
Expand Up @@ -3817,32 +3817,30 @@ public function write_to_db()
if ($this->type == 'quiz' && $this->get_prevent_reinit() == 0 &&
$this->get_status() == 'completed'
) {
if (!api_is_invitee()) {
// We force the item to be restarted.
$this->restart();
$params = array(
"c_id" => $course_id,
"total_time" => $this->get_total_time(),
"start_time" => $this->current_start_time,
"score" => $this->get_score(),
"status" => $this->get_status(false),
"max_score" => $this->get_max(),
"lp_item_id" => $this->db_id,
"lp_view_id" => $this->view_id,
"view_count" => $this->get_attempt_id() ,
"suspend_data" => $this->current_data,
//"max_time_allowed" => ,
"lesson_location" => $this->lesson_location
// We force the item to be restarted.
$this->restart();
$params = array(
"c_id" => $course_id,
"total_time" => $this->get_total_time(),
"start_time" => $this->current_start_time,
"score" => $this->get_score(),
"status" => $this->get_status(false),
"max_score" => $this->get_max(),
"lp_item_id" => $this->db_id,
"lp_view_id" => $this->view_id,
"view_count" => $this->get_attempt_id() ,
"suspend_data" => $this->current_data,
//"max_time_allowed" => ,
"lesson_location" => $this->lesson_location
);
if (self::debug > 2) {
error_log(
'learnpathItem::write_to_db() - Inserting into item_view forced: ' . print_r($params, 1),
0
);
if (self::debug > 2) {
error_log(
'learnpathItem::write_to_db() - Inserting into item_view forced: ' . print_r($params, 1),
0
);
}
$this->db_item_view_id = Database::insert($item_view_table, $params);
$inserted = true;
}
$this->db_item_view_id = Database::insert($item_view_table, $params);
$inserted = true;
}

$item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
Expand All @@ -3862,49 +3860,45 @@ public function write_to_db()
// 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) {
if (!api_is_invitee()) {
$params = array(
"c_id" => $course_id,
"total_time" => $this->get_total_time(),
"start_time" => $this->current_start_time,
"score" => $this->get_score(),
"status" => $this->get_status(false),
"max_score" => $this->get_max(),
"lp_item_id" => $this->db_id,
"lp_view_id" => $this->view_id,
"view_count" => $this->get_attempt_id() ,
"suspend_data" => $this->current_data,
//"max_time_allowed" => ,$this->get_max_time_allowed()
"lesson_location" => $this->lesson_location
);

if (self::debug > 2) {
error_log(
'learnpathItem::write_to_db() - Inserting into item_view forced: ' . print_r($params, 1),
0
);
}
$params = array(
"c_id" => $course_id,
"total_time" => $this->get_total_time(),
"start_time" => $this->current_start_time,
"score" => $this->get_score(),
"status" => $this->get_status(false),
"max_score" => $this->get_max(),
"lp_item_id" => $this->db_id,
"lp_view_id" => $this->view_id,
"view_count" => $this->get_attempt_id() ,
"suspend_data" => $this->current_data,
//"max_time_allowed" => ,$this->get_max_time_allowed()
"lesson_location" => $this->lesson_location
);

$this->db_item_view_id = Database::insert($item_view_table, $params);
if (self::debug > 2) {
error_log(
'learnpathItem::write_to_db() - Inserting into item_view forced: ' . print_r($params, 1),
0
);
}

$this->db_item_view_id = Database::insert($item_view_table, $params);
} else {
if ($this->type == 'hotpotatoes') {
if (!api_is_invitee()) {
$params = array(
'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' => $this->current_data,
'lesson_location' => $this->lesson_location
);
$where = array(
'c_id = ? AND lp_item_id = ? AND lp_view_id = ? AND view_count = ?' =>
$params = array(
'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' => $this->current_data,
'lesson_location' => $this->lesson_location
);
$where = array(
'c_id = ? AND lp_item_id = ? AND lp_view_id = ? AND view_count = ?' =>
array($course_id, $this->db_id, $this->view_id, $this->get_attempt_id())
);
Database::update($item_view_table, $params, $where);
}
);
Database::update($item_view_table, $params, $where);
} else {
// For all other content types...
if ($this->type == 'quiz') {
Expand Down Expand Up @@ -4028,40 +4022,36 @@ public function write_to_db()
}

if ($this->type == 'sco') {
if (!api_is_invitee()) {
//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 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 {
if (!api_is_invitee()) {
//" 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();
}
//" 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();
}
Expand All @@ -4071,9 +4061,7 @@ public function write_to_db()
0
);
}
if (!empty($sql)) {
Database::query($sql);
}
Database::query($sql);
}

if (is_array($this->interactions) && count($this->interactions) > 0) {
Expand Down

0 comments on commit 8095571

Please sign in to comment.