From 42140421dbc6443c70e69dcd82c5ff86daf4c780 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Mon, 4 Jan 2010 17:56:01 +0000 Subject: [PATCH] Work in progress on "Number of errors" grading strategy. Does not work yet. --- .../grading/accumulative/strategy.php | 15 -- mod/workshop/grading/assessment_form.php | 2 - mod/workshop/grading/edit_form.php | 1 - mod/workshop/grading/lib.php | 11 +- .../grading/noerrors/assessment_form.php | 79 ++++++++++ mod/workshop/grading/noerrors/edit_form.php | 1 - mod/workshop/grading/noerrors/strategy.php | 139 +++++++----------- 7 files changed, 132 insertions(+), 116 deletions(-) create mode 100644 mod/workshop/grading/noerrors/assessment_form.php diff --git a/mod/workshop/grading/accumulative/strategy.php b/mod/workshop/grading/accumulative/strategy.php index 6aab51dddd..dd342ccae2 100644 --- a/mod/workshop/grading/accumulative/strategy.php +++ b/mod/workshop/grading/accumulative/strategy.php @@ -55,13 +55,6 @@ class workshop_accumulative_strategy implements workshop_strategy { /// Public API - /** - * @return string - */ - public function name() { - return 'accumulative'; - } - /** * Factory method returning an instance of an assessment form editor class * @@ -115,10 +108,6 @@ class workshop_accumulative_strategy implements workshop_strategy { public function save_edit_strategy_form(stdClass $data) { global $DB, $PAGE; - if (!isset($data->strategyname) || ($data->strategyname != $this->name())) { - // the workshop strategy has changed since the form was opened for editing - throw new moodle_exception('strategyhaschanged', 'workshop'); - } $workshopid = $data->workshopid; $norepeats = $data->norepeats; @@ -215,10 +204,6 @@ class workshop_accumulative_strategy implements workshop_strategy { public function save_assessment(stdClass $assessment, stdClass $data) { global $DB; - if (!isset($data->strategyname) || ($data->strategyname != $this->name())) { - // the workshop strategy has changed since the form was opened for editing - throw new moodle_exception('strategyhaschanged', 'workshop'); - } if (!isset($data->nodims)) { throw coding_expection('You did not send me the number of assessment dimensions to process'); } diff --git a/mod/workshop/grading/assessment_form.php b/mod/workshop/grading/assessment_form.php index 3db9fd2c7d..77754a82f3 100644 --- a/mod/workshop/grading/assessment_form.php +++ b/mod/workshop/grading/assessment_form.php @@ -55,8 +55,6 @@ class workshop_assessment_form extends moodleform { $this->mode = $this->_customdata['mode']; // influences the save buttons $this->strategy = $this->_customdata['strategy']; // strategy name sends back for cross check - $mform->addElement('hidden', 'strategyname', $this->strategy->name()); - // add the strategy-specific fields $this->definition_inner($mform); diff --git a/mod/workshop/grading/edit_form.php b/mod/workshop/grading/edit_form.php index ecd5d0b17f..dc552e5fc8 100644 --- a/mod/workshop/grading/edit_form.php +++ b/mod/workshop/grading/edit_form.php @@ -59,7 +59,6 @@ class workshop_edit_strategy_form extends moodleform { $this->strategy = $this->_customdata['strategy']; $mform->addElement('hidden', 'workshopid', $this->workshop->id); - $mform->addElement('hidden', 'strategyname', $this->strategy->name()); $this->definition_inner($mform); diff --git a/mod/workshop/grading/lib.php b/mod/workshop/grading/lib.php index f896bf1aac..13f0ee9536 100644 --- a/mod/workshop/grading/lib.php +++ b/mod/workshop/grading/lib.php @@ -33,15 +33,6 @@ define('WORKSHOP_STRATEGY_ADDDIMS', 2); // number of dimensions to add */ interface workshop_strategy { - /** - * Returns name of the strategy - * - * The name may be used to generate table names, class names, paths etc. - * - * @return string - */ - public function name(); - /** * Factory method returning a form that is used to define the assessment form * @@ -77,7 +68,7 @@ interface workshop_strategy { * * @param stdClass $assessment Assessment being filled * @param stdClass $data Raw data as returned by the assessment form - * @return float|float Percentual grade for submission as suggested by the peer or null if impossible to count + * @return float|null Percentual grade for submission as suggested by the peer or null if impossible to count */ public function save_assessment(stdClass $assessment, stdClass $data); } diff --git a/mod/workshop/grading/noerrors/assessment_form.php b/mod/workshop/grading/noerrors/assessment_form.php new file mode 100644 index 0000000000..e5d5df5acd --- /dev/null +++ b/mod/workshop/grading/noerrors/assessment_form.php @@ -0,0 +1,79 @@ +. + +/** + * This file defines an mform to assess a submission by noerrors grading strategy + * + * @package mod-workshop + * @copyright 2009 David Mudrak + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +require_once(dirname(dirname(__FILE__)).'/assessment_form.php'); // parent class definition + +/** + * Class representing a form for assessing submissions by noerrors grading strategy + * + * @uses moodleform + */ +class workshop_noerrors_assessment_form extends workshop_assessment_form { + + /** + * Define the elements to be displayed at the form + * + * Called by the parent::definition() + * + * @return void + */ + protected function definition_inner(&$mform) { + $fields = $this->_customdata['fields']; + $current = $this->_customdata['current']; + $nodims = $this->_customdata['nodims']; // number of assessment dimensions + + $mform->addElement('hidden', 'nodims', $nodims); + + for ($i = 0; $i < $nodims; $i++) { + // dimension header + $dimtitle = get_string('dimensionnumbernoerrors', 'workshop', $i+1); + $mform->addElement('header', "dimensionhdr__idx_$i", $dimtitle); + + // dimension id + $mform->addElement('hidden', 'dimensionid__idx_'.$i, $fields->{'dimensionid__idx_'.$i}); + + // grade id + $mform->addElement('hidden', 'gradeid__idx_'.$i); // value set by set_data() later + + // dimension description + $desc = '
'."\n"; + $desc .= format_text($fields->{'description__idx_'.$i}, $fields->{'description__idx_'.$i.'format'}); + $desc .= "\n
"; + $mform->addElement('html', $desc); + + // evaluation of the assertion todo + $label = get_string('dimensiongradenoerrors', 'workshop'); + //$options = make_grades_menu($fields->{'grade__idx_' . $i}); + //$mform->addElement('select', 'grade__idx_' . $i, $label, $options); + + // comment + $label = get_string('dimensioncomment', 'workshop'); + $mform->addElement('textarea', 'peercomment__idx_' . $i, $label, array('cols' => 60, 'rows' => 5)); + } + $this->set_data($current); + } +} diff --git a/mod/workshop/grading/noerrors/edit_form.php b/mod/workshop/grading/noerrors/edit_form.php index 3b4a92e868..eee8248d76 100644 --- a/mod/workshop/grading/noerrors/edit_form.php +++ b/mod/workshop/grading/noerrors/edit_form.php @@ -79,7 +79,6 @@ class workshop_edit_noerrors_strategy_form extends workshop_edit_strategy_form { $percents[$i] = get_string('percents', 'workshop', $i); } $mform->addElement('static', 'mappingzero', 0, get_string('percents', 'workshop', 100)); - $mform->addElement('hidden', 'map__idx_0', 100); for ($i = 1; $i <= $norepeats; $i++) { $selects = array(); $selects[] = $mform->createElement('select', 'map__idx_'.$i, $i, $percents); diff --git a/mod/workshop/grading/noerrors/strategy.php b/mod/workshop/grading/noerrors/strategy.php index fd1a76dc3f..6c83b0fb06 100644 --- a/mod/workshop/grading/noerrors/strategy.php +++ b/mod/workshop/grading/noerrors/strategy.php @@ -59,13 +59,6 @@ class workshop_noerrors_strategy implements workshop_strategy { /// Public API methods - /** - * @return string - */ - public function name() { - return 'noerrors'; - } - /** * Factory method returning an instance of an assessment form editor class * @@ -119,10 +112,6 @@ class workshop_noerrors_strategy implements workshop_strategy { public function save_edit_strategy_form(stdClass $data) { global $DB, $PAGE; - if (!isset($data->strategyname) || ($data->strategyname != $this->name())) { - // the workshop strategy has changed since the form was opened for editing - throw new moodle_exception('strategyhaschanged', 'workshop'); - } $workshopid = $data->workshopid; $norepeats = $data->norepeats; @@ -160,43 +149,32 @@ class workshop_noerrors_strategy implements workshop_strategy { $this->delete_dimensions($todelete); // re-save the mappings - $current = array(); - $currentx = $DB->get_records('workshop_forms_noerrors_map', array('workshopid' => $this->workshop->id)); - foreach ($currentx as $id => $map) { - $current[$map->nonegative] = $map->grade; - } - unset($currentx); $todelete = array(); - - foreach ($data->map as $nonegative => $grade) { - if ($nonegative == 0) { - // no negative response automatically maps to 100%, do not save such mapping - continue; - } - if (!is_numeric($grade)) { + foreach ($data->mappings as $nonegative => $grade) { + if (is_null($grade)) { // no grade set for this number of negative responses $todelete[] = $nonegative; continue; } - if (isset($current[$nonegative])) { - $DB->set_field('workshop_forms_noerrors_map', 'grade', $grade, - array('workshopid' => $this->workshop->id, 'nonegative' => $nonegative)); + if (isset($this->mappings[$nonegative])) { + $DB->set_field("workshop_forms_noerrors_map", "grade", $grade, + array("workshopid" => $this->workshop->id, "nonegative" => $nonegative)); } else { - $DB->insert_record('workshop_forms_noerrors_map', - (object)array('workshopid' => $this->workshop->id, 'nonegative' => $nonegative, 'grade' => $grade)); + $DB->insert_record("workshop_forms_noerrors_map", + (object)array("workshopid" => $this->workshop->id, "nonegative" => $nonegative, "grade" => $grade)); } } // clear mappings that are not valid any more if (!empty($todelete)) { - list($insql, $params) = $DB->get_in_or_equal($todelete); - $insql = 'nonegative ' . $insql . ' OR '; + list($insql, $params) = $DB->get_in_or_equal($todelete, SQL_PARAMS_NAMED); + $insql = "nonegative $insql OR "; } else { - list($insql, $params) = array('', array()); + $insql = ""; } - $sql = 'DELETE FROM {workshop_forms_noerrors_map} - WHERE ((' . $insql . 'nonegative > ?) AND (workshopid = ?))'; - $params[] = count($data->map) - 1; - $params[] = $this->workshop->id; + $sql = "DELETE FROM {workshop_forms_noerrors_map} + WHERE (($insql nonegative > :nodimensions) AND (workshopid = :workshopid))"; + $params['nodimensions'] = $norepeats; + $params['workshopid'] = $this->workshop->id; if (!$DB->execute($sql, $params)){ print_error('err_removegrademappings', 'workshop'); } @@ -262,10 +240,6 @@ class workshop_noerrors_strategy implements workshop_strategy { public function save_assessment(stdClass $assessment, stdClass $data) { global $DB; - if (!isset($data->strategyname) || ($data->strategyname != $this->name())) { - // the workshop strategy has changed since the form was opened for editing - throw new moodle_exception('strategyhaschanged', 'workshop'); - } if (!isset($data->nodims)) { throw coding_expection('You did not send me the number of assessment dimensions to process'); } @@ -288,48 +262,6 @@ class workshop_noerrors_strategy implements workshop_strategy { return $this->update_peer_grade($assessment); } - /** - * Save the definition of a "Number of errors" grading form - * - * The dimensions data are stored in workshop_forms_noerrors. The data that map the - * number of errors to a grade are saved into workshop_forms_noerrors_map. - * - * @uses $DB - * @param stdClass $data Raw data returned by the dimension editor form - * @return void - */ - public function save_form(stdClass $data) { - global $DB; - - if (!isset($data->strategyname) || ($data->strategyname != $this->name())) { - // the workshop strategy has changed since the form was opened for editing - throw new moodle_exception('strategyhaschanged', 'workshop'); - } - - // save the dimensions data - $dims = $this->_cook_form_data($data); - $todelete = array(); - foreach ($dims as $record) { - if (empty($record->description)) { - if (!empty($record->id)) { - // existing record with empty description - to be deleted - $todelete[] = $record->id; - } - continue; - } - if (empty($record->id)) { - // new field - $record->id = $DB->insert_record('workshop_forms_' . $this->name(), $record); - } else { - // exiting field - $DB->update_record('workshop_forms_' . $this->name(), $record); - } - } - // delete dimensions if the teacher removed the description - $DB->delete_records_list('workshop_forms_' . $this->name(), 'id', $todelete); - - } - /// Internal methods /** @@ -376,7 +308,6 @@ class workshop_noerrors_strategy implements workshop_strategy { $formdata->{'dimensionid__idx_' . $key} = $dimension->id; // master id, not the local one! $formdata->{'description__idx_' . $key} = $dimension->description; $formdata->{'description__idx_' . $key.'format'} = $dimension->descriptionformat; - $formdata->{'description__idx_' . $key.'trust'} = $dimension->descriptiontrust; $formdata->{'grade0__idx_' . $key} = $dimension->grade0; $formdata->{'grade1__idx_' . $key} = $dimension->grade1; $formdata->{'weight__idx_' . $key} = $dimension->weight; @@ -446,14 +377,48 @@ class workshop_noerrors_strategy implements workshop_strategy { $cook->noerrors[$i]->grade1 = $raw->{'grade1__idx_'.$i}; $cook->noerrors[$i]->weight = $raw->{'weight__idx_'.$i}; - if (empty($raw->{'map__idx_'.$i})) { - $cook->mappings[$i] = null; + if (is_numeric($raw->{'map__idx_'.($i+1) })) { + $cook->mappings[$i+1] = $raw->{'map__idx_'.($i+1)}; // 0, 1, 2, ... } else { - $cook->mappings[$i] = new stdClass(); - $cook->mappings[$i]->grade = $raw->{'map__idx_'.$i}; + $cook->mappings[$i+1] = null; // not set anything } } return $cook; } + /** + * Returns the list of current grades filled by the reviewer + * + * @param stdClass $assessment Assessment record + * @return array of filtered records from the table workshop_grades + */ + protected function get_current_assessment_data(stdClass $assessment) { + global $DB; + + // fetch all grades accociated with this assessment + $grades = $DB->get_records("workshop_grades", array("assessmentid" => $assessment->id)); + + // filter grades given under an other strategy or assessment form + foreach ($grades as $grade) { + if (!isset($this->dimensions[$grade->dimensionid])) { + unset ($grades[$grade->id]); + } + } + return $grades; + } + + /** + * Reindexes the records returned by {@link get_current_assessment_data} by dimensionid + * + * @param mixed $grades + * @return array + */ + protected function reindex_grades_by_dimension($grades) { + $reindexed = array(); + foreach ($grades as $grade) { + $reindexed[$grade->dimensionid] = $grade; + } + return $reindexed; + } + } -- 2.39.5