]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-12517 reverting the moving of data processign, returning array of warnings instea...
authorskodak <skodak>
Tue, 18 Dec 2007 13:53:18 +0000 (13:53 +0000)
committerskodak <skodak>
Tue, 18 Dec 2007 13:53:18 +0000 (13:53 +0000)
grade/report/grader/index.php
grade/report/grader/lib.php

index 76b40fb3a5869521e5855fba3598a46ef297104e..f749be7ff46ca581b6a3de0c21df597a628fe663 100644 (file)
@@ -121,13 +121,22 @@ if (!empty($target) && !empty($action) && confirm_sesskey()) {
 // Initialise the grader report object
 $report = new grade_report_grader($courseid, $gpr, $context, $page, $sortitemid);
 
+
+/// processing posted grades & feedback here
+if ($data = data_submitted() and confirm_sesskey() and has_capability('moodle/grade:edit', $context)) {
+    $warnings = $report->process_data($data);
+} else {
+    $warings = array();
+}
+
+
 // Override perpage if set in URL
 if ($perpageurl) {
     $report->user_prefs['studentsperpage'] = $perpageurl;
 }
 
+// final grades MUST be loaded after the processing
 $report->load_users();
-
 $numusers = $report->get_numusers();
 $report->load_final_grades();
 
@@ -146,9 +155,9 @@ echo $report->group_selector;
 echo '<div class="clearer"></div>';
 echo $report->get_toggles_html();
 
-/// processing posted grades & feedback here
-if ($data = data_submitted() and confirm_sesskey()) {
-    $report->process_data($data);
+//show warnings if any
+foreach($warnings as $warning) {
+    notify($warning);
 }
 
 $studentsperpage = $report->get_pref('studentsperpage');
index 51af47b80036a2b4bd562a1fa9bd9bda352e4ddb..dcae2552c0c418ff2f7f11f47a7296abf19e0d4c 100644 (file)
@@ -146,14 +146,12 @@ class grade_report_grader extends grade_report {
 
     /**
      * Processes the data sent by the form (grades and feedbacks).
-     * @var array $data
-     * @return bool Success or Failure (array of errors).
+     * Caller is reposible for all access control checks
+     * @param array $data form submission (with magic quotes)
+     * @return array empty array if success, array of warnings if something fails.
      */
     function process_data($data) {
-
-        if (!has_capability('moodle/grade:edit', $this->context)) {
-            return false;
-        }
+        $warnings = array();
 
         // always initialize all arrays
         $queue = array();
@@ -209,11 +207,11 @@ class grade_report_grader extends grade_report {
                     $errorstr = 'morethanmax';
                 }
                 if ($errorstr) {
-                    $user = get_record('user', 'id', $userid,'','','','','id, firstname, lastname');
+                    $user = get_record('user', 'id', $userid, '', '', '', '', 'id, firstname, lastname');
                     $gradestr = new object();
                     $gradestr->username = fullname($user);
                     $gradestr->itemname = $grade_item->get_name();
-                    notify(get_string($errorstr, 'grades', $gradestr)); 
+                    $warnings[] = get_string($errorstr, 'grades', $gradestr); 
                 }
 
             } else if ($data_type == 'feedback') {
@@ -229,7 +227,7 @@ class grade_report_grader extends grade_report {
             $grade_item->update_final_grade($userid, $finalgrade, 'gradebook', $feedback, FORMAT_MOODLE);
         }
 
-        return true;
+        return $warnings;
     }