Skip to content

Commit

Permalink
MDL-54751 core_grades: Gradebook highlights modules pending deletion
Browse files Browse the repository at this point in the history
Added warning to all gradebook pages if any modules are pending
deletion. Modified the return values for get_name, and is_locked for
affected grade items to indicate their pending deletion.
  • Loading branch information
snake committed Nov 6, 2016
1 parent 3869d77 commit 45bd824
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
7 changes: 7 additions & 0 deletions grade/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,13 @@ function print_grade_page_head($courseid, $active_type, $active_plugin=null,
$user = null) {
global $CFG, $OUTPUT, $PAGE;

// Put a warning on all gradebook pages if the course has modules currently scheduled for background deletion.
require_once($CFG->dirroot . '/course/lib.php');
if (course_modules_pending_deletion($courseid)) {
\core\notification::add(get_string('gradesmoduledeletionpendingwarning', 'grades'),
\core\output\notification::NOTIFY_WARNING);
}

if ($active_type === 'preferences') {
// In Moodle 2.8 report preferences were moved under 'settings'. Allow backward compatibility for 3rd party grade reports.
$active_type = 'settings';
Expand Down
2 changes: 2 additions & 0 deletions lang/en/grades.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@
$string['gradesforuser'] = 'Grades for {$a->user}';
$string['singleview'] = 'Single view for {$a}';
$string['gradesonly'] = 'Change to grades only';
$string['gradesmoduledeletionpendingwarning'] = 'Warning: Activity deletion in progress! Some grades are about to be removed.';
$string['gradesmoduledeletionprefix'] = '[Deletion in progress]';
$string['gradessettings'] = 'Grade settings';
$string['gradetype'] = 'Grade type';
$string['gradetype_help'] = 'There are 4 grade types:
Expand Down
15 changes: 14 additions & 1 deletion lib/grade/grade_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,14 @@ public function add_idnumber($idnumber) {
* @return bool Locked state
*/
public function is_locked($userid=NULL) {
global $CFG;

// Override for any grade items belonging to activities which are in the process of being deleted.
require_once($CFG->dirroot . '/course/lib.php');
if (course_module_instance_pending_deletion($this->courseid, $this->itemmodule, $this->iteminstance)) {
return true;
}

if (!empty($this->locked)) {
return true;
}
Expand Down Expand Up @@ -1393,7 +1401,12 @@ public static function fix_duplicate_sortorder($courseid) {
public function get_name($fulltotal=false) {
if (strval($this->itemname) !== '') {
// MDL-10557
return format_string($this->itemname);

// Make it obvious to users if the course module to which this grade item relates, is currently being removed.
$deletionpending = course_module_instance_pending_deletion($this->courseid, $this->itemmodule, $this->iteminstance);
$deletionnotice = get_string('gradesmoduledeletionprefix', 'grades');

return $deletionpending ? format_string($deletionnotice . ' ' . $this->itemname) : format_string($this->itemname);

} else if ($this->is_course_item()) {
return get_string('coursetotal', 'grades');
Expand Down

0 comments on commit 45bd824

Please sign in to comment.