} else {
- debugging('Found more than one grading item');
+ debugging('Found more than one grade item');
return GRADE_UPDATE_MULTIPLE;
}
* 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,
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));
}
}
var $usehtmleditor;
var $defaultformat;
var $context;
+ var $lockedgrades;
/**
* Constructor for the base assignment class
$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');
//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()) {
* 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);
$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);
}
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').'" />';