Example #1
0
function sp_calculate_student_progress($studyplanid = null, $userid = null, $store = true, $gettext = true)
{
    global $USER, $STUDENT, $DB;
    global $STUDENT_PROGRESS;
    if ($studyplanid === null) {
        return;
    }
    if ($userid === null) {
        return;
    }
    if ($userid != $STUDENT->id) {
        $STUDENT = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
    }
    $STUDENT_PROGRESS = array();
    $studyplan = $DB->get_record('studyplan', array('id' => $studyplanid), '*', MUST_EXIST);
    $attempts = quiz_get_user_attempts($studyplan->quiz, $userid, 'finished', true);
    if (!empty($attempts)) {
        $lastfinishedattempt = end($attempts);
        $attemptobj = quiz_attempt::create($lastfinishedattempt->id);
        $questionids = sp_get_questionids_from_attempt($attemptobj);
        $presummary = sp_presummarize($attemptobj, $questionids);
        #calculate percent by rendering the block
        sp_render_block($studyplan->id, $presummary, false, true);
    }
    if ($store) {
        sp_store_student_progress($studyplanid, $userid);
    }
    if (!$gettext) {
        return;
    }
    return sp_student_progress_as_percentage_text();
}
Example #2
0
$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();
Example #3
0
if (isset($STUDENT)) {
    $heading = "{$studyplan->name} for {$STUDENT->firstname} {$STUDENT->lastname}";
}
echo $OUTPUT->heading($heading);
if (isset($STUDENT)) {
    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, $STUDENT->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, has_capability('mod/studyplan:assign', $context), false, $showtabulation, "teacher");
    }
}
echo "</td>";
echo "</tr></table>";
// Finish the page
echo $OUTPUT->footer();