Beispiel #1
0
 /**
  * Given a URL containing attempt={this attempt id}, return an array of variant URLs
  * @param moodle_url $url a URL.
  * @return string HTML fragment. Comma-separated list of links to the other
  * attempts with the attempt number as the link text. The curent attempt is
  * included but is not a link.
  */
 public function links_to_other_attempts(moodle_url $url)
 {
     $attempts = reader_get_user_attempts($this->get_reader()->id, $this->attempt->userid, 'all');
     if (count($attempts) <= 1) {
         return false;
     }
     $links = new mod_reader_links_to_other_attempts();
     foreach ($attempts as $at) {
         if ($at->id == $this->attempt->id) {
             $links->links[$at->attempt] = null;
         } else {
             $links->links[$at->attempt] = new moodle_url($url, array('attempt' => $at->id));
         }
     }
     return $links;
 }
Beispiel #2
0
}
if (!($reader = $DB->get_record('reader', array('id' => $cm->instance)))) {
    print_error('invalidcoursemodule');
}
require_login($course, true, $cm);
$readerobj = reader::create($reader->id, $USER->id, $book);
// This script should only ever be posted to, so set page URL to the view page.
$PAGE->set_url($readerobj->view_url());
// Check login and sesskey.
$PAGE->set_pagelayout('base');
// if no questions have been set up yet redirect to edit.php
if (!$readerobj->has_questions()) {
    redirect($readerobj->edit_url());
}
// Look for an existing attempt.
$attempts = reader_get_user_attempts($reader->id, $USER->id, 'all');
$lastattempt = end($attempts);
// If an in-progress attempt exists, check password then redirect to it.
if ($lastattempt && !$lastattempt->timefinish) {
    redirect($readerobj->attempt_url($lastattempt->id, $page));
}
// Get number for the next or unfinished attempt             опнбепхрэ онякедмхи юррелор гдеяэ
$lastattempt = false;
$attemptnumber = 1;
$quba = question_engine::make_questions_usage_by_activity('mod_reader', $readerobj->get_context());
$quba->set_preferred_behaviour('deferredfeedback');
// Create the new attempt and initialize the question sessions
$attempt = reader_create_attempt($reader, $attemptnumber, $book);
if (!($reader->attemptonlast && $lastattempt)) {
    // Starting a normal, new, reader attempt.
    // Fully load all the questions in this reader.
Beispiel #3
0
function reader_save_best_grade($reader, $userid = null)
{
    global $USER, $DB;
    if (empty($userid)) {
        $userid = $USER->id;
    }
    // Get all the attempts made by the user
    if (!($attempts = reader_get_user_attempts($reader->id, $userid))) {
        notify('Could not find any user attempts');
        return false;
    }
    // Calculate the best grade
    $bestgrade = reader_calculate_best_grade($reader, $attempts);
    $bestgrade = reader_rescale_grade($bestgrade, $reader);
    // Save the best grade in the database
    if ($grade = $DB->get_record('reader_grades', array('reader' => $reader->id, 'userid' => $userid))) {
        $grade->grade = $bestgrade;
        $grade->timemodified = time();
        if (!$DB->update_record('reader_grades', $grade)) {
            notify('Could not update best grade');
            return false;
        }
    } else {
        $grade->reader = $reader->id;
        $grade->userid = $userid;
        $grade->grade = $bestgrade;
        $grade->timemodified = time();
        if (!$DB->insert_record('reader_grades', $grade)) {
            notify('Could not insert new best grade');
            return false;
        }
    }
    reader_update_grades($reader, $userid);
    return true;
}