Exemplo n.º 1
0
 public function user_picture()
 {
     global $DB;
     if ($this->attemptobj->get_quiz()->showuserpicture == QUIZ_SHOWIMAGE_NONE) {
         return null;
     }
     $user = $DB->get_record('user', array('id' => $this->attemptobj->get_userid()));
     $userpicture = new user_picture($user);
     $userpicture->courseid = $this->attemptobj->get_courseid();
     if ($this->attemptobj->get_quiz()->showuserpicture == QUIZ_SHOWIMAGE_LARGE) {
         $userpicture->size = true;
     }
     return $userpicture;
 }
Exemplo n.º 2
0
    /**
     * Ouputs the form for making an attempt
     *
     * @param quiz_attempt $attemptobj
     * @param int $page Current page number
     * @param array $slots Array of integers relating to questions
     * @param int $id ID of the attempt
     * @param int $nextpage Next page number
     */
    public function attempt_form($attemptobj, $page, $slots, $id, $nextpage) {
        $output = '';

        // Start the form.
        $output .= html_writer::start_tag('form',
                array('action' => $attemptobj->processattempt_url(), 'method' => 'post',
                'enctype' => 'multipart/form-data', 'accept-charset' => 'utf-8',
                'id' => 'responseform'));
        $output .= html_writer::start_tag('div');

        // Print all the questions.
        foreach ($slots as $slot) {
            $output .= $attemptobj->render_question($slot, false, $this,
                    $attemptobj->attempt_url($slot, $page), $this);
        }

        $navmethod = $attemptobj->get_quiz()->navmethod;
        $output .= $this->attempt_navigation_buttons($page, $attemptobj->is_last_page($page), $navmethod);

        // Some hidden fields to trach what is going on.
        $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'attempt',
                'value' => $attemptobj->get_attemptid()));
        $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'thispage',
                'value' => $page, 'id' => 'followingpage'));
        $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'nextpage',
                'value' => $nextpage));
        $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'timeup',
                'value' => '0', 'id' => 'timeup'));
        $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey',
                'value' => sesskey()));
        $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'scrollpos',
                'value' => '', 'id' => 'scrollpos'));

        // Add a hidden field with questionids. Do this at the end of the form, so
        // if you navigate before the form has finished loading, it does not wipe all
        // the student's answers.
        $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'slots',
                'value' => implode(',', $attemptobj->get_active_slots($page))));

        // Finish the form.
        $output .= html_writer::end_tag('div');
        $output .= html_writer::end_tag('form');

        $output .= $this->connection_warning();

        return $output;
    }
Exemplo n.º 3
0
    public function user_picture() {
        global $DB;

        if (!$this->attemptobj->get_quiz()->showuserpicture) {
            return null;
        }

        $user = $DB->get_record('user', array('id' => $this->attemptobj->get_userid()));
        $userpicture = new user_picture($user);
        $userpicture->courseid = $this->attemptobj->get_courseid();
        return $userpicture;
    }
