Exemple #1
0
function workshop_gradinggrade($workshop, $student)
{
    // returns the current (external) grading grade of the based on their (cold) assessments
    // (needed as it's called by grade)
    $gradinggrade = 0;
    if ($assessments = workshop_get_user_assessments($workshop, $student)) {
        $n = 0;
        foreach ($assessments as $assessment) {
            $gradinggrade += $assessment->gradinggrade;
            $n++;
        }
        if ($n < $workshop->ntassessments + $workshop->nsassessments) {
            // the minimum students should do
            $n = $workshop->ntassessments + $workshop->nsassessments;
        }
        $gradinggrade = $gradinggrade / $n;
    }
    return number_format($gradinggrade * $workshop->gradinggrade / 100, 1);
}
Exemple #2
0
function workshop_list_teacher_submissions($workshop, $user)
{
    global $CFG;
    // set threshold on re-assessments
    $reassessthreshold = 80;
    if (!($cm = get_coursemodule_from_instance("workshop", $workshop->id, $workshop->course))) {
        error("Course Module ID was incorrect");
    }
    if (!($course = get_record("course", "id", $workshop->course))) {
        error("Course is misconfigured");
    }
    $table->head = array(get_string("title", "workshop"), get_string("action", "workshop"), get_string("comment", "workshop"));
    $table->align = array("left", "left", "left");
    $table->size = array("*", "*", "*");
    $table->cellpadding = 2;
    $table->cellspacing = 0;
    // get the number of assessments this user has done
    $nassessed = count_records_select("workshop_assessments", "workshopid = {$workshop->id}\n                    AND userid = {$user->id}");
    if ($nassessed < $workshop->ntassessments) {
        // if user has not assessed enough, set up "future" assessment records for this user for the teacher submissions...
        // ... first count the number of assessments for each teacher submission...
        if ($submissions = workshop_get_teacher_submissions($workshop)) {
            srand((double) microtime() * 1000000);
            // initialise random number generator
            foreach ($submissions as $submission) {
                $n = count_records("workshop_assessments", "submissionid", $submission->id);
                // ...OK to have zero, we add a small random number to randomise things...
                $nassessments[$submission->id] = $n + rand(0, 99) / 100;
            }
            // ...put the submissions with the lowest number of assessments first...
            asort($nassessments);
            reset($nassessments);
            foreach ($nassessments as $submissionid => $n) {
                // break out of loop when we allocated enough assessments...
                $submission = get_record("workshop_submissions", "id", $submissionid);
                // ... provided the user has NOT already assessed that submission...
                if (!get_record("workshop_assessments", "submissionid", $submission->id, "userid", $user->id)) {
                    $yearfromnow = time() + 365 * 86400;
                    // ...create one and set timecreated way in the future, this is reset when record is updated
                    unset($assessment);
                    // clear previous version of object (if any)
                    $assessment->workshopid = $workshop->id;
                    $assessment->submissionid = $submission->id;
                    $assessment->userid = $user->id;
                    $assessment->grade = -1;
                    // set impossible grade
                    $assessment->timecreated = $yearfromnow;
                    if (!($assessment->id = insert_record("workshop_assessments", $assessment))) {
                        error("Could not insert workshop assessment!");
                    }
                    $nassessed++;
                    if ($nassessed >= $workshop->ntassessments) {
                        break;
                    }
                }
            }
        }
    }
    // now list user's assessments (but only list those which come from teacher submissions)
    if ($assessments = workshop_get_user_assessments($workshop, $user)) {
        $timenow = time();
        foreach ($assessments as $assessment) {
            if (!($submission = get_record("workshop_submissions", "id", $assessment->submissionid))) {
                error("workshop_list_teacher_submissions: unable to get submission");
            }
            // submission from a teacher?
            if (workshop_is_teacher($workshop, $submission->userid)) {
                $comment = '';
                // user assessment has two states: record created but not assessed (date created in the future);
                // assessed but always available for re-assessment
                if ($assessment->timecreated > $timenow) {
                    // user needs to assess this submission
                    $action = "<a href=\"assess.php?id={$cm->id}&amp;sid={$submission->id}\">" . get_string("assess", "workshop") . "</a>";
                } elseif ($assessment->timegraded and $assessment->gradinggrade < $reassessthreshold) {
                    // allow student to improve on their assessment once it's been graded and is below threshold
                    $action = "<a href=\"assess.php?id={$cm->id}&amp;sid={$submission->id}\">" . get_string("reassess", "workshop") . "</a>";
                } else {
                    // allow student  just to see their assessment if it hasn't been graded (or above threshold)
                    $action = "<a href=\"viewassessment.php?id={$cm->id}&amp;aid={$assessment->id}\">" . get_string("view", "workshop") . "</a>";
                }
                // see if the assessment is graded
                if ($assessment->timegraded) {
                    // show grading grade (supressed if workshop not graded)
                    if ($workshop->gradingstrategy) {
                        $comment = get_string("thegradeforthisassessmentis", "workshop", number_format($assessment->gradinggrade * $workshop->gradinggrade / 100, 1)) . " / " . $workshop->gradinggrade;
                    }
                } elseif ($assessment->timecreated < $timenow) {
                    $comment = get_string("awaitinggradingbyteacher", "workshop", $course->teacher);
                }
                $table->data[] = array(workshop_print_submission_title($workshop, $submission), $action, $comment);
            }
        }
    }
    print_table($table);
}