public static function fill_discussion_subscription_cache($forumid, $userid = null) {
        global $DB;

        if (!isset(self::$discussionfetchedforums[$forumid])) {
            // This forum hasn't been fetched as a whole yet.
            if (isset($userid)) {
                if (!isset(self::$forumdiscussioncache[$userid])) {
                    self::$forumdiscussioncache[$userid] = array();
                }

                if (!isset(self::$forumdiscussioncache[$userid][$forumid])) {
                    $subscriptions = $DB->get_recordset('forum_discussion_subs', array(
                        'userid' => $userid,
                        'forum' => $forumid,
                    ), null, 'id, discussion, preference');
                    foreach ($subscriptions as $id => $data) {
                        self::add_to_discussion_cache($forumid, $userid, $data->discussion, $data->preference);
                    }
                    $subscriptions->close();
                }
            } else {
                $subscriptions = $DB->get_recordset('forum_discussion_subs', array(
                    'forum' => $forumid,
                ), null, 'id, userid, discussion, preference');
                foreach ($subscriptions as $id => $data) {
                    self::add_to_discussion_cache($forumid, $data->userid, $data->discussion, $data->preference);
                }
                self::$discussionfetchedforums[$forumid] = true;
                $subscriptions->close();
            }
        }
    }
public static function fill_discussion_subscription_cache($forumid, $userid = null) {
        global $DB;

        if (!isset(self::$discussionfetchedforums[$forumid])) {
            // This forum hasn't been fetched as a whole yet.
            if (isset($userid)) {
                if (!isset(self::$forumdiscussioncache[$userid])) {
                    self::$forumdiscussioncache[$userid] = array();
                }

                if (!isset(self::$forumdiscussioncache[$userid][$forumid])) {
                    $subscriptions = $DB->get_recordset('forum_discussion_subs', array(
                        'userid' => $userid,
                        'forum' => $forumid,
                    ), null, 'id, discussion, preference');
                    foreach ($subscriptions as $id => $data) {
                        self::add_to_discussion_cache($forumid, $userid, $data->discussion, $data->preference);
                    }
                    $subscriptions->close();
                }
            } else {
                $subscriptions = $DB->get_recordset('forum_discussion_subs', array(
                    'forum' => $forumid,
                ), null, 'id, userid, discussion, preference');
                foreach ($subscriptions as $id => $data) {
                    self::add_to_discussion_cache($forumid, $data->userid, $data->discussion, $data->preference);
                }
                self::$discussionfetchedforums[$forumid] = true;
                $subscriptions->close();
            }
        }
    }
public static function fill_discussion_subscription_cache ( $ forumid , $ userid = null ) { global $ DB ; if ( ! isset ( self :: $ discussionfetchedforums [ $ forumid ] ) ) { // This forum hasn't been fetched as a whole yet. if ( isset ( $ userid ) ) { if ( ! isset ( self :: $ forumdiscussioncache [ $ userid ] ) ) { self :: $ forumdiscussioncache [ $ userid ] = array ( ) ; } if ( ! isset ( self :: $ forumdiscussioncache [ $ userid ] [ $ forumid ] ) ) { $ subscriptions = $ DB -> get_recordset ( 'forum_discussion_subs' , array ( 'userid' => $ userid , 'forum' => $ forumid , ) , null , 'id, discussion, preference' ) ; foreach ( $ subscriptions as $ id => $ data ) { self :: add_to_discussion_cache ( $ forumid , $ userid , $ data -> discussion , $ data -> preference ) ; } $ subscriptions -> close ( ) ; } } else { $ subscriptions = $ DB -> get_recordset ( 'forum_discussion_subs' , array ( 'forum' => $ forumid , ) , null , 'id, userid, discussion, preference' ) ; foreach ( $ subscriptions as $ id => $ data ) { self :: add_to_discussion_cache ( $ forumid , $ data -> userid , $ data -> discussion , $ data -> preference ) ; } self :: $ discussionfetchedforums [ $ forumid ] = true ; $ subscriptions -> close ( ) ; } } }
Fill the discussion subscription data for the specified userid and forum.

If the userid is not specified, then all discussion subscription data for that forum is fetched in a single query
and used for subsequent lookups without requiring further database queries.

@param int $forumid The forum to retrieve a cache for
@param int $userid The user ID
@return void
Fill the discussion subscription data for the specified userid and forum .