]> git.mjollnir.org Git - moodle.git/commitdiff
More work on the strategy API
authorDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 17:35:56 +0000 (17:35 +0000)
committerDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 17:35:56 +0000 (17:35 +0000)
mod/workshop/editgradingform.php
mod/workshop/grading/accumulative/gradingform.php
mod/workshop/grading/accumulative/strategy.php [new file with mode: 0644]
mod/workshop/grading/strategy.php
mod/workshop/lang/en_utf8/workshop.php

index c35e2671ab4bd659ed2228d492630afae12c9298..0a9660907dd2117639857608590eaba112cc4602 100644 (file)
@@ -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;
index f35f63370e681d24dd384043004e48640e27d5c3..15360d2b67001732a27e886d45e7e23213e7484f 100644 (file)
@@ -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 (file)
index 0000000..f9a63d3
--- /dev/null
@@ -0,0 +1,39 @@
+<?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 a class with accumulative grading strategy logic
+ *
+ * @package   mod-workshop
+ * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
+ * @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 {
+
+}
index 078b0fe56c5573b5b17cdd5e72ec2bc7bfd6e94c..e820445593cf319c3cda7680246446fef3cddc4b 100644 (file)
@@ -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 <david.mudrak@gmail.com>
@@ -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');
+    }
+
 }
index 82312478cdf77006d31683b55aac2767906596d5..dc2b3e97026c0702bc6c566f37136b21f5ad394f 100644 (file)
@@ -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';