original_string: public static function fetch_subscribed_users($forum, $groupid = 0, $context = null, $fields = null,
              $includediscussionsubscriptions = false) {
          global $CFG, $DB;
  
          if (empty($fields)) {
              $allnames = get_all_user_name_fields(true, 'u');
              $fields ="u.id,
                        u.username,
                        $allnames,
                        u.maildisplay,
                        u.mailformat,
                        u.maildigest,
                        u.imagealt,
                        u.email,
                        u.emailstop,
                        u.city,
                        u.country,
                        u.lastaccess,
                        u.lastlogin,
                        u.picture,
                        u.timezone,
                        u.theme,
                        u.lang,
                        u.trackforums,
                        u.mnethostid";
          }
  
          // Retrieve the forum context if it wasn't specified.
          $context = forum_get_context($forum->id, $context);
  
          if (self::is_forcesubscribed($forum)) {
              $results = \mod_forum\subscriptions::get_potential_subscribers($context, $groupid, $fields, "u.email ASC");
  
          } else {
              // Only active enrolled users or everybody on the frontpage.
              list($esql, $params) = get_enrolled_sql($context, '', $groupid, true);
              $params['forumid'] = $forum->id;
  
              if ($includediscussionsubscriptions) {
                  $params['sforumid'] = $forum->id;
                  $params['dsforumid'] = $forum->id;
                  $params['unsubscribed'] = self::FORUM_DISCUSSION_UNSUBSCRIBED;
  
                  $sql = "SELECT $fields
                          FROM (
                              SELECT userid FROM {forum_subscriptions} s
                              WHERE
                                  s.forum = :sforumid
                                  UNION
                              SELECT userid FROM {forum_discussion_subs} ds
                              WHERE
                                  ds.forum = :dsforumid AND ds.preference <> :unsubscribed
                          ) subscriptions
                          JOIN {user} u ON u.id = subscriptions.userid
                          JOIN ($esql) je ON je.id = u.id
                          ORDER BY u.email ASC";
  
              } else {
                  $sql = "SELECT $fields
                          FROM {user} u
                          JOIN ($esql) je ON je.id = u.id
                          JOIN {forum_subscriptions} s ON s.userid = u.id
                          WHERE
                            s.forum = :forumid
                          ORDER BY u.email ASC";
              }
              $results = $DB->get_records_sql($sql, $params);
          }
  
          // Guest user should never be subscribed to a forum.
          unset($results[$CFG->siteguest]);
  
          // Apply the activity module availability resetrictions.
          $cm = get_coursemodule_from_instance('forum', $forum->id, $forum->course);
          $modinfo = get_fast_modinfo($forum->course);
          $info = new \core_availability\info_module($modinfo->get_cm($cm->id));
          $results = $info->filter_user_list($results);
  
          return $results;
      }
code: public static function fetch_subscribed_users($forum, $groupid = 0, $context = null, $fields = null,
              $includediscussionsubscriptions = false) {
          global $CFG, $DB;
  
          if (empty($fields)) {
              $allnames = get_all_user_name_fields(true, 'u');
              $fields ="u.id,
                        u.username,
                        $allnames,
                        u.maildisplay,
                        u.mailformat,
                        u.maildigest,
                        u.imagealt,
                        u.email,
                        u.emailstop,
                        u.city,
                        u.country,
                        u.lastaccess,
                        u.lastlogin,
                        u.picture,
                        u.timezone,
                        u.theme,
                        u.lang,
                        u.trackforums,
                        u.mnethostid";
          }
  
          // Retrieve the forum context if it wasn't specified.
          $context = forum_get_context($forum->id, $context);
  
          if (self::is_forcesubscribed($forum)) {
              $results = \mod_forum\subscriptions::get_potential_subscribers($context, $groupid, $fields, "u.email ASC");
  
          } else {
              // Only active enrolled users or everybody on the frontpage.
              list($esql, $params) = get_enrolled_sql($context, '', $groupid, true);
              $params['forumid'] = $forum->id;
  
              if ($includediscussionsubscriptions) {
                  $params['sforumid'] = $forum->id;
                  $params['dsforumid'] = $forum->id;
                  $params['unsubscribed'] = self::FORUM_DISCUSSION_UNSUBSCRIBED;
  
                  $sql = "SELECT $fields
                          FROM (
                              SELECT userid FROM {forum_subscriptions} s
                              WHERE
                                  s.forum = :sforumid
                                  UNION
                              SELECT userid FROM {forum_discussion_subs} ds
                              WHERE
                                  ds.forum = :dsforumid AND ds.preference <> :unsubscribed
                          ) subscriptions
                          JOIN {user} u ON u.id = subscriptions.userid
                          JOIN ($esql) je ON je.id = u.id
                          ORDER BY u.email ASC";
  
              } else {
                  $sql = "SELECT $fields
                          FROM {user} u
                          JOIN ($esql) je ON je.id = u.id
                          JOIN {forum_subscriptions} s ON s.userid = u.id
                          WHERE
                            s.forum = :forumid
                          ORDER BY u.email ASC";
              }
              $results = $DB->get_records_sql($sql, $params);
          }
  
          // Guest user should never be subscribed to a forum.
          unset($results[$CFG->siteguest]);
  
          // Apply the activity module availability resetrictions.
          $cm = get_coursemodule_from_instance('forum', $forum->id, $forum->course);
          $modinfo = get_fast_modinfo($forum->course);
          $info = new \core_availability\info_module($modinfo->get_cm($cm->id));
          $results = $info->filter_user_list($results);
  
          return $results;
      }
