]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-20058 workshop allows override grade for submission
authorDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 18:23:22 +0000 (18:23 +0000)
committerDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 18:23:22 +0000 (18:23 +0000)
mod/workshop/feedbackauthor_form.php [new file with mode: 0644]
mod/workshop/lang/en_utf8/workshop.php
mod/workshop/locallib.php
mod/workshop/submission.php

diff --git a/mod/workshop/feedbackauthor_form.php b/mod/workshop/feedbackauthor_form.php
new file mode 100644 (file)
index 0000000..ab711b5
--- /dev/null
@@ -0,0 +1,65 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * A form used by teachers to give feedback to authors on their submission
+ *
+ * @package   mod-workshop
+ * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+require_once($CFG->dirroot . '/lib/formslib.php');
+
+class workshop_feedbackauthor_form extends moodleform {
+
+    function definition() {
+        $mform = $this->_form;
+
+        $current    = $this->_customdata['current'];
+        $workshop   = $this->_customdata['workshop'];
+        $opts       = $this->_customdata['feedbackopts'];
+
+        $mform->addElement('header', 'feedbackauthorform', get_string('feedbackauthor', 'workshop'));
+
+        $mform->addElement('static', 'grade', get_string('gradecalculated', 'workshop'));
+
+        $grades = array('' => get_string('notoverridden', 'workshop'));
+        for ($i = (int)$workshop->grade; $i >= 0; $i--) {
+            $grades[$i] = $i;
+        }
+        $mform->addElement('select', 'gradeover', get_string('gradeover', 'workshop'), $grades);
+
+        $mform->addElement('editor', 'feedbackauthor_editor', get_string('feedbackauthor', 'workshop'), null, $opts);
+        $mform->setType('feedbackauthor_editor', PARAM_RAW);
+
+        $mform->addElement('hidden', 'submissionid');
+
+        $mform->addElement('submit', 'save', get_string('saveandclose', 'workshop'));
+
+        $this->set_data($current);
+    }
+
+    function validation($data, $files) {
+        global $CFG, $USER, $DB;
+
+        $errors = parent::validation($data, $files);
+        return $errors;
+    }
+}
index f5bea340b81f4e61c488af635bad364d54dfb01a..aec261240f6f3e2fe32107562792bc579dbec57e 100644 (file)
@@ -82,15 +82,18 @@ $string['examplesbeforeassessment'] = 'Examples are available after own submissi
 $string['examplesbeforesubmission'] = 'Examples must be assessed before own submission';
 $string['examplesmode'] = 'Mode of examples assessment';
 $string['examplesvoluntary'] = 'Assessment of example submission is voluntary';
+$string['feedbackauthor'] = 'Feedback for the author';
 $string['feedbackreviewer'] = 'Feedback for the reviewer';
 $string['formataggregatedgrade'] = '$a->grade';
 $string['formataggregatedgradeover'] = '<del>$a->grade</del><br /><ins>$a->over</ins>';
 $string['formatpeergrade'] = '$a->grade ($a->gradinggrade)';
 $string['formatpeergradeover'] = '$a->grade (<del>$a->gradinggrade</del> / <ins>$a->gradinggradeover</ins>)';
-$string['givengradestatus'] = 'Status: $a';
 $string['givengrades'] = 'Given grades';
+$string['givengradestatus'] = 'Status: $a';
+$string['gradecalculated'] = 'Calculated grade for submission';
 $string['gradedecimals'] = 'Decimal places in grades';
 $string['gradegivento'] = ' &gt; ';
+$string['gradeover'] = 'Override grade for submission';
 $string['gradereceivedfrom'] = ' &lt; ';
 $string['gradinggradecalculated'] = 'Calculated grade for assessment';
 $string['gradinggrade'] = 'Grade for assessment';
index 4984c93245e0bf29640b777b3b05e2f764242de5..e5fff4b2ac32b3d31e38050190465b21ee8187b9 100644 (file)
@@ -1239,7 +1239,7 @@ class workshop {
      */
     public function real_grade_value($value, $max) {
         $localized = true;
-        if (is_null($value)) {
+        if (is_null($value) or $value === '') {
             return null;
         } elseif ($max == 0) {
             return 0;
@@ -1258,7 +1258,7 @@ class workshop {
      * @return float       suitable to be stored as numeric(10,5)
      */
     public function raw_grade_value($value, $max) {
-        if (is_null($value)) {
+        if (is_null($value) or $value === '') {
             return null;
         }
         if ($max == 0 or $value < 0) {
@@ -1278,7 +1278,7 @@ class workshop {
      * @return string
      */
     public function format_total_grade($raw) {
-        if (is_null($raw)) {
+        if (is_null($raw) or $raw === '') {
             return null;
         }
         return format_float($raw, $this->gradedecimals, true);
@@ -1491,10 +1491,10 @@ class workshop {
 
         $current = new stdClass();
         $current->submissionid          = $submission->id;
-        $current->grade                 = $this->real_grade($assessment->grade);
-        $current->gradeover             = $this->real_grade($assessment->gradeover);
-        $current->feedbackauthor        = $assessment->feedbackreviewer;
-        $current->feedbackauthorformat  = $assessment->feedbackreviewerformat;
+        $current->grade                 = $this->real_grade($submission->grade);
+        $current->gradeover             = $this->real_grade($submission->gradeover);
+        $current->feedbackauthor        = $submission->feedbackauthor;
+        $current->feedbackauthorformat  = $submission->feedbackauthorformat;
         if (is_null($current->grade)) {
             $current->grade = get_string('nullgrade', 'workshop');
         }
index 2957235c9d2160d85fb3295ff9e3016c40a4178e..d1449bff2535edf067a7487a5617dc3de06c3e85 100644 (file)
@@ -93,6 +93,7 @@ if ($edit and $ownsubmission) {
             $formdata->example        = 0; // todo add examples support
             $formdata->authorid       = $USER->id;
             $formdata->timecreated    = $timenow;
+            $formdata->feedbackauthorformat = FORMAT_HTML; // todo better default
         }
         $formdata->timemodified       = $timenow;
         $formdata->title              = trim($formdata->title);
@@ -114,6 +115,22 @@ if ($edit and $ownsubmission) {
     }
 }
 
+// load the form to override gradinggrade and process the submitted data eventually
+if (!$edit and $canoverride) {
+    $feedbackform = $workshop->get_feedbackauthor_form($PAGE->url, $submission);
+    if ($data = $feedbackform->get_data()) {
+        $data = file_postupdate_standard_editor($data, 'feedbackauthor', array(), $workshop->context);
+        $record = new stdClass();
+        $record->id = $submission->id;
+        $record->gradeover = $workshop->raw_grade_value($data->gradeover, $workshop->grade);
+        $record->gradeoverby = $USER->id;
+        $record->feedbackauthor = $data->feedbackauthor;
+        $record->feedbackauthorformat = $data->feedbackauthorformat;
+        $DB->update_record('workshop_submissions', $record);
+        redirect($workshop->view_url());
+    }
+}
+
 $PAGE->set_title($workshop->name);
 $PAGE->set_heading($course->fullname);
 if ($edit) {
@@ -184,4 +201,9 @@ if ($canviewallassessments) {
     $strategy = $workshop->grading_strategy_instance();
 }
 
+if (!$edit and $canoverride) {
+    // display a form to override the submission grade
+    $feedbackform->display();
+}
+
 echo $OUTPUT->footer();