';
$lp = new learnpath($item['code'], $lpId, $userId);
/** @var learnpathItem $lpItem */
foreach ($lp->items as $lpItem) {
if ($lpItem->get_type() == 'quiz' &&
$lpItem->get_path() == $item['exe_exo_id']
) {
$lpItemId = $lpItem->get_id();
$table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
$tableView = Database::get_course_table(TABLE_LP_VIEW);
$sql = "SELECT *, iv.id lp_item_view_id FROM $table iv INNER JOIN $tableView v
ON iv.c_id = v.c_id AND iv.lp_view_id = v.id
WHERE
lp_item_id = $lpItemId AND
iv.c_id = $courseId AND
status = 'completed' AND
user_id = $userId AND
lp_id = $lpId AND
session_id = $sessionId
";
$result = Database::query($sql);
$attempts = Database::store_result($result, 'ASSOC');
var_dump($sql);
echo '
';
$count = count($attempts);
if ($count == 1) {
$attempt = current($attempts);
$score = $item['exe_result'];
/* The attempt has empty exe_result and the LP is good
there must be another attempt, do nothing. */
if ((empty($item['exe_result']) || $item['exe_result'] == 0) && !empty($attempt['score'])) {
var_dump('Skipped');
echo '
';
continue;
}
echo "Score: ".$attempt['score']. ' - '.$item['exe_result'].'
';
$itemViewId = $attempt['lp_item_view_id'];
$sql = "UPDATE $table SET
score = $score
WHERE
id = $itemViewId AND
lp_item_id = $lpItemId AND
c_id = $courseId AND
";
//Database::query($sql);
var_dump($sql);
echo '
';
$sql = "UPDATE $tableExercise
SET orig_lp_item_view_id = $itemViewId
WHERE exe_id = $exeId";
//Database::query($sql);
var_dump($sql);
echo '
';
} else {
echo 'Cannot update multiple attempts checking attempts:
';
foreach ($attempts as $attempt) {
if ($attempt['score'] == $item['exe_result']) {
/*echo "Score: ".$attempt['score']. ' - '.$item['exe_result'].'
';
$itemViewId = $attempt['id'];
$sql = "UPDATE $tableExercise
SET orig_lp_item_view_id = $itemViewId
WHERE exe_id = $exeId";
//Database::query($sql);
var_dump($sql);
echo '
';*/
}
}
}
}
}
echo '
';
}
}