Exemplo n.º 4
0
/// adaptive mode.
if ($nextpage == -1) {
    $nexturl = $attemptobj->summary_url();
} else {
    $nexturl = $attemptobj->attempt_url(0, $nextpage);
}
/// We treat automatically closed attempts just like normally closed attempts
if ($timeup) {
    $finishattempt = 1;
}
/// Check login.
require_login($attemptobj->get_courseid(), false, $attemptobj->get_cm());
confirm_sesskey();
/// Check that this attempt belongs to this user.
if ($attemptobj->get_userid() != $USER->id) {
    quiz_error($attemptobj->get_quiz(), 'notyourattempt');
}
/// Check capabilites.
if (!$attemptobj->is_preview_user()) {
    $attemptobj->require_capability('mod/quiz:attempt');
}
/// If the attempt is already closed, send them to the review page.
if ($attemptobj->is_finished()) {
    quiz_error($attemptobj->get_quiz(), 'attemptalreadyclosed');
}
/// Don't log - we will end with a redirect to a page that is logged.
/// Get the list of questions needed by this page.
if (!empty($submittedquestionids)) {
    $submittedquestionids = explode(',', $submittedquestionids);
} else {
    $submittedquestionids = array();
Exemplo n.º 5
0
/**
 * Send the notification message when a quiz attempt becomes overdue.
 *
 * @param quiz_attempt $attemptobj all the data about the quiz attempt.
 */
function quiz_send_overdue_message($attemptobj)
{
    global $CFG, $DB;
    $submitter = $DB->get_record('user', array('id' => $attemptobj->get_userid()), '*', MUST_EXIST);
    if (!$attemptobj->has_capability('mod/quiz:emailwarnoverdue', $submitter->id, false)) {
        return;
        // Message not required.
    }
    if (!$attemptobj->has_response_to_at_least_one_graded_question()) {
        return;
        // Message not required.
    }
    // Prepare lots of useful information that admins might want to include in
    // the email message.
    $quizname = format_string($attemptobj->get_quiz_name());
    $deadlines = array();
    if ($attemptobj->get_quiz()->timelimit) {
        $deadlines[] = $attemptobj->get_attempt()->timestart + $attemptobj->get_quiz()->timelimit;
    }
    if ($attemptobj->get_quiz()->timeclose) {
        $deadlines[] = $attemptobj->get_quiz()->timeclose;
    }
    $duedate = min($deadlines);
    $graceend = $duedate + $attemptobj->get_quiz()->graceperiod;
    $a = new stdClass();
    // Course info.
    $a->coursename = format_string($attemptobj->get_course()->fullname);
    $a->courseshortname = format_string($attemptobj->get_course()->shortname);
    // Quiz info.
    $a->quizname = $quizname;
    $a->quizurl = $attemptobj->view_url();
    $a->quizlink = '<a href="' . $a->quizurl . '">' . $quizname . '</a>';
    // Attempt info.
    $a->attemptduedate = userdate($duedate);
    $a->attemptgraceend = userdate($graceend);
    $a->attemptsummaryurl = $attemptobj->summary_url()->out(false);
    $a->attemptsummarylink = '<a href="' . $a->attemptsummaryurl . '">' . $quizname . ' review</a>';
    // Student's info.
    $a->studentidnumber = $submitter->idnumber;
    $a->studentname = fullname($submitter);
    $a->studentusername = $submitter->username;
    // Prepare the message.
    $eventdata = new stdClass();
    $eventdata->component = 'mod_quiz';
    $eventdata->name = 'attempt_overdue';
    $eventdata->notification = 1;
    $eventdata->userfrom = core_user::get_noreply_user();
    $eventdata->userto = $submitter;
    $eventdata->subject = get_string('emailoverduesubject', 'quiz', $a);
    $eventdata->fullmessage = get_string('emailoverduebody', 'quiz', $a);
    $eventdata->fullmessageformat = FORMAT_PLAIN;
    $eventdata->fullmessagehtml = '';
    $eventdata->smallmessage = get_string('emailoverduesmall', 'quiz', $a);
    $eventdata->contexturl = $a->quizurl;
    $eventdata->contexturlname = $a->quizname;
    // Send the message.
    return message_send($eventdata);
}
Exemplo n.º 6
0
 public function get_contents()
 {
     global $PAGE;
     $PAGE->requires->js_init_call('M.mod_quiz.nav.init', null, false, quiz_get_js_module());
     $content = '';
     if ($this->attemptobj->get_quiz()->showuserpicture) {
         $content .= $this->get_user_picture() . "\n";
     }
     $content .= $this->get_before_button_bits();
     $content .= $this->get_question_buttons() . "\n";
     $content .= '<div class="othernav">' . "\n" . $this->get_end_bits() . "\n</div>\n";
     $bc = new block_contents();
     $bc->id = 'quiznavigation';
     $bc->title = get_string('quiznavigation', 'quiz');
     $bc->content = $content;
     return $bc;
 }
 /**
  * Check that attempt results are as specified in $result.
  *
  * @param array        $result             row of data read from csv file.
  * @param quiz_attempt $attemptobj         the attempt object loaded from db.
  * @throws coding_exception
  */
 protected function check_attempt_results($result, $attemptobj)
 {
     foreach ($result as $fieldname => $value) {
         if ($value === '!NULL!') {
             $value = null;
         }
         switch ($fieldname) {
             case 'quizattempt':
                 break;
             case 'attemptnumber':
                 $this->assertEquals($value, $attemptobj->get_attempt_number());
                 break;
             case 'slots':
                 foreach ($value as $slotno => $slottests) {
                     foreach ($slottests as $slotfieldname => $slotvalue) {
                         switch ($slotfieldname) {
                             case 'mark':
                                 $this->assertEquals(round($slotvalue, 2), $attemptobj->get_question_mark($slotno), "Mark for slot {$slotno} of attempt {$result['quizattempt']}.");
                                 break;
                             default:
                                 throw new coding_exception('Unknown slots sub field column in csv file ' . s($slotfieldname));
                         }
                     }
                 }
                 break;
             case 'finished':
                 $this->assertEquals((bool) $value, $attemptobj->is_finished());
                 break;
             case 'summarks':
                 $this->assertEquals($value, $attemptobj->get_sum_marks(), "Sum of marks of attempt {$result['quizattempt']}.");
                 break;
             case 'quizgrade':
                 // Check quiz grades.
                 $grades = quiz_get_user_grades($attemptobj->get_quiz(), $attemptobj->get_userid());
                 $grade = array_shift($grades);
                 $this->assertEquals($value, $grade->rawgrade, "Quiz grade for attempt {$result['quizattempt']}.");
                 break;
             case 'gradebookgrade':
                 // Check grade book.
                 $gradebookgrades = grade_get_grades($attemptobj->get_courseid(), 'mod', 'quiz', $attemptobj->get_quizid(), $attemptobj->get_userid());
                 $gradebookitem = array_shift($gradebookgrades->items);
                 $gradebookgrade = array_shift($gradebookitem->grades);
                 $this->assertEquals($value, $gradebookgrade->grade, "Gradebook grade for attempt {$result['quizattempt']}.");
                 break;
             default:
                 throw new coding_exception('Unknown column in csv file ' . s($fieldname));
         }
     }
 }
Exemplo n.º 8
0
require_once $CFG->dirroot . '/mod/quiz/report/reportlib.php';
$attemptid = required_param('attempt', PARAM_INT);
$page = optional_param('page', 0, PARAM_INT);
$showall = optional_param('showall', 0, PARAM_BOOL);
$attemptobj = new quiz_attempt($attemptid);
/// Check login.
require_login($attemptobj->get_courseid(), false, $attemptobj->get_cm());
$attemptobj->check_review_capability();
/// Create an object to manage all the other (non-roles) access rules.
$accessmanager = $attemptobj->get_access_manager(time());
$options = $attemptobj->get_review_options();
/// Permissions checks for normal users who do not have quiz:viewreports capability.
if (!$attemptobj->has_capability('mod/quiz:viewreports')) {
    /// Can't review other users' attempts.
    if (!$attemptobj->is_own_attempt()) {
        quiz_error($attemptobj->get_quiz(), 'notyourattempt');
    }
    /// Can't review during the attempt - send them back to the attempt page.
    if (!$attemptobj->is_finished()) {
        redirect($attemptobj->attempt_url(0, $page));
    }
    /// Can't review unless Students may review -> Responses option is turned on.
    if (!$options->responses) {
        $accessmanager->back_to_view_page($attemptobj->is_preview_user(), $accessmanager->cannot_review_message($options));
    }
}
/// Load the questions and states needed by this page.
if ($showall) {
    $questionids = $attemptobj->get_question_ids();
} else {
    $questionids = $attemptobj->get_question_ids($page);
Exemplo n.º 9
0
        }
        redirect($CFG->wwwroot . '/mod/quiz/startattempt.php?cmid=' . $cm->id . '&sesskey=' . sesskey());
    }
}
/// Get submitted parameters.
$attemptid = required_param('attempt', PARAM_INT);
$page = optional_param('page', 0, PARAM_INT);
$attemptobj = new quiz_attempt($attemptid);
/// Check login.
require_login($attemptobj->get_courseid(), false, $attemptobj->get_cm());
/// Check that this attempt belongs to this user.
if ($attemptobj->get_userid() != $USER->id) {
    if ($attemptobj->has_capability('mod/quiz:viewreports')) {
        redirect($attemptobj->review_url(0, $page));
    } else {
        quiz_error($attemptobj->get_quiz(), 'notyourattempt');
    }
}
/// Check capabilites.
if ($attemptobj->is_preview_user()) {
} else {
    $attemptobj->require_capability('mod/quiz:attempt');
}
/// If the attempt is already closed, send them to the review page.
if ($attemptobj->is_finished()) {
    redirect($attemptobj->review_url(0, $page));
}
/// Check the access rules.
$accessmanager = $attemptobj->get_access_manager(time());
$messages = $accessmanager->prevent_access();
if (!$attemptobj->is_preview_user() && $messages) {
Exemplo n.º 10
0
    $attemptobj->print_restart_preview_button();
}
print_heading($strreviewtitle);
/// Print the navigation panel in a left column.
print_container_start();
echo '<div id="left-column">';
$attemptobj->print_navigation_panel('quiz_review_nav_panel', $page);
echo '</div>';
print_container_end();
/// Start the main column.
echo '<div id="middle-column">';
echo skip_main_destination();
/// Summary table start ============================================================================
/// Work out some time-related things.
$attempt = $attemptobj->get_attempt();
$quiz = $attemptobj->get_quiz();
$overtime = 0;
if ($attempt->timefinish) {
    if ($timetaken = $attempt->timefinish - $attempt->timestart) {
        if ($quiz->timelimit && $timetaken > $quiz->timelimit + 60) {
            $overtime = $timetaken - $quiz->timelimit;
            $overtime = format_time($overtime);
        }
        $timetaken = format_time($timetaken);
    } else {
        $timetaken = "-";
    }
} else {
    $timetaken = get_string('unfinished', 'quiz');
}
/// Print summary table about the whole attempt.