Skip to content

Commit

Permalink
More work on the strategy API
Browse files Browse the repository at this point in the history
  • Loading branch information
mudrd8mz committed Jan 4, 2010
1 parent 725d615 commit 7b5d01a
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 13 deletions.
23 changes: 13 additions & 10 deletions mod/workshop/editgradingform.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,21 @@
$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;
Expand Down
2 changes: 1 addition & 1 deletion mod/workshop/grading/accumulative/gradingform.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function definition_inner(&$mform) {

$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);
Expand Down
39 changes: 39 additions & 0 deletions mod/workshop/grading/accumulative/strategy.php
Original file line number Diff line number Diff line change
@@ -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 {

}
65 changes: 64 additions & 1 deletion mod/workshop/grading/strategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -34,11 +34,74 @@
*/
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();

}

/**
* Base class for grading strategy logic.
*/
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');
}

}
3 changes: 2 additions & 1 deletion mod/workshop/lang/en_utf8/workshop.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
$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';
Expand Down

0 comments on commit 7b5d01a

Please sign in to comment.