original_string: public static function get_forums_by_courses($courseids = array()) {
          global $CFG;
  
          require_once($CFG->dirroot . "/mod/forum/lib.php");
  
          $params = self::validate_parameters(self::get_forums_by_courses_parameters(), array('courseids' => $courseids));
  
          $courses = array();
          if (empty($params['courseids'])) {
              $courses = enrol_get_my_courses();
              $params['courseids'] = array_keys($courses);
          }
  
          // Array to store the forums to return.
          $arrforums = array();
          $warnings = array();
  
          // Ensure there are courseids to loop through.
          if (!empty($params['courseids'])) {
  
              list($courses, $warnings) = external_util::validate_courses($params['courseids'], $courses);
  
              // Get the forums in this course. This function checks users visibility permissions.
              $forums = get_all_instances_in_courses("forum", $courses);
              foreach ($forums as $forum) {
  
                  $course = $courses[$forum->course];
                  $cm = get_coursemodule_from_instance('forum', $forum->id, $course->id);
                  $context = context_module::instance($cm->id);
  
                  // Skip forums we are not allowed to see discussions.
                  if (!has_capability('mod/forum:viewdiscussion', $context)) {
                      continue;
                  }
  
                  $forum->name = external_format_string($forum->name, $context->id);
                  // Format the intro before being returning using the format setting.
                  list($forum->intro, $forum->introformat) = external_format_text($forum->intro, $forum->introformat,
                                                                                  $context->id, 'mod_forum', 'intro', null);
                  $forum->introfiles = external_util::get_area_files($context->id, 'mod_forum', 'intro', false, false);
                  // Discussions count. This function does static request cache.
                  $forum->numdiscussions = forum_count_discussions($forum, $cm, $course);
                  $forum->cmid = $forum->coursemodule;
                  $forum->cancreatediscussions = forum_user_can_post_discussion($forum, null, -1, $cm, $context);
                  $forum->istracked = forum_tp_is_tracked($forum);
                  if ($forum->istracked) {
                      $forum->unreadpostscount = forum_tp_count_forum_unread_posts($cm, $course);
                  }
  
                  // Add the forum to the array to return.
                  $arrforums[$forum->id] = $forum;
              }
          }
  
          return $arrforums;
      }
code: public static function get_forums_by_courses($courseids = array()) {
          global $CFG;
  
          require_once($CFG->dirroot . "/mod/forum/lib.php");
  
          $params = self::validate_parameters(self::get_forums_by_courses_parameters(), array('courseids' => $courseids));
  
          $courses = array();
          if (empty($params['courseids'])) {
              $courses = enrol_get_my_courses();
              $params['courseids'] = array_keys($courses);
          }
  
          // Array to store the forums to return.
          $arrforums = array();
          $warnings = array();
  
          // Ensure there are courseids to loop through.
          if (!empty($params['courseids'])) {
  
              list($courses, $warnings) = external_util::validate_courses($params['courseids'], $courses);
  
              // Get the forums in this course. This function checks users visibility permissions.
              $forums = get_all_instances_in_courses("forum", $courses);
              foreach ($forums as $forum) {
  
                  $course = $courses[$forum->course];
                  $cm = get_coursemodule_from_instance('forum', $forum->id, $course->id);
                  $context = context_module::instance($cm->id);
  
                  // Skip forums we are not allowed to see discussions.
                  if (!has_capability('mod/forum:viewdiscussion', $context)) {
                      continue;
                  }
  
                  $forum->name = external_format_string($forum->name, $context->id);
                  // Format the intro before being returning using the format setting.
                  list($forum->intro, $forum->introformat) = external_format_text($forum->intro, $forum->introformat,
                                                                                  $context->id, 'mod_forum', 'intro', null);
                  $forum->introfiles = external_util::get_area_files($context->id, 'mod_forum', 'intro', false, false);
                  // Discussions count. This function does static request cache.
                  $forum->numdiscussions = forum_count_discussions($forum, $cm, $course);
                  $forum->cmid = $forum->coursemodule;
                  $forum->cancreatediscussions = forum_user_can_post_discussion($forum, null, -1, $cm, $context);
                  $forum->istracked = forum_tp_is_tracked($forum);
                  if ($forum->istracked) {
                      $forum->unreadpostscount = forum_tp_count_forum_unread_posts($cm, $course);
                  }
  
                  // Add the forum to the array to return.
                  $arrforums[$forum->id] = $forum;
              }
          }
  
          return $arrforums;
      }
code_tokens: public static function get_forums_by_courses ( $ courseids = array ( ) ) { global $ CFG ; require_once ( $ CFG -> dirroot . "/mod/forum/lib.php" ) ; $ params = self :: validate_parameters ( self :: get_forums_by_courses_parameters ( ) , array ( 'courseids' => $ courseids ) ) ; $ courses = array ( ) ; if ( empty ( $ params [ 'courseids' ] ) ) { $ courses = enrol_get_my_courses ( ) ; $ params [ 'courseids' ] = array_keys ( $ courses ) ; } // Array to store the forums to return. $ arrforums = array ( ) ; $ warnings = array ( ) ; // Ensure there are courseids to loop through. if ( ! empty ( $ params [ 'courseids' ] ) ) { list ( $ courses , $ warnings ) = external_util :: validate_courses ( $ params [ 'courseids' ] , $ courses ) ; // Get the forums in this course. This function checks users visibility permissions. $ forums = get_all_instances_in_courses ( "forum" , $ courses ) ; foreach ( $ forums as $ forum ) { $ course = $ courses [ $ forum -> course ] ; $ cm = get_coursemodule_from_instance ( 'forum' , $ forum -> id , $ course -> id ) ; $ context = context_module :: instance ( $ cm -> id ) ; // Skip forums we are not allowed to see discussions. if ( ! has_capability ( 'mod/forum:viewdiscussion' , $ context ) ) { continue ; } $ forum -> name = external_format_string ( $ forum -> name , $ context -> id ) ; // Format the intro before being returning using the format setting. list ( $ forum -> intro , $ forum -> introformat ) = external_format_text ( $ forum -> intro , $ forum -> introformat , $ context -> id , 'mod_forum' , 'intro' , null ) ; $ forum -> introfiles = external_util :: get_area_files ( $ context -> id , 'mod_forum' , 'intro' , false , false ) ; // Discussions count. This function does static request cache. $ forum -> numdiscussions = forum_count_discussions ( $ forum , $ cm , $ course ) ; $ forum -> cmid = $ forum -> coursemodule ; $ forum -> cancreatediscussions = forum_user_can_post_discussion ( $ forum , null , - 1 , $ cm , $ context ) ; $ forum -> istracked = forum_tp_is_tracked ( $ forum ) ; if ( $ forum -> istracked ) { $ forum -> unreadpostscount = forum_tp_count_forum_unread_posts ( $ cm , $ course ) ; } // Add the forum to the array to return. $ arrforums [ $ forum -> id ] = $ forum ; } } return $ arrforums ; }
docstring: Returns a list of forums in a provided list of courses,
  if no list is provided all forums that the user can view
  will be returned.
  
  @param array $courseids the course ids
  @return array the forum details
  @since Moodle 2.5
docstring_tokens: Returns a list of forums in a provided list of courses if no list is provided all forums that the user can view will be returned .