$learningtable->align[] = 'center'; } /// Now let's process the learning forums if ($course->id != SITEID) { // Only real courses have learning forums // 'format_.'$course->format only applicable when not SITEID (format_site is not a format) $strsectionname = get_string('sectionname', 'format_' . $course->format); // Add extra field for section number, at the front array_unshift($learningtable->head, $strsectionname); array_unshift($learningtable->align, 'center'); if ($learningforums) { $currentsection = ''; foreach ($learningforums as $forum) { $cm = $modinfo->instances['hsuforum'][$forum->id]; $context = context_module::instance($cm->id); $count = hsuforum_count_discussions($forum, $cm, $course); if ($unread = hsuforum_count_forum_unread_posts($cm, $course)) { $unreadlink = '<span class="unread"><a href="view.php?f=' . $forum->id . '">' . $unread . '</a>'; } else { $unreadlink = '<span class="read">0</span>'; } $forum->intro = shorten_text(format_module_intro('hsuforum', $forum, $cm->id), $config->shortpost); if ($cm->sectionnum != $currentsection) { $printsection = get_section_name($course, $cm->sectionnum); if ($currentsection) { $learningtable->data[] = 'hr'; } $currentsection = $cm->sectionnum; } else { $printsection = ''; }
/** * 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 */ public static function get_forums_by_courses($courseids = array()) { global $CFG; require_once $CFG->dirroot . "/mod/hsuforum/lib.php"; $params = self::validate_parameters(self::get_forums_by_courses_parameters(), array('courseids' => $courseids)); if (empty($params['courseids'])) { // Get all the courses the user can view. $courseids = array_keys(enrol_get_my_courses()); } else { $courseids = $params['courseids']; } // Array to store the forums to return. $arrforums = array(); // Ensure there are courseids to loop through. if (!empty($courseids)) { // Array of the courses we are going to retrieve the forums from. $dbcourses = array(); // Mod info for courses. $modinfocourses = array(); // Go through the courseids and return the forums. foreach ($courseids as $courseid) { // Check the user can function in this context. try { $context = context_course::instance($courseid); self::validate_context($context); $modinfocourses[$courseid] = get_fast_modinfo($courseid); $dbcourses[$courseid] = $modinfocourses[$courseid]->get_course(); } catch (Exception $e) { continue; } } // Get the forums in this course. This function checks users visibility permissions. if ($forums = get_all_instances_in_courses("hsuforum", $dbcourses)) { foreach ($forums as $forum) { $course = $dbcourses[$forum->course]; $cm = $modinfocourses[$course->id]->get_cm($forum->coursemodule); $context = context_module::instance($cm->id); // Skip forums we are not allowed to see discussions. if (!has_capability('mod/hsuforum:viewdiscussion', $context)) { continue; } // 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_hsuforum', 'intro', 0); // Discussions count. This function does static request cache. $forum->numdiscussions = hsuforum_count_discussions($forum, $cm, $course); $forum->cmid = $forum->coursemodule; // Add the forum to the array to return. $arrforums[$forum->id] = $forum; } } } return $arrforums; }