Commit 45d24d39 authored by David Mudrak's avatar David Mudrak
Browse files

Added the skelet for grading evaluation subplugins

parent f05c168d
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Contains logic class and interface for the grading evaluation plugin "Comparison
* with the best assessment".
*
* @package mod-workshop
* @copyright 2009 David Mudrak <david.mudrak@gmail.com>
* @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 {
}
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Defines the version of the subplugin
*
* @package mod-workshop
* @copyright 2009 David Mudrak <david.mudrak@gmail.com>
* @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
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file defines interface of all grading evaluation classes
*
* @package mod-workshop
* @copyright 2009 David Mudrak <david.mudrak@gmail.com>
* @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 {
}
......@@ -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
......
......@@ -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);
}
......@@ -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 //
////////////////////////////////////////////////////////////////////////////////
......
......@@ -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
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment