From 9ecb50e6e3750c16fd47e1a9b2709f12b71ac1f3 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Fri, 18 Jan 2013 16:44:16 +1100 Subject: [PATCH] MDL-33774 instead of checking that activity is label we check that it has view url --- .../recent_activity/block_recent_activity.php | 17 +++--- course/lib.php | 2 +- course/yui/toolboxes/toolboxes.js | 37 +++++++----- report/log/locallib.php | 60 +++++++++---------- 4 files changed, 61 insertions(+), 55 deletions(-) diff --git a/blocks/recent_activity/block_recent_activity.php b/blocks/recent_activity/block_recent_activity.php index 846ab9816ed..b62eefb7851 100644 --- a/blocks/recent_activity/block_recent_activity.php +++ b/blocks/recent_activity/block_recent_activity.php @@ -113,7 +113,8 @@ class block_recent_activity extends block_base { * Returns list of recent changes in course structure * * It includes adding, editing or deleting of the resources or activities - * Excludes changes on labels, and also if activity was both added and deleted + * Excludes changes on modules without a view link (i.e. labels), and also + * if activity was both added and deleted * * @return array array of changes. Each element is an array containing attributes: * 'action' - one of: 'add mod', 'update mod', 'delete mod' @@ -135,13 +136,6 @@ class block_recent_activity extends block_base { foreach ($logs as $key => $log) { $info = explode(' ', $log->info); - // note: in most cases I replaced hardcoding of label with use of - // $cm->has_view() but it was not possible to do this here because - // we don't necessarily have the $cm for it - if ($info[0] == 'label') { // Labels are ignored in recent activity - continue; - } - if (count($info) != 2) { debugging("Incorrect log entry info: id = ".$log->id, DEBUG_DEVELOPER); continue; @@ -151,6 +145,11 @@ class block_recent_activity extends block_base { $instanceid = $info[1]; if ($log->action == 'delete mod') { + if (plugin_supports('mod', $modname, FEATURE_NO_VIEW_LINK, false)) { + // we should better call cm_info::has_view() because it can be + // dynamic. But there is no instance of cm_info now + continue; + } // unfortunately we do not know if the mod was visible if (!array_key_exists($log->info, $newgones)) { $changelist[$log->info] = array('action' => $log->action, @@ -168,7 +167,7 @@ class block_recent_activity extends block_base { continue; } $cm = $modinfo->instances[$modname][$instanceid]; - if ($cm->uservisible && empty($changelist[$log->info])) { + if ($cm->has_view() && $cm->uservisible && empty($changelist[$log->info])) { $changelist[$log->info] = array('action' => $log->action, 'module' => $cm); } } diff --git a/course/lib.php b/course/lib.php index 5b901b2005a..257fec8fc6b 100644 --- a/course/lib.php +++ b/course/lib.php @@ -2531,7 +2531,7 @@ function course_get_cm_edit_actions(cm_info $mod, $indent = -1, $sr = null) { $actions = array(); // AJAX edit title - if ($mod->modname !== 'label' && $hasmanageactivities && + if ($mod->has_view() && $hasmanageactivities && (($mod->course == $COURSE->id && course_ajax_enabled($COURSE)) || ($mod->course == SITEID && course_ajax_enabled($SITE)))) { // we will not display link if we are on some other-course page (where we should not see this module anyway) diff --git a/course/yui/toolboxes/toolboxes.js b/course/yui/toolboxes/toolboxes.js index 4e6ad157239..8560eef29c4 100644 --- a/course/yui/toolboxes/toolboxes.js +++ b/course/yui/toolboxes/toolboxes.js @@ -15,7 +15,6 @@ YUI.add('moodle-course-toolboxes', function(Y) { GROUPSNONE : 'a.editing_groupsnone', GROUPSSEPARATE : 'a.editing_groupsseparate', GROUPSVISIBLE : 'a.editing_groupsvisible', - HASLABEL : 'label', HIDE : 'a.editing_hide', HIGHLIGHT : 'a.editing_highlight', INSTANCENAME : 'span.instancename', @@ -62,7 +61,7 @@ YUI.add('moodle-course-toolboxes', function(Y) { var dimarea; var toggle_class; - if (this.is_label(element)) { + if (this.get_instance_name(element) == null) { toggle_class = CSS.DIMMEDTEXT; dimarea = element.all(CSS.MODINDENTDIV + ' > div').item(1); } else { @@ -172,8 +171,19 @@ YUI.add('moodle-course-toolboxes', function(Y) { Y.io(uri, config); return responsetext; }, - is_label : function(target) { - return target.hasClass(CSS.HASLABEL); + /** + * Return the name of the activity instance + * + * If activity has no name (for example label) null is returned + * + * @param element The
  • element to determine a name for + * @return string|null Instance name + */ + get_instance_name : function(target) { + if (target.one(CSS.INSTANCENAME)) { + return target.one(CSS.INSTANCENAME).get('firstChild').get('data'); + } + return null; }, /** * Return the module ID for the specified element @@ -330,19 +340,16 @@ YUI.add('moodle-course-toolboxes', function(Y) { // Get the element we're working on var element = e.target.ancestor(CSS.ACTIVITYLI); + // Create confirm string (different if element has or does not have name) var confirmstring = ''; - if (this.is_label(element)) { - // Labels are slightly different to other activities - var plugindata = { - type : M.util.get_string('pluginname', 'label') - } - confirmstring = M.util.get_string('deletechecktype', 'moodle', plugindata) - } else { - var plugindata = { - type : M.util.get_string('pluginname', element.getAttribute('class').match(/modtype_([^\s]*)/)[1]), - name : element.one(CSS.INSTANCENAME).get('firstChild').get('data') - } + var plugindata = { + type : M.util.get_string('pluginname', element.getAttribute('class').match(/modtype_([^\s]*)/)[1]) + } + if (this.get_instance_name(element) != null) { + plugindata.name = this.get_instance_name(element) confirmstring = M.util.get_string('deletechecktypename', 'moodle', plugindata); + } else { + confirmstring = M.util.get_string('deletechecktype', 'moodle', plugindata) } // Confirm element removal diff --git a/report/log/locallib.php b/report/log/locallib.php index 4d5f1ae54be..df2b2a8645e 100644 --- a/report/log/locallib.php +++ b/report/log/locallib.php @@ -223,28 +223,28 @@ function report_log_print_mnet_selector_form($hostid, $course, $selecteduser=0, $activities = array(); $selectedactivity = ""; -/// Casting $course->modinfo to string prevents one notice when the field is null - if ($modinfo = unserialize((string)$course->modinfo)) { + $modinfo = get_fast_modinfo($course); + if (!empty($modinfo->cms)) { $section = 0; - foreach ($modinfo as $mod) { - if ($mod->mod == "label") { + foreach ($modinfo->cms as $cm) { + if (!$cm->uservisible || !$cm->has_view()) { continue; } - if ($mod->section > 0 and $section <> $mod->section) { - $activities["section/$mod->section"] = '--- '.get_section_name($course, $mod->section).' ---'; + if ($cm->sectionnum > 0 and $section <> $cm->sectionnum) { + $activities["section/$cm->sectionnum"] = '--- '.get_section_name($course, $cm->sectionnum).' ---'; } - $section = $mod->section; - $mod->name = strip_tags(format_string($mod->name, true)); - if (textlib::strlen($mod->name) > 55) { - $mod->name = textlib::substr($mod->name, 0, 50)."..."; + $section = $cm->sectionnum; + $modname = strip_tags($cm->get_formatted_name()); + if (textlib::strlen($modname) > 55) { + $modname = textlib::substr($modname, 0, 50)."..."; } - if (!$mod->visible) { - $mod->name = "(".$mod->name.")"; + if (!$cm->visible) { + $modname = "(".$modname.")"; } - $activities["$mod->cm"] = $mod->name; + $activities["$cm->id"] = $modname; - if ($mod->cm == $modid) { - $selectedactivity = "$mod->cm"; + if ($cm->id == $modid) { + $selectedactivity = "$cm->id"; } } } @@ -475,28 +475,28 @@ function report_log_print_selector_form($course, $selecteduser=0, $selecteddate= $activities = array(); $selectedactivity = ""; -/// Casting $course->modinfo to string prevents one notice when the field is null - if ($modinfo = unserialize((string)$course->modinfo)) { + $modinfo = get_fast_modinfo($course); + if (!empty($modinfo->cms)) { $section = 0; - foreach ($modinfo as $mod) { - if ($mod->mod == "label") { + foreach ($modinfo->cms as $cm) { + if (!$cm->uservisible || !$cm->has_view()) { continue; } - if ($mod->section > 0 and $section <> $mod->section) { - $activities["section/$mod->section"] = '--- '.get_section_name($course, $mod->section).' ---'; + if ($cm->sectionnum > 0 and $section <> $cm->sectionnum) { + $activities["section/$cm->sectionnum"] = '--- '.get_section_name($course, $cm->sectionnum).' ---'; } - $section = $mod->section; - $mod->name = strip_tags(format_string($mod->name, true)); - if (textlib::strlen($mod->name) > 55) { - $mod->name = textlib::substr($mod->name, 0, 50)."..."; + $section = $cm->sectionnum; + $modname = strip_tags($cm->get_formatted_name()); + if (textlib::strlen($modname) > 55) { + $modname = textlib::substr($modname, 0, 50)."..."; } - if (!$mod->visible) { - $mod->name = "(".$mod->name.")"; + if (!$cm->visible) { + $modname = "(".$modname.")"; } - $activities["$mod->cm"] = $mod->name; + $activities["$cm->id"] = $modname; - if ($mod->cm == $modid) { - $selectedactivity = "$mod->cm"; + if ($cm->id == $modid) { + $selectedactivity = "$cm->id"; } } }