]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10076 finalize grade_is_locked() and implement grade item locking in assignment
authorskodak <skodak>
Sun, 10 Jun 2007 20:34:07 +0000 (20:34 +0000)
committerskodak <skodak>
Sun, 10 Jun 2007 20:34:07 +0000 (20:34 +0000)
lang/en_utf8/grades.php
lib/grade/grade_grades_final.php
lib/gradelib.php
lib/simpletest/testgradelib.php
mod/assignment/lib.php

index b281c91fe550124ef48a67711c9cc8003e619f06..d574c577ea43f0144662b65fe4f40cb6a98c5093 100644 (file)
@@ -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';
index be25dc4ecee6deb0d852d2a29c038a4baa1f5f7e..cfe6efa228a11723f4ae75ccfd75498a0d26a0e7 100644 (file)
@@ -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.
index 4a8ed110e5b1ba7e306e2fabdd48199cc0cc73e1..d99e26bc5e83ed85063c48c732db2c9fe07603ba 100644 (file)
@@ -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,
index ad3027f82f1d0933b7524f6a62c902ba3c4b1390..01ddbcf97ae04ff238f61798af392ee15a8b346c 100644 (file)
@@ -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)); 
         }
     }
 
index c24edf1dae5b0496a8d61c858c8915fe04eca1f6..344fcfb15c0b17862e1c0a7648a4af97f15da396 100644 (file)
@@ -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.'&amp;userid='.$auser->id.'&amp;mode=single'.'&amp;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.'&amp;userid='.$auser->id.'&amp;mode=single'.'&amp;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').'" />';