From becec954e6c4c61cf5407c7c4cd152b342fb4212 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Mon, 4 Jan 2010 18:27:41 +0000 Subject: [PATCH] MDL-20652 workshop: more work on example submissions --- mod/workshop/assessment.php | 2 +- mod/workshop/db/access.php | 3 +- mod/workshop/exassessment.php | 104 ++++++++++++++++++ .../{example.php => exsubmission.php} | 102 +++++++++++------ mod/workshop/lang/en_utf8/workshop.php | 10 +- mod/workshop/locallib.php | 29 ++++- mod/workshop/renderer.php | 6 +- mod/workshop/styles.css | 5 +- mod/workshop/tabs.php | 3 + mod/workshop/view.php | 2 +- 10 files changed, 217 insertions(+), 49 deletions(-) create mode 100644 mod/workshop/exassessment.php rename mod/workshop/{example.php => exsubmission.php} (62%) diff --git a/mod/workshop/assessment.php b/mod/workshop/assessment.php index 1e6fe9ddc5..4c9606158a 100644 --- a/mod/workshop/assessment.php +++ b/mod/workshop/assessment.php @@ -39,7 +39,7 @@ 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); -$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); diff --git a/mod/workshop/db/access.php b/mod/workshop/db/access.php index 4cc47e2c6e..635823356e 100644 --- a/mod/workshop/db/access.php +++ b/mod/workshop/db/access.php @@ -75,7 +75,8 @@ $mod_workshop_capabilities = array( ), // 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, diff --git a/mod/workshop/exassessment.php b/mod/workshop/exassessment.php new file mode 100644 index 0000000000..fadcaff301 --- /dev/null +++ b/mod/workshop/exassessment.php @@ -0,0 +1,104 @@ +. + +/** + * Assess an example submission + * + * @package mod-workshop + * @copyright 2009 David Mudrak + * @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(); diff --git a/mod/workshop/example.php b/mod/workshop/exsubmission.php similarity index 62% rename from mod/workshop/example.php rename to mod/workshop/exsubmission.php index d4d7d1d274..ac430596d0 100644 --- a/mod/workshop/example.php +++ b/mod/workshop/exsubmission.php @@ -16,7 +16,7 @@ // along with Moodle. If not, see . /** - * View or edit a single example example + * View, create or edit single example submission * * @package mod-workshop * @copyright 2009 David Mudrak @@ -27,14 +27,15 @@ require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); 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()) { @@ -44,7 +45,7 @@ if (isguestuser()) { $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); @@ -56,7 +57,16 @@ if ($id) { // example is specified } $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(); @@ -64,12 +74,25 @@ if ($id and $delete and $confirm and $canmanage) { 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) { @@ -119,7 +142,7 @@ if ($edit and $canmanage) { } // 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)); } } @@ -133,7 +156,7 @@ if ($edit) { // Output starts here echo $OUTPUT->header(); -$currenttab = 'submission'; +$currenttab = 'example'; include(dirname(__FILE__) . '/tabs.php'); echo $OUTPUT->heading(format_string($workshop->name), 2); @@ -150,28 +173,39 @@ if ($example->id) { 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(); diff --git a/mod/workshop/lang/en_utf8/workshop.php b/mod/workshop/lang/en_utf8/workshop.php index 40bb067832..4d29f725f1 100644 --- a/mod/workshop/lang/en_utf8/workshop.php +++ b/mod/workshop/lang/en_utf8/workshop.php @@ -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'; @@ -43,7 +43,9 @@ $string['areainstructauthors'] = 'Instructions for submitting'; $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'; @@ -77,7 +79,7 @@ $string['evaluategradeswait'] = 'Please wait until the assessments are evaluated $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'; diff --git a/mod/workshop/locallib.php b/mod/workshop/locallib.php index e85a04d45b..0ea77b315c 100644 --- a/mod/workshop/locallib.php +++ b/mod/workshop/locallib.php @@ -538,9 +538,10 @@ class workshop { * @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))) { @@ -553,7 +554,7 @@ class workshop { $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 @@ -679,6 +680,16 @@ class workshop { 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 */ @@ -691,9 +702,9 @@ class workshop { * @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)); } /** @@ -752,6 +763,16 @@ class workshop { 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? diff --git a/mod/workshop/renderer.php b/mod/workshop/renderer.php index 3b3c3d800f..1cce3408cb 100644 --- a/mod/workshop/renderer.php +++ b/mod/workshop/renderer.php @@ -304,7 +304,7 @@ class mod_workshop_renderer extends plugin_renderer_base { $classes = 'submission-summary example'; $o .= $this->output->container_start($classes); // main wrapper $link = new html_link(); - $link->url = new moodle_url($CFG->wwwroot . '/mod/workshop/example.php', + $link->url = new moodle_url($CFG->wwwroot . '/mod/workshop/exsubmission.php', array('cmid' => $this->page->context->instanceid, 'id' => $example->id)); $link->text = format_string($example->title); $link->set_classes('title'); @@ -313,14 +313,14 @@ class mod_workshop_renderer extends plugin_renderer_base { $icon = new moodle_action_icon(); $icon->image->src = $this->old_icon_url('i/edit'); $icon->image->alt = get_string('edit'); - $icon->link->url = new moodle_url($CFG->wwwroot . '/mod/workshop/example.php', + $icon->link->url = new moodle_url($CFG->wwwroot . '/mod/workshop/exsubmission.php', array('cmid' => $this->page->context->instanceid, 'id' => $example->id, 'edit' => 'on')); $o .= $this->output->action_icon($icon); $icon = new moodle_action_icon(); $icon->image->src = $this->old_icon_url('t/delete'); $icon->image->alt = get_string('delete'); - $icon->link->url = new moodle_url($CFG->wwwroot . '/mod/workshop/example.php', + $icon->link->url = new moodle_url($CFG->wwwroot . '/mod/workshop/exsubmission.php', array('cmid' => $this->page->context->instanceid, 'id' => $example->id, 'delete' => 1)); $o .= $this->output->action_icon($icon); diff --git a/mod/workshop/styles.css b/mod/workshop/styles.css index 8ca8db9805..9b1464b58d 100644 --- a/mod/workshop/styles.css +++ b/mod/workshop/styles.css @@ -69,8 +69,11 @@ margin: 0px 0px 0px 5px; } +.mod-workshop .submission-full .header .userdate.created { + padding-right: 10px; +} + .mod-workshop .submission-full .header .userdate.modified { - margin-left: 10px; padding-left: 10px; border-left: 1px solid #000; } diff --git a/mod/workshop/tabs.php b/mod/workshop/tabs.php index 7c93e311a3..27b08b09d2 100644 --- a/mod/workshop/tabs.php +++ b/mod/workshop/tabs.php @@ -46,6 +46,9 @@ if (has_capability('mod/workshop:view', $PAGE->context)) { if (has_capability('mod/workshop:editdimensions', $PAGE->context)) { $row[] = new tabobject('editform', $workshop->editform_url()->out(), get_string('editassessmentform', 'workshop')); } +if ($currenttab == 'example' and has_any_capability(array('mod/workshop:submit', 'mod/workshop:manageexamples'), $PAGE->context)) { + $row[] = new tabobject('example', '', get_string('example', 'workshop')); +} if (has_capability('mod/workshop:submit', $PAGE->context)) { $row[] = new tabobject('submission', $workshop->submission_url()->out(), get_string('submission', 'workshop')); } diff --git a/mod/workshop/view.php b/mod/workshop/view.php index d35ed28759..e4516e4cd7 100644 --- a/mod/workshop/view.php +++ b/mod/workshop/view.php @@ -95,7 +95,7 @@ case workshop::PHASE_SETUP: $editbutton = new html_form(); $editbutton->method = 'get'; $editbutton->button->text = get_string('exampleadd', 'workshop'); - $editbutton->url = new moodle_url($workshop->example_url(0), array('edit' => 'on')); + $editbutton->url = new moodle_url($workshop->exsubmission_url(0), array('edit' => 'on')); echo $OUTPUT->button($editbutton); echo $OUTPUT->box_end(); } -- 2.39.5