Skip to content

Commit

Permalink
MDL-52253 scales: Prevent deletion of the last global scale
Browse files Browse the repository at this point in the history
  • Loading branch information
Damyon Wiese authored and David Monllao committed May 13, 2016
1 parent 8de0b1a commit d03602c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/grade/grade_scale.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,22 @@ public static function fetch_all_local($courseid) {
return grade_scale::fetch_all(array('courseid'=>$courseid));
}

/**
* Checks if this is the last scale on the site.
*
* @return bool
*/
public function is_last_global_scale() {
return ($this->courseid == 0) && (count(self::fetch_all_global()) == 1);
}

/**
* Checks if scale can be deleted.
*
* @return bool
*/
public function can_delete() {
return !$this->is_used();
return !$this->is_used() && !$this->is_last_global_scale();
}

/**
Expand Down

0 comments on commit d03602c

Please sign in to comment.