* 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'
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;
$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,
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);
}
}
$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)
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',
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 {
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 <li> 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
// 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
$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";
}
}
}
$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";
}
}
}