function retriveTrack($id_reference, $id_test, $id_user, $do_not_create = false) { $id_track = false; if (isset($_POST['idTrack']) || isset($_GET['idTrack'])) { return importVar('idTrack', true, 0); } if ($id_reference !== FALSE) { if (Track_Test::isTrack(Docebo::user()->getIdst(), $id_test, $id_reference)) { // Load existing info track $track_info = Track_Test::getTrackInfo($id_user, $id_test, $id_reference); $id_track = $track_info['idTrack']; } elseif ($do_not_create == false) { $id_track = Track_Test::createNewTrack($id_user, $id_test, $id_reference); if ($id_track) { Track_Test::createTrack($id_reference, $id_track, $id_user, date('Y-m-d H:i:s'), 'attempted', 'test'); } else { $id_track = false; } } } else { // try to retrive by user, test $id_track = Track_Test::getTrack($id_test, $id_user); if (!$id_track) { // create a new one $id_track = Track_Test::createNewTrack($id_user, $id_test, 0); } } return $id_track; }
/** * save some score info related with id_test and is_user * @param int $id_test the id of the test, * @param array $users_scores the score of the users associated with the proper idst_userid * @param array $date_attempts the date of the attempt time * @param array $comments comments to the test */ function saveTestUsersScores($id_test, $users_scores, $date_attempts, $comments) { require_once $GLOBALS['where_lms'] . '/class.module/track.test.php'; $query_test = "\r\n\t\tSELECT point_required, show_only_status \r\n\t\tFROM " . $GLOBALS['prefix_lms'] . "_test \r\n\t\tWHERE idTest = '" . $id_test . "'"; $re_test = sql_query($query_test); list($point_required, $show_only_status) = sql_fetch_row($re_test); $old_scores =& $this->getTestsScores(array($id_test), false, true); $re = true; while (list($idst_user, $score) = each($users_scores)) { $query_scores = "\r\n\t\t\tUPDATE " . $GLOBALS['prefix_lms'] . "_testtrack\r\n\t\t\tSET date_attempt_mod = '" . Format::dateDb($date_attempts[$idst_user]) . "', \r\n\t\t\t\tbonus_score = '" . ($score - $old_scores[$id_test][$idst_user]['score']) . "', \r\n\t\t\t\tscore_status = 'valid',\r\n\t\t\t\tcomment = '" . $comments[$idst_user] . "'\r\n\t\t\tWHERE idTest = '" . $id_test . "' AND idUser = '******'"; $re &= sql_query($query_scores); if ($score >= $point_required) { // update status in lesson $id_track = Track_Test::getTrack($id_test, $idst_user); if ($id_track) { $test_track = new Track_Test($id_track); $test_track->setDate(date('Y-m-d H:i:s')); $test_track->status = 'passed'; $test_track->update(); } } else { $id_track = Track_Test::getTrack($id_test, $idst_user); if ($id_track) { $test_track = new Track_Test($id_track); $test_track->setDate(date('Y-m-d H:i:s')); $test_track->status = 'failed'; $test_track->update(); } } $test_man = new TestManagement($id_test); $play_man = new PlayTestManagement($id_test, $idst_user, $id_track, $test_man); $test_info = $test_man->getTestAllInfo(); $track_info = $play_man->getTrackAllInfo(); $test_status = $score >= $point_required ? 'passed' : 'failed'; if ($test_info['use_suspension']) { $suspend_info = array(); if ($test_status == 'failed') { $suspend_info['attempts_for_suspension'] = $track_info['attempts_for_suspension'] + 1; if ($suspend_info['attempts_for_suspension'] >= $test_info['suspension_num_attempts']) { //should we reset learning_test.suspension_num_attempts ?? $suspend_info['attempts_for_suspension'] = 0; //from now on, it uses the suspended_until parameter, so only the date is needed, we can reset the attempts count $suspend_info['suspended_until'] = date("Y-m-d H:i:s", time() + $test_info['suspension_num_hours'] * 3600); } $re = Track_Test::updateTrack($id_track, $suspend_info); } else { if ($test_status == 'completed' || $test_status == 'passed') { $suspend_info['attempts_for_suspension'] = 0; $re = Track_Test::updateTrack($id_track, $suspend_info); } } } } return $re; }