code_tokens: public static function fetch_subscribed_users ( $ forum , $ groupid = 0 , $ context = null , $ fields = null , $ includediscussionsubscriptions = false ) { global $ CFG , $ DB ; if ( empty ( $ fields ) ) { $ allnames = get_all_user_name_fields ( true , 'u' ) ; $ fields = "u.id,
                        u.username,
                        $allnames,
                        u.maildisplay,
                        u.mailformat,
                        u.maildigest,
                        u.imagealt,
                        u.email,
                        u.emailstop,
                        u.city,
                        u.country,
                        u.lastaccess,
                        u.lastlogin,
                        u.picture,
                        u.timezone,
                        u.theme,
                        u.lang,
                        u.trackforums,
                        u.mnethostid" ; } // Retrieve the forum context if it wasn't specified. $ context = forum_get_context ( $ forum -> id , $ context ) ; if ( self :: is_forcesubscribed ( $ forum ) ) { $ results = \ mod_forum \ subscriptions :: get_potential_subscribers ( $ context , $ groupid , $ fields , "u.email ASC" ) ; } else { // Only active enrolled users or everybody on the frontpage. list ( $ esql , $ params ) = get_enrolled_sql ( $ context , '' , $ groupid , true ) ; $ params [ 'forumid' ] = $ forum -> id ; if ( $ includediscussionsubscriptions ) { $ params [ 'sforumid' ] = $ forum -> id ; $ params [ 'dsforumid' ] = $ forum -> id ; $ params [ 'unsubscribed' ] = self :: FORUM_DISCUSSION_UNSUBSCRIBED ; $ sql = "SELECT $fields
                          FROM (
                              SELECT userid FROM {forum_subscriptions} s
                              WHERE
                                  s.forum = :sforumid
                                  UNION
                              SELECT userid FROM {forum_discussion_subs} ds
                              WHERE
                                  ds.forum = :dsforumid AND ds.preference <> :unsubscribed
                          ) subscriptions
                          JOIN {user} u ON u.id = subscriptions.userid
                          JOIN ($esql) je ON je.id = u.id
                          ORDER BY u.email ASC" ; } else { $ sql = "SELECT $fields
                          FROM {user} u
                          JOIN ($esql) je ON je.id = u.id
                          JOIN {forum_subscriptions} s ON s.userid = u.id
                          WHERE
                            s.forum = :forumid
                          ORDER BY u.email ASC" ; } $ results = $ DB -> get_records_sql ( $ sql , $ params ) ; } // Guest user should never be subscribed to a forum. unset ( $ results [ $ CFG -> siteguest ] ) ; // Apply the activity module availability resetrictions. $ cm = get_coursemodule_from_instance ( 'forum' , $ forum -> id , $ forum -> course ) ; $ modinfo = get_fast_modinfo ( $ forum -> course ) ; $ info = new \ core_availability \ info_module ( $ modinfo -> get_cm ( $ cm -> id ) ) ; $ results = $ info -> filter_user_list ( $ results ) ; return $ results ; }
docstring: Returns a list of user objects who are subscribed to this forum.
  
  @param stdClass $forum The forum record.
  @param int $groupid The group id if restricting subscriptions to a group of users, or 0 for all.
  @param context_module $context the forum context, to save re-fetching it where possible.
  @param string $fields requested user fields (with "u." table prefix).
  @param boolean $includediscussionsubscriptions Whether to take discussion subscriptions and unsubscriptions into consideration.
  @return array list of users.
docstring_tokens: Returns a list of user objects who are subscribed to this forum .