original_string: public function get_users($sort, $direction='ASC', $page=0, $perpage=25) {
          global $DB;
          if ($direction !== 'ASC') {
              $direction = 'DESC';
          }
          $key = md5("$sort-$direction-$page-$perpage");
          if (!array_key_exists($key, $this->users)) {
              list($instancessql, $params, $filter) = $this->get_instance_sql();
              list($filtersql, $moreparams) = $this->get_filter_sql();
              $params += $moreparams;
              $extrafields = get_extra_user_fields($this->get_context());
              $extrafields[] = 'lastaccess';
              $ufields = user_picture::fields('u', $extrafields);
              $sql = "SELECT DISTINCT $ufields, COALESCE(ul.timeaccess, 0) AS lastcourseaccess
                        FROM {user} u
                        JOIN {user_enrolments} ue ON (ue.userid = u.id  AND ue.enrolid $instancessql)
                        JOIN {enrol} e ON (e.id = ue.enrolid)
                   LEFT JOIN {user_lastaccess} ul ON (ul.courseid = e.courseid AND ul.userid = u.id)";
              if ($this->groupfilter) {
                  $sql .= " LEFT JOIN ({groups_members} gm JOIN {groups} g ON (g.id = gm.groupid))
                                      ON (u.id = gm.userid AND g.courseid = e.courseid)";
              }
              $sql .= "WHERE $filtersql
                    ORDER BY $sort $direction";
              $this->users[$key] = $DB->get_records_sql($sql, $params, $page*$perpage, $perpage);
          }
          return $this->users[$key];
      }
code: public function get_users($sort, $direction='ASC', $page=0, $perpage=25) {
          global $DB;
          if ($direction !== 'ASC') {
              $direction = 'DESC';
          }
          $key = md5("$sort-$direction-$page-$perpage");
          if (!array_key_exists($key, $this->users)) {
              list($instancessql, $params, $filter) = $this->get_instance_sql();
              list($filtersql, $moreparams) = $this->get_filter_sql();
              $params += $moreparams;
              $extrafields = get_extra_user_fields($this->get_context());
              $extrafields[] = 'lastaccess';
              $ufields = user_picture::fields('u', $extrafields);
              $sql = "SELECT DISTINCT $ufields, COALESCE(ul.timeaccess, 0) AS lastcourseaccess
                        FROM {user} u
                        JOIN {user_enrolments} ue ON (ue.userid = u.id  AND ue.enrolid $instancessql)
                        JOIN {enrol} e ON (e.id = ue.enrolid)
                   LEFT JOIN {user_lastaccess} ul ON (ul.courseid = e.courseid AND ul.userid = u.id)";
              if ($this->groupfilter) {
                  $sql .= " LEFT JOIN ({groups_members} gm JOIN {groups} g ON (g.id = gm.groupid))
                                      ON (u.id = gm.userid AND g.courseid = e.courseid)";
              }
              $sql .= "WHERE $filtersql
                    ORDER BY $sort $direction";
              $this->users[$key] = $DB->get_records_sql($sql, $params, $page*$perpage, $perpage);
          }
          return $this->users[$key];
      }
code_tokens: public function get_users ( $ sort , $ direction = 'ASC' , $ page = 0 , $ perpage = 25 ) { global $ DB ; if ( $ direction !== 'ASC' ) { $ direction = 'DESC' ; } $ key = md5 ( "$sort-$direction-$page-$perpage" ) ; if ( ! array_key_exists ( $ key , $ this -> users ) ) { list ( $ instancessql , $ params , $ filter ) = $ this -> get_instance_sql ( ) ; list ( $ filtersql , $ moreparams ) = $ this -> get_filter_sql ( ) ; $ params += $ moreparams ; $ extrafields = get_extra_user_fields ( $ this -> get_context ( ) ) ; $ extrafields [ ] = 'lastaccess' ; $ ufields = user_picture :: fields ( 'u' , $ extrafields ) ; $ sql = "SELECT DISTINCT $ufields, COALESCE(ul.timeaccess, 0) AS lastcourseaccess
                        FROM {user} u
                        JOIN {user_enrolments} ue ON (ue.userid = u.id  AND ue.enrolid $instancessql)
                        JOIN {enrol} e ON (e.id = ue.enrolid)
                   LEFT JOIN {user_lastaccess} ul ON (ul.courseid = e.courseid AND ul.userid = u.id)" ; if ( $ this -> groupfilter ) { $ sql .= " LEFT JOIN ({groups_members} gm JOIN {groups} g ON (g.id = gm.groupid))
                                      ON (u.id = gm.userid AND g.courseid = e.courseid)" ; } $ sql .= "WHERE $filtersql
                    ORDER BY $sort $direction" ; $ this -> users [ $ key ] = $ DB -> get_records_sql ( $ sql , $ params , $ page * $ perpage , $ perpage ) ; } return $ this -> users [ $ key ] ; }
docstring: Gets all of the users enrolled in this course.
  
  If a filter was specified this will be the users who were enrolled
  in this course by means of that instance. If role or search filters were
  specified then these will also be applied.
  
  @global moodle_database $DB
  @param string $sort
  @param string $direction ASC or DESC
  @param int $page First page should be 0
  @param int $perpage Defaults to 25
  @return array
docstring_tokens: Gets all of the users enrolled in this course .