$dimensions = $strategy->load_dimensions();
// load the form to edit the grading strategy dimensions
-$mform = $strategy->get_edit_strategy_form($selfurl, true, count($dimensions));
+$mform = $strategy->get_edit_strategy_form($selfurl, count($dimensions));
// initialize form data
$formdata = new stdClass;
-$formdata->workshopid = $workshop->id;
-$formdata->strategy = $workshop->strategy;
-$formdata->dimensions = $dimensions;
+$formdata->dimensions = $dimensions;
$mform->set_data($formdata);
if ($mform->is_cancelled()) {
/** strategy logic instance that this class is editor of */
protected $strategy;
- /** number of dimensions that are populated from DB */
- protected $numofdimensions;
-
- /**
- * Constructor
- *
- * @param object $strategy The instance of the strategy logic
- * @param str $actionurl URL to handle data
- * @param bool $editable Should the form be editable?
- * @param int $initialdimensions Number of assessment dimensions that are already filled
- * @access public
- * @return void
- */
- public function __construct(workshop_strategy $strategy, $actionurl, $editable=true, $initialdimensions=0) {
-
- $this->strategy = $strategy;
- $this->numofdimensions = $initialdimensions;
- parent::moodleform($actionurl, null, 'post', '', array('class' => 'editstrategyform'), $editable);
- }
-
+ /** number of current dimensions loaded from DB */
+ protected $nocurrentdims;
/**
* Add the fields that are common for all grading strategies.
global $CFG;
$mform = $this->_form;
+ $this->strategy = $this->_customdata['strategy'];
+ $this->nocurrentdims = $this->_customdata['nocurrentdims'];
- $mform->addElement('hidden', 'workshopid');
- $mform->setType('id', PARAM_INT);
-
- $mform->addElement('hidden', 'strategy');
- $mform->setType('id', PARAM_ALPHA);
+ $mform->addElement('hidden', 'strategyname', $this->strategy->name);
$this->definition_inner($mform);
/**
* Factory method returning an instance of an assessment form editor class
*
- * The returned class will probably expand the base workshop_edit_strategy_form
+ * The returned class will probably expand the base workshop_edit_strategy_form. The number of
+ * dimensions that will be passed by set_data() must be already known here becase the
+ * definition() of the form has to know the number and it is called before set_data().
*
* @param string $actionurl URL of the action handler script
- * @param boolean $edit Open the form in editing mode
- * @param int $nodimensions Number of dimensions to be provided by set_data
+ * @param int $nocurrentdims Number of current dimensions to be set later by set_data()
* @access public
* @return object The instance of the assessment form editor class
*/
- public function get_edit_strategy_form($actionurl, $edit=true, $nodimensions=0);
+ public function get_edit_strategy_form($actionurl, $nocurrentdims=0);
/**
public $name;
/** the parent workshop instance */
- protected $_workshop;
+ protected $workshop;
/**
* Constructor
*/
public function __construct($workshop) {
- $this->name = $workshop->strategy;
- $this->_workshop = $workshop;
+ $this->name = $workshop->strategy;
+ $this->workshop = $workshop;
}
* By default, the class is defined in grading/{strategy}/gradingform.php and is named
* workshop_edit_{strategy}_strategy_form
*/
- public function get_edit_strategy_form($actionurl, $edit=true, $nodimensions=0) {
+ public function get_edit_strategy_form($actionurl, $nocurrentdims=0) {
global $CFG; // needed because the included files use it
$strategyform = dirname(__FILE__) . '/' . $this->name . '/gradingform.php';
}
$classname = 'workshop_edit_' . $this->name . '_strategy_form';
- return new $classname($this, $actionurl, $edit, $nodimensions);
+ $customdata = new stdClass;
+ $customdata = array(
+ 'strategy' => $this,
+ 'nocurrentdims' => $nocurrentdims,
+
+ );
+ $attributes = array('class' => 'editstrategyform');
+
+ return new $classname($actionurl, $customdata, 'post', '', $attributes);
}
public function load_dimensions() {
global $DB;
- return $DB->get_records('workshop_forms_' . $this->name, array('workshopid' => $this->_workshop->id), 'sort');
+ return $DB->get_records('workshop_forms_' . $this->name, array('workshopid' => $this->workshop->id), 'sort');
}
public function save_dimensions($data) {
global $DB;
+ if (!isset($data->strategyname) || ($data->strategyname != $this->name)) {
+ // the workshop strategy has changed since the form was opened for editing
+ throw new moodle_exception('strategyhaschanged', 'workshop');
+ }
+
$data = $this->cook_form_data($data);
foreach ($data as $record) {
/**
* The default implementation transposes the returned structure
*
- * It automatically adds 'sort' column and 'workshopid' column into every record.
+ * It automatically adds some columns into every record.
* The sorting is done by the order of the returned array and starts with 1.
*
* @param object $raw
foreach (array_flip($this->map_dimension_fieldnames()) as $formfield => $dbfield) {
for ($k = 0; $k < $raw->numofdimensions; $k++) {
$cook[$k]->{$dbfield} = isset($raw->{$formfield}[$k]) ? $raw->{$formfield}[$k] : null;
- $cook[$k]->sort = $k + 1;
- $cook[$k]->workshopid = $raw->workshopid;
+ $cook[$k]->descriptionformat = FORMAT_HTML;
+ $cook[$k]->sort = $k + 1;
+ $cook[$k]->workshopid = $this->workshop->id;
}
}
return $cook;