original_string: public static function get_unsubscribable_forums() {
          global $USER, $DB;
  
          // Get courses that $USER is enrolled in and can see.
          $courses = enrol_get_my_courses();
          if (empty($courses)) {
              return array();
          }
  
          $courseids = array();
          foreach($courses as $course) {
              $courseids[] = $course->id;
          }
          list($coursesql, $courseparams) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED, 'c');
  
          // Get all forums from the user's courses that they are subscribed to and which are not set to forced.
          // It is possible for users to be subscribed to a forum in subscription disallowed mode so they must be listed
          // here so that that can be unsubscribed from.
          $sql = "SELECT f.id, cm.id as cm, cm.visible, f.course
                  FROM {forum} f
                  JOIN {course_modules} cm ON cm.instance = f.id
                  JOIN {modules} m ON m.name = :modulename AND m.id = cm.module
                  LEFT JOIN {forum_subscriptions} fs ON (fs.forum = f.id AND fs.userid = :userid)
                  WHERE f.forcesubscribe <> :forcesubscribe
                  AND fs.id IS NOT NULL
                  AND cm.course
                  $coursesql";
          $params = array_merge($courseparams, array(
              'modulename'=>'forum',
              'userid' => $USER->id,
              'forcesubscribe' => FORUM_FORCESUBSCRIBE,
          ));
          $forums = $DB->get_recordset_sql($sql, $params);
  
          $unsubscribableforums = array();
          foreach($forums as $forum) {
              if (empty($forum->visible)) {
                  // The forum is hidden - check if the user can view the forum.
                  $context = \context_module::instance($forum->cm);
                  if (!has_capability('moodle/course:viewhiddenactivities', $context)) {
                      // The user can't see the hidden forum to cannot unsubscribe.
                      continue;
                  }
              }
  
              $unsubscribableforums[] = $forum;
          }
          $forums->close();
  
          return $unsubscribableforums;
      }
code: public static function get_unsubscribable_forums() {
          global $USER, $DB;
  
          // Get courses that $USER is enrolled in and can see.
          $courses = enrol_get_my_courses();
          if (empty($courses)) {
              return array();
          }
  
          $courseids = array();
          foreach($courses as $course) {
              $courseids[] = $course->id;
          }
          list($coursesql, $courseparams) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED, 'c');
  
          // Get all forums from the user's courses that they are subscribed to and which are not set to forced.
          // It is possible for users to be subscribed to a forum in subscription disallowed mode so they must be listed
          // here so that that can be unsubscribed from.
          $sql = "SELECT f.id, cm.id as cm, cm.visible, f.course
                  FROM {forum} f
                  JOIN {course_modules} cm ON cm.instance = f.id
                  JOIN {modules} m ON m.name = :modulename AND m.id = cm.module
                  LEFT JOIN {forum_subscriptions} fs ON (fs.forum = f.id AND fs.userid = :userid)
                  WHERE f.forcesubscribe <> :forcesubscribe
                  AND fs.id IS NOT NULL
                  AND cm.course
                  $coursesql";
          $params = array_merge($courseparams, array(
              'modulename'=>'forum',
              'userid' => $USER->id,
              'forcesubscribe' => FORUM_FORCESUBSCRIBE,
          ));
          $forums = $DB->get_recordset_sql($sql, $params);
  
          $unsubscribableforums = array();
          foreach($forums as $forum) {
              if (empty($forum->visible)) {
                  // The forum is hidden - check if the user can view the forum.
                  $context = \context_module::instance($forum->cm);
                  if (!has_capability('moodle/course:viewhiddenactivities', $context)) {
                      // The user can't see the hidden forum to cannot unsubscribe.
                      continue;
                  }
              }
  
              $unsubscribableforums[] = $forum;
          }
          $forums->close();
  
          return $unsubscribableforums;
      }
code_tokens: public static function get_unsubscribable_forums ( ) { global $ USER , $ DB ; // Get courses that $USER is enrolled in and can see. $ courses = enrol_get_my_courses ( ) ; if ( empty ( $ courses ) ) { return array ( ) ; } $ courseids = array ( ) ; foreach ( $ courses as $ course ) { $ courseids [ ] = $ course -> id ; } list ( $ coursesql , $ courseparams ) = $ DB -> get_in_or_equal ( $ courseids , SQL_PARAMS_NAMED , 'c' ) ; // Get all forums from the user's courses that they are subscribed to and which are not set to forced. // It is possible for users to be subscribed to a forum in subscription disallowed mode so they must be listed // here so that that can be unsubscribed from. $ sql = "SELECT f.id, cm.id as cm, cm.visible, f.course
                  FROM {forum} f
                  JOIN {course_modules} cm ON cm.instance = f.id
                  JOIN {modules} m ON m.name = :modulename AND m.id = cm.module
                  LEFT JOIN {forum_subscriptions} fs ON (fs.forum = f.id AND fs.userid = :userid)
                  WHERE f.forcesubscribe <> :forcesubscribe
                  AND fs.id IS NOT NULL
                  AND cm.course
                  $coursesql" ; $ params = array_merge ( $ courseparams , array ( 'modulename' => 'forum' , 'userid' => $ USER -> id , 'forcesubscribe' => FORUM_FORCESUBSCRIBE , ) ) ; $ forums = $ DB -> get_recordset_sql ( $ sql , $ params ) ; $ unsubscribableforums = array ( ) ; foreach ( $ forums as $ forum ) { if ( empty ( $ forum -> visible ) ) { // The forum is hidden - check if the user can view the forum. $ context = \ context_module :: instance ( $ forum -> cm ) ; if ( ! has_capability ( 'moodle/course:viewhiddenactivities' , $ context ) ) { // The user can't see the hidden forum to cannot unsubscribe. continue ; } } $ unsubscribableforums [ ] = $ forum ; } $ forums -> close ( ) ; return $ unsubscribableforums ; }
docstring: Returns an array of forums that the current user is subscribed to and is allowed to unsubscribe from
  
  @return array An array of unsubscribable forums
docstring_tokens: Returns an array of forums that the current user is subscribed to and is allowed to unsubscribe from