]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-11580 support for hidden state modification in gradebook from activities (quiz...
authorskodak <skodak>
Thu, 4 Oct 2007 22:57:14 +0000 (22:57 +0000)
committerskodak <skodak>
Thu, 4 Oct 2007 22:57:14 +0000 (22:57 +0000)
the hiding/unhiding should be IMO locked in gradebook UI when activity overrides it

lib/gradelib.php
mod/quiz/lib.php

index 096ee4f500d824a32421e6f5c9931f7cd5f41558..5a5b05894b085b7342d8fd75dedf6093814d98c7 100644 (file)
@@ -47,7 +47,7 @@ require_once($CFG->libdir . '/grade/grade_outcome.php');
  * or key means do not change existing.
  *
  * Only following grade item properties can be changed 'itemname', 'idnumber', 'gradetype', 'grademax',
- * 'grademin', 'scaleid', 'multfactor', 'plusfactor', 'deleted'.
+ * 'grademin', 'scaleid', 'multfactor', 'plusfactor', 'deleted' and 'hidden'.
  *
  * Manual, course or category items can not be updated by this function.
 
@@ -64,7 +64,7 @@ function grade_update($source, $courseid, $itemtype, $itemmodule, $iteminstance,
     global $USER;
 
     // only following grade_item properties can be changed in this function
-    $allowed = array('itemname', 'idnumber', 'gradetype', 'grademax', 'grademin', 'scaleid', 'multfactor', 'plusfactor', 'deleted');
+    $allowed = array('itemname', 'idnumber', 'gradetype', 'grademax', 'grademin', 'scaleid', 'multfactor', 'plusfactor', 'deleted', 'hidden');
 
     // grade item identification
     $params = compact('courseid', 'itemtype', 'itemmodule', 'iteminstance', 'itemnumber');
index 1dd6175b2542802ac67fe353d4773b9b04f658b0..08af5445756455bac29b083ccaf9ddf23f4c0c25 100644 (file)
@@ -345,6 +345,30 @@ function quiz_grade_item_update($quiz) {
         $params['gradetype'] = GRADE_TYPE_NONE;
     }
 
+/* description by TJ:
+1/ If the quiz is set to not show scores while the quiz is still open, and is set to show scores after
+   the quiz is closed, then create the grade_item with a show-after date that is the quiz close date.
+2/ If the quiz is set to not show scores at either of those times, create the grade_item as hidden.
+3/ If the quiz is set to show scores, create the grade_item visible.
+*/
+    if (!($quiz->review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_CLOSED)
+    and !($quiz->review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_OPEN)) {
+        $params['hidden'] = 1;
+
+    } else if ( ($quiz->review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_CLOSED)
+           and !($quiz->review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_OPEN)) {
+        if ($quiz->timeclose) {
+            $params['hidden'] = $quiz->timeclose;
+        } else {
+            $params['hidden'] = 1;
+        }
+
+    } else {
+        // a) both open and closed enabled
+        // b) open enabled, closed disabled - we can not "hide after", grades are kept visible even after closing
+        $params['hidden'] = 0;
+    }
+
     return grade_update('mod/quiz', $quiz->course, 'mod', 'quiz', $quiz->id, 0, NULL, $params);
 }