]> git.mjollnir.org Git - moodle.git/commitdiff
Assessments overrides and feedbacks
authorDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 18:20:24 +0000 (18:20 +0000)
committerDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 18:20:24 +0000 (18:20 +0000)
This requires the patch of MDL-20623 to be applied

mod/workshop/assessment.php
mod/workshop/feedbackreviewer_form.php [new file with mode: 0644]
mod/workshop/lang/en_utf8/workshop.php
mod/workshop/locallib.php

index dd6ec8f3a156194601875b44b604333e9ccee507..c6339ca19eaa57b3dd76723654c69cd3e1cc9f2a 100644 (file)
@@ -78,12 +78,10 @@ if ($isreviewer and $workshop->assessing_allowed()) {
 // load the grading strategy logic
 $strategy = $workshop->grading_strategy_instance();
 
-// load the assessment form
+// load the assessment form and process the submitted data eventually
 $mform = $strategy->get_assessment_form($PAGE->url, 'assessment', $assessment, $assessmenteditable);
-
 if ($mform->is_cancelled()) {
     redirect($workshop->view_url());
-
 } elseif ($assessmenteditable and ($data = $mform->get_data())) {
     $rawgrade = $strategy->save_assessment($assessment, $data);
     if (!is_null($rawgrade) and isset($data->saveandclose)) {
@@ -95,13 +93,19 @@ if ($mform->is_cancelled()) {
     }
 }
 
-// load the form to override gradinggrade
+// load the form to override gradinggrade and process the submitted data eventually
 if ($canoverridegrades) {
-    $feedbackform = $workshop->get_feedbackreviewer_form($PAGE->url, $assessment, $canoverridegrades);
+    $feedbackform = $workshop->get_feedbackreviewer_form($PAGE->url, $assessment);
     if ($data = $feedbackform->get_data()) {
-        print_object($data); die(); // DONOTCOMMIT
-        // todo
-        redirect($PAGE->url);
+        $data = file_postupdate_standard_editor($data, 'feedbackreviewer', array(), $workshop->context);
+        $record = new stdClass();
+        $record->id = $assessment->id;
+        $record->gradinggradeover = $workshop->raw_grade_value($data->gradinggradeover, $workshop->gradinggrade);
+        $record->gradinggradeoverby = $USER->id;
+        $record->feedbackreviewer = $data->feedbackreviewer;
+        $record->feedbackreviewerformat = $data->feedbackreviewerformat;
+        $DB->update_record('workshop_assessments', $record);
+        redirect($workshop->view_url());
     }
 }
 
@@ -124,8 +128,8 @@ if ($isreviewer) {
 } else {
     echo $OUTPUT->heading(get_string('assessmentbyunknown', 'workshop'), 2);
 }
-$mform->display();
 
+$mform->display();
 if ($canoverridegrades) {
     $feedbackform->display();
     echo $OUTPUT->footer();
diff --git a/mod/workshop/feedbackreviewer_form.php b/mod/workshop/feedbackreviewer_form.php
new file mode 100644 (file)
index 0000000..adf5807
--- /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 reviewers on assessments
+ *
+ * @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_feedbackreviewer_form extends moodleform {
+
+    function definition() {
+        $mform = $this->_form;
+
+        $current    = $this->_customdata['current'];
+        $workshop   = $this->_customdata['workshop'];
+        $opts       = $this->_customdata['feedbackopts'];
+
+        $mform->addElement('header', 'feedbackreviewerform', get_string('feedbackreviewer', 'workshop'));
+
+        $mform->addElement('static', 'gradinggrade', get_string('gradinggradecalculated', 'workshop'));
+
+        $grades = array('' => get_string('notoverridden', 'workshop'));
+        for ($i = (int)$workshop->gradinggrade; $i >= 0; $i--) {
+            $grades[$i] = $i;
+        }
+        $mform->addElement('select', 'gradinggradeover', get_string('gradinggradeover', 'workshop'), $grades);
+
+        $mform->addElement('editor', 'feedbackreviewer_editor', get_string('feedbackreviewer', 'workshop'), null, $opts);
+        $mform->setType('feedbackreviewer_editor', PARAM_RAW);
+
+        $mform->addElement('hidden', 'asid');
+
+        $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 d00f3852802304a45ae5d3c38ba90f7985021ec4..3c735c401cceffeae526d49716c92c7a99f25d90 100644 (file)
@@ -32,10 +32,8 @@ $string[''] = '';
 $string[''] = '';
 $string[''] = '';
 $string[''] = '';
-$string['assessmentbyyourself'] = 'Assessment by yourself';
-$string['assessmentbyunknown'] = 'Assessment';
-$string['assessmentbyknown'] = 'Assessment by $a';
-$string['assessedsubmission'] = 'Assessed submission';
+$string[''] = '';
+$string[''] = '';
 $string['accesscontrol'] = 'Access control';
 $string['aggregategrades'] = 'Re-calculate grades';
 $string['aggregation'] = 'Grades aggregation';
@@ -52,7 +50,11 @@ $string['areasubmissionattachment'] = 'Submission attachments';
 $string['areasubmissioncontent'] = 'Submission texts';
 $string['assessallexamples'] = 'Assess all examples';
 $string['assess'] = 'Assess';
+$string['assessedsubmission'] = 'Assessed submission';
 $string['assessingsubmission'] = 'Assessing submission';
+$string['assessmentbyknown'] = 'Assessment by $a';
+$string['assessmentbyunknown'] = 'Assessment';
+$string['assessmentbyyourself'] = 'Assessment by yourself';
 $string['assessmentcomps'] = 'Required level of assessments similarity';
 $string['assessmentdeleted'] = 'Assessment deallocated';
 $string['assessmentend'] = 'End of assessment phase';
@@ -93,6 +95,7 @@ $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['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)';
@@ -102,8 +105,10 @@ $string['givengrades'] = 'Given grades';
 $string['gradedecimals'] = 'Decimal places in grades';
 $string['gradegivento'] = ' &gt; ';
 $string['gradereceivedfrom'] = ' &lt; ';
+$string['gradinggradecalculated'] = 'Calculated grade for assessment';
 $string['gradinggrade'] = 'Grade for assessment';
 $string['gradinggradeof'] = 'Grade for assessment (of $a)';
+$string['gradinggradeover'] = 'Override grade for assessment';
 $string['gradingsettings'] = 'Grading settings';
 $string['chooseuser'] = 'Choose user...';
 $string['iamsure'] = 'Yes, I am sure';
@@ -124,6 +129,7 @@ $string['nogradeyet'] = 'No grade yet';
 $string['nosubmissionfound'] = 'No submission found for this user';
 $string['nosubmissions'] = 'No submissions yet in this workshop';
 $string['nothingtoreview'] = 'Nothing to review';
+$string['notoverridden'] = 'Not overriden';
 $string['noworkshops'] = 'There are no workshops in this course';
 $string['noyoursubmission'] = 'You have not submitted your work yet';
 $string['nsassessments'] = 'Number of required assessments of other users\' work';
index b0ef2befea0c5784ff018551456e1b35faaaf1c0..e8e4597f0a124cd5c06057699373fc0b9c7b2001 100644 (file)
@@ -429,11 +429,13 @@ class workshop {
 
         $now = time();
         $assessment = new stdClass();
-        $assessment->submissionid   = $submission->id;
-        $assessment->reviewerid     = $reviewerid;
-        $assessment->timecreated    = $now;
-        $assessment->timemodified   = $now;
-        $assessment->weight         = 1;    // todo better handling of the weight value/default
+        $assessment->submissionid           = $submission->id;
+        $assessment->reviewerid             = $reviewerid;
+        $assessment->timecreated            = $now;
+        $assessment->timemodified           = $now;
+        $assessment->weight                 = 1;
+        $assessment->generalcommentformat   = FORMAT_HTML;  // todo better default handling
+        $assessment->feedbackreviewerformat = FORMAT_HTML;  // todo better default handling
 
         return $DB->insert_record('workshop_assessments', $assessment, true, $bulk);
     }
@@ -1169,6 +1171,29 @@ class workshop {
         }
     }
 
+    /**
+     * Calculates the raw (percentual) value from a real grade
+     *
+     * This is used in cases when a user wants to give a grade such as 12 of 20 and we need to save
+     * this value in a raw percentual form into DB
+     * @param float $value given grade
+     * @param float $max   the maximal grade
+     * @return float       suitable to be stored as numeric(10,5)
+     */
+    public function raw_grade_value($value, $max) {
+        if (empty($value)) {
+            return null;
+        }
+        if ($max == 0 or $value < 0) {
+            return 0;
+        }
+        $p = $value / $max * 100;
+        if ($p > 100) {
+            return $max;
+        }
+        return grade_floatval($p);
+    }
+
     /**
      * Rounds the value from DB to be displayed
      *
@@ -1357,12 +1382,25 @@ class workshop {
      * @param array $actionurl 
      * @return TODO
      */
-    public function get_feedbackreviewer_form(moodle_url $actionurl, stdClass $assessment, $editable) {
+    public function get_feedbackreviewer_form(moodle_url $actionurl, stdClass $assessment, $editable=true) {
         global $CFG;
         require_once(dirname(__FILE__) . '/feedbackreviewer_form.php');
 
+        $current = new stdClass();
+        $current->asid                      = $assessment->id;
+        $current->gradinggrade              = $this->real_grading_grade($assessment->gradinggrade);
+        $current->gradinggradeover          = $this->real_grading_grade($assessment->gradinggradeover);
+        $current->feedbackreviewer          = $assessment->feedbackreviewer;
+        $current->feedbackreviewerformat    = $assessment->feedbackreviewerformat;
+        if (is_null($current->gradinggrade)) {
+            $current->gradinggrade = get_string('nullgrade', 'workshop');
+        }
+
+        // prepare wysiwyg editor
+        $current = file_prepare_standard_editor($current, 'feedbackreviewer', array());
+
         return new workshop_feedbackreviewer_form($actionurl,
-                array('workshop' => $this, 'current' => $assessment, 'feedbackopts' => array()),
+                array('workshop' => $this, 'current' => $current, 'feedbackopts' => array()),
                 'post', '', null, $editable);
     }