original_string: public function count_submissions_with_status($status, $currentgroup = null) {
          global $DB;
  
          if ($currentgroup === null) {
              $currentgroup = groups_get_activity_group($this->get_course_module(), true);
          }
          list($esql, $params) = get_enrolled_sql($this->get_context(), 'mod/assign:submit', $currentgroup, true);
  
          $params['assignid'] = $this->get_instance()->id;
          $params['assignid2'] = $this->get_instance()->id;
          $params['submissionstatus'] = $status;
  
          if ($this->get_instance()->teamsubmission) {
  
              $groupsstr = '';
              if ($currentgroup != 0) {
                  // If there is an active group we should only display the current group users groups.
                  $participants = $this->list_participants($currentgroup, true);
                  $groups = groups_get_all_groups($this->get_course()->id,
                                                  array_keys($participants),
                                                  $this->get_instance()->teamsubmissiongroupingid,
                                                  'DISTINCT g.id, g.name');
                  if (empty($groups)) {
                      // If $groups is empty it means it is not part of $this->get_instance()->teamsubmissiongroupingid.
                      // All submissions from students that do not belong to any of teamsubmissiongroupingid groups
                      // count towards groupid = 0. Setting to true as only '0' key matters.
                      $groups = [true];
                  }
                  list($groupssql, $groupsparams) = $DB->get_in_or_equal(array_keys($groups), SQL_PARAMS_NAMED);
                  $groupsstr = 's.groupid ' . $groupssql . ' AND';
                  $params = $params + $groupsparams;
              }
              $sql = 'SELECT COUNT(s.groupid)
                          FROM {assign_submission} s
                          WHERE
                              s.latest = 1 AND
                              s.assignment = :assignid AND
                              s.timemodified IS NOT NULL AND
                              s.userid = :groupuserid AND '
                              . $groupsstr . '
                              s.status = :submissionstatus';
              $params['groupuserid'] = 0;
          } else {
              $sql = 'SELECT COUNT(s.userid)
                          FROM {assign_submission} s
                          JOIN(' . $esql . ') e ON e.id = s.userid
                          WHERE
                              s.latest = 1 AND
                              s.assignment = :assignid AND
                              s.timemodified IS NOT NULL AND
                              s.status = :submissionstatus';
  
          }
  
          return $DB->count_records_sql($sql, $params);
      }
code: public function count_submissions_with_status($status, $currentgroup = null) {
          global $DB;
  
          if ($currentgroup === null) {
              $currentgroup = groups_get_activity_group($this->get_course_module(), true);
          }
          list($esql, $params) = get_enrolled_sql($this->get_context(), 'mod/assign:submit', $currentgroup, true);
  
          $params['assignid'] = $this->get_instance()->id;
          $params['assignid2'] = $this->get_instance()->id;
          $params['submissionstatus'] = $status;
  
          if ($this->get_instance()->teamsubmission) {
  
              $groupsstr = '';
              if ($currentgroup != 0) {
                  // If there is an active group we should only display the current group users groups.
                  $participants = $this->list_participants($currentgroup, true);
                  $groups = groups_get_all_groups($this->get_course()->id,
                                                  array_keys($participants),
                                                  $this->get_instance()->teamsubmissiongroupingid,
                                                  'DISTINCT g.id, g.name');
                  if (empty($groups)) {
                      // If $groups is empty it means it is not part of $this->get_instance()->teamsubmissiongroupingid.
                      // All submissions from students that do not belong to any of teamsubmissiongroupingid groups
                      // count towards groupid = 0. Setting to true as only '0' key matters.
                      $groups = [true];
                  }
                  list($groupssql, $groupsparams) = $DB->get_in_or_equal(array_keys($groups), SQL_PARAMS_NAMED);
                  $groupsstr = 's.groupid ' . $groupssql . ' AND';
                  $params = $params + $groupsparams;
              }
              $sql = 'SELECT COUNT(s.groupid)
                          FROM {assign_submission} s
                          WHERE
                              s.latest = 1 AND
                              s.assignment = :assignid AND
                              s.timemodified IS NOT NULL AND
                              s.userid = :groupuserid AND '
                              . $groupsstr . '
                              s.status = :submissionstatus';
              $params['groupuserid'] = 0;
          } else {
              $sql = 'SELECT COUNT(s.userid)
                          FROM {assign_submission} s
                          JOIN(' . $esql . ') e ON e.id = s.userid
                          WHERE
                              s.latest = 1 AND
                              s.assignment = :assignid AND
                              s.timemodified IS NOT NULL AND
                              s.status = :submissionstatus';
  
          }
  
          return $DB->count_records_sql($sql, $params);
      }
code_tokens: public function count_submissions_with_status ( $ status , $ currentgroup = null ) { global $ DB ; if ( $ currentgroup === null ) { $ currentgroup = groups_get_activity_group ( $ this -> get_course_module ( ) , true ) ; } list ( $ esql , $ params ) = get_enrolled_sql ( $ this -> get_context ( ) , 'mod/assign:submit' , $ currentgroup , true ) ; $ params [ 'assignid' ] = $ this -> get_instance ( ) -> id ; $ params [ 'assignid2' ] = $ this -> get_instance ( ) -> id ; $ params [ 'submissionstatus' ] = $ status ; if ( $ this -> get_instance ( ) -> teamsubmission ) { $ groupsstr = '' ; if ( $ currentgroup != 0 ) { // If there is an active group we should only display the current group users groups. $ participants = $ this -> list_participants ( $ currentgroup , true ) ; $ groups = groups_get_all_groups ( $ this -> get_course ( ) -> id , array_keys ( $ participants ) , $ this -> get_instance ( ) -> teamsubmissiongroupingid , 'DISTINCT g.id, g.name' ) ; if ( empty ( $ groups ) ) { // If $groups is empty it means it is not part of $this->get_instance()->teamsubmissiongroupingid. // All submissions from students that do not belong to any of teamsubmissiongroupingid groups // count towards groupid = 0. Setting to true as only '0' key matters. $ groups = [ true ] ; } list ( $ groupssql , $ groupsparams ) = $ DB -> get_in_or_equal ( array_keys ( $ groups ) , SQL_PARAMS_NAMED ) ; $ groupsstr = 's.groupid ' . $ groupssql . ' AND' ; $ params = $ params + $ groupsparams ; } $ sql = 'SELECT COUNT(s.groupid)
                          FROM {assign_submission} s
                          WHERE
                              s.latest = 1 AND
                              s.assignment = :assignid AND
                              s.timemodified IS NOT NULL AND
                              s.userid = :groupuserid AND ' . $ groupsstr . '
                              s.status = :submissionstatus' ; $ params [ 'groupuserid' ] = 0 ; } else { $ sql = 'SELECT COUNT(s.userid)
                          FROM {assign_submission} s
                          JOIN(' . $ esql . ') e ON e.id = s.userid
                          WHERE
                              s.latest = 1 AND
                              s.assignment = :assignid AND
                              s.timemodified IS NOT NULL AND
                              s.status = :submissionstatus' ; } return $ DB -> count_records_sql ( $ sql , $ params ) ; }
docstring: Load a count of submissions with a specified status.
  
  @param string $status The submission status - should match one of the constants
  @param mixed $currentgroup int|null the group for counting (if null the function will determine it)
  @return int number of matching submissions
docstring_tokens: Load a count of submissions with a specified status .