MDL-10223 module grades are now refreshed after unlocking
This commit is contained in:
+1
-1
@@ -114,7 +114,7 @@ function print_grade_plugin_selector($courseid, $active_type, $active_plugin, $r
|
||||
$menu[$url] = get_string('scales');
|
||||
}
|
||||
|
||||
if (!empty($CFG->enableoutcomes) && (has_capability('moodle/grade:manage', $context) or
|
||||
if (!empty($CFG->enableoutcomes) && (has_capability('moodle/grade:manage', $context) or
|
||||
has_capability('moodle/course:update', $context))) {
|
||||
if (has_capability('moodle/course:update', $context)) { // Default to course assignment
|
||||
$url = 'edit/outcome/course.php?id='.$courseid;
|
||||
|
||||
@@ -206,7 +206,7 @@ class grade_category extends grade_object {
|
||||
$category->delete($source);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ($items = grade_item::fetch_all(array('courseid'=>$this->courseid))) {
|
||||
foreach ($items as $item) {
|
||||
if ($item->id == $grade_item->id) {
|
||||
@@ -218,9 +218,9 @@ class grade_category extends grade_object {
|
||||
|
||||
} else {
|
||||
$this->force_regrading();
|
||||
|
||||
|
||||
$parent = $this->load_parent_category();
|
||||
|
||||
|
||||
// Update children's categoryid/parent field first
|
||||
if ($children = grade_item::fetch_all(array('categoryid'=>$this->id))) {
|
||||
foreach ($children as $child) {
|
||||
@@ -681,7 +681,7 @@ class grade_category extends grade_object {
|
||||
if ($child_array['type'] == 'courseitem' or $child_array['type'] == 'categoryitem') {
|
||||
$result['children'][$sortorder] = grade_category::_fetch_course_tree_recursion($child_array, $sortorder);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach($category_array['children'] as $oldorder=>$child_array) {
|
||||
if ($child_array['type'] != 'courseitem' and $child_array['type'] != 'categoryitem') {
|
||||
$result['children'][++$sortorder] = grade_category::_fetch_course_tree_recursion($child_array, $sortorder);
|
||||
@@ -1008,21 +1008,29 @@ class grade_category extends grade_object {
|
||||
* Sets the grade_item's locked variable and updates the grade_item.
|
||||
* Method named after grade_item::set_locked().
|
||||
* @param int $locked 0, 1 or a timestamp int(10) after which date the item will be locked.
|
||||
* @param boolean $refresh refresh grades when unlocking
|
||||
* @return boolean success if category locked (not all children mayb be locked though)
|
||||
*/
|
||||
function set_locked($lockedstate) {
|
||||
function set_locked($lockedstate, $refresh=true) {
|
||||
$this->load_grade_item();
|
||||
$result = $this->grade_item->set_locked($lockedstate);
|
||||
|
||||
$result = $this->grade_item->set_locked($lockedstate, true);
|
||||
if ($children = grade_item::fetch_all(array('categoryid'=>$this->id))) {
|
||||
foreach($children as $child) {
|
||||
$child->set_locked($lockedstate);
|
||||
$child->set_locked($lockedstate, false);
|
||||
if (empty($lockedstate) and $refresh) {
|
||||
//refresh when unlocking
|
||||
$child->refresh_grades();
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($children = grade_category::fetch_all(array('parent'=>$this->id))) {
|
||||
foreach($children as $child) {
|
||||
$child->set_locked($lockedstate);
|
||||
$child->set_locked($lockedstate, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
@@ -258,10 +258,11 @@ class grade_grade extends grade_object {
|
||||
/**
|
||||
* Lock/unlock this grade.
|
||||
*
|
||||
* @param boolean $lockstate true means lock, false unlock grade
|
||||
* @param int $locked 0, 1 or a timestamp int(10) after which date the item will be locked.
|
||||
* @param boolean $refresh refresh grades when unlocking
|
||||
* @return boolean true if sucessful, false if can not set new lock state for grade
|
||||
*/
|
||||
function set_locked($lockedstate) {
|
||||
function set_locked($lockedstate, $refresh=true) {
|
||||
$this->load_grade_item();
|
||||
|
||||
if ($lockedstate) {
|
||||
@@ -293,6 +294,11 @@ class grade_grade extends grade_object {
|
||||
|
||||
$this->update();
|
||||
|
||||
if ($refresh) {
|
||||
//refresh when unlocking
|
||||
$this->grade_item->refresh_grades($this->userid);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -424,11 +424,11 @@ class grade_item extends grade_object {
|
||||
|
||||
/**
|
||||
* Locks or unlocks this grade_item and (optionally) all its associated final grades.
|
||||
* @param boolean $update_final Whether to update final grades too
|
||||
* @param boolean $new_state Optional new state. Will use inverse of current state otherwise.
|
||||
* @param int $locked 0, 1 or a timestamp int(10) after which date the item will be locked.
|
||||
* @param boolean $refresh refresh grades when unlocking
|
||||
* @return boolean true if grade_item all grades updated, false if at least one update fails
|
||||
*/
|
||||
function set_locked($lockedstate) {
|
||||
function set_locked($lockedstate, $refresh=true) {
|
||||
if ($lockedstate) {
|
||||
/// setting lock
|
||||
if (!empty($this->locked)) {
|
||||
@@ -448,7 +448,7 @@ class grade_item extends grade_object {
|
||||
foreach($grades as $g) {
|
||||
$grade = new grade_grade($g, false);
|
||||
$grade->grade_item =& $this;
|
||||
if (!$grade->set_locked(true)) {
|
||||
if (!$grade->set_locked(1, false)) {
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
@@ -478,12 +478,17 @@ class grade_item extends grade_object {
|
||||
$result = false; // can not unlock grade that should be already locked
|
||||
}
|
||||
|
||||
if (!$grade->set_locked(false)) {
|
||||
if (!$grade->set_locked(0, false)) {
|
||||
$result = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($refresh) {
|
||||
//refresh when unlocking
|
||||
$this->refresh_grades();
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
@@ -1169,6 +1174,34 @@ class grade_item extends grade_object {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refetch grades from moudles, plugins.
|
||||
* @param int $userid optional, one user only
|
||||
*/
|
||||
function refresh_grades($userid=0) {
|
||||
if ($this->itemtype == 'mod') {
|
||||
if ($this->is_outcome_item()) {
|
||||
//nothing to do
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$activity = get_record($this->itemmodule, 'id', $this->iteminstance)) {
|
||||
debuggin('Can not find activity');
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $cm = get_coursemodule_from_instance($this->itemmodule, $activity->id, $this->courseid)) {
|
||||
debuggin('Can not find course module');
|
||||
return;
|
||||
}
|
||||
|
||||
$activity->modname = $this->itemmodule;
|
||||
$activity->cmidnumber = $cm->idnumber;
|
||||
|
||||
grade_update_mod_grades($activity);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates final grade value for given user, this is a only way to update final
|
||||
* grades from gradebook and import because it logs the change in history table
|
||||
|
||||
+10
-5
@@ -619,7 +619,7 @@ function grade_grab_grades() {
|
||||
* @param object $modinstance object with extra cmidnumber and modname property
|
||||
* @return boolean success
|
||||
*/
|
||||
function grade_update_mod_grades($modinstance) {
|
||||
function grade_update_mod_grades($modinstance, $userid=0) {
|
||||
global $CFG;
|
||||
|
||||
$fullmod = $CFG->dirroot.'/mod/'.$modinstance->modname;
|
||||
@@ -635,6 +635,8 @@ function grade_update_mod_grades($modinstance) {
|
||||
$updateitemfunc = $modinstance->modname.'_grade_item_update';
|
||||
|
||||
if (function_exists($gradefunc)) {
|
||||
|
||||
// legacy module - not yet converted
|
||||
if ($oldgrades = $gradefunc($modinstance->id)) {
|
||||
|
||||
$grademax = $oldgrades->maxgrade;
|
||||
@@ -654,9 +656,12 @@ function grade_update_mod_grades($modinstance) {
|
||||
}
|
||||
|
||||
$grades = array();
|
||||
foreach ($oldgrades->grades as $userid=>$usergrade) {
|
||||
foreach ($oldgrades->grades as $uid=>$usergrade) {
|
||||
if ($userid and $uid != $userid) {
|
||||
continue;
|
||||
}
|
||||
$grade = new object();
|
||||
$grade->userid = $userid;
|
||||
$grade->userid = $uid;
|
||||
|
||||
if ($usergrade == '-') {
|
||||
// no grade
|
||||
@@ -681,10 +686,10 @@ function grade_update_mod_grades($modinstance) {
|
||||
} else if (function_exists($updategradesfunc) and function_exists($updateitemfunc)) {
|
||||
//new grading supported, force updating of grades
|
||||
$updateitemfunc($modinstance);
|
||||
$updategradesfunc($modinstance);
|
||||
$updategradesfunc($modinstance, $userid);
|
||||
|
||||
} else {
|
||||
// mudule does not support grading
|
||||
// mudule does not support grading??
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user