From 45d24d396e835ce7482884060abf2e206f553037 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Mon, 4 Jan 2010 18:06:26 +0000 Subject: [PATCH] Added the skelet for grading evaluation subplugins --- mod/workshop/eval/best/lib.php | 36 ++++++++++++++++++++++++ mod/workshop/eval/best/version.php | 29 +++++++++++++++++++ mod/workshop/eval/lib.php | 33 ++++++++++++++++++++++ mod/workshop/form/accumulative/lib.php | 10 +++++-- mod/workshop/form/lib.php | 17 ++++++++++- mod/workshop/form/numerrors/lib.php | 30 ++++++++++++++++++-- mod/workshop/locallib.php | 39 +++++++++++++++++++++++--- 7 files changed, 185 insertions(+), 9 deletions(-) create mode 100644 mod/workshop/eval/best/lib.php create mode 100644 mod/workshop/eval/best/version.php create mode 100644 mod/workshop/eval/lib.php diff --git a/mod/workshop/eval/best/lib.php b/mod/workshop/eval/best/lib.php new file mode 100644 index 0000000000..c1b60f0c39 --- /dev/null +++ b/mod/workshop/eval/best/lib.php @@ -0,0 +1,36 @@ +. + +/** + * Contains logic class and interface for the grading evaluation plugin "Comparison + * with the best assessment". + * + * @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 + +/** + * Defines the computation login of the grading evaluation subplugin + */ +class workshop_best_evaluation implements workshop_evaluation { + +} diff --git a/mod/workshop/eval/best/version.php b/mod/workshop/eval/best/version.php new file mode 100644 index 0000000000..77e48f5e14 --- /dev/null +++ b/mod/workshop/eval/best/version.php @@ -0,0 +1,29 @@ +. + +/** + * Defines the version of the subplugin + * + * @package mod-workshop + * @copyright 2009 David Mudrak + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$plugin->version = 2009091100; +$plugin->requires = 2009091100; // Requires this Moodle version diff --git a/mod/workshop/eval/lib.php b/mod/workshop/eval/lib.php new file mode 100644 index 0000000000..36fe679152 --- /dev/null +++ b/mod/workshop/eval/lib.php @@ -0,0 +1,33 @@ +. + +/** + * This file defines interface of all grading evaluation classes + * + * @package mod-workshop + * @copyright 2009 David Mudrak + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +/** + * Defines all methods that grading evaluation subplugins has to implement + */ +interface workshop_evaluation { + +} diff --git a/mod/workshop/form/accumulative/lib.php b/mod/workshop/form/accumulative/lib.php index 609291ce20..4746659334 100644 --- a/mod/workshop/form/accumulative/lib.php +++ b/mod/workshop/form/accumulative/lib.php @@ -32,6 +32,12 @@ require_once(dirname(dirname(__FILE__)) . '/lib.php'); // interface definition */ class workshop_accumulative_strategy implements workshop_strategy { + /** @const default number of dimensions to show */ + const MINDIMS = 3; + + /** @const number of dimensions to add */ + const ADDDIMS = 2; + /** @var workshop the parent workshop instance */ protected $workshop; @@ -66,11 +72,11 @@ class workshop_accumulative_strategy implements workshop_strategy { $fields = $this->prepare_form_fields($this->dimensions); $nodimensions = count($this->dimensions); - $norepeatsdefault = max($nodimensions + WORKSHOP_STRATEGY_ADDDIMS, WORKSHOP_STRATEGY_MINDIMS); + $norepeatsdefault = max($nodimensions + self::ADDDIMS, self::MINDIMS); $norepeats = optional_param('norepeats', $norepeatsdefault, PARAM_INT); // number of dimensions $noadddims = optional_param('noadddims', '', PARAM_ALPHA); // shall we add more? if ($noadddims) { - $norepeats += WORKSHOP_STRATEGY_ADDDIMS; + $norepeats += self::ADDDIMS; } // prepare the embeded files diff --git a/mod/workshop/form/lib.php b/mod/workshop/form/lib.php index bd5239c7c1..b8c3be5037 100644 --- a/mod/workshop/form/lib.php +++ b/mod/workshop/form/lib.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); -define('WORKSHOP_STRATEGY_MINDIMS', 3); // default number of dimensions to show +define('WORKSHOPFORM_MINDIMS', 3); // default number of dimensions to show define('WORKSHOP_STRATEGY_ADDDIMS', 2); // number of dimensions to add /** @@ -80,4 +80,19 @@ interface workshop_strategy { * @return boolean */ public function form_ready(); + + /** + * Returns true if the given evaluation method is supported by this strategy + * + * To support an evaluation method, the strategy subplugin must usually implement some + * required public methods. In theory, this is what interfaces should be used for. + * Unfortunatelly, we can't extend "implements" declaration as the interface must + * be known to the PHP interpret. So we can't declare implementation of a non-installed + * evaluation subplugin. + * + * @param workshop_evaluation $evaluation the instance of grading evaluation class + * @return bool true if the evaluation method is supported, false otherwise + */ + public function evaluation_supported(workshop_evaluation $evaluation); + } diff --git a/mod/workshop/form/numerrors/lib.php b/mod/workshop/form/numerrors/lib.php index 5a6e494fd1..8e432a57fb 100644 --- a/mod/workshop/form/numerrors/lib.php +++ b/mod/workshop/form/numerrors/lib.php @@ -33,6 +33,12 @@ require_once($CFG->libdir . '/gradelib.php'); // to handle float vs de */ class workshop_numerrors_strategy implements workshop_strategy { + /** @const default number of dimensions to show */ + const MINDIMS = 3; + + /** @const number of dimensions to add */ + const ADDDIMS = 2; + /** @var workshop the parent workshop instance */ protected $workshop; @@ -71,11 +77,11 @@ class workshop_numerrors_strategy implements workshop_strategy { $fields = $this->prepare_form_fields($this->dimensions, $this->mappings); $nodimensions = count($this->dimensions); - $norepeatsdefault = max($nodimensions + WORKSHOP_STRATEGY_ADDDIMS, WORKSHOP_STRATEGY_MINDIMS); + $norepeatsdefault = max($nodimensions + self::ADDDIMS, self::MINDIMS); $norepeats = optional_param('norepeats', $norepeatsdefault, PARAM_INT); // number of dimensions $noadddims = optional_param('noadddims', '', PARAM_ALPHA); // shall we add more? if ($noadddims) { - $norepeats += WORKSHOP_STRATEGY_ADDDIMS; + $norepeats += self::ADDDIMS; } // prepare the embeded files @@ -269,6 +275,26 @@ class workshop_numerrors_strategy implements workshop_strategy { return false; } + /** + * Returns true if the given evaluation method is supported by this strategy + * + * To support an evaluation method, the strategy subplugin must usually implement some + * required public methods. In theory, this is what interfaces should be used for. + * Unfortunatelly, we can't extend "implements" declaration as the interface must + * be known to the PHP interpret. So we can't declare implementation of a non-installed + * evaluation subplugin. + * + * @param workshop_evaluation $evaluation the instance of grading evaluation class + * @return bool true if the evaluation method is supported, false otherwise + */ + public function evaluation_supported(workshop_evaluation $evaluation) { + if (is_a($evaluation, 'workshop_best_evaluation')) { + return true; + } + // all other evaluation methods are not supported yet + return false; + } + //////////////////////////////////////////////////////////////////////////////// // Internal methods // //////////////////////////////////////////////////////////////////////////////// diff --git a/mod/workshop/locallib.php b/mod/workshop/locallib.php index 87b067af24..0b12eaa489 100644 --- a/mod/workshop/locallib.php +++ b/mod/workshop/locallib.php @@ -64,6 +64,12 @@ class workshop { */ protected $strategyinstance = null; + /** + * @var workshop_evaluation grading evaluation instance + * Do not use directly, get the instance using {@link workshop::grading_evaluation_instance()} + */ + protected $evaluationinstance = null; + /** * Initializes the workshop API instance using the data from DB * @@ -78,10 +84,11 @@ class workshop { foreach ($dbrecord as $field => $value) { $this->{$field} = $value; } - $this->cm = $cm; - $this->course = $course; // beware - this replaces the standard course field in the instance table - // this is intentional - IMO there should be no such field as it violates - // 3rd normal form with no real performance gain + $this->evaluation = 'best'; // todo make this configurable + $this->cm = $cm; + $this->course = $course; // beware - this replaces the standard course field in the instance table + // this is intentional - IMO there should be no such field as it violates + // 3rd normal form with no real performance gain } /** @@ -475,6 +482,30 @@ class workshop { return $this->strategyinstance; } + /** + * Returns instance of grading evaluation class + * + * @return stdClass Instance of a grading evaluation + */ + public function grading_evaluation_instance() { + global $CFG; // because we require other libs here + + if (is_null($this->evaluationinstance)) { + $evaluationlib = dirname(__FILE__) . '/eval/' . $this->evaluation . '/lib.php'; + if (is_readable($evaluationlib)) { + require_once($evaluationlib); + } else { + throw new coding_exception('the grading evaluation subplugin must contain library ' . $evaluationlib); + } + $classname = 'workshop_' . $this->evaluation . '_evaluation'; + $this->evaluationinstance = new $classname($this); + if (!in_array('workshop_evaluation', class_implements($this->evaluationinstance))) { + throw new coding_exception($classname . ' does not implement workshop_evaluation interface'); + } + } + return $this->evaluationinstance; + } + /** * Return list of available allocation methods * -- 2.39.5