]> git.mjollnir.org Git - moodle.git/commitdiff
Prepared a framework for calculating the grade for submission as suggested by the...
authorDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 17:51:34 +0000 (17:51 +0000)
committerDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 17:51:34 +0000 (17:51 +0000)
mod/workshop/assessment.php
mod/workshop/grading/accumulative/strategy.php
mod/workshop/grading/lib.php
mod/workshop/lang/en_utf8/workshop.php

index e400882f8b2a2dc88ee8d8af38bc4b0ffe466222..528f911a0bbf3f17d22ad2fa7b13f80c4a99ce96 100644 (file)
@@ -69,30 +69,7 @@ if ('preview' == $mode) {
     $PAGE->set_heading($course->fullname);
 }
 
-// load the grading strategy logic
-$strategy = $workshop->grading_strategy_instance();
-
-// load the form to edit the grading strategy dimensions
-$mform = $strategy->get_assessment_form($PAGE->url, $mode, $assessment);
-
-if ($mform->is_cancelled()) {
-    redirect($workshop->view_url());
-
-} elseif ($data = $mform->get_data()) {
-    if (isset($data->backtoeditform)) {
-        // user wants to return from preview to form editing
-        redirect($workshop->editform_url());
-    }
-    $strategy->save_assessment($assessment, $data);
-    if (isset($data->saveandclose)) {
-        redirect($workshop->view_url());
-    } else {
-        // save and continue - redirect to self to prevent data being re-posted by pressing "Reload"
-        redirect($PAGE->url);
-    }
-}
-
-// build the navigation and the header
+// build the navigation and the header - todo this will be changed by the new navigation api
 $navlinks = array();
 $navlinks[] = array('name' => get_string('modulenameplural', 'workshop'),
                     'link' => "index.php?id=$course->id",
@@ -114,6 +91,34 @@ if ($mode == 'preview') {
 }
 $navigation = build_navigation($navlinks);
 
+// load the grading strategy logic
+$strategy = $workshop->grading_strategy_instance();
+
+// load the form to edit the grading strategy dimensions
+$mform = $strategy->get_assessment_form($PAGE->url, $mode, $assessment);
+
+if ($mform->is_cancelled()) {
+    redirect($workshop->view_url());
+
+} elseif ($data = $mform->get_data()) {
+    if (isset($data->backtoeditform)) {
+        // user wants to return from preview to form editing
+        redirect($workshop->editform_url());
+    }
+    $rawgrade = $strategy->save_assessment($assessment, $data);
+    if (isset($data->saveandclose)) {
+        echo $OUTPUT->header($navigation);
+        echo $OUTPUT->heading(get_string('assessmentresult', 'workshop'), 2);
+        echo $OUTPUT->box('Given grade: ' . $rawgrade); // todo more detailed info using own renderer
+        echo $OUTPUT->continue_button($workshop->view_url());
+        echo $OUTPUT->footer();
+        die();  // bye-bye
+    } else {
+        // save and continue - redirect to self to prevent data being re-posted by pressing "Reload"
+        redirect($PAGE->url);
+    }
+}
+
 // Output starts here
 
 echo $OUTPUT->header($navigation);
index 310f239aefbce1e3ee6bf3610de25cee6a4ac8bf..41ded34f9bfc37a2aa4aef88bd44e83dbdd425e1 100644 (file)
@@ -35,8 +35,8 @@ class workshop_accumulative_strategy extends workshop_base_strategy implements w
     /** @var workshop the parent workshop instance */
     protected $workshop;
 
-    /** @var int number of dimensions defined in database, must be set in {@link load_fields()} */
-    protected $nodimensions=null;
+    /** @var array definition of the assessment form fields */
+    protected $dimensions = null;
 
     /** @var array options for dimension description fields */
     protected $descriptionopts;
@@ -49,6 +49,7 @@ class workshop_accumulative_strategy extends workshop_base_strategy implements w
      */
     public function __construct($workshop) {
         $this->workshop         = $workshop;
+        $this->dimensions       = $this->load_fields();
         $this->descriptionopts  = array('trusttext' => true, 'subdirs' => true, 'maxfiles' => -1);
     }
 
@@ -70,11 +71,9 @@ class workshop_accumulative_strategy extends workshop_base_strategy implements w
 
         require_once(dirname(__FILE__) . '/edit_form.php');
 
-        $fields = $this->load_fields();
-        if (is_null($this->nodimensions)) {
-            throw new coding_exception('You forgot to set the number of dimensions in load_fields()');
-        }
-        $norepeatsdefault   = max($this->nodimensions + WORKSHOP_STRATEGY_ADDDIMS, WORKSHOP_STRATEGY_MINDIMS);
+        $fields             = $this->prepare_form_fields($this->dimensions);
+        $nodimensions       = count($this->dimensions);
+        $norepeatsdefault   = max($nodimensions + WORKSHOP_STRATEGY_ADDDIMS, WORKSHOP_STRATEGY_MINDIMS);
         $norepeats          = optional_param('norepeats', $norepeatsdefault, PARAM_INT);    // number of dimensions
         $noadddims          = optional_param('noadddims', '', PARAM_ALPHA);                 // shall we add more?
         if ($noadddims) {
@@ -82,7 +81,7 @@ class workshop_accumulative_strategy extends workshop_base_strategy implements w
         }
 
         // prepare the embeded files
-        for ($i = 0; $i < $this->nodimensions; $i++) {
+        for ($i = 0; $i < $nodimensions; $i++) {
             // prepare all editor elements
             $fields = file_prepare_standard_editor($fields, 'description__idx_'.$i, $this->descriptionopts,
                 $PAGE->context, 'workshop_dimension_description', $fields->{'dimensionid__idx_'.$i});
@@ -100,7 +99,9 @@ class workshop_accumulative_strategy extends workshop_base_strategy implements w
     }
 
     /**
-     * Returns the fields of the assessment form and sets {@var nodimensions}
+     * Loads the fields of the assessment form
+     *
+     * @return array definition of assessment dimensions
      */
     protected function load_fields() {
         global $DB;
@@ -112,22 +113,16 @@ class workshop_accumulative_strategy extends workshop_base_strategy implements w
                 ORDER BY master.sort';
         $params[0] = $this->workshop->id;
 
-        $dims = $DB->get_records_sql($sql, $params);
-        $this->nodimensions = count($dims);
-        $fields = $this->_cook_dimension_records($dims);
-        return $fields;
+        return $DB->get_records_sql($sql, $params);
     }
 
     /**
-     * Maps the data from DB to their form fields
-     *
-     * Called internally from load_form(). Could be private but keeping protected
-     * for unit testing purposes.
+     * Maps the dimension data from DB to the form fields
      *
-     * @param array $raw Array of raw dimension records as fetched by get_record()
+     * @param array $raw Array of raw dimension records as returned by {@link load_fields()}
      * @return array Array of fields data to be used by the mform set_data
      */
-    protected function _cook_dimension_records(array $raw) {
+    protected function prepare_form_fields(array $raw) {
 
         $formdata = new stdClass();
         $key = 0;
@@ -256,13 +251,11 @@ class workshop_accumulative_strategy extends workshop_base_strategy implements w
         global $DB;
         require_once(dirname(__FILE__) . '/assessment_form.php');
 
-        $fields = $this->load_fields();
-        if (is_null($this->nodimensions)) {
-            throw new coding_exception('You forgot to set the number of dimensions in load_fields()');
-        }
+        $fields         = $this->prepare_form_fields($this->dimensions);
+        $nodimensions   = count($this->dimensions);
 
         // rewrite URLs to the embeded files
-        for ($i = 0; $i < $this->nodimensions; $i++) {
+        for ($i = 0; $i < $nodimensions; $i++) {
             $fields->{'description__idx_'.$i} = file_rewrite_pluginfile_urls($fields->{'description__idx_'.$i},
                 'pluginfile.php', $PAGE->context->id, 'workshop_dimension_description', $fields->{'dimensionid__idx_'.$i});
         }
@@ -271,7 +264,7 @@ class workshop_accumulative_strategy extends workshop_base_strategy implements w
             // load the previously saved assessment data
             $grades = $DB->get_records('workshop_grades', array('assessmentid' => $assessment->id), '', 'dimensionid,*');
             $current = new stdClass();
-            for ($i = 0; $i < $this->nodimensions; $i++) {
+            for ($i = 0; $i < $nodimensions; $i++) {
                 $dimid = $fields->{'dimensionid__idx_'.$i};
                 if (isset($grades[$dimid])) {
                     $current->{'gradeid__idx_'.$i}      = $grades[$dimid]->id;
@@ -286,7 +279,7 @@ class workshop_accumulative_strategy extends workshop_base_strategy implements w
         $customdata['mode']     = $mode;
 
         // set up strategy-specific custom data
-        $customdata['nodims']   = $this->nodimensions;
+        $customdata['nodims']   = $nodimensions;
         $customdata['fields']   = $fields;
         $customdata['current']  = isset($current) ? $current : null;
         $attributes = array('class' => 'assessmentform accumulative');
@@ -301,7 +294,7 @@ class workshop_accumulative_strategy extends workshop_base_strategy implements w
      *
      * @param object $assessment Assessment being filled
      * @param object $data       Raw data as returned by the assessment form
-     * @return void
+     * @return float             Percentual grade for submission as suggested by the peer
      */
     public function save_assessment(stdClass $assessment, stdClass $data) {
         global $DB;
@@ -329,7 +322,16 @@ class workshop_accumulative_strategy extends workshop_base_strategy implements w
                 $DB->update_record('workshop_grades', $grade);
             }
         }
-        // todo recalculate grades immediately or by cron ?
+        return $this->update_peer_grade($assessment);
     }
 
+    /**
+     * Aggregate the assessment form data and set the grade for the submission given by the peer
+     *
+     * @param stdClass $assessment Assessment record
+     * @return float               Percentual grade for submission as suggested by the peer
+     */
+    protected function update_peer_grade(stdClass $assessment) {
+        return 60.2;
+    }
 }
index 36f0d9d65bdf6f76d9809c3ff79fac9f333afe3b..eaaaed59fa34ecf2203e9457cb88f3c174fc8fbf 100644 (file)
@@ -71,13 +71,13 @@ interface workshop_strategy {
     public function get_assessment_form(moodle_url $actionurl=null, $mode='preview');
 
     /**
-     * Saves the filled assessment
+     * Saves the filled assessment and returns the grade for submission as suggested by the reviewer
      *
      * This method processes data submitted using the form returned by {@link get_assessment_form()}
      *
      * @param object $assessment Assessment being filled
      * @param object $data       Raw data as returned by the assessment form
-     * @return void
+     * @return float             Percentual grade for submission as suggested by the peer
      */
     public function save_assessment(stdClass $assessment, stdClass $data);
 }
index 9d4ca29ac2675b255a04b829632999e3b5d913e2..cdc15560ff59c16a49101723bde299e72fa0748d 100644 (file)
@@ -41,7 +41,6 @@ $string[''] = '';
 $string[''] = '';
 $string[''] = '';
 $string[''] = '';
-$string[''] = '';
 $string['accesscontrol'] = 'Access control';
 $string['addmoredimensionsaccumulative'] = 'Blanks for $a more aspects';
 $string['addmoredimensionsnoerrors'] = 'Blanks for $a more assertions';
@@ -72,6 +71,7 @@ $string['assessmentdeleted'] = 'Assessment deallocated';
 $string['assessmentdeleteddetail'] = 'Assessment deallocated: <strong>$a->reviewername</strong> is no longer reviewer of <strong>$a->authorname</strong>';
 $string['assessmentend'] = 'End of assessment phase';
 $string['assessmentform'] = 'Assessment form';
+$string['assessmentresult'] = 'Assessment result';
 $string['assessmentsettings'] = 'Assessment settings';
 $string['assessmentstart'] = 'Start of assessment phase';
 $string['assesswosubmission'] = 'Users can assess without their own submission';