mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 12:32:08 +02:00
MDL-33774 filter_activitynames removed hardcoded label module type
This commit is contained in:
parent
9ecb50e6e3
commit
173115e14c
@ -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 @@ class filter_activitynames extends moodle_text_filter {
|
||||
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 (& " < >) add that filter too. MDL-17545
|
||||
self::$activitylist[] = new filterobject($entitisedname, $href_tag_begin, '</a>', false, true);
|
||||
|
Loading…
x
Reference in New Issue
Block a user