mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
Accumulative assessment saves (and loads already saved) evaluation
This commit is contained in:
parent
decfb3bef6
commit
0715308cd1
@ -63,6 +63,7 @@ if ('preview' == $mode) {
|
||||
if (!has_any_capability(array('mod/workshop:peerassess', 'mod/workshop:assessallsubmissions'), $PAGE->context)) {
|
||||
print_error('nopermissions', '', $workshop->view_url());
|
||||
}
|
||||
// todo do a check that the user is allowed to assess this submission
|
||||
$PAGE->set_url($workshop->assess_url($assessment->id));
|
||||
$PAGE->set_title($workshop->name);
|
||||
$PAGE->set_heading($course->fullname);
|
||||
@ -71,17 +72,11 @@ if ('preview' == $mode) {
|
||||
// load the grading strategy logic
|
||||
$strategy = $workshop->grading_strategy_instance();
|
||||
|
||||
// load the assessment form definition from the database
|
||||
// this must be called before get_assessment_form() where we have to know
|
||||
// the number of repeating fieldsets
|
||||
|
||||
//todo $formdata = $strategy->load_assessment($assessment);
|
||||
|
||||
// load the form to edit the grading strategy dimensions
|
||||
$mform = $strategy->get_assessment_form($PAGE->url, $mode);
|
||||
$mform = $strategy->get_assessment_form($PAGE->url, $mode, $assessment);
|
||||
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect($returnurl);
|
||||
redirect($workshop->view_url());
|
||||
|
||||
} elseif ($data = $mform->get_data()) {
|
||||
if (isset($data->backtoeditform)) {
|
||||
|
@ -37,6 +37,9 @@ require_capability('mod/workshop:editdimensions', $PAGE->context);
|
||||
$workshop = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST);
|
||||
$workshop = new workshop($workshop, $cm, $course);
|
||||
|
||||
// todo: check if there already is some assessment done and do not allowed the change of the form
|
||||
// once somebody already used it to assess
|
||||
|
||||
$PAGE->set_url($workshop->editform_url());
|
||||
$PAGE->set_title($workshop->name);
|
||||
$PAGE->set_heading($course->fullname);
|
||||
|
@ -42,8 +42,9 @@ class workshop_accumulative_assessment_form extends workshop_assessment_form {
|
||||
* @return void
|
||||
*/
|
||||
protected function definition_inner(&$mform) {
|
||||
$fields = (array)$this->_customdata['fields'];
|
||||
$nodims = $this->_customdata['nodims']; // number of assessment dimensions
|
||||
$fields = $this->_customdata['fields'];
|
||||
$current = $this->_customdata['current'];
|
||||
$nodims = $this->_customdata['nodims']; // number of assessment dimensions
|
||||
|
||||
$mform->addElement('hidden', 'nodims', $nodims);
|
||||
|
||||
@ -53,17 +54,20 @@ class workshop_accumulative_assessment_form extends workshop_assessment_form {
|
||||
$mform->addElement('header', "dimensionhdr__idx_$i", $dimtitle);
|
||||
|
||||
// dimension id
|
||||
$mform->addElement('hidden', 'dimensionid__idx_'.$i, $fields['dimensionid__idx_'.$i]);
|
||||
$mform->addElement('hidden', 'dimensionid__idx_'.$i, $fields->{'dimensionid__idx_'.$i});
|
||||
|
||||
// grade id
|
||||
$mform->addElement('hidden', 'gradeid__idx_'.$i); // value set by set_data() later
|
||||
|
||||
// dimension description
|
||||
$desc = '<div id="id_dim_'.$fields['dimensionid__idx_'.$i].'_desc" class="fitem description accumulative">'."\n";
|
||||
$desc .= format_text($fields['description__idx_'.$i], $fields['description__idx_'.$i.'format']);
|
||||
$desc = '<div id="id_dim_'.$fields->{'dimensionid__idx_'.$i}.'_desc" class="fitem description accumulative">'."\n";
|
||||
$desc .= format_text($fields->{'description__idx_'.$i}, $fields->{'description__idx_'.$i.'format'});
|
||||
$desc .= "\n</div>";
|
||||
$mform->addElement('html', $desc);
|
||||
|
||||
// grade for this aspect
|
||||
$label = get_string('dimensiongrade', 'workshop');
|
||||
$options = make_grades_menu($fields['grade__idx_' . $i]);
|
||||
$options = make_grades_menu($fields->{'grade__idx_' . $i});
|
||||
$mform->addElement('select', 'grade__idx_' . $i, $label, $options);
|
||||
|
||||
// comment
|
||||
@ -71,7 +75,6 @@ class workshop_accumulative_assessment_form extends workshop_assessment_form {
|
||||
//$mform->addElement('editor', 'peercomment__idx_' . $i, $label, null, array('maxfiles' => 0));
|
||||
$mform->addElement('textarea', 'peercomment__idx_' . $i, $label, array('cols' => 60, 'rows' => 5));
|
||||
}
|
||||
|
||||
$this->set_data($current);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -250,9 +250,10 @@ class workshop_accumulative_strategy extends workshop_base_strategy implements w
|
||||
* @param moodle_url $actionurl URL of form handler, defaults to auto detect the current url
|
||||
* @param string $mode Mode to open the form in: preview/assessment
|
||||
*/
|
||||
public function get_assessment_form(moodle_url $actionurl=null, $mode='preview') {
|
||||
public function get_assessment_form(moodle_url $actionurl=null, $mode='preview', stdClass $assessment=null) {
|
||||
global $CFG; // needed because the included files use it
|
||||
global $PAGE;
|
||||
global $DB;
|
||||
require_once(dirname(__FILE__) . '/assessment_form.php');
|
||||
|
||||
$fields = $this->load_fields();
|
||||
@ -266,6 +267,20 @@ class workshop_accumulative_strategy extends workshop_base_strategy implements w
|
||||
'pluginfile.php', $PAGE->context->id, 'workshop_dimension_description', $fields->{'dimensionid__idx_'.$i});
|
||||
}
|
||||
|
||||
if ('assessment' === $mode and !empty($assessment)) {
|
||||
// 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++) {
|
||||
$dimid = $fields->{'dimensionid__idx_'.$i};
|
||||
if (isset($grades[$dimid])) {
|
||||
$current->{'gradeid__idx_'.$i} = $grades[$dimid]->id;
|
||||
$current->{'grade__idx_'.$i} = $grades[$dimid]->grade;
|
||||
$current->{'peercomment__idx_'.$i} = $grades[$dimid]->peercomment;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set up the required custom data common for all strategies
|
||||
$customdata['strategy'] = $this;
|
||||
$customdata['mode'] = $mode;
|
||||
@ -273,6 +288,7 @@ class workshop_accumulative_strategy extends workshop_base_strategy implements w
|
||||
// set up strategy-specific custom data
|
||||
$customdata['nodims'] = $this->nodimensions;
|
||||
$customdata['fields'] = $fields;
|
||||
$customdata['current'] = isset($current) ? $current : null;
|
||||
$attributes = array('class' => 'assessmentform accumulative');
|
||||
|
||||
return new workshop_accumulative_assessment_form($actionurl, $customdata, 'post', '', $attributes);
|
||||
@ -297,45 +313,23 @@ class workshop_accumulative_strategy extends workshop_base_strategy implements w
|
||||
if (!isset($data->nodims)) {
|
||||
throw coding_expection('You did not send me the number of assessment dimensions to process');
|
||||
}
|
||||
|
||||
foreach ($this->_cook_assessment_form_data($assessment, $data) as $cooked) {
|
||||
$cooked->id = $DB->get_field('workshop_grades', 'id', array('assessmentid' => $cooked->assessmentid,
|
||||
'strategy' => 'accumulative',
|
||||
'dimensionid' => $cooked->dimensionid));
|
||||
if (false === $cooked->id) {
|
||||
// not found - new grade
|
||||
$cooked->id = $DB->insert_record('workshop_grades', $cooked);
|
||||
for ($i = 0; $i < $data->nodims; $i++) {
|
||||
$grade = new stdClass();
|
||||
$grade->id = $data->{'gradeid__idx_' . $i};
|
||||
$grade->assessmentid = $assessment->id;
|
||||
$grade->dimensionid = $data->{'dimensionid__idx_' . $i};
|
||||
$grade->grade = $data->{'grade__idx_' . $i};
|
||||
$grade->peercomment = $data->{'peercomment__idx_' . $i};
|
||||
$grade->peercommentformat = FORMAT_HTML;
|
||||
if (empty($grade->id)) {
|
||||
// new grade
|
||||
$grade->id = $DB->insert_record('workshop_grades', $grade);
|
||||
} else {
|
||||
// update existing grade
|
||||
$DB->update_record('workshop_grades', $cooked);
|
||||
// updated grade
|
||||
$DB->update_record('workshop_grades', $grade);
|
||||
}
|
||||
}
|
||||
// todo recalculate grades
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares data returned by {@link workshop_accumulative_assessment_form} so they can be saved into database
|
||||
*
|
||||
* Called internally from {@link save_assessment()} only. Could be private but
|
||||
* keeping protected for unit testing purposes.
|
||||
*
|
||||
* @param object $raw Raw data returned by mform
|
||||
* @return array Array of objects to be inserted/updated in DB
|
||||
*/
|
||||
protected function _cook_assessment_form_data(stdClass $assessment, stdClass $raw) {
|
||||
$raw = (array)$raw;
|
||||
$cooked = array();
|
||||
for ($i = 0; $i < $raw['nodims']; $i++) {
|
||||
$grade = new stdClass();
|
||||
$grade->assessmentid = $assessment->id;
|
||||
$grade->strategy = $raw['strategyname'];
|
||||
$grade->dimensionid = $raw['dimensionid__idx_' . $i];
|
||||
$grade->grade = $raw['grade__idx_' . $i];
|
||||
$grade->peercomment = $raw['peercomment__idx_' . $i];
|
||||
$grade->peercommentformat = FORMAT_HTML;
|
||||
$cooked[$i] = $grade;
|
||||
}
|
||||
return $cooked;
|
||||
// todo recalculate grades immediately or by cron ?
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user