}
 // Construct forums array
 $forums = forum::get_course_forums($course, 0, forum::UNREAD_DISCUSSIONS, array(), true);
 // Display all forums
 $currentsection = 0;
 $cansubscribesomething = false;
 $canunsubscribesomething = false;
 foreach ($forums as $forum) {
     $cm = $forum->get_course_module();
     // Skip forum if it's not visible or you can't read discussions there
     if (!$cm->uservisible || !has_capability('mod/forumng:viewdiscussion', $forum->get_context())) {
         continue;
     }
     // Additional OU access restrictions
     if (class_exists('ouflags')) {
         list($accessible, $visible, $message) = is_module_student_accessible($cm, $course);
         if (!$accessible) {
             continue;
         }
     }
     $row = array();
     //        $options = new StdClass;
     //        $options->para=false;
     // Get section number
     if ($cm->sectionnum != $currentsection) {
         $printsection = $cm->sectionnum;
         // Between each section add a horizontal gap (copied this code,
         // can't say I like it)
         if ($currentsection) {
             $learningtable->data[] = 'hr';
         }
 /**
  * Checks whether a user can be subscribed to the forum, regardless of
  * subscription option. Includes a variety of other checks. [These are
  * supposed to be the same as checks done when building the list of people
  * for email.]
  * @param int $userid User ID or 0 for current
  * @return bool True if user can be subscribed
  */
 private function can_be_subscribed($userid = 0)
 {
     global $USER;
     $userid = forum_utils::get_real_userid($userid);
     $cm = $this->get_course_module();
     $course = $this->get_course();
     $context = $this->get_context();
     // Guests cannot subscribe
     if (isguest($userid)) {
         return false;
     }
     // Get from cache if possible
     if (!isset($this->cache->can_be_subscribed)) {
         $this->cache->can_be_subscribed = array();
     }
     if (array_key_exists($userid, $this->cache->can_be_subscribed)) {
         return $this->cache->can_be_subscribed[$userid];
     }
     // This is not a loop, just so I can use break
     do {
         // Check user can see forum
         if (!has_capability('mod/forumng:viewdiscussion', $context, $userid)) {
             $result = false;
             break;
         }
         // For current user, can take shortcut
         if ($userid == $USER->id) {
             if (empty($cm->uservisible)) {
                 $uservisible = false;
             } else {
                 $uservisible = true;
             }
             if (!$uservisible) {
                 $result = false;
                 break;
             }
         } else {
             $visible = $cm->visible;
             if (class_exists('ouflags')) {
                 // OU extra access restrictions
                 require_once $CFG->libdir . '/conditionlib.php';
                 require_once $CFG->dirroot . '/local/module_access.php';
                 $conditioninfo = new condition_info($cm);
                 $visible = $visible && $conditioninfo->is_available($crap, false, $userid) && is_module_student_accessible($cm, $course);
             }
             if (!$visible && !has_capability('moodle/site:viewhiddenactivities', $context, $userid)) {
                 $result = false;
                 break;
             }
             if ($cm->groupmembersonly && !has_capability('moodle/site:accessallgroups', $context, $userid)) {
                 // If the forum is restricted to group members only, then
                 // limit it to people within groups on the course - or
                 // groups in the grouping, if one is selected
                 $groupobjs = groups_get_all_groups($course->id, $userid, $cm->groupingid, 'g.id');
                 if (!$groupobjs || count($groupobjs) == 0) {
                     $result = false;
                     break;
                 }
             }
         }
         $result = true;
         break;
     } while (false);
     $this->cache->can_be_subscribed[$userid] = $result;
     return $result;
 }