/** * Returns a list of twfs in a provided list of courses, * if no list is provided all twfs that the user can view * will be returned. * * @param array $courseids the course ids * @return array the twf details * @since Moodle 2.5 */ public static function get_twfs_by_courses($courseids = array()) { global $CFG; require_once $CFG->dirroot . "/mod/twf/lib.php"; $params = self::validate_parameters(self::get_twfs_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 twfs to return. $arrtwfs = array(); // Ensure there are courseids to loop through. if (!empty($courseids)) { // Array of the courses we are going to retrieve the twfs from. $dbcourses = array(); // Mod info for courses. $modinfocourses = array(); // Go through the courseids and return the twfs. foreach ($courseids as $courseid) { // Check the user can function in this context. try { $context = context_course::instance($courseid); self::validate_context($context); // Get the modinfo for the course. $modinfocourses[$courseid] = get_fast_modinfo($courseid); $dbcourses[$courseid] = $modinfocourses[$courseid]->get_course(); } catch (Exception $e) { continue; } } // Get the twfs in this course. This function checks users visibility permissions. if ($twfs = get_all_instances_in_courses("twf", $dbcourses)) { foreach ($twfs as $twf) { $course = $dbcourses[$twf->course]; $cm = $modinfocourses[$course->id]->get_cm($twf->coursemodule); $context = context_module::instance($cm->id); // Skip twfs we are not allowed to see discussions. if (!has_capability('mod/twf:viewdiscussion', $context)) { continue; } // Format the intro before being returning using the format setting. list($twf->intro, $twf->introformat) = external_format_text($twf->intro, $twf->introformat, $context->id, 'mod_twf', 'intro', 0); // Discussions count. This function does static request cache. $twf->numdiscussions = twf_count_discussions($twf, $cm, $course); $twf->cmid = $twf->coursemodule; // Add the twf to the array to return. $arrtwfs[$twf->id] = $twf; } } } return $arrtwfs; }
$learningtable->align[] = 'center'; } /// Now let's process the learning twfs if ($course->id != SITEID) { // Only real courses have learning twfs // '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 ($learningtwfs) { $currentsection = ''; foreach ($learningtwfs as $twf) { $cm = $modinfo->instances['twf'][$twf->id]; $context = context_module::instance($cm->id); $count = twf_count_discussions($twf, $cm, $course); if ($usetracking) { if ($twf->trackingtype == FORUM_TRACKING_OFF) { $unreadlink = '-'; $trackedlink = '-'; } else { if (isset($untracked[$twf->id])) { $unreadlink = '-'; } else { if ($unread = twf_tp_count_twf_unread_posts($cm, $course)) { $unreadlink = '<span class="unread"><a href="view.php?f=' . $twf->id . '">' . $unread . '</a>'; $unreadlink .= '<a title="' . $strmarkallread . '" href="markposts.php?f=' . $twf->id . '&mark=read"><img src="' . $OUTPUT->pix_url('t/markasread') . '" alt="' . $strmarkallread . '" class="iconsmall" /></a></span>'; } else { $unreadlink = '<span class="read">0</span>'; } }