protected function regrade_attempts($quiz, $dryrun = false,
            \core\dml\sql_join$groupstudentsjoins = null, $attemptids = array()) {
        global $DB;
        $this->unlock_session();

        $sql = "SELECT quiza.*
                  FROM {quiz_attempts} quiza";
        $where = "quiz = :qid AND preview = 0";
        $params = array('qid' => $quiz->id);

        if ($this->hasgroupstudents && !empty($groupstudentsjoins->joins)) {
            $sql .= "\nJOIN {user} u ON u.id = quiza.userid
                    {$groupstudentsjoins->joins}";
            $where .= " AND {$groupstudentsjoins->wheres}";
            $params += $groupstudentsjoins->params;
        }

        if ($attemptids) {
            $aids = join(',', $attemptids);
            $where .= " AND quiza.id IN ({$aids})";
        }

        $sql .= "\nWHERE {$where}";
        $attempts = $DB->get_records_sql($sql, $params);
        if (!$attempts) {
            return;
        }

        $this->clear_regrade_table($quiz, $groupstudentsjoins);

        $progressbar = new progress_bar('quiz_overview_regrade', 500, true);
        $a = array(
            'count' => count($attempts),
            'done'  => 0,
        );
        foreach ($attempts as $attempt) {
            $this->regrade_attempt($attempt, $dryrun);
            $a['done']++;
            $progressbar->update($a['done'], $a['count'],
                    get_string('regradingattemptxofy', 'quiz_overview', $a));
        }

        if (!$dryrun) {
            $this->update_overall_grades($quiz);
        }
    }
protected function regrade_attempts($quiz, $dryrun = false,
            \core\dml\sql_join$groupstudentsjoins = null, $attemptids = array()) {
        global $DB;
        $this->unlock_session();

        $sql = "SELECT quiza.*
                  FROM {quiz_attempts} quiza";
        $where = "quiz = :qid AND preview = 0";
        $params = array('qid' => $quiz->id);

        if ($this->hasgroupstudents && !empty($groupstudentsjoins->joins)) {
            $sql .= "\nJOIN {user} u ON u.id = quiza.userid
                    {$groupstudentsjoins->joins}";
            $where .= " AND {$groupstudentsjoins->wheres}";
            $params += $groupstudentsjoins->params;
        }

        if ($attemptids) {
            $aids = join(',', $attemptids);
            $where .= " AND quiza.id IN ({$aids})";
        }

        $sql .= "\nWHERE {$where}";
        $attempts = $DB->get_records_sql($sql, $params);
        if (!$attempts) {
            return;
        }

        $this->clear_regrade_table($quiz, $groupstudentsjoins);

        $progressbar = new progress_bar('quiz_overview_regrade', 500, true);
        $a = array(
            'count' => count($attempts),
            'done'  => 0,
        );
        foreach ($attempts as $attempt) {
            $this->regrade_attempt($attempt, $dryrun);
            $a['done']++;
            $progressbar->update($a['done'], $a['count'],
                    get_string('regradingattemptxofy', 'quiz_overview', $a));
        }

        if (!$dryrun) {
            $this->update_overall_grades($quiz);
        }
    }
protected function regrade_attempts ( $ quiz , $ dryrun = false , \ core \ dml \ sql_join $ groupstudentsjoins = null , $ attemptids = array ( ) ) { global $ DB ; $ this -> unlock_session ( ) ; $ sql = "SELECT quiza.*
                  FROM {quiz_attempts} quiza" ; $ where = "quiz = :qid AND preview = 0" ; $ params = array ( 'qid' => $ quiz -> id ) ; if ( $ this -> hasgroupstudents && ! empty ( $ groupstudentsjoins -> joins ) ) { $ sql .= "\nJOIN {user} u ON u.id = quiza.userid
                    {$groupstudentsjoins->joins}" ; $ where .= " AND {$groupstudentsjoins->wheres}" ; $ params += $ groupstudentsjoins -> params ; } if ( $ attemptids ) { $ aids = join ( ',' , $ attemptids ) ; $ where .= " AND quiza.id IN ({$aids})" ; } $ sql .= "\nWHERE {$where}" ; $ attempts = $ DB -> get_records_sql ( $ sql , $ params ) ; if ( ! $ attempts ) { return ; } $ this -> clear_regrade_table ( $ quiz , $ groupstudentsjoins ) ; $ progressbar = new progress_bar ( 'quiz_overview_regrade' , 500 , true ) ; $ a = array ( 'count' => count ( $ attempts ) , 'done' => 0 , ) ; foreach ( $ attempts as $ attempt ) { $ this -> regrade_attempt ( $ attempt , $ dryrun ) ; $ a [ 'done' ] ++ ; $ progressbar -> update ( $ a [ 'done' ] , $ a [ 'count' ] , get_string ( 'regradingattemptxofy' , 'quiz_overview' , $ a ) ) ; } if ( ! $ dryrun ) { $ this -> update_overall_grades ( $ quiz ) ; } }
Regrade attempts for this quiz, exactly which attempts are regraded is
controlled by the parameters.
@param object $quiz the quiz settings.
@param bool $dryrun if true, do a pretend regrade, otherwise do it for real.
@param \core\dml\sql_join|array $groupstudentsjoins empty for all attempts, otherwise regrade attempts
for these users.
@param array $attemptids blank for all attempts, otherwise only regrade
attempts whose id is in this list.
Regrade attempts for this quiz exactly which attempts are regraded is controlled by the parameters .