From 173115e14cbe102b762c1d4cab63b64a3edc8b04 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Wed, 23 Jan 2013 15:48:24 +1100 Subject: [PATCH] MDL-33774 filter_activitynames removed hardcoded label module type --- filter/activitynames/filter.php | 34 +++++++++++---------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/filter/activitynames/filter.php b/filter/activitynames/filter.php index bef80bc31166f..dc2b636b53a26 100644 --- a/filter/activitynames/filter.php +++ b/filter/activitynames/filter.php @@ -36,8 +36,6 @@ class filter_activitynames extends moodle_text_filter { static $cachedcourseid; function filter($text, array $options = array()) { - global $CFG, $COURSE, $DB; - if (!$courseid = get_courseid_from_context($this->context)) { return $text; } @@ -53,35 +51,25 @@ function filter($text, array $options = array()) { if (is_null(self::$activitylist)) { self::$activitylist = array(); - if ($COURSE->id == $courseid) { - $course = $COURSE; - } else { - $course = $DB->get_record("course", array("id"=>$courseid)); - } - - if (!isset($course->modinfo)) { - return $text; - } - - /// Casting $course->modinfo to string prevents one notice when the field is null - $modinfo = unserialize((string)$course->modinfo); - - if (!empty($modinfo)) { - + $modinfo = get_fast_modinfo($courseid); + if (!empty($modinfo->cms)) { self::$activitylist = array(); /// We will store all the activities here //Sort modinfo by name length - usort($modinfo, 'filter_activitynames_comparemodulenamesbylength'); + $sortedactivities = fullclone($modinfo->cms); + usort($sortedactivities, 'filter_activitynames_comparemodulenamesbylength'); - foreach ($modinfo as $activity) { + foreach ($sortedactivities as $cm) { //Exclude labels, hidden activities and activities for group members only - if ($activity->mod != "label" and $activity->visible and empty($activity->groupmembersonly)) { - $title = s(trim(strip_tags($activity->name))); - $currentname = trim($activity->name); + if ($cm->visible and empty($cm->groupmembersonly) and $cm->has_view()) { + $title = s(trim(strip_tags($cm->name))); + $currentname = trim($cm->name); $entitisedname = s($currentname); /// Avoid empty or unlinkable activity names if (!empty($title)) { - $href_tag_begin = "wwwroot/mod/$activity->mod/view.php?id=$activity->cm\">"; + $href_tag_begin = html_writer::start_tag('a', + array('class' => 'autolink', 'title' => $title, + 'href' => $cm->get_url())); self::$activitylist[] = new filterobject($currentname, $href_tag_begin, '', false, true); if ($currentname != $entitisedname) { /// If name has some entity (& " < >) add that filter too. MDL-17545 self::$activitylist[] = new filterobject($entitisedname, $href_tag_begin, '', false, true);