original_string: public function add_from_sql(string $fieldname, string $sql, array $params) : userlist {
          global $DB;
  
          // Able to guess a field name.
          $wrapper = "
              SELECT DISTINCT u.id
              FROM {user} u
              JOIN ({$sql}) target ON u.id = target.{$fieldname}";
  
          $users = $DB->get_records_sql($wrapper, $params);
          $this->add_userids(array_keys($users));
  
          return $this;
      }
code: public function add_from_sql(string $fieldname, string $sql, array $params) : userlist {
          global $DB;
  
          // Able to guess a field name.
          $wrapper = "
              SELECT DISTINCT u.id
              FROM {user} u
              JOIN ({$sql}) target ON u.id = target.{$fieldname}";
  
          $users = $DB->get_records_sql($wrapper, $params);
          $this->add_userids(array_keys($users));
  
          return $this;
      }
code_tokens: public function add_from_sql ( string $ fieldname , string $ sql , array $ params ) : userlist { global $ DB ; // Able to guess a field name. $ wrapper = "
              SELECT DISTINCT u.id
              FROM {user} u
              JOIN ({$sql}) target ON u.id = target.{$fieldname}" ; $ users = $ DB -> get_records_sql ( $ wrapper , $ params ) ; $ this -> add_userids ( array_keys ( $ users ) ) ; return $ this ; }
docstring: Add a set of users from  SQL.
  
  The SQL should only return a list of user IDs.
  
  @param   string  $fieldname The name of the field which holds the user id
  @param   string  $sql    The SQL which will fetch the list of * user IDs
  @param   array   $params The set of SQL parameters
  @return  $this
docstring_tokens: Add a set of users from SQL .