From 7f8312728b68f479de368ea8edef566bcfce3d45 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Mon, 4 Jan 2010 17:55:45 +0000 Subject: [PATCH] Added a dummy grading strategy to demonstrate the basic structure of the component --- .../grading/dummy/assessment_form.php | 51 ++++++++ mod/workshop/grading/dummy/edit_form.php | 48 +++++++ mod/workshop/grading/dummy/strategy.php | 122 ++++++++++++++++++ mod/workshop/lang/en_utf8/workshop.php | 1 + 4 files changed, 222 insertions(+) create mode 100644 mod/workshop/grading/dummy/assessment_form.php create mode 100644 mod/workshop/grading/dummy/edit_form.php create mode 100644 mod/workshop/grading/dummy/strategy.php diff --git a/mod/workshop/grading/dummy/assessment_form.php b/mod/workshop/grading/dummy/assessment_form.php new file mode 100644 index 0000000000..047371ba7b --- /dev/null +++ b/mod/workshop/grading/dummy/assessment_form.php @@ -0,0 +1,51 @@ +. + +/** + * This file defines an mform to assess a submission by dummy 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 dummy grading strategy + * + * @uses moodleform + */ +class workshop_dummy_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) { + + $mform->addElement('modgrade', 'grade', 'This is the dummy assessment form. + The output of every review is always a grade 0-100. So, you can fake the calculated grade + by direct setting it here. The dummy strategy does not save it.'); + + } +} diff --git a/mod/workshop/grading/dummy/edit_form.php b/mod/workshop/grading/dummy/edit_form.php new file mode 100644 index 0000000000..5a68ff4efe --- /dev/null +++ b/mod/workshop/grading/dummy/edit_form.php @@ -0,0 +1,48 @@ +. + +/** + * This file defines an mform to edit dummy grading strategy forms. + * + * @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(dirname(__FILE__))).'/lib.php'); // module library +require_once(dirname(dirname(__FILE__)).'/edit_form.php'); // parent class definition + +/** + * Class for editing dummy grading strategy forms. + * + * @uses moodleform + */ +class workshop_edit_dummy_strategy_form extends workshop_edit_strategy_form { + + /** + * Define the elements to be displayed at the form + * + * Called by the parent::definition() + * + * @return void + */ + protected function definition_inner(&$mform) { + $mform->addElement('static', 'just_a_text', 'Nothing to do here in this dummy strategy'); + } +} diff --git a/mod/workshop/grading/dummy/strategy.php b/mod/workshop/grading/dummy/strategy.php new file mode 100644 index 0000000000..712d39189e --- /dev/null +++ b/mod/workshop/grading/dummy/strategy.php @@ -0,0 +1,122 @@ +. + +/** + * This file defines a class with dummy grading strategy logic + * + * @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__)) . '/lib.php'); // interface definition + +/** + * Dummy grading strategy logic + * + * This is not a real strategy, it is used during the development only to demonstrate + * the basic idea of the strategy plugin. Consider this as a "hello world" grading strategy. + */ +class workshop_dummy_strategy implements workshop_strategy { + + /** @var workshop the parent workshop instance */ + protected $workshop; + + /** + * Constructor + * + * @param workshop $workshop The workshop instance record + * @return void + */ + public function __construct(workshop $workshop) { + $this->workshop = $workshop; + } + +/// Public API + + /** + * @param $actionurl URL of form handler, defaults to auto detect the current url + */ + public function get_edit_strategy_form($actionurl=null) { + global $CFG; // needed because the included files use it + global $PAGE; + + require_once(dirname(__FILE__) . '/edit_form.php'); + + $customdata = array(); + $customdata['workshop'] = $this->workshop; + $customdata['strategy'] = $this; + $attributes = array('class' => 'editstrategyform'); + + return new workshop_edit_dummy_strategy_form($actionurl, $customdata, 'post', '', $attributes); + } + + /** + * In dummy strategy, we can't really edit the assessment form. All other "real" strategies save + * the form definition into {workshop_forms} and {workshop_forms_*} tables. + * + * @param stdClass $data Raw data returned by the dimension editor form + */ + public function save_edit_strategy_form(stdClass $data) { } + + /** + * Factory method returning an instance of an assessment form + * + * This dummy strategy uses the static assessment form that does not saves the filled data. + * All other "real" strategies load the form definition from {workshop_forms} and {workshop_forms_*} tables + * and save the filled data into {workshop_grades} table. + * + * @param moodle_url $actionurl URL of form handler, defaults to auto detect the current url + * @param string $mode Mode to open the form in: preview/assessment + */ + public function get_assessment_form(moodle_url $actionurl=null, $mode='preview', stdClass $assessment=null) { + global $CFG; // needed because the included files use it + require_once(dirname(__FILE__) . '/assessment_form.php'); + + // set up the required custom data common for all strategies + $customdata['strategy'] = $this; + $customdata['mode'] = $mode; + + // set up strategy-specific custom data + $attributes = array('class' => 'assessmentform dummy'); + + return new workshop_dummy_assessment_form($actionurl, $customdata, 'post', '', $attributes); + } + + /** + * Real strategies would calculate and save the filled assessment here + * + * This method processes data submitted using the form returned by {@link get_assessment_form()} + * We do not calculate nor save anything in this dummy strategy. + * + * @param stdClass $assessment Assessment being filled + * @param stdClass $data Raw data as returned by the assessment form + * @return float|null Percentual grade for submission as suggested by the peer + */ + public function save_assessment(stdClass $assessment, stdClass $data) { + global $DB; + + if ($grade >= 0) { + return $data->grade / 100; + } else { + return 0; + } + } + +} diff --git a/mod/workshop/lang/en_utf8/workshop.php b/mod/workshop/lang/en_utf8/workshop.php index 3397a0f79b..c5257e8dfa 100644 --- a/mod/workshop/lang/en_utf8/workshop.php +++ b/mod/workshop/lang/en_utf8/workshop.php @@ -154,6 +154,7 @@ $string['saveandclose'] = 'Save and close'; $string['saveandcontinue'] = 'Save and continue editing'; $string['saveandpreview'] = 'Save and preview'; $string['strategyaccumulative'] = 'Accumulative grading'; +$string['strategydummy'] = 'Dummy strategy'; $string['strategy'] = 'Grading strategy'; $string['strategyhaschanged'] = 'The workshop grading strategy has changed since the form was opened for editing.'; $string['strategynoerrors'] = 'Number of errors'; -- 2.39.5