Skip to content

Commit

Permalink
MDL-20652 workshop: more work on example submissions
Browse files Browse the repository at this point in the history
  • Loading branch information
mudrd8mz committed Jan 4, 2010
1 parent 81eccf0 commit becec95
Show file tree
Hide file tree
Showing 10 changed files with 217 additions and 49 deletions.
2 changes: 1 addition & 1 deletion mod/workshop/assessment.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

$asid = required_param('asid', PARAM_INT); // assessment id
$assessment = $DB->get_record('workshop_assessments', array('id' => $asid), '*', MUST_EXIST);
$submission = $DB->get_record('workshop_submissions', array('id' => $assessment->submissionid), '*', MUST_EXIST);
$submission = $DB->get_record('workshop_submissions', array('id' => $assessment->submissionid, 'example' => 0), '*', MUST_EXIST);
$workshop = $DB->get_record('workshop', array('id' => $submission->workshopid), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $workshop->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('workshop', $workshop->id, $course->id, false, MUST_EXIST);
Expand Down
3 changes: 2 additions & 1 deletion mod/workshop/db/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
),

// Ability to be a reviewer of a submission. All users with this capability are considered
// as potential reviewers for the allocation purposes.
// as potential reviewers for the allocation purposes and can train assessment process on the
// example submissions.
'mod/workshop:peerassess' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
Expand Down
104 changes: 104 additions & 0 deletions mod/workshop/exassessment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?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/>.

