From 7b5d01a7e8a47eae09e0b20e887f64051044afde Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Mon, 4 Jan 2010 17:35:56 +0000 Subject: [PATCH] More work on the strategy API --- mod/workshop/editgradingform.php | 23 ++++--- .../grading/accumulative/gradingform.php | 2 +- .../grading/accumulative/strategy.php | 39 +++++++++++ mod/workshop/grading/strategy.php | 65 ++++++++++++++++++- mod/workshop/lang/en_utf8/workshop.php | 3 +- 5 files changed, 119 insertions(+), 13 deletions(-) create mode 100644 mod/workshop/grading/accumulative/strategy.php diff --git a/mod/workshop/editgradingform.php b/mod/workshop/editgradingform.php index c35e2671ab..0a9660907d 100644 --- a/mod/workshop/editgradingform.php +++ b/mod/workshop/editgradingform.php @@ -66,18 +66,21 @@ add_to_log($course->id, "workshop", "editgradingform", "editgradingform.php?id=$ $returnurl = "{$CFG->wwwroot}/mod/workshop/view.php?id={$cm->id}"; $selfurl = "{$CFG->wwwroot}/mod/workshop/editgradingform.php?id={$cm->id}"; -// todo -$dimensions = $DB->get_records('workshop_forms_accumulative', array('workshopid' => $workshop->id), 'sort'); - -// load the form to edit the grading strategy dimensions -$strategyform = dirname(__FILE__) . '/grading/' . $workshop->strategy . '/gradingform.php'; -if (file_exists($strategyform)) { - require_once($strategyform); +// load the grading strategy logic +$strategylib = dirname(__FILE__) . '/grading/' . $workshop->strategy . '/strategy.php'; +if (file_exists($strategylib)) { + require_once($strategylib); } else { - print_error('errloadingstrategyform', 'workshop', $returnurl); + print_error('errloadingstrategylib', 'workshop', $returnurl); } -$classname = 'workshop_edit_' . $workshop->strategy . '_strategy_form'; -$mform = new $classname($selfurl, true, count($dimensions)); +$classname = 'workshop_' . $workshop->strategy . '_strategy'; +$strategy = new $classname($workshop); + +// load the dimensions from the database +$dimensions = $strategy->load_dimensions(); + +// load the form to edit the grading strategy dimensions +$mform = $strategy->get_edit_strategy_form($selfurl, true, count($dimensions)); // initialize form data $formdata = new stdClass; diff --git a/mod/workshop/grading/accumulative/gradingform.php b/mod/workshop/grading/accumulative/gradingform.php index f35f63370e..15360d2b67 100644 --- a/mod/workshop/grading/accumulative/gradingform.php +++ b/mod/workshop/grading/accumulative/gradingform.php @@ -53,7 +53,7 @@ class workshop_edit_accumulative_strategy_form extends workshop_edit_strategy_fo $repeated = array(); $repeated[] =& $mform->createElement('hidden', 'dimensionid', 0); - $repeated[] =& $mform->createElement('header', 'dimension', get_string('dimension', 'workshop')); + $repeated[] =& $mform->createElement('header', 'dimension', get_string('dimensionnumber', 'workshop', '{no}')); $repeated[] =& $mform->createElement('textarea', 'description', get_string('dimensiondescription', 'workshop'), array('cols'=>60)); $repeated[] =& $mform->createElement('select', 'grade', get_string('grade'), $gradeoptions); diff --git a/mod/workshop/grading/accumulative/strategy.php b/mod/workshop/grading/accumulative/strategy.php new file mode 100644 index 0000000000..f9a63d3ada --- /dev/null +++ b/mod/workshop/grading/accumulative/strategy.php @@ -0,0 +1,39 @@ +. + + +/** + * This file defines a class with accumulative grading strategy logic + * + * @package mod-workshop + * @copyright 2009 David Mudrak + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +if (!defined('MOODLE_INTERNAL')) { + die('Direct access to this script is forbidden.'); // It must be included from a Moodle page +} + +require_once(dirname(dirname(__FILE__)) . '/strategy.php'); // parent class + + +/** + * Accumulative grading strategy logic. + */ +class workshop_accumulative_strategy extends workshop_strategy { + +} diff --git a/mod/workshop/grading/strategy.php b/mod/workshop/grading/strategy.php index 078b0fe56c..e820445593 100644 --- a/mod/workshop/grading/strategy.php +++ b/mod/workshop/grading/strategy.php @@ -17,7 +17,7 @@ /** - * This file defines a base class for all grading strategy editing forms. + * This file defines a base class for all grading strategy logic * * @package mod-workshop * @copyright 2009 David Mudrak @@ -34,6 +34,19 @@ if (!defined('MOODLE_INTERNAL')) { */ interface workshop_strategy_interface { + /** + * Load the assessment dimensions from database + * + * Assessment dimension (also know as assessment element) represents one aspect or criterion + * to be evaluated. Each dimension consists of a set of form fields. Strategy-specific information + * are saved in workshop_forms_{strategyname} tables. + * + * @uses $DB + * @access public + * @return void + */ + public function load_dimensions(); + } /** @@ -41,4 +54,54 @@ interface workshop_strategy_interface { */ class workshop_strategy implements workshop_strategy_interface { + /** the name of the strategy */ + public $name; + + /** the parent workshop instance */ + protected $_workshop; + + /** + * Constructor + * + * @param object $workshop The workshop instance record + * @access public + * @return void + */ + public function __construct($workshop) { + + $this->name = $workshop->strategy; + $this->_workshop = $workshop; + } + + + public function get_edit_strategy_form($actionurl, $edit=true, $nodimensions=0) { + global $CFG; // needed because the included files use it + + $strategyform = dirname(__FILE__) . '/' . $this->name . '/gradingform.php'; + if (file_exists($strategyform)) { + require_once($strategyform); + } else { + throw new moodle_exception('errloadingstrategyform', 'workshop'); + } + $classname = 'workshop_edit_' . $this->name . '_strategy_form'; + + return new $classname($actionurl, $edit, $nodimensions); + + } + + /** + * Load the assessment dimensions from database + * + * This base method just fetches all relevant records from the strategy form table. + * + * @uses $DB + * @access public + * @return void + */ + public function load_dimensions() { + global $DB; + + return $DB->get_records('workshop_forms_' . $this->name, array('workshopid' => $this->_workshop->id), 'sort'); + } + } diff --git a/mod/workshop/lang/en_utf8/workshop.php b/mod/workshop/lang/en_utf8/workshop.php index 82312478cd..dc2b3e9702 100644 --- a/mod/workshop/lang/en_utf8/workshop.php +++ b/mod/workshop/lang/en_utf8/workshop.php @@ -58,7 +58,8 @@ $string['editgradingform'] = 'Edit grading form'; $string['editinggradingform'] = 'Editing grading form'; $string['dimensiondescription'] = 'Dimension description'; $string['dimensionweight'] = 'Dimension weight'; -$string['dimension'] = 'Dimension of assessment'; +$string['dimension'] = 'Assessment dimension'; +$string['dimensionnumber'] = 'Dimension $a'; $string['examplesbeforeassessment'] = 'Examples are available after own submission and must be assessed before peer/self assessment phase'; $string['examplesbeforesubmission'] = 'Examples must be assessed before own submission'; $string['examplesmode'] = 'Mode of examples assessment'; -- 2.39.5