MDL-9628 non-existent grades can be locked/hidden/edited :-)

This commit is contained in:
skodak 2007-08-07 08:30:25 +00:00
parent 5730bc6119
commit d3c3da1b77
5 changed files with 57 additions and 10 deletions

View File

@ -26,6 +26,7 @@ if (!$element = $gtree->locate_element($eid)) {
error('Incorrect element id!', $returnurl);
}
$object = $element['object'];
$type = $element['type'];
switch ($action) {
@ -34,6 +35,9 @@ switch ($action) {
if (!has_capability('moodle/grade:manage', $context) and !has_capability('moodle/grade:hide', $context)) {
error('No permission to hide!', $returnurl);
}
if ($type == 'grade' and empty($object->id)) {
$object->insert();
}
$object->set_hidden(1);
}
break;
@ -43,6 +47,9 @@ switch ($action) {
if (!has_capability('moodle/grade:manage', $context) and !has_capability('moodle/grade:hide', $context)) {
error('No permission to show!', $returnurl);
}
if ($type == 'grade' and empty($object->id)) {
$object->insert();
}
$object->set_hidden(0);
}
break;
@ -52,6 +59,9 @@ switch ($action) {
if (!has_capability('moodle/grade:manage', $context) and !has_capability('moodle/grade:lock', $context)) {
error('No permission to lock!', $returnurl);
}
if ($type == 'grade' and empty($object->id)) {
$object->insert();
}
$object->set_locked(1);
}
break;
@ -61,6 +71,9 @@ switch ($action) {
if (!has_capability('moodle/grade:manage', $context) and !has_capability('moodle/grade:unlock', $context)) {
error('No permission to unlock!', $returnurl);
}
if ($type == 'grade' and empty($object->id)) {
$object->insert();
}
$object->set_locked(0);
}
break;

View File

@ -43,7 +43,7 @@ class edit_grade_form extends moodleform {
/// hiding
/// advcheckbox is not compatible with disabledIf !!
$mform->addElement('checkbox', 'hidden', get_string('hidden', 'grades'));
$mform->addElement('date_time_selector', 'hiddenuntil', get_string('hiddeuntil', 'grades'), array('optional'=>true));
$mform->addElement('date_time_selector', 'hiddenuntil', get_string('hiddenuntil', 'grades'), array('optional'=>true));
$mform->disabledIf('hiddenuntil', 'hidden', 'checked');
/// locking

View File

@ -46,7 +46,7 @@ class edit_outcomeitem_form extends moodleform {
/// hiding
/// advcheckbox is not compatible with disabledIf !!
$mform->addElement('checkbox', 'hidden', get_string('hidden', 'grades'));
$mform->addElement('date_time_selector', 'hiddenuntil', get_string('hiddeuntil', 'grades'), array('optional'=>true));
$mform->addElement('date_time_selector', 'hiddenuntil', get_string('hiddenuntil', 'grades'), array('optional'=>true));
$mform->disabledIf('hiddenuntil', 'hidden', 'checked');
//locking

View File

@ -648,8 +648,27 @@ class grade_tree {
* @return object element
*/
function locate_element($eid) {
if (strpos($eid, 'g') === 0) {
// it is a grade construct a new object
// it is a grade - construct a new object
if (strpos($eid, 'n') === 0) {
if (!preg_match('/n(\d+)u(\d+)/', $eid, $matches)) {
return null;
}
$itemid = $matches[1];
$userid = $matches[2];
//extra security check - the grade item must be in this tree
if (!$item_el = $this->locate_element('i'.$itemid)) {
return null;
}
// $gradea->id may be null - means does not exist yet
$grade = new grade_grade(array('itemid'=>$itemid, 'userid'=>$userid));
$grade->grade_item =& $item_el['object']; // this may speedup grade_grade methods!
return array('eid'=>'n'.$itemid.'u'.$userid,'object'=>$grade, 'type'=>'grade');
} else if (strpos($eid, 'g') === 0) {
$id = (int)substr($eid, 1);
if (!$grade = grade_grade::fetch(array('id'=>$id))) {
return null;
@ -677,6 +696,19 @@ class grade_tree {
return null;
}
/**
* Returns the grade eid - the grade may not exist yet.
* @param $grade_grade object
* @return string eid
*/
function get_grade_eid($grade_grade) {
if (empty($grade_grade->id)) {
return 'n'.$grade_grade->itemid.'u'.$grade_grade->userid;
} else {
return 'g'.$grade_grade->id;
}
}
/**
* Return edit icon for give element
* @param object $element
@ -715,8 +747,11 @@ class grade_tree {
break;
case 'grade':
//TODO: improve dealing with new grades
if (empty($object->id)) {
$url = $CFG->wwwroot.'/grade/edit/tree/grade.php?courseid='.$this->courseid.'&itemid='.$object->itemid.'&userid='.$object->userid;
} else {
$url = $CFG->wwwroot.'/grade/edit/tree/grade.php?courseid='.$this->courseid.'&id='.$object->id;
}
$url = $gpr->add_url_params($url);
if (!empty($object->feedback)) {
$feedback = format_text($object->feedback, $object->feedbackformat);

View File

@ -562,7 +562,6 @@ class grade_report_grader extends grade_report {
if (isset($this->finalgrades[$userid][$item->id])) {
$gradeval = $this->finalgrades[$userid][$item->id]->finalgrade;
$grade = new grade_grade($this->finalgrades[$userid][$item->id], false);
$grade->feedback = stripslashes_safe($this->finalgrades[$userid][$item->id]->feedback);
$grade->feedbackformat = $this->finalgrades[$userid][$item->id]->feedbackformat;
@ -577,7 +576,8 @@ class grade_report_grader extends grade_report {
$grade->grade_item =& $this->items[$itemid]; // this speedsup is_hidden() and other grade_grade methods
// emulate grade element
$element = array('eid'=>'g'.$grade->id, 'object'=>$grade, 'type'=>'grade');
$eid = $this->gtree->get_grade_eid($grade);
$element = array('eid'=>$eid, 'object'=>$grade, 'type'=>'grade');
if ($grade->is_overridden()) {
$studentshtml .= '<td class="overridden">';
@ -590,8 +590,7 @@ class grade_report_grader extends grade_report {
}
// Do not show any icons if no grade (no record in DB to match)
// TODO: change edit/hide/etc. links to use itemid and userid to allow creating of new grade objects
if (!$item->needsupdate and !empty($grade->id) and $USER->gradeediting[$this->courseid]) {
if (!$item->needsupdate and $USER->gradeediting[$this->courseid]) {
$studentshtml .= $this->get_icons($element);
}