original_string: protected static function get_users_sql_and_params($context, $search = '', $count = false) {
  
          // Fields we need from the user table.
          $extrafields = get_extra_user_fields($context);
          $params = array();
          if (!empty($search)) {
              list($filtersql, $params) = users_search_sql($search, 'u', true, $extrafields);
              $filtersql .= ' AND ';
          } else {
              $filtersql = '';
          }
  
          $ufields = \user_picture::fields('u', $extrafields).',u.username';
          if ($count) {
              $select = "SELECT COUNT(DISTINCT u.id) ";
              $orderby = "";
          } else {
              $select = "SELECT DISTINCT $ufields ";
              $orderby = " ORDER BY u.lastname ASC, u.firstname ASC";
          }
          $sql = "$select
                   FROM {user} u
                   JOIN {grade_grades_history} ggh ON u.id = ggh.userid
                   JOIN {grade_items} gi ON gi.id = ggh.itemid
                  WHERE $filtersql gi.courseid = :courseid";
          $sql .= $orderby;
          $params['courseid'] = $context->instanceid;
  
          return array($sql, $params);
      }
code: protected static function get_users_sql_and_params($context, $search = '', $count = false) {
  
          // Fields we need from the user table.
          $extrafields = get_extra_user_fields($context);
          $params = array();
          if (!empty($search)) {
              list($filtersql, $params) = users_search_sql($search, 'u', true, $extrafields);
              $filtersql .= ' AND ';
          } else {
              $filtersql = '';
          }
  
          $ufields = \user_picture::fields('u', $extrafields).',u.username';
          if ($count) {
              $select = "SELECT COUNT(DISTINCT u.id) ";
              $orderby = "";
          } else {
              $select = "SELECT DISTINCT $ufields ";
              $orderby = " ORDER BY u.lastname ASC, u.firstname ASC";
          }
          $sql = "$select
                   FROM {user} u
                   JOIN {grade_grades_history} ggh ON u.id = ggh.userid
                   JOIN {grade_items} gi ON gi.id = ggh.itemid
                  WHERE $filtersql gi.courseid = :courseid";
          $sql .= $orderby;
          $params['courseid'] = $context->instanceid;
  
          return array($sql, $params);
      }
code_tokens: protected static function get_users_sql_and_params ( $ context , $ search = '' , $ count = false ) { // Fields we need from the user table. $ extrafields = get_extra_user_fields ( $ context ) ; $ params = array ( ) ; if ( ! empty ( $ search ) ) { list ( $ filtersql , $ params ) = users_search_sql ( $ search , 'u' , true , $ extrafields ) ; $ filtersql .= ' AND ' ; } else { $ filtersql = '' ; } $ ufields = \ user_picture :: fields ( 'u' , $ extrafields ) . ',u.username' ; if ( $ count ) { $ select = "SELECT COUNT(DISTINCT u.id) " ; $ orderby = "" ; } else { $ select = "SELECT DISTINCT $ufields " ; $ orderby = " ORDER BY u.lastname ASC, u.firstname ASC" ; } $ sql = "$select
                   FROM {user} u
                   JOIN {grade_grades_history} ggh ON u.id = ggh.userid
                   JOIN {grade_items} gi ON gi.id = ggh.itemid
                  WHERE $filtersql gi.courseid = :courseid" ; $ sql .= $ orderby ; $ params [ 'courseid' ] = $ context -> instanceid ; return array ( $ sql , $ params ) ; }
docstring: Get sql and params to use to get list of users.
  
  @param \context $context Context of the page where the results would be shown.
  @param string $search the text to search for (empty string = find all).
  @param bool $count setting this to true, returns an sql to get count only instead of the complete data records.
  
  @return array sql and params list
docstring_tokens: Get sql and params to use to get list of users .