/**
* Assess an example submission
*
* @package mod-workshop
* @copyright 2009 David Mudrak <david.mudrak@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once(dirname(__FILE__).'/locallib.php');

$asid = required_param('asid', PARAM_INT); // assessment id
$assessment = $DB->get_record('workshop_assessments', array('id' => $asid), '*', MUST_EXIST);
$example = $DB->get_record('workshop_submissions', array('id' => $assessment->submissionid, 'example' => 1), '*', MUST_EXIST);
$workshop = $DB->get_record('workshop', array('id' => $example->workshopid), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $workshop->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('workshop', $workshop->id, $course->id, false, MUST_EXIST);

require_login($course, false, $cm);
if (isguestuser()) {
print_error('guestsarenotallowed');
}
$workshop = new workshop($workshop, $cm, $course);

$PAGE->set_url($workshop->exassess_url($assessment->id));
$PAGE->set_title($workshop->name);
$PAGE->set_heading($course->fullname);
$PAGE->navbar->add(get_string('assessingexample', 'workshop'));
$currenttab = 'assessment';

$canmanage = has_capability('mod/workshop:manageexamples', $workshop->context);
$isreviewer = ($USER->id == $assessment->reviewerid);

if ($isreviewer or $canmanage) {
// such a user can continue
} else {
print_error('nopermissions', '', $workshop->view_url());
}

// only the reviewer is allowed to modify the assessment
if ($canmanage or ($isreviewer and $workshop->assessing_examples_allowed())) {
$assessmenteditable = true;
} else {
$assessmenteditable = false;
}

// load the grading strategy logic
$strategy = $workshop->grading_strategy_instance();

// load the assessment form and process the submitted data eventually
$mform = $strategy->get_assessment_form($PAGE->url, 'assessment', $assessment, $assessmenteditable);
if ($mform->is_cancelled()) {
redirect($workshop->view_url());
} elseif ($assessmenteditable and ($data = $mform->get_data())) {
$rawgrade = $strategy->save_assessment($assessment, $data);
$DB->set_field('workshop_assessments', 'reviewerid', $USER->id, array('id' => $assessment->id));
if (!is_null($rawgrade) and isset($data->saveandclose)) {
redirect($workshop->view_url());
} else {
// either it is not possible to calculate the $rawgrade
// or the reviewer has chosen "Save and continue"
redirect($PAGE->url);
}
}

// output starts here
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('assessedexample', 'workshop'), 2);

$wsoutput = $PAGE->theme->get_renderer('mod_workshop', $PAGE); // workshop renderer
$example = $workshop->get_example_by_id($example->id); // reload so can be passed to the renderer
echo $wsoutput->example_full($example);

if ($canmanage) {
echo $OUTPUT->heading(get_string('assessmentreference', 'workshop'), 2);
} elseif ($isreviewer) {
echo $OUTPUT->heading(get_string('assessmentbyyourself', 'workshop'), 2);
} else {
$assessment = $workshop->get_assessment_by_id($assessment->id); // extend the current record with user details
$reviewer = new stdClass();
$reviewer->firstname = $assessment->reviewerfirstname;
$reviewer->lastname = $assessment->reviewerlastname;
echo $OUTPUT->heading(get_string('assessmentbyknown', 'workshop', fullname($reviewer)), 2);
}

$mform->display();
echo $OUTPUT->footer();
102 changes: 68 additions & 34 deletions mod/workshop/example.php → mod/workshop/exsubmission.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* View or edit a single example example
* View, create or edit single example submission
*
* @package mod-workshop
* @copyright 2009 David Mudrak <david.mudrak@gmail.com>
Expand All @@ -27,14 +27,15 @@
require_once(dirname(__FILE__).'/lib.php');
require_once(dirname(__FILE__).'/locallib.php');

$cmid = required_param('cmid', PARAM_INT); // course module id
$id = required_param('id', PARAM_INT); // example submission id, 0 for the new one
$edit = optional_param('edit', false, PARAM_BOOL); // open for editing?
$delete = optional_param('delete', false, PARAM_BOOL); // example removal requested
$confirm = optional_param('confirm', false, PARAM_BOOL); // example removal request confirmed
$cmid = required_param('cmid', PARAM_INT); // course module id
$id = required_param('id', PARAM_INT); // example submission id, 0 for the new one
$edit = optional_param('edit', false, PARAM_BOOL); // open for editing?
$delete = optional_param('delete', false, PARAM_BOOL); // example removal requested
$confirm = optional_param('confirm', false, PARAM_BOOL); // example removal request confirmed
$assess = optional_param('assess', false, PARAM_BOOL); // assessment required

$cm = get_coursemodule_from_id('workshop', $cmid, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_id('workshop', $cmid, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);

require_login($course, false, $cm);
if (isguestuser()) {
Expand All @@ -44,7 +45,7 @@
$workshop = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST);
$workshop = new workshop($workshop, $cm, $course);

$PAGE->set_url(new moodle_url($workshop->example_url($id), array('edit' => $edit)));
$PAGE->set_url(new moodle_url($workshop->exsubmission_url($id), array('edit' => $edit)));

if ($id) { // example is specified
$example = $workshop->get_example_by_id($id);
Expand All @@ -56,20 +57,42 @@
}

$canmanage = has_capability('mod/workshop:manageexamples', $workshop->context);
$isreviewer = $DB->record_exists('workshop_assessments', array('submissionid' => $example->id, 'reviewerid' => $USER->id));
$canassess = has_capability('mod/workshop:peerassess', $workshop->context);
$refasid = $DB->get_field('workshop_assessments', 'id', array('submissionid' => $example->id, 'weight' => 1));

if ($example->id and ($canmanage or ($workshop->assessing_examples_allowed() and $canassess))) {
// ok you can go
} elseif (is_null($example->id) and $canmanage) {
// ok you can go
} else {
print_error('nopermissions');
}

if ($id and $delete and $confirm and $canmanage) {
require_sesskey();
$workshop->delete_submission($example);
redirect($workshop->view_url());
}

if ($example->id and ($canmanage or $isreviewer)) {
// ok you can go
} elseif (is_null($example->id) and $canmanage) {
// ok you can go
} else {
print_error('nopermissions');
if ($id and $assess and $canmanage) {
// reference assessment of an example is the assessment with the weight = 1. There should be just one
// such assessment
require_sesskey();
if (!$refasid) {
$refasid = $workshop->add_allocation($example, $USER->id, false, 1);
}
redirect($workshop->exassess_url($refasid));
}

if ($id and $assess and $canassess) {
// training assessment of an example is the assessment with the weight = 0
require_sesskey();
$asid = $DB->get_field('workshop_assessments', 'id',
array('submissionid' => $example->id, 'weight' => 0, 'reviewerid' => $USER->id));
if (!$asid) {
$asid = $workshop->add_allocation($example, $USER->id, false, 0);
}
redirect($workshop->exassess_url($asid));
}

if ($edit and $canmanage) {
Expand Down Expand Up @@ -119,7 +142,7 @@
}
// store the updated values or re-save the new example (re-saving needed because URLs are now rewritten)
$DB->update_record('workshop_submissions', $formdata);
redirect($workshop->example_url($formdata->id));
redirect($workshop->exsubmission_url($formdata->id));
}
}

Expand All @@ -133,7 +156,7 @@

// Output starts here
echo $OUTPUT->header();
$currenttab = 'submission';
$currenttab = 'example';
include(dirname(__FILE__) . '/tabs.php');
echo $OUTPUT->heading(format_string($workshop->name), 2);

Expand All @@ -150,28 +173,39 @@
echo $OUTPUT->confirm(get_string('exampledeleteconfirm', 'workshop'),
new moodle_url($PAGE->url, array('delete' => 1, 'confirm' => 1)), $workshop->view_url());
}
if ($canmanage and !$delete and !$DB->record_exists_select('workshop_assessments',
'grade IS NOT NULL AND weight=1 AND submissionid = ?', array($example->id))) {
echo $OUTPUT->confirm(get_string('assessmentreferenceneeded', 'workshop'),
new moodle_url($PAGE->url, array('assess' => 1)), $workshop->view_url());
}
$wsoutput = $PAGE->theme->get_renderer('mod_workshop', $PAGE);
echo $wsoutput->example_full($example, true);
}
// ...with an option to edit and remove it
// ...with an option to edit or remove it
echo $OUTPUT->container_start('buttonsbar');
if ($canmanage) {
echo $OUTPUT->container_start('buttonsbar');
if (empty($edit) and empty($delete)) {
$editbutton = new html_form();
$editbutton->method = 'get';
$editbutton->button->text = get_string('exampleedit', 'workshop');
$editbutton->url = new moodle_url($workshop->example_url($example->id), array('edit' => 'on'));
echo $OUTPUT->button($editbutton);
}
if (empty($delete)) {
$deletebutton = new html_form();
$deletebutton->method = 'get';
$deletebutton->button->text = get_string('exampledelete', 'workshop');
$deletebutton->url = new moodle_url($workshop->example_url($example->id), array('delete' => 'on'));
echo $OUTPUT->button($deletebutton);
$button = new html_form();
$button->method = 'get';
$button->button->text = get_string('exampleedit', 'workshop');
$button->url = new moodle_url($workshop->exsubmission_url($example->id), array('edit' => 'on'));
echo $OUTPUT->button($button);

$button = new html_form();
$button->method = 'get';
$button->button->text = get_string('exampledelete', 'workshop');
$button->url = new moodle_url($workshop->exsubmission_url($example->id), array('delete' => 'on'));
echo $OUTPUT->button($button);
}
echo $OUTPUT->container_end();
}

// ...and optionally assess it
if ($canassess or ($canmanage and empty($edit) and empty($delete))) {
$button = new html_form();
$button->method = 'get';
$button->button->text = get_string('exampleassess', 'workshop');
$button->url = new moodle_url($workshop->exsubmission_url($example->id), array('assess' => 'on', 'sesskey' => sesskey()));
echo $OUTPUT->button($button);
}
echo $OUTPUT->container_end(); // buttonsbar
// and possibly display the example's review(s) - todo
echo $OUTPUT->footer();
10 changes: 6 additions & 4 deletions mod/workshop/lang/en_utf8/workshop.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
defined('MOODLE_INTERNAL') || die();

$string[''] = '';
$string[''] = '';
$string[''] = '';
$string[''] = '';
$string['exampleassess'] = 'Assess example submission';
$string['assessmentreference'] = 'Reference assessment';
$string['assessmentreferenceneeded'] = 'You have to assess this example submission to provide a reference assessment. Click \'Continue\' button to assess the submission.';
$string['accesscontrol'] = 'Access control';
$string['aggregategrades'] = 'Re-calculate grades';
$string['aggregation'] = 'Grades aggregation';
Expand All @@ -43,7 +43,9 @@
$string['areasubmissionattachment'] = 'Submission attachments';
$string['areasubmissioncontent'] = 'Submission texts';
$string['assess'] = 'Assess';
$string['assessedexample'] = 'Assessed example submission';
$string['assessedsubmission'] = 'Assessed submission';
$string['assessingexample'] = 'Assessing example submission';
$string['assessingsubmission'] = 'Assessing submission';
$string['assessmentbyknown'] = 'Assessment by $a';
$string['assessmentbyunknown'] = 'Assessment';
Expand Down Expand Up @@ -77,7 +79,7 @@
$string['evaluation'] = 'Grading evaluation';
$string['evaluationmethod'] = 'Grading evaluation method';
$string['exampleadd'] = 'Add example submission';
$string['exampledeleteconfirm'] = 'Are you sure you want to delete the following example submission?';
$string['exampledeleteconfirm'] = 'Are you sure you want to delete the following example submission? Click \'Continue\' button to delete the submission.';
$string['exampledelete'] = 'Delete example';
$string['exampleedit'] = 'Edit example';
$string['exampleediting'] = 'Editing example';
Expand Down
29 changes: 25 additions & 4 deletions mod/workshop/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -538,9 +538,10 @@ public function get_assessments_by_reviewer($reviewerid) {
* @param stdClass $submission Submission record
* @param int $reviewerid User ID
* @param bool $bulk repeated inserts into DB expected
* @param int $weight of the new assessment, from 0 to 16
* @return int ID of the new assessment or an error code
*/
public function add_allocation(stdClass $submission, $reviewerid, $bulk=false) {
public function add_allocation(stdClass $submission, $reviewerid, $bulk=false, $weight=1) {
global $DB;

if ($DB->record_exists('workshop_assessments', array('submissionid' => $submission->id, 'reviewerid' => $reviewerid))) {
Expand All @@ -553,7 +554,7 @@ public function add_allocation(stdClass $submission, $reviewerid, $bulk=false) {
$assessment->reviewerid = $reviewerid;
$assessment->timecreated = $now;
$assessment->timemodified = $now;
$assessment->weight = 1;
$assessment->weight = $weight;
$assessment->generalcommentformat = FORMAT_HTML; // todo better default handling
$assessment->feedbackreviewerformat = FORMAT_HTML; // todo better default handling

Expand Down Expand Up @@ -679,6 +680,16 @@ public function assess_url($assessmentid) {
return new moodle_url($CFG->wwwroot . '/mod/workshop/assessment.php', array('asid' => $assessmentid));
}

/**
* @param int $assessmentid The ID of assessment record
* @return moodle_url of the example assessment page
*/
public function exassess_url($assessmentid) {
global $CFG;
$assessmentid = clean_param($assessmentid, PARAM_INT);
return new moodle_url($CFG->wwwroot . '/mod/workshop/exassessment.php', array('asid' => $assessmentid));
}

/**
* @return moodle_url of the page to view a submission, defaults to the own one
*/
Expand All @@ -691,9 +702,9 @@ public function submission_url($id=null) {
* @param int $id example submission id
* @return moodle_url of the page to view an example submission
*/
public function example_url($id) {
public function exsubmission_url($id) {
global $CFG;
return new moodle_url($CFG->wwwroot . '/mod/workshop/example.php', array('cmid' => $this->cm->id, 'id' => $id));
return new moodle_url($CFG->wwwroot . '/mod/workshop/exsubmission.php', array('cmid' => $this->cm->id, 'id' => $id));
}

/**
Expand Down Expand Up @@ -752,6 +763,16 @@ public function assessing_allowed() {
return true;
}

/**
* Are reviewers allowed to create/edit their assessments of the example submissions?
*
* TODO: this depends on the workshop phase, phase deadlines
*
* @return bool
*/
public function assessing_examples_allowed() {
return true;
}

/**
* Are the peer-reviews available to the authors?
Expand Down
Loading

0 comments on commit becec95

Please sign in to comment.