From: skodak Date: Sun, 10 Jun 2007 20:34:07 +0000 (+0000) Subject: MDL-10076 finalize grade_is_locked() and implement grade item locking in assignment X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=34e67f76a8f6b09183fa7954cb33713ce81815da;p=moodle.git MDL-10076 finalize grade_is_locked() and implement grade item locking in assignment --- diff --git a/lang/en_utf8/grades.php b/lang/en_utf8/grades.php index b281c91fe5..d574c577ea 100644 --- a/lang/en_utf8/grades.php +++ b/lang/en_utf8/grades.php @@ -42,6 +42,7 @@ $string['gradeexceptions'] = 'Grade Exceptions'; $string['gradeexceptionshelp'] = 'Grade Exceptions Help'; $string['gradehelp'] = 'Grade Help'; $string['gradeitem'] = 'Grade Item'; +$string['gradeitemlocked'] = 'Grading locked'; $string['gradeitemaddusers'] = 'Exclude from Grading'; $string['gradeitemmembersselected'] = 'Excluded from Grading'; $string['gradeitemnonmembers'] = 'Included in Grading'; diff --git a/lib/grade/grade_grades_final.php b/lib/grade/grade_grades_final.php index be25dc4ece..cfe6efa228 100644 --- a/lib/grade/grade_grades_final.php +++ b/lib/grade/grade_grades_final.php @@ -36,7 +36,7 @@ class grade_grades_final extends grade_object { * Array of class variables that are not part of the DB table fields * @var array $nonfields */ - var $nonfields = array('nonfields', 'table'); + var $nonfields = array('nonfields', 'table', 'grade_grades_text', 'grade_item'); /** * The id of the grade_item this final grade belongs to. diff --git a/lib/gradelib.php b/lib/gradelib.php index 4a8ed110e5..d99e26bc5e 100644 --- a/lib/gradelib.php +++ b/lib/gradelib.php @@ -106,7 +106,7 @@ function grade_update($source, $courseid, $itemtype, $itemmodule, $iteminstance, } else { - debugging('Found more than one grading item'); + debugging('Found more than one grade item'); return GRADE_UPDATE_MULTIPLE; } @@ -271,21 +271,38 @@ function grade_update($source, $courseid, $itemtype, $itemmodule, $iteminstance, * the method will return true no matter the locked state of the specific grade being checked. If unlocked, it will * return the locked state of the specific grade. * +* @param int $courseid id of course * @param string $itemtype 'mod', 'blocks', 'import', 'calculated' etc * @param string $itemmodule 'forum, 'quiz', 'csv' etc * @param int $iteminstance id of the item module -* @param int $itemnumber Optional number of the item to check -* @param int $userid ID of the user who owns the grade +* @param int $itemnumber most probably 0, modules can use other numbers when having more than one grades for each user +* @param int $userid ID of the graded user * @return boolean Whether the grade is locked or not */ -function grade_is_locked($itemtype, $itemmodule, $iteminstance, $itemnumber=NULL, $userid=NULL) { - $grade_item = new grade_item(compact('itemtype', 'itemmodule', 'iteminstance', 'itemnumber')); - return $grade_item->is_locked($userid); -} +function grade_is_locked($courseid, $itemtype, $itemmodule, $iteminstance, $itemnumber, $userid=NULL) { + + $grade_item = new grade_item(compact('courseid', 'itemtype', 'itemmodule', 'iteminstance', 'itemnumber'), false); + if (!$grade_items = $grade_item->fetch_all_using_this()) { + return false; + } else if (count($grade_items) == 1){ + $grade_item = reset($grade_items); + return $grade_item->is_locked($userid); + + } else { + debugging('Found more than one grade item'); + foreach ($grade_items as $grade_item) { + if ($grade_item->is_locked($userid)) { + return true; + } + } + return false; + } +} /***** END OF PUBLIC API *****/ + /** * Extracts from the gradebook all the grade items attached to the calling object. * For example, an assignment may want to retrieve all the grade_items for itself, diff --git a/lib/simpletest/testgradelib.php b/lib/simpletest/testgradelib.php index ad3027f82f..01ddbcf97a 100644 --- a/lib/simpletest/testgradelib.php +++ b/lib/simpletest/testgradelib.php @@ -101,9 +101,9 @@ class gradelib_test extends grade_test { function test_grade_is_locked() { if (get_class($this) == 'gradelib_test') { $grade_item = $this->grade_items[0]; - $this->assertFalse(grade_is_locked($grade_item->itemtype, $grade_item->itemmodule, $grade_item->iteminstance, $grade_item->itemnumber)); + $this->assertFalse(grade_is_locked($grade_item->courseid, $grade_item->itemtype, $grade_item->itemmodule, $grade_item->iteminstance, $grade_item->itemnumber)); $grade_item = $this->grade_items[1]; - $this->assertTrue(grade_is_locked($grade_item->itemtype, $grade_item->itemmodule, $grade_item->iteminstance, $grade_item->itemnumber)); + $this->assertTrue(grade_is_locked($grade_item->courseid, $grade_item->itemtype, $grade_item->itemmodule, $grade_item->iteminstance, $grade_item->itemnumber)); } } diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index c24edf1dae..344fcfb15c 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -35,6 +35,7 @@ class assignment_base { var $usehtmleditor; var $defaultformat; var $context; + var $lockedgrades; /** * Constructor for the base assignment class @@ -80,6 +81,9 @@ class assignment_base { $this->assignment->cmidnumber = $this->cm->id; // compatibility with modedit assignment obj $this->assignment->courseid = $this->course->id; // compatibility with modedit assignment obj + require_once($CFG->libdir.'/gradelib.php'); + $this->lockedgrades = grade_is_locked($this->course->id, 'mod', 'assignment', $this->assignment->id, 0); + $this->strassignment = get_string('modulename', 'assignment'); $this->strassignments = get_string('modulenameplural', 'assignment'); $this->strsubmissions = get_string('submissions', 'assignment'); @@ -494,6 +498,11 @@ class assignment_base { //make user global so we can use the id global $USER; + // no grading when grades are locked + if ($this->lockedgrades) { + $mode = 'all'; + } + switch ($mode) { case 'grade': // We are in a popup window grading if ($submission = $this->process_feedback()) { @@ -931,7 +940,12 @@ class assignment_base { * from database */ $perpage = get_user_preferences('assignment_perpage', 10); - $quickgrade = get_user_preferences('assignment_quickgrade', 0); + + if ($this->lockedgrades) { + $quickgrade = 0; + } else { + $quickgrade = get_user_preferences('assignment_quickgrade', 0); + } $teacherattempts = true; /// Temporary measure $page = optional_param('page', 0, PARAM_INT); @@ -1112,12 +1126,15 @@ class assignment_base { $buttontext = ($auser->status == 1) ? $strupdate : $strgrade; - ///No more buttons, we use popups ;-). - $button = link_to_popup_window ('/mod/assignment/submissions.php?id='.$this->cm->id.'&userid='.$auser->id.'&mode=single'.'&offset='.$offset++, - 'grade'.$auser->id, $buttontext, 500, 780, $buttontext, 'none', true, 'button'.$auser->id); - - $status = '
'.$button.'
'; - + if ($this->lockedgrades) { + $status = get_string('gradeitemlocked', 'grades'); + } else { + ///No more buttons, we use popups ;-). + $button = link_to_popup_window ('/mod/assignment/submissions.php?id='.$this->cm->id.'&userid='.$auser->id.'&mode=single'.'&offset='.$offset++, + 'grade'.$auser->id, $buttontext, 500, 780, $buttontext, 'none', true, 'button'.$auser->id); + + $status = '
'.$button.'
'; + } $row = array($picture, fullname($auser), $grade, $comment, $studentmodified, $teachermodified, $status); $table->add_data($row); } @@ -1155,18 +1172,20 @@ class assignment_base { echo ''; helpbutton('pagesize', get_string('pagesize','assignment'), 'assignment'); echo ''; - echo ''; - echo ''; - print_string('quickgrade','assignment'); - echo ':'; - echo ''; - if ($quickgrade){ - echo ''; - } else { - echo ''; + if (!$this->lockedgrades) { + echo ''; + echo ''; + print_string('quickgrade','assignment'); + echo ':'; + echo ''; + if ($quickgrade){ + echo ''; + } else { + echo ''; + } + helpbutton('quickgrade', get_string('quickgrade', 'assignment'), 'assignment').'

'; + echo ''; } - helpbutton('quickgrade', get_string('quickgrade', 'assignment'), 'assignment').'

'; - echo ''; echo ''; echo ''; echo '';