MDL-10076 finalize grade_is_locked() and implement grade item locking in assignment
This commit is contained in:
@@ -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';
|
||||
|
||||
@@ -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.
|
||||
|
||||
+24
-7
@@ -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,
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+37
-18
@@ -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 = '<div id="up'.$auser->id.'" class="s'.$auser->status.'">'.$button.'</div>';
|
||||
|
||||
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 = '<div id="up'.$auser->id.'" class="s'.$auser->status.'">'.$button.'</div>';
|
||||
}
|
||||
$row = array($picture, fullname($auser), $grade, $comment, $studentmodified, $teachermodified, $status);
|
||||
$table->add_data($row);
|
||||
}
|
||||
@@ -1155,18 +1172,20 @@ class assignment_base {
|
||||
echo '<input type="text" id="perpage" name="perpage" size="1" value="'.$perpage.'" />';
|
||||
helpbutton('pagesize', get_string('pagesize','assignment'), 'assignment');
|
||||
echo '</td></tr>';
|
||||
echo '<tr align="right">';
|
||||
echo '<td>';
|
||||
print_string('quickgrade','assignment');
|
||||
echo ':</td>';
|
||||
echo '<td align="left">';
|
||||
if ($quickgrade){
|
||||
echo '<input type="checkbox" name="quickgrade" value="1" checked="checked" />';
|
||||
} else {
|
||||
echo '<input type="checkbox" name="quickgrade" value="1" />';
|
||||
if (!$this->lockedgrades) {
|
||||
echo '<tr align="right">';
|
||||
echo '<td>';
|
||||
print_string('quickgrade','assignment');
|
||||
echo ':</td>';
|
||||
echo '<td align="left">';
|
||||
if ($quickgrade){
|
||||
echo '<input type="checkbox" name="quickgrade" value="1" checked="checked" />';
|
||||
} else {
|
||||
echo '<input type="checkbox" name="quickgrade" value="1" />';
|
||||
}
|
||||
helpbutton('quickgrade', get_string('quickgrade', 'assignment'), 'assignment').'</p></div>';
|
||||
echo '</td></tr>';
|
||||
}
|
||||
helpbutton('quickgrade', get_string('quickgrade', 'assignment'), 'assignment').'</p></div>';
|
||||
echo '</td></tr>';
|
||||
echo '<tr>';
|
||||
echo '<td colspan="2" align="right">';
|
||||
echo '<input type="submit" value="'.get_string('savepreferences').'" />';
|
||||
|
||||
Reference in New Issue
Block a user