$PAGE->set_heading($course->fullname);
}
-// load the grading strategy logic
-$strategy = $workshop->grading_strategy_instance();
-
-// load the form to edit the grading strategy dimensions
-$mform = $strategy->get_assessment_form($PAGE->url, $mode, $assessment);
-
-if ($mform->is_cancelled()) {
- redirect($workshop->view_url());
-
-} elseif ($data = $mform->get_data()) {
- if (isset($data->backtoeditform)) {
- // user wants to return from preview to form editing
- redirect($workshop->editform_url());
- }
- $strategy->save_assessment($assessment, $data);
- if (isset($data->saveandclose)) {
- redirect($workshop->view_url());
- } else {
- // save and continue - redirect to self to prevent data being re-posted by pressing "Reload"
- redirect($PAGE->url);
- }
-}
-
-// build the navigation and the header
+// build the navigation and the header - todo this will be changed by the new navigation api
$navlinks = array();
$navlinks[] = array('name' => get_string('modulenameplural', 'workshop'),
'link' => "index.php?id=$course->id",
}
$navigation = build_navigation($navlinks);
+// load the grading strategy logic
+$strategy = $workshop->grading_strategy_instance();
+
+// load the form to edit the grading strategy dimensions
+$mform = $strategy->get_assessment_form($PAGE->url, $mode, $assessment);
+
+if ($mform->is_cancelled()) {
+ redirect($workshop->view_url());
+
+} elseif ($data = $mform->get_data()) {
+ if (isset($data->backtoeditform)) {
+ // user wants to return from preview to form editing
+ redirect($workshop->editform_url());
+ }
+ $rawgrade = $strategy->save_assessment($assessment, $data);
+ if (isset($data->saveandclose)) {
+ echo $OUTPUT->header($navigation);
+ echo $OUTPUT->heading(get_string('assessmentresult', 'workshop'), 2);
+ echo $OUTPUT->box('Given grade: ' . $rawgrade); // todo more detailed info using own renderer
+ echo $OUTPUT->continue_button($workshop->view_url());
+ echo $OUTPUT->footer();
+ die(); // bye-bye
+ } else {
+ // save and continue - redirect to self to prevent data being re-posted by pressing "Reload"
+ redirect($PAGE->url);
+ }
+}
+
// Output starts here
echo $OUTPUT->header($navigation);
/** @var workshop the parent workshop instance */
protected $workshop;
- /** @var int number of dimensions defined in database, must be set in {@link load_fields()} */
- protected $nodimensions=null;
+ /** @var array definition of the assessment form fields */
+ protected $dimensions = null;
/** @var array options for dimension description fields */
protected $descriptionopts;
*/
public function __construct($workshop) {
$this->workshop = $workshop;
+ $this->dimensions = $this->load_fields();
$this->descriptionopts = array('trusttext' => true, 'subdirs' => true, 'maxfiles' => -1);
}
require_once(dirname(__FILE__) . '/edit_form.php');
- $fields = $this->load_fields();
- if (is_null($this->nodimensions)) {
- throw new coding_exception('You forgot to set the number of dimensions in load_fields()');
- }
- $norepeatsdefault = max($this->nodimensions + WORKSHOP_STRATEGY_ADDDIMS, WORKSHOP_STRATEGY_MINDIMS);
+ $fields = $this->prepare_form_fields($this->dimensions);
+ $nodimensions = count($this->dimensions);
+ $norepeatsdefault = max($nodimensions + WORKSHOP_STRATEGY_ADDDIMS, WORKSHOP_STRATEGY_MINDIMS);
$norepeats = optional_param('norepeats', $norepeatsdefault, PARAM_INT); // number of dimensions
$noadddims = optional_param('noadddims', '', PARAM_ALPHA); // shall we add more?
if ($noadddims) {
}
// prepare the embeded files
- for ($i = 0; $i < $this->nodimensions; $i++) {
+ for ($i = 0; $i < $nodimensions; $i++) {
// prepare all editor elements
$fields = file_prepare_standard_editor($fields, 'description__idx_'.$i, $this->descriptionopts,
$PAGE->context, 'workshop_dimension_description', $fields->{'dimensionid__idx_'.$i});
}
/**
- * Returns the fields of the assessment form and sets {@var nodimensions}
+ * Loads the fields of the assessment form
+ *
+ * @return array definition of assessment dimensions
*/
protected function load_fields() {
global $DB;
ORDER BY master.sort';
$params[0] = $this->workshop->id;
- $dims = $DB->get_records_sql($sql, $params);
- $this->nodimensions = count($dims);
- $fields = $this->_cook_dimension_records($dims);
- return $fields;
+ return $DB->get_records_sql($sql, $params);
}
/**
- * Maps the data from DB to their form fields
- *
- * Called internally from load_form(). Could be private but keeping protected
- * for unit testing purposes.
+ * Maps the dimension data from DB to the form fields
*
- * @param array $raw Array of raw dimension records as fetched by get_record()
+ * @param array $raw Array of raw dimension records as returned by {@link load_fields()}
* @return array Array of fields data to be used by the mform set_data
*/
- protected function _cook_dimension_records(array $raw) {
+ protected function prepare_form_fields(array $raw) {
$formdata = new stdClass();
$key = 0;
global $DB;
require_once(dirname(__FILE__) . '/assessment_form.php');
- $fields = $this->load_fields();
- if (is_null($this->nodimensions)) {
- throw new coding_exception('You forgot to set the number of dimensions in load_fields()');
- }
+ $fields = $this->prepare_form_fields($this->dimensions);
+ $nodimensions = count($this->dimensions);
// rewrite URLs to the embeded files
- for ($i = 0; $i < $this->nodimensions; $i++) {
+ for ($i = 0; $i < $nodimensions; $i++) {
$fields->{'description__idx_'.$i} = file_rewrite_pluginfile_urls($fields->{'description__idx_'.$i},
'pluginfile.php', $PAGE->context->id, 'workshop_dimension_description', $fields->{'dimensionid__idx_'.$i});
}
// load the previously saved assessment data
$grades = $DB->get_records('workshop_grades', array('assessmentid' => $assessment->id), '', 'dimensionid,*');
$current = new stdClass();
- for ($i = 0; $i < $this->nodimensions; $i++) {
+ for ($i = 0; $i < $nodimensions; $i++) {
$dimid = $fields->{'dimensionid__idx_'.$i};
if (isset($grades[$dimid])) {
$current->{'gradeid__idx_'.$i} = $grades[$dimid]->id;
$customdata['mode'] = $mode;
// set up strategy-specific custom data
- $customdata['nodims'] = $this->nodimensions;
+ $customdata['nodims'] = $nodimensions;
$customdata['fields'] = $fields;
$customdata['current'] = isset($current) ? $current : null;
$attributes = array('class' => 'assessmentform accumulative');
*
* @param object $assessment Assessment being filled
* @param object $data Raw data as returned by the assessment form
- * @return void
+ * @return float Percentual grade for submission as suggested by the peer
*/
public function save_assessment(stdClass $assessment, stdClass $data) {
global $DB;
$DB->update_record('workshop_grades', $grade);
}
}
- // todo recalculate grades immediately or by cron ?
+ return $this->update_peer_grade($assessment);
}
+ /**
+ * Aggregate the assessment form data and set the grade for the submission given by the peer
+ *
+ * @param stdClass $assessment Assessment record
+ * @return float Percentual grade for submission as suggested by the peer
+ */
+ protected function update_peer_grade(stdClass $assessment) {
+ return 60.2;
+ }
}