]> git.mjollnir.org Git - moodle.git/commitdiff
Added the skelet for grading evaluation subplugins
authorDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 18:06:26 +0000 (18:06 +0000)
committerDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 18:06:26 +0000 (18:06 +0000)
mod/workshop/eval/best/lib.php [new file with mode: 0644]
mod/workshop/eval/best/version.php [new file with mode: 0644]
mod/workshop/eval/lib.php [new file with mode: 0644]
mod/workshop/form/accumulative/lib.php
mod/workshop/form/lib.php
mod/workshop/form/numerrors/lib.php
mod/workshop/locallib.php

diff --git a/mod/workshop/eval/best/lib.php b/mod/workshop/eval/best/lib.php
new file mode 100644 (file)
index 0000000..c1b60f0
--- /dev/null
@@ -0,0 +1,36 @@
+<?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 {
+
+}
diff --git a/mod/workshop/eval/best/version.php b/mod/workshop/eval/best/version.php
new file mode 100644 (file)
index 0000000..77e48f5
--- /dev/null
@@ -0,0 +1,29 @@
+<?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
diff --git a/mod/workshop/eval/lib.php b/mod/workshop/eval/lib.php
new file mode 100644 (file)
index 0000000..36fe679
--- /dev/null
@@ -0,0 +1,33 @@
+<?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 {
+
+}
index 609291ce2044be6967914c2c82c4917d18d0e63b..47466593347577347b5391072ab20372008c2e26 100644 (file)
@@ -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
index bd5239c7c1aab4c82ab72018c42fc88c3df175d6..b8c3be5037a69137a6741cb3cf25bce95a2214a5 100644 (file)
@@ -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);
+
 }
index 5a6e494fd16343c6d371da609209a9b925b50b9e..8e432a57fbe1423c2bfd164ae455c9a78318ad0a 100644 (file)
@@ -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                                                           //
 ////////////////////////////////////////////////////////////////////////////////
index 87b067af248ea9688eec981a71002ed82f7ad4ea..0b12eaa48994c84b9b570de9ad69dd0923545bdb 100644 (file)
@@ -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
      *