original_string: public static function unsubscribe_user($userid, $forum, $context = null, $userrequest = false) {
          global $DB;
  
          $sqlparams = array(
              'userid' => $userid,
              'forum' => $forum->id,
          );
          $DB->delete_records('forum_digests', $sqlparams);
  
          if ($forumsubscription = $DB->get_record('forum_subscriptions', $sqlparams)) {
              $DB->delete_records('forum_subscriptions', array('id' => $forumsubscription->id));
  
              if ($userrequest) {
                  $discussionsubscriptions = $DB->get_recordset('forum_discussion_subs', $sqlparams);
                  $DB->delete_records('forum_discussion_subs',
                          array('userid' => $userid, 'forum' => $forum->id, 'preference' => self::FORUM_DISCUSSION_UNSUBSCRIBED));
  
                  // We know that the there were previously entries and there aren't any more.
                  if (isset(self::$forumdiscussioncache[$userid]) && isset(self::$forumdiscussioncache[$userid][$forum->id])) {
                      self::$forumdiscussioncache[$userid][$forum->id] = array();
                  }
              }
  
              // Reset the cache for this forum.
              self::$forumcache[$userid][$forum->id] = false;
  
              $context = forum_get_context($forum->id, $context);
              $params = array(
                  'context' => $context,
                  'objectid' => $forumsubscription->id,
                  'relateduserid' => $userid,
                  'other' => array('forumid' => $forum->id),
  
              );
              $event = event\subscription_deleted::create($params);
              $event->add_record_snapshot('forum_subscriptions', $forumsubscription);
              if ($userrequest && $discussionsubscriptions) {
                  foreach ($discussionsubscriptions as $subscription) {
                      $event->add_record_snapshot('forum_discussion_subs', $subscription);
                  }
                  $discussionsubscriptions->close();
              }
              $event->trigger();
          }
  
          return true;
      }
code: public static function unsubscribe_user($userid, $forum, $context = null, $userrequest = false) {
          global $DB;
  
          $sqlparams = array(
              'userid' => $userid,
              'forum' => $forum->id,
          );
          $DB->delete_records('forum_digests', $sqlparams);
  
          if ($forumsubscription = $DB->get_record('forum_subscriptions', $sqlparams)) {
              $DB->delete_records('forum_subscriptions', array('id' => $forumsubscription->id));
  
              if ($userrequest) {
                  $discussionsubscriptions = $DB->get_recordset('forum_discussion_subs', $sqlparams);
                  $DB->delete_records('forum_discussion_subs',
                          array('userid' => $userid, 'forum' => $forum->id, 'preference' => self::FORUM_DISCUSSION_UNSUBSCRIBED));
  
                  // We know that the there were previously entries and there aren't any more.
                  if (isset(self::$forumdiscussioncache[$userid]) && isset(self::$forumdiscussioncache[$userid][$forum->id])) {
                      self::$forumdiscussioncache[$userid][$forum->id] = array();
                  }
              }
  
              // Reset the cache for this forum.
              self::$forumcache[$userid][$forum->id] = false;
  
              $context = forum_get_context($forum->id, $context);
              $params = array(
                  'context' => $context,
                  'objectid' => $forumsubscription->id,
                  'relateduserid' => $userid,
                  'other' => array('forumid' => $forum->id),
  
              );
              $event = event\subscription_deleted::create($params);
              $event->add_record_snapshot('forum_subscriptions', $forumsubscription);
              if ($userrequest && $discussionsubscriptions) {
                  foreach ($discussionsubscriptions as $subscription) {
                      $event->add_record_snapshot('forum_discussion_subs', $subscription);
                  }
                  $discussionsubscriptions->close();
              }
              $event->trigger();
          }
  
          return true;
      }
code_tokens: public static function unsubscribe_user ( $ userid , $ forum , $ context = null , $ userrequest = false ) { global $ DB ; $ sqlparams = array ( 'userid' => $ userid , 'forum' => $ forum -> id , ) ; $ DB -> delete_records ( 'forum_digests' , $ sqlparams ) ; if ( $ forumsubscription = $ DB -> get_record ( 'forum_subscriptions' , $ sqlparams ) ) { $ DB -> delete_records ( 'forum_subscriptions' , array ( 'id' => $ forumsubscription -> id ) ) ; if ( $ userrequest ) { $ discussionsubscriptions = $ DB -> get_recordset ( 'forum_discussion_subs' , $ sqlparams ) ; $ DB -> delete_records ( 'forum_discussion_subs' , array ( 'userid' => $ userid , 'forum' => $ forum -> id , 'preference' => self :: FORUM_DISCUSSION_UNSUBSCRIBED ) ) ; // We know that the there were previously entries and there aren't any more. if ( isset ( self :: $ forumdiscussioncache [ $ userid ] ) && isset ( self :: $ forumdiscussioncache [ $ userid ] [ $ forum -> id ] ) ) { self :: $ forumdiscussioncache [ $ userid ] [ $ forum -> id ] = array ( ) ; } } // Reset the cache for this forum. self :: $ forumcache [ $ userid ] [ $ forum -> id ] = false ; $ context = forum_get_context ( $ forum -> id , $ context ) ; $ params = array ( 'context' => $ context , 'objectid' => $ forumsubscription -> id , 'relateduserid' => $ userid , 'other' => array ( 'forumid' => $ forum -> id ) , ) ; $ event = event \ subscription_deleted :: create ( $ params ) ; $ event -> add_record_snapshot ( 'forum_subscriptions' , $ forumsubscription ) ; if ( $ userrequest && $ discussionsubscriptions ) { foreach ( $ discussionsubscriptions as $ subscription ) { $ event -> add_record_snapshot ( 'forum_discussion_subs' , $ subscription ) ; } $ discussionsubscriptions -> close ( ) ; } $ event -> trigger ( ) ; } return true ; }
docstring: Removes user from the subscriber list
  
  @param int $userid The ID of the user to unsubscribe
  @param \stdClass $forum The forum record for this forum.
  @param \context_module|null $context Module context, may be omitted if not known or if called for the current
  module set in page.
  @param boolean $userrequest Whether the user requested this change themselves. This has an effect on whether
  discussion subscriptions are removed too.
  @return boolean Always returns true.
docstring_tokens: Removes user from the subscriber list