original_string: protected function count_question_attempts_needing_regrade($quiz, \core\dml\sql_join $groupstudentsjoins) {
          global $DB;
  
          $userjoin = '';
          $usertest = '';
          $params = array();
          if ($this->hasgroupstudents) {
              $userjoin = "JOIN {user} u ON u.id = quiza.userid
                      {$groupstudentsjoins->joins}";
              $usertest = "{$groupstudentsjoins->wheres} AND u.id = quiza.userid AND ";
              $params = $groupstudentsjoins->params;
          }
  
          $params['cquiz'] = $quiz->id;
          $sql = "SELECT COUNT(DISTINCT quiza.id)
                    FROM {quiz_attempts} quiza
                    JOIN {quiz_overview_regrades} qqr ON quiza.uniqueid = qqr.questionusageid
                  $userjoin
                   WHERE
                        $usertest
                        quiza.quiz = :cquiz AND
                        quiza.preview = 0 AND
                        qqr.regraded = 0";
          return $DB->count_records_sql($sql, $params);
      }
code: protected function count_question_attempts_needing_regrade($quiz, \core\dml\sql_join $groupstudentsjoins) {
          global $DB;
  
          $userjoin = '';
          $usertest = '';
          $params = array();
          if ($this->hasgroupstudents) {
              $userjoin = "JOIN {user} u ON u.id = quiza.userid
                      {$groupstudentsjoins->joins}";
              $usertest = "{$groupstudentsjoins->wheres} AND u.id = quiza.userid AND ";
              $params = $groupstudentsjoins->params;
          }
  
          $params['cquiz'] = $quiz->id;
          $sql = "SELECT COUNT(DISTINCT quiza.id)
                    FROM {quiz_attempts} quiza
                    JOIN {quiz_overview_regrades} qqr ON quiza.uniqueid = qqr.questionusageid
                  $userjoin
                   WHERE
                        $usertest
                        quiza.quiz = :cquiz AND
                        quiza.preview = 0 AND
                        qqr.regraded = 0";
          return $DB->count_records_sql($sql, $params);
      }
code_tokens: protected function count_question_attempts_needing_regrade ( $ quiz , \ core \ dml \ sql_join $ groupstudentsjoins ) { global $ DB ; $ userjoin = '' ; $ usertest = '' ; $ params = array ( ) ; if ( $ this -> hasgroupstudents ) { $ userjoin = "JOIN {user} u ON u.id = quiza.userid
                      {$groupstudentsjoins->joins}" ; $ usertest = "{$groupstudentsjoins->wheres} AND u.id = quiza.userid AND " ; $ params = $ groupstudentsjoins -> params ; } $ params [ 'cquiz' ] = $ quiz -> id ; $ sql = "SELECT COUNT(DISTINCT quiza.id)
                    FROM {quiz_attempts} quiza
                    JOIN {quiz_overview_regrades} qqr ON quiza.uniqueid = qqr.questionusageid
                  $userjoin
                   WHERE
                        $usertest
                        quiza.quiz = :cquiz AND
                        quiza.preview = 0 AND
                        qqr.regraded = 0" ; return $ DB -> count_records_sql ( $ sql , $ params ) ; }
docstring: Count the number of attempts in need of a regrade.
  @param object $quiz the quiz settings.
  @param \core\dml\sql_join $groupstudentsjoins (joins, wheres, params) If this is given, only data relating
  to these users is cleared.
docstring_tokens: Count the number of attempts in need of a regrade .