Beispiel #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;
 }
Beispiel #2
0
/**
 * This page prints a summary of a quiz attempt before it is submitted.
 *
 * @author Tim Hunt others.
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 * @package quiz
 */
require_once dirname(__FILE__) . '/../../config.php';
require_once $CFG->dirroot . '/mod/quiz/locallib.php';
$attemptid = required_param('attempt', PARAM_INT);
// The attempt to summarise.
$attemptobj = new quiz_attempt($attemptid);
/// Check login.
require_login($attemptobj->get_courseid(), false, $attemptobj->get_cm());
/// If this is not our own attempt, display an error.
if ($attemptobj->get_userid() != $USER->id) {
    print_error('notyourattempt', 'quiz', $attemptobj->view_url());
}
/// If the attempt is alreadyuj closed, redirect them to the review page.
if ($attemptobj->is_finished()) {
    redirect($attemptobj->review_url());
}
/// Check access.
$accessmanager = $attemptobj->get_access_manager(time());
$messages = $accessmanager->prevent_access();
if (!$attemptobj->is_preview_user() && $messages) {
    print_error('attempterror', 'quiz', $attemptobj->view_url(), $accessmanager->print_messages($messages, true));
}
$accessmanager->do_password_check($attemptobj->is_preview_user());
/// Log this page view.
add_to_log($attemptobj->get_courseid(), 'quiz', 'view summary', 'summary.php?attempt=' . $attemptobj->get_attemptid(), $attemptobj->get_quizid(), $attemptobj->get_cmid());
Beispiel #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;
    }
Beispiel #4
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);
}
Beispiel #5
0
 protected function get_user_picture()
 {
     global $DB, $OUTPUT;
     $user = $DB->get_record('user', array('id' => $this->attemptobj->get_userid()));
     $output = '';
     $output .= '<div id="user-picture" class="clearfix">';
     $output .= $OUTPUT->user_picture($user, array('courseid' => $this->attemptobj->get_courseid()));
     $output .= ' ' . fullname($user);
     $output .= '</div>';
     return $output;
 }
if ($stateid) {
    $attemptobj->load_specific_question_state($questionid, $stateid);
}
/// Work out the base URL of this page.
$baseurl = $CFG->wwwroot . '/mod/quiz/reviewquestion.php?attempt=' . $attemptobj->get_attemptid() . '&amp;question=' . $questionid;
/// Log this review.
add_to_log($attemptobj->get_courseid(), 'quiz', 'review', 'reviewquestion.php?attempt=' . $attemptobj->get_attemptid() . '&question=' . $questionid . ($stateid ? '&state=' . $stateid : ''), $attemptobj->get_quizid(), $attemptobj->get_cmid());
/// Print the page header
$headtags = $attemptobj->get_question_html_head_contributions($questionid);
print_header('', '', '', '', $headtags);
echo '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;"></div>';
// for overlib
/// Print infobox
$rows = array();
/// User picture and name.
if ($attemptobj->get_userid() != $USER->id) {
    // Print user picture and name
    $student = $DB->get_record('user', array('id' => $attemptobj->get_userid()));
    $picture = print_user_picture($student, $attemptobj->get_courseid(), $student->picture, false, true);
    $rows[] = '<tr><th scope="row" class="cell">' . $picture . '</th><td class="cell"><a href="' . $CFG->wwwroot . '/user/view.php?id=' . $student->id . '&amp;course=' . $attemptobj->get_courseid() . '">' . fullname($student, true) . '</a></td></tr>';
}
/// Quiz name.
$rows[] = '<tr><th scope="row" class="cell">' . get_string('modulename', 'quiz') . '</th><td class="cell">' . format_string($attemptobj->get_quiz_name()) . '</td></tr>';
/// Question name.
$rows[] = '<tr><th scope="row" class="cell">' . get_string('question', 'quiz') . '</th><td class="cell">' . format_string($attemptobj->get_question($questionid)->name) . '</td></tr>';
/// Other attempts at the quiz.
if ($attemptobj->has_capability('mod/quiz:viewreports')) {
    $attemptlist = $attemptobj->links_to_other_attempts($baseurl);
    if ($attemptlist) {
        $rows[] = '<tr><th scope="row" class="cell">' . get_string('attempts', 'quiz') . '</th><td class="cell">' . $attemptlist . '</td></tr>';
    }
 /**
  * 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));
         }
     }
 }
Beispiel #8
0
        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.
/// First we assemble all the rows that are appopriate to the current situation in
/// an array, then later we only output the table if there are any rows to show.
$rows = array();
if (!$attemptobj->get_quiz()->showuserpicture && $attemptobj->get_userid() != $USER->id) {
    /// If showuserpicture is true, the picture is shown elsewhere, so don't repeat it.
    $student = $DB->get_record('user', array('id' => $attemptobj->get_userid()));
    $picture = $OUTPUT->user_picture(moodle_user_picture::make($student, $attemptobj->get_courseid()));
    $rows[] = '<tr><th scope="row" class="cell">' . $picture . '</th><td class="cell"><a href="' . $CFG->wwwroot . '/user/view.php?id=' . $student->id . '&amp;course=' . $attemptobj->get_courseid() . '">' . fullname($student, true) . '</a></td></tr>';
}
if ($attemptobj->has_capability('mod/quiz:viewreports')) {
    $attemptlist = $attemptobj->links_to_other_attempts($attemptobj->review_url(0, $page, $showall));
    if ($attemptlist) {
        $rows[] = '<tr><th scope="row" class="cell">' . get_string('attempts', 'quiz') . '</th><td class="cell">' . $attemptlist . '</td></tr>';
    }
}
/// Timing information.
$rows[] = '<tr><th scope="row" class="cell">' . get_string('startedon', 'quiz') . '</th><td class="cell">' . userdate($attempt->timestart) . '</td></tr>';
if ($attempt->timefinish) {
    $rows[] = '<tr><th scope="row" class="cell">' . get_string('completedon', 'quiz') . '</th><td class="cell">' . userdate($attempt->timefinish) . '</td></tr>';