MDL-76897 quiz: quiz_update_all_attempt_sumgrades -> grade_calculator
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
namespace mod_quiz;
|
||||
|
||||
use question_engine_data_mapper;
|
||||
|
||||
/**
|
||||
* This class contains all the logic for computing the grade of a quiz.
|
||||
*
|
||||
@@ -84,4 +86,26 @@ class grade_calculator {
|
||||
quiz_set_grade(0, $quiz);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the sumgrades field of attempts at this quiz.
|
||||
*/
|
||||
public function recompute_all_attempt_sumgrades(): void {
|
||||
global $DB;
|
||||
$dm = new question_engine_data_mapper();
|
||||
$timenow = time();
|
||||
|
||||
$DB->execute("
|
||||
UPDATE {quiz_attempts}
|
||||
SET timemodified = :timenow,
|
||||
sumgrades = (
|
||||
{$dm->sum_usage_marks_subquery('uniqueid')}
|
||||
)
|
||||
WHERE quiz = :quizid AND state = :finishedstate
|
||||
", [
|
||||
'timenow' => $timenow,
|
||||
'quizid' => $this->quizobj->get_quizid(),
|
||||
'finishedstate' => quiz_attempt::FINISHED
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace mod_quiz\local\reports;
|
||||
|
||||
use coding_exception;
|
||||
use context_module;
|
||||
use mod_quiz\quiz_settings;
|
||||
use moodle_url;
|
||||
use stdClass;
|
||||
use table_sql;
|
||||
@@ -63,6 +64,9 @@ abstract class attempts_report extends report_base {
|
||||
/** @var boolean caches the results of {@see should_show_grades()}. */
|
||||
protected $showgrades = null;
|
||||
|
||||
/** @var quiz_settings|null quiz settings object. Set in the init method. */
|
||||
protected $quizobj = null;
|
||||
|
||||
/**
|
||||
* Initialise various aspects of this report.
|
||||
*
|
||||
@@ -80,8 +84,8 @@ abstract class attempts_report extends report_base {
|
||||
*/
|
||||
public function init($mode, $formclass, $quiz, $cm, $course): array {
|
||||
$this->mode = $mode;
|
||||
|
||||
$this->context = context_module::instance($cm->id);
|
||||
$this->quizobj = new quiz_settings($quiz, $cm, $course);
|
||||
$this->context = $this->quizobj->get_context();
|
||||
|
||||
[$currentgroup, $studentsjoins, $groupstudentsjoins, $allowedjoins] = $this->get_students_joins(
|
||||
$cm, $course);
|
||||
|
||||
@@ -322,3 +322,16 @@ function quiz_update_sumgrades($quiz) {
|
||||
'Please use a standard grade_calculator::recompute_quiz_sumgrades instead.', DEBUG_DEVELOPER);
|
||||
quiz_settings::create($quiz->id)->get_grade_calculator()->recompute_quiz_sumgrades();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the sumgrades field of the attempts at a quiz.
|
||||
*
|
||||
* @param stdClass $quiz a quiz.
|
||||
* @deprecated since Moodle 4.2. Please use grade_calculator::recompute_all_attempt_sumgrades.
|
||||
* @todo MDL-76612 Final deprecation in Moodle 4.6
|
||||
*/
|
||||
function quiz_update_all_attempt_sumgrades($quiz) {
|
||||
debugging('quiz_update_all_attempt_sumgrades is deprecated. ' .
|
||||
'Please use a standard grade_calculator::recompute_all_attempt_sumgrades instead.', DEBUG_DEVELOPER);
|
||||
quiz_settings::create($quiz->id)->get_grade_calculator()->recompute_all_attempt_sumgrades();
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ switch($requestmethod) {
|
||||
// Grade has really changed.
|
||||
quiz_delete_previews($quiz);
|
||||
$gradecalculator->recompute_quiz_sumgrades();
|
||||
quiz_update_all_attempt_sumgrades($quiz);
|
||||
$gradecalculator->recompute_all_attempt_sumgrades();
|
||||
quiz_update_all_final_grades($quiz);
|
||||
quiz_update_grades($quiz, 0, true);
|
||||
}
|
||||
|
||||
@@ -628,27 +628,6 @@ function quiz_has_feedback($quiz) {
|
||||
return $cache[$quiz->id];
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the sumgrades field of the attempts at a quiz.
|
||||
*
|
||||
* @param stdClass $quiz a quiz.
|
||||
*/
|
||||
function quiz_update_all_attempt_sumgrades($quiz) {
|
||||
global $DB;
|
||||
$dm = new question_engine_data_mapper();
|
||||
$timenow = time();
|
||||
|
||||
$sql = "UPDATE {quiz_attempts}
|
||||
SET
|
||||
timemodified = :timenow,
|
||||
sumgrades = (
|
||||
{$dm->sum_usage_marks_subquery('uniqueid')}
|
||||
)
|
||||
WHERE quiz = :quizid AND state = :finishedstate";
|
||||
$DB->execute($sql, ['timenow' => $timenow, 'quizid' => $quiz->id,
|
||||
'finishedstate' => quiz_attempt::FINISHED]);
|
||||
}
|
||||
|
||||
/**
|
||||
* The quiz grade is the maximum that student's results are marked out of. When it
|
||||
* changes, the corresponding data in quiz_grades and quiz_feedback needs to be
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
use mod_quiz\local\reports\attempts_report;
|
||||
use mod_quiz\question\bank\qbank_helper;
|
||||
use mod_quiz\quiz_attempt;
|
||||
use mod_quiz\quiz_settings;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -59,7 +60,7 @@ class quiz_overview_report extends attempts_report {
|
||||
protected $newquestionidsforold = null;
|
||||
|
||||
public function display($quiz, $cm, $course) {
|
||||
global $DB, $OUTPUT, $PAGE;
|
||||
global $DB, $PAGE;
|
||||
|
||||
list($currentgroup, $studentsjoins, $groupstudentsjoins, $allowedjoins) = $this->init(
|
||||
'overview', 'quiz_overview_settings_form', $quiz, $cm, $course);
|
||||
@@ -687,7 +688,8 @@ class quiz_overview_report extends attempts_report {
|
||||
* @param stdClass $quiz the quiz settings.
|
||||
*/
|
||||
protected function update_overall_grades($quiz) {
|
||||
quiz_update_all_attempt_sumgrades($quiz);
|
||||
$gradecalculator = $this->quizobj->get_grade_calculator();
|
||||
$gradecalculator->recompute_all_attempt_sumgrades();
|
||||
quiz_update_all_final_grades($quiz);
|
||||
quiz_update_grades($quiz);
|
||||
}
|
||||
|
||||
@@ -79,7 +79,8 @@ This files describes API changes in the quiz code.
|
||||
|
||||
* Various functions related to calculating grades have moved into a new class mod_quiz\grade_calculator.
|
||||
You get that using $quizobj->get_grade_calculator(), then the following old functions have become these new methods.
|
||||
- recompute_quiz_sumgrades -> recompute_quiz_sumgrades
|
||||
- quiz_update_sumgrades -> recompute_quiz_sumgrades
|
||||
- quiz_update_all_attempt_sumgrades -> recompute_all_attempt_sumgrades
|
||||
|
||||
* Final deprecation (complete removal) of the following functions which were deprecated long ago:
|
||||
- quiz_groups_member_added_handler - deprecated since 2.6
|
||||
|
||||
@@ -1173,11 +1173,11 @@ ORDER BY
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a subquery that computes the sum of the marks for all the questions
|
||||
* in a usage. Which useage to compute the sum for is controlled bu the $qubaid
|
||||
* Return a sub-query that computes the sum of the marks for all the questions
|
||||
* in a usage. Which usage to compute the sum for is controlled by the $qubaid
|
||||
* parameter.
|
||||
*
|
||||
* See {@link quiz_update_all_attempt_sumgrades()} for an example of the usage of
|
||||
* See {@see \mod_quiz\grade_calculator::recompute_all_attempt_sumgrades()} for an example of the usage of
|
||||
* this method.
|
||||
*
|
||||
* This method may be called publicly.
|
||||
|
||||
Reference in New Issue
Block a user