$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;
$category->delete($source);
}
}
-
+
if ($items = grade_item::fetch_all(array('courseid'=>$this->courseid))) {
foreach ($items as $item) {
if ($item->id == $grade_item->id) {
} 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) {
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);
* 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;
}
/**
* 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) {
$this->update();
+ if ($refresh) {
+ //refresh when unlocking
+ $this->grade_item->refresh_grades($this->userid);
+ }
+
return true;
}
}
/**
* 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)) {
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;
}
}
$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;
}
}
}
+ /**
+ * 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
* @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;
$updateitemfunc = $modinstance->modname.'_grade_item_update';
if (function_exists($gradefunc)) {
+
+ // legacy module - not yet converted
if ($oldgrades = $gradefunc($modinstance->id)) {
$grademax = $oldgrades->maxgrade;
}
$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
} 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;