Permalink
Browse files

MDL-33774 filter_activitynames removed hardcoded label module type

  • Loading branch information...
1 parent 9ecb50e commit 173115e14cbe102b762c1d4cab63b64a3edc8b04 @marinaglancy marinaglancy committed Jan 23, 2013
Showing with 11 additions and 23 deletions.
  1. +11 −23 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 = "<a class=\"autolink\" title=\"$title\" href=\"$CFG->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, '</a>', false, true);
if ($currentname != $entitisedname) { /// If name has some entity (&amp; &quot; &lt; &gt;) add that filter too. MDL-17545
self::$activitylist[] = new filterobject($entitisedname, $href_tag_begin, '</a>', false, true);

0 comments on commit 173115e

Please sign in to comment.