本文整理汇总了PHP中quiz_get_user_attempts函数的典型用法代码示例。如果您正苦于以下问题:PHP quiz_get_user_attempts函数的具体用法?PHP quiz_get_user_attempts怎么用?PHP quiz_get_user_attempts使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了quiz_get_user_attempts函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: accessmanager_process
private static function accessmanager_process($quizobj, $accessmanager, $forcenew, $uid)
{
self::new_preview_request($quizobj, $accessmanager, $forcenew, $uid);
// Look for an existing attempt.
$attempts = quiz_get_user_attempts($quizobj->get_quizid(), $uid, 'all', true);
$lastattempt = end($attempts);
// Get number for the next or unfinished attempt.
if ($lastattempt && !$lastattempt->preview && !$quizobj->is_preview_user()) {
$attemptnumber = $lastattempt->attempt + 1;
} else {
$lastattempt = false;
$attemptnumber = 1;
}
$currentattemptid = null;
$accessmanager->notify_preflight_check_passed($currentattemptid);
// Delete any previous preview attempts belonging to this user.
quiz_delete_previews($quizobj->get_quiz(), $uid);
$res = new stdClass();
$res->lastattempt = $lastattempt;
$res->attemptnumber = $attemptnumber;
return $res;
}
示例2: quiz_validate_new_attempt
/**
* Validate permissions for creating a new attempt and start a new preview attempt if required.
*
* @param quiz $quizobj quiz object
* @param quiz_access_manager $accessmanager quiz access manager
* @param bool $forcenew whether was required to start a new preview attempt
* @param int $page page to jump to in the attempt
* @param bool $redirect whether to redirect or throw exceptions (for web or ws usage)
* @return array an array containing the attempt information, access error messages and the page to jump to in the attempt
* @throws moodle_quiz_exception
* @since Moodle 3.1
*/
function quiz_validate_new_attempt(quiz $quizobj, quiz_access_manager $accessmanager, $forcenew, $page, $redirect)
{
global $DB, $USER;
$timenow = time();
if ($quizobj->is_preview_user() && $forcenew) {
$accessmanager->current_attempt_finished();
}
// Check capabilities.
if (!$quizobj->is_preview_user()) {
$quizobj->require_capability('mod/quiz:attempt');
}
// Check to see if a new preview was requested.
if ($quizobj->is_preview_user() && $forcenew) {
// To force the creation of a new preview, we mark the current attempt (if any)
// as finished. It will then automatically be deleted below.
$DB->set_field('quiz_attempts', 'state', quiz_attempt::FINISHED, array('quiz' => $quizobj->get_quizid(), 'userid' => $USER->id));
}
// Look for an existing attempt.
$attempts = quiz_get_user_attempts($quizobj->get_quizid(), $USER->id, 'all', true);
$lastattempt = end($attempts);
$attemptnumber = null;
// If an in-progress attempt exists, check password then redirect to it.
if ($lastattempt && ($lastattempt->state == quiz_attempt::IN_PROGRESS || $lastattempt->state == quiz_attempt::OVERDUE)) {
$currentattemptid = $lastattempt->id;
$messages = $accessmanager->prevent_access();
// If the attempt is now overdue, deal with that.
$quizobj->create_attempt_object($lastattempt)->handle_if_time_expired($timenow, true);
// And, if the attempt is now no longer in progress, redirect to the appropriate place.
if ($lastattempt->state == quiz_attempt::ABANDONED || $lastattempt->state == quiz_attempt::FINISHED) {
if ($redirect) {
redirect($quizobj->review_url($lastattempt->id));
} else {
throw new moodle_quiz_exception($quizobj, 'attemptalreadyclosed');
}
}
// If the page number was not explicitly in the URL, go to the current page.
if ($page == -1) {
$page = $lastattempt->currentpage;
}
} else {
while ($lastattempt && $lastattempt->preview) {
$lastattempt = array_pop($attempts);
}
// Get number for the next or unfinished attempt.
if ($lastattempt) {
$attemptnumber = $lastattempt->attempt + 1;
} else {
$lastattempt = false;
$attemptnumber = 1;
}
$currentattemptid = null;
$messages = $accessmanager->prevent_access() + $accessmanager->prevent_new_attempt(count($attempts), $lastattempt);
if ($page == -1) {
$page = 0;
}
}
return array($currentattemptid, $attemptnumber, $lastattempt, $messages, $page);
}
示例3: get_attempt_access_information
/**
* Return access information for a given attempt in a quiz.
*
* @param int $quizid quiz instance id
* @param int $attemptid attempt id, 0 for the user last attempt if exists
* @return array of warnings and the access information
* @since Moodle 3.1
* @throws moodle_quiz_exception
*/
public static function get_attempt_access_information($quizid, $attemptid = 0)
{
global $DB, $USER;
$warnings = array();
$params = array('quizid' => $quizid, 'attemptid' => $attemptid);
$params = self::validate_parameters(self::get_attempt_access_information_parameters(), $params);
list($quiz, $course, $cm, $context) = self::validate_quiz($params['quizid']);
$attempttocheck = 0;
if (!empty($params['attemptid'])) {
$attemptobj = quiz_attempt::create($params['attemptid']);
if ($attemptobj->get_userid() != $USER->id) {
throw new moodle_quiz_exception($attemptobj->get_quizobj(), 'notyourattempt');
}
$attempttocheck = $attemptobj->get_attempt();
}
// Access manager now.
$quizobj = quiz::create($cm->instance, $USER->id);
$ignoretimelimits = has_capability('mod/quiz:ignoretimelimits', $context, null, false);
$timenow = time();
$accessmanager = new quiz_access_manager($quizobj, $timenow, $ignoretimelimits);
$attempts = quiz_get_user_attempts($quiz->id, $USER->id, 'finished', true);
$lastfinishedattempt = end($attempts);
if ($unfinishedattempt = quiz_get_user_attempt_unfinished($quiz->id, $USER->id)) {
$attempts[] = $unfinishedattempt;
// Check if the attempt is now overdue. In that case the state will change.
$quizobj->create_attempt_object($unfinishedattempt)->handle_if_time_expired(time(), false);
if ($unfinishedattempt->state != quiz_attempt::IN_PROGRESS and $unfinishedattempt->state != quiz_attempt::OVERDUE) {
$lastfinishedattempt = $unfinishedattempt;
}
}
$numattempts = count($attempts);
if (!$attempttocheck) {
$attempttocheck = $unfinishedattempt ? $unfinishedattempt : $lastfinishedattempt;
}
$result = array();
$result['isfinished'] = $accessmanager->is_finished($numattempts, $lastfinishedattempt);
$result['preventnewattemptreasons'] = $accessmanager->prevent_new_attempt($numattempts, $lastfinishedattempt);
if ($attempttocheck) {
$endtime = $accessmanager->get_end_time($attempttocheck);
$result['endtime'] = $endtime === false ? 0 : $endtime;
$attemptid = $unfinishedattempt ? $unfinishedattempt->id : null;
$result['ispreflightcheckrequired'] = $accessmanager->is_preflight_check_required($attemptid);
}
$result['warnings'] = $warnings;
return $result;
}
示例4: quiz_save_best_grade
/**
* Save the overall grade for a user at a quiz in the quiz_grades table
*
* @param object $quiz The quiz for which the best grade is to be calculated and then saved.
* @param integer $userid The userid to calculate the grade for. Defaults to the current user.
* @return boolean Indicates success or failure.
*/
function quiz_save_best_grade($quiz, $userid = null)
{
global $USER;
if (empty($userid)) {
$userid = $USER->id;
}
// Get all the attempts made by the user
if (!($attempts = quiz_get_user_attempts($quiz->id, $userid))) {
notify('Could not find any user attempts');
return false;
}
// Calculate the best grade
$bestgrade = quiz_calculate_best_grade($quiz, $attempts);
$bestgrade = quiz_rescale_grade($bestgrade, $quiz);
// Save the best grade in the database
if ($grade = get_record('quiz_grades', 'quiz', $quiz->id, 'userid', $userid)) {
$grade->grade = $bestgrade;
$grade->timemodified = time();
if (!update_record('quiz_grades', $grade)) {
notify('Could not update best grade');
return false;
}
} else {
$grade->quiz = $quiz->id;
$grade->userid = $userid;
$grade->grade = $bestgrade;
$grade->timemodified = time();
if (!insert_record('quiz_grades', $grade)) {
notify('Could not insert new best grade');
return false;
}
}
quiz_update_grades($quiz, $userid);
return true;
}
示例5: print_string
<input type="submit" name="cancelpassword" value="<?php
print_string('cancel');
?>
" />
</div>
</form>
<?php
print_box_end();
print_footer('empty');
exit;
}
}
}
if (!empty($quiz->delay1) or !empty($quiz->delay2)) {
//quiz enforced time delay
if ($attempts = quiz_get_user_attempts($quiz->id, $USER->id)) {
$numattempts = count($attempts);
} else {
$numattempts = 0;
}
$timenow = time();
$lastattempt_obj = get_record_select('quiz_attempts', "quiz = {$quiz->id} AND attempt = {$numattempts} AND userid = {$USER->id}", 'timefinish, timestart');
if ($lastattempt_obj) {
$lastattempt = $lastattempt_obj->timefinish;
if ($quiz->timelimit > 0) {
$lastattempt = min($lastattempt, $lastattempt_obj->timestart + $quiz->timelimit * 60);
}
}
if ($numattempts == 1 && !empty($quiz->delay1)) {
if ($timenow - $quiz->delay1 < $lastattempt) {
print_error('timedelay', 'quiz', 'view.php?q=' . $quiz->id);
示例6: array
$accessmanager = $quizobj->get_access_manager($timenow);
if ($quizobj->is_preview_user() && $forcenew) {
$accessmanager->current_attempt_finished();
}
// Check capabilities.
if (!$quizobj->is_preview_user()) {
$quizobj->require_capability('mod/quiz:attempt');
}
// Check to see if a new preview was requested.
if ($quizobj->is_preview_user() && $forcenew) {
// To force the creation of a new preview, we mark the current attempt (if any)
// as finished. It will then automatically be deleted below.
$DB->set_field('quiz_attempts', 'state', quiz_attempt::FINISHED, array('quiz' => $quizobj->get_quizid(), 'userid' => $USER->id));
}
// Look for an existing attempt.
$attempts = quiz_get_user_attempts($quizobj->get_quizid(), $USER->id, 'all', true);
$lastattempt = end($attempts);
// If an in-progress attempt exists, check password then redirect to it.
if ($lastattempt && ($lastattempt->state == quiz_attempt::IN_PROGRESS || $lastattempt->state == quiz_attempt::OVERDUE)) {
$currentattemptid = $lastattempt->id;
$messages = $accessmanager->prevent_access();
// If the attempt is now overdue, deal with that.
$quizobj->create_attempt_object($lastattempt)->handle_if_time_expired($timenow, true);
// And, if the attempt is now no longer in progress, redirect to the appropriate place.
if ($lastattempt->state == quiz_attempt::OVERDUE) {
redirect($quizobj->summary_url($lastattempt->id));
} else {
if ($lastattempt->state != quiz_attempt::IN_PROGRESS) {
redirect($quizobj->review_url($lastattempt->id));
}
}
示例7: dirname
$PAGE->set_heading(format_string($course->fullname));
$PAGE->set_context($context);
$PAGE->set_cacheable(false);
$PAGE->requires->css("/mod/studyplan/view.css");
$PAGE->add_body_class('studyplan-view');
echo $OUTPUT->header();
// Output starts here
echo $OUTPUT->heading($studyplan->name);
if ($studyplan->intro) {
// Conditions to show the intro can change to look for own settings or whatever
echo $OUTPUT->box(format_module_intro('studyplan', $studyplan, $cm->id), 'studyplan-intro', 'studyplanintro');
}
if ($studyplan->standardblock) {
echo '<div class="studyplan-standard">';
include dirname(__FILE__) . '/intro.php';
echo '</div>';
}
$attempts = quiz_get_user_attempts($studyplan->quiz, $USER->id, 'finished', true);
if (empty($attempts)) {
$url = new moodle_url('/mod/quiz/view.php', array('q' => $studyplan->quiz));
$quiz_name = htmlentities(sp_get_quiz_name($studyplan->quiz));
print "<h2 class=\"studyplan-header studyplan-no-quiz\">" . get_string('youhavenotfinished', 'studyplan') . " <a href=\"{$url}\">{$quiz_name}</a>." . "</h2>";
} else {
$lastfinishedattempt = end($attempts);
$attemptobj = quiz_attempt::create($lastfinishedattempt->id);
$questionids = sp_get_questionids_from_attempt($attemptobj);
$presummary = sp_presummarize($attemptobj, $questionids, $showtabulation);
echo sp_render_block($studyplan->id, $presummary, false, false, $showtabulation, "student");
}
// Finish the page
echo $OUTPUT->footer();
示例8: quiz_save_best_grade
/**
* Save the overall grade for a user at a quiz in the quiz_grades table
*
* @param object $quiz The quiz for which the best grade is to be calculated and then saved.
* @param int $userid The userid to calculate the grade for. Defaults to the current user.
* @param array $attempts The attempts of this user. Useful if you are
* looping through many users. Attempts can be fetched in one master query to
* avoid repeated querying.
* @return bool Indicates success or failure.
*/
function quiz_save_best_grade($quiz, $userid = null, $attempts = array()) {
global $DB, $OUTPUT, $USER;
if (empty($userid)) {
$userid = $USER->id;
}
if (!$attempts) {
// Get all the attempts made by the user.
$attempts = quiz_get_user_attempts($quiz->id, $userid);
}
// Calculate the best grade.
$bestgrade = quiz_calculate_best_grade($quiz, $attempts);
$bestgrade = quiz_rescale_grade($bestgrade, $quiz, false);
// Save the best grade in the database.
if (is_null($bestgrade)) {
$DB->delete_records('quiz_grades', array('quiz' => $quiz->id, 'userid' => $userid));
} else if ($grade = $DB->get_record('quiz_grades',
array('quiz' => $quiz->id, 'userid' => $userid))) {
$grade->grade = $bestgrade;
$grade->timemodified = time();
$DB->update_record('quiz_grades', $grade);
} else {
$grade = new stdClass();
$grade->quiz = $quiz->id;
$grade->userid = $userid;
$grade->grade = $bestgrade;
$grade->timemodified = time();
$DB->insert_record('quiz_grades', $grade);
}
quiz_update_grades($quiz, $userid);
}
示例9: sp_get_activity_completed
function sp_get_activity_completed($activityid = 0)
{
global $DB, $COURSE, $USER, $STUDENT;
$user_id = $USER->id;
if (isset($STUDENT)) {
$user_id = $STUDENT->id;
}
if ($activityid <= 0) {
return false;
}
$cms = get_fast_modinfo($COURSE)->get_cms();
$mod = $cms[$activityid];
$completion = new completion_info($COURSE);
// echo "<br />COMPLETION: " . print_r($mod->modname, true);
if ($mod->modname == "quiz") {
$attempts = quiz_get_user_attempts($studyplan->quiz, $user_id, 'finished', true);
if (empty($attempts)) {
return false;
}
return true;
} else {
#http://docs.moodle.org/dev/Course_completion & http://docs.moodle.org/dev/Activity_completion_API
#lib/completionlib.php - line # 907 - get_data
$comp_data = $completion->get_data($mod, false, $user_id);
if (empty($comp_data)) {
return false;
}
if ($comp_data->completionstate >= COMPLETION_COMPLETE) {
return true;
}
}
return false;
}
示例10: walkthrough_attempts
/**
* @param $steps PHPUnit_Extensions_Database_DataSet_ITable the step data from the csv file.
* @return array attempt no as in csv file => the id of the quiz_attempt as stored in the db.
*/
protected function walkthrough_attempts($steps)
{
global $DB;
$attemptids = array();
for ($rowno = 0; $rowno < $steps->getRowCount(); $rowno++) {
$step = $this->explode_dot_separated_keys_to_make_subindexs($steps->getRow($rowno));
// Find existing user or make a new user to do the quiz.
$username = array('firstname' => $step['firstname'], 'lastname' => $step['lastname']);
if (!($user = $DB->get_record('user', $username))) {
$user = $this->getDataGenerator()->create_user($username);
}
if (!isset($attemptids[$step['quizattempt']])) {
// Start the attempt.
$quizobj = quiz::create($this->quiz->id, $user->id);
$quba = question_engine::make_questions_usage_by_activity('mod_quiz', $quizobj->get_context());
$quba->set_preferred_behaviour($quizobj->get_quiz()->preferredbehaviour);
$prevattempts = quiz_get_user_attempts($this->quiz->id, $user->id, 'all', true);
$attemptnumber = count($prevattempts) + 1;
$timenow = time();
$attempt = quiz_create_attempt($quizobj, $attemptnumber, false, $timenow, false, $user->id);
// Select variant and / or random sub question.
if (!isset($step['variants'])) {
$step['variants'] = array();
}
if (isset($step['randqs'])) {
// Replace 'names' with ids.
foreach ($step['randqs'] as $slotno => $randqname) {
$step['randqs'][$slotno] = $this->randqids[$slotno][$randqname];
}
} else {
$step['randqs'] = array();
}
quiz_start_new_attempt($quizobj, $quba, $attempt, $attemptnumber, $timenow, $step['randqs'], $step['variants']);
quiz_attempt_save_started($quizobj, $quba, $attempt);
$attemptid = $attemptids[$step['quizattempt']] = $attempt->id;
} else {
$attemptid = $attemptids[$step['quizattempt']];
}
// Process some responses from the student.
$attemptobj = quiz_attempt::create($attemptid);
$attemptobj->process_submitted_actions($timenow, false, $step['responses']);
// Finish the attempt.
if (!isset($step['finished']) || $step['finished'] == 1) {
$attemptobj = quiz_attempt::create($attemptid);
$attemptobj->process_finish($timenow, false);
}
}
return $attemptids;
}
示例11: evaluate_quiz
function evaluate_quiz($acode, $jobid, $newattempt, $blended)
{
global $USER;
global $CFG;
mtrace("Evaluation QUIZ Processing..." . "<BR><BR>");
try {
print "New Attempt is: " . $newattempt . "<BR/>";
$detected_userid = find_userid($acode, $jobid);
if ($detected_userid == null or $detected_userid == '') {
throw new EvaluationError(get_string('ErrorUserIDEmpty', 'blended'), EvaluationError::USERID_IS_EMPTY);
}
$user_reg = blended_get_user($detected_userid, $blended);
if ($user_reg == null) {
throw new EvaluationError(get_string('ErrorUserNotInCourse', 'blended'), EvaluationError::USER_NOT_IN_THIS_COURSE);
}
$userid = $user_reg->id;
mtrace('Obtained USERID value: ' . $userid . " OK. <BR/>");
$quiz = get_quiz($acode);
$attempts = quiz_get_user_attempts($quiz->id, $userid, 'all', true);
mtrace("Searching quiz... Success." . "<BR/>");
$uniqueid = get_uniqueid($acode);
mtrace('Obtained uniqueid: OK. <BR/>');
$timestamp = get_timestamp($acode);
mtrace('Obtained timestamp: OK. <BR/>');
if (!get_record('quiz_attempts', 'uniqueid', $uniqueid)) {
$newattempt = true;
} else {
$newattempt = false;
mtrace("User {$userid} had opened this attempt already.");
}
$attemptnumber = 1;
if ($newattempt == false) {
mtrace('Obtaining user attempt...<BR/>');
set_attempt_unfinished($uniqueid);
$attempt = quiz_get_user_attempt_unfinished($quiz->id, $userid);
} elseif ($newattempt == true) {
mtrace('Creating new attempt...<BR/>');
$attempt = create_new_attempt($quiz, $attemptnumber, $userid, $acode, $uniqueid, $timestamp);
// Save the attempt
if (!insert_record('quiz_attempts', $attempt)) {
throw new EvaluationError(get_string('ErrorCouldNotCreateAttempt', 'blended'), EvaluationError::CREATE_QUIZ_ATTEMPT_ERROR);
}
// Actualizamos el estado de las imágenes para indicar que ya está creado un nuevo attempt
update_images_status($acode, $jobid);
}
update_question_attempts($uniqueid);
// /*
mtrace('<BR>Getting questions and question options... ');
$questions = get_questions($attempt, $quiz);
if (!get_question_options($questions)) {
error('Could not load question options');
}
mtrace('Success! <BR>');
// print ("<BR>He obtenido questions: ");
//print_object($questions);
$lastattemptid = false;
// if ($attempt->attempt > 1 and $quiz->attemptonlast and !$attempt->preview) {
// Find the previous attempt
// if (!$lastattemptid = get_field('quiz_attempts', 'uniqueid', 'quiz', $attempt->quiz, 'userid', $attempt->userid, 'attempt', $attempt->attempt-1)) {
// error('Could not find previous attempt to build on');
// }
//}
//print ('He obtenido lastattemptid');
mtrace('Getting question states... ');
if (!($states = get_question_states($questions, $quiz, $attempt, $lastattemptid))) {
error('Could not restore question sessions');
}
mtrace('Success! <BR>');
mtrace('Getting responses... <BR>');
$responses = get_responses($acode, $jobid, $attempt);
//print('Estas son las responses:');
//print_object($responses);
//$timestamp=time();
$event = 8;
$actions = question_extract_responses($questions, $responses, $event);
$questionids = get_questionids($acode);
// print $questionids;
$questionidarray = explode(',', $questionids);
$success = true;
mtrace('<BR> Processing responses and saving session... ');
foreach ($questionidarray as $i) {
if (!isset($actions[$i])) {
$actions[$i]->responses = array('' => '');
$actions[$i]->event = QUESTION_EVENTOPEN;
}
$actions[$i]->timestamp = $timestamp;
if (question_process_responses($questions[$i], $states[$i], $actions[$i], $quiz, $attempt)) {
save_question_session($questions[$i], $states[$i]);
} else {
$success = false;
}
}
mtrace('Success! <BR>');
// Set the attempt to be finished
$timestamp = time();
//$attempt->timefinish = $timestamp;
// Update the quiz attempt and the overall grade for the quiz
mtrace('<BR> Finishing the attempt... ');
// print_object ($attempt);
if (set_field('quiz_attempts', 'timefinish', $timestamp, 'uniqueid', $uniqueid) == false) {
//.........这里部分代码省略.........
示例12: get_employeescore
function get_employeescore($id,$course,$userid) {
$cm = get_coursemodule_from_instance("quiz", $id, $course);
$quizobj = quiz::create($cm->instance, $userid);
$quiz = $quizobj->get_quiz();
$viewobj = new mod_quiz_view_object();
$attempts = quiz_get_user_attempts($id, $userid, 'finished', true);
$lastfinishedattempt = end($attempts);
$numattempts = count($attempts);
$viewobj->attempts = $attempts;
$viewobj->attemptobjs = array();
foreach ($attempts as $attempt) {
$viewobj->attemptobjs[] = new quiz_attempt($attempt, $quiz, $cm, $quiz->course, false);
}
/*Function to display attemps and grades */
$attemptgrade='';
foreach ($viewobj->attemptobjs as $attemptobj) {
$attemptgrade = quiz_rescale_grade($attemptobj->get_sum_marks(), $quiz, false);
}
return $attemptgrade;
}
示例13: is_quiz_finished
function is_quiz_finished($cmid)
{
global $USER, $CFG;
require_once $CFG->dirroot . '/mod/quiz/locallib.php';
require_once $CFG->dirroot . '/mod/quiz/lib.php';
$cm = get_coursemodule_from_id('quiz', $cmid);
$quizobj = quiz::create($cm->instance, $USER->id);
$attempts = quiz_get_user_attempts($quizobj->get_quizid(), $USER->id, 'all', true);
foreach ($attempts as $attempt) {
if ($attempt && $attempt->state == quiz_attempt::FINISHED && $attempt->sumgrades == 1) {
return true;
}
}
return false;
}
示例14: quiz_save_best_grade
/**
* Save the overall grade for a user at a quiz in the quiz_grades table
*
* @param object $quiz The quiz for which the best grade is to be calculated and then saved.
* @param integer $userid The userid to calculate the grade for. Defaults to the current user.
* @param array $attempts The attempts of this user. Useful if you are
* looping through many users. Attempts can be fetched in one master query to
* avoid repeated querying.
* @return boolean Indicates success or failure.
*/
function quiz_save_best_grade($quiz, $userid = null, $attempts = array())
{
global $DB;
global $USER, $OUTPUT;
if (empty($userid)) {
$userid = $USER->id;
}
if (!$attempts) {
// Get all the attempts made by the user
if (!($attempts = quiz_get_user_attempts($quiz->id, $userid))) {
echo $OUTPUT->notification('Could not find any user attempts');
return false;
}
}
// Calculate the best grade
$bestgrade = quiz_calculate_best_grade($quiz, $attempts);
$bestgrade = quiz_rescale_grade($bestgrade, $quiz, false);
// Save the best grade in the database
if ($grade = $DB->get_record('quiz_grades', array('quiz' => $quiz->id, 'userid' => $userid))) {
$grade->grade = $bestgrade;
$grade->timemodified = time();
$DB->update_record('quiz_grades', $grade);
} else {
$grade->quiz = $quiz->id;
$grade->userid = $userid;
$grade->grade = $bestgrade;
$grade->timemodified = time();
$DB->insert_record('quiz_grades', $grade);
}
quiz_update_grades($quiz, $userid);
return true;
}
示例15: navbuttons_mod_quiz_showbuttons
/**
* @param $cm
* @return bool
*/
function navbuttons_mod_quiz_showbuttons($cm)
{
global $USER, $CFG;
require_once $CFG->dirroot . '/mod/quiz/locallib.php';
if (quiz_get_user_attempt_unfinished($cm->instance, $USER->id)) {
return false;
// Unfinished attempt in progress
}
if (!quiz_get_user_attempts($cm->instance, $USER->id, 'finished', true)) {
return false;
// No finished attempts
}
return true;
}