/** * Verify that there is a valid set of grades to export. * @param $courseid int The course being exported */ function export_verify_grades($courseid) { if (grade_needs_regrade_final_grades($courseid)) { throw new moodle_exception('gradesneedregrading', 'grades'); } }
/** * Check whether regarding of final grades is required and, if so, perform the regrade. * * If the regrade is expected to be time consuming (see grade_needs_regrade_progress_bar), then this * function will output the progress bar, and redirect to the current PAGE->url after regrading * completes. Otherwise the regrading will happen immediately and the page will be loaded as per * normal. * * A callback may be specified, which is called if regrading has taken place. * The callback may optionally return a URL which will be redirected to when the progress bar is present. * * @param stdClass $course The course to regrade * @param callable $callback A function to call if regrading took place * @return moodle_url The URL to redirect to if redirecting */ function grade_regrade_final_grades_if_required($course, callable $callback = null) { global $PAGE, $OUTPUT; if (!grade_needs_regrade_final_grades($course->id)) { return false; } if (grade_needs_regrade_progress_bar($course->id)) { $PAGE->set_heading($course->fullname); echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('recalculatinggrades', 'grades')); $progress = new \core\progress\display(true); grade_regrade_final_grades($course->id, null, null, $progress); if ($callback) { // $url = call_user_func($callback); } if (empty($url)) { $url = $PAGE->url; } echo $OUTPUT->continue_button($url); echo $OUTPUT->footer(); die; } else { $result = grade_regrade_final_grades($course->id); if ($callback) { call_user_func($callback); } return $result; } }
/** * Check whether regarding of final grades is required and, if so, perform the regrade. * * If the regrade is expected to be time consuming (see grade_needs_regrade_progress_bar), then this * function will output the progress bar, and redirect to the current PAGE->url after regrading * completes. Otherwise the regrading will happen immediately and the page will be loaded as per * normal. * * A callback may be specified, which is called if regrading has taken place. * The callback may optionally return a URL which will be redirected to when the progress bar is present. * * @param stdClass $course The course to regrade * @param callable $callback A function to call if regrading took place * @return moodle_url The URL to redirect to if redirecting */ function grade_regrade_final_grades_if_required($course, callable $callback = null) { global $PAGE, $OUTPUT; if (!grade_needs_regrade_final_grades($course->id)) { return false; } if (grade_needs_regrade_progress_bar($course->id)) { $PAGE->set_heading($course->fullname); echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('recalculatinggrades', 'grades')); $progress = new \core\progress\display(true); $status = grade_regrade_final_grades($course->id, null, null, $progress); // Show regrade errors and set the course to no longer needing regrade (stop endless loop). if (is_array($status)) { foreach ($status as $error) { $errortext = new \core\output\notification($error, \core\output\notification::NOTIFY_ERROR); echo $OUTPUT->render($errortext); } $courseitem = grade_item::fetch_course_item($course->id); $courseitem->regrading_finished(); } if ($callback) { // $url = call_user_func($callback); } if (empty($url)) { $url = $PAGE->url; } echo $OUTPUT->continue_button($url); echo $OUTPUT->footer(); die; } else { $result = grade_regrade_final_grades($course->id); if ($callback) { call_user_func($callback); } return $result; } }