]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-20652 workshop: more work on example submissions
authorDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 18:27:41 +0000 (18:27 +0000)
committerDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 18:27:41 +0000 (18:27 +0000)
mod/workshop/assessment.php
mod/workshop/db/access.php
mod/workshop/exassessment.php [new file with mode: 0644]
mod/workshop/exsubmission.php [moved from mod/workshop/example.php with 62% similarity]
mod/workshop/lang/en_utf8/workshop.php
mod/workshop/locallib.php
mod/workshop/renderer.php
mod/workshop/styles.css
mod/workshop/tabs.php
mod/workshop/view.php

index 1e6fe9ddc5912657b2806688cf79ee5ca4c9d644..4c9606158ac200780a5048f3841ae33d5966d653 100644 (file)
@@ -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);
index 4cc47e2c6eb1a16152724902211ebf7819997268..635823356e8e49ea9e1954e2e51003ad44c7d7de 100644 (file)
@@ -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 (file)
index 0000000..fadcaff
--- /dev/null
@@ -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();
similarity index 62%
rename from mod/workshop/example.php
rename to mod/workshop/exsubmission.php
index d4d7d1d274974d70c99d7abe628746723d59b5fb..ac430596d0b5baa7a5bdef15eb4d97281858ccc8 100644 (file)
@@ -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>
@@ -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();
index 40bb067832361a056034b4dfe8004192638ef42e..4d29f725f108ca234d6991ef8ec965c3e9e8e910 100644 (file)
@@ -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';
index e85a04d45b2ac7945874e5849c5c0ae021216e96..0ea77b315cc8aced3a8dbb3d7287b90441f8b235 100644 (file)
@@ -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?
index 3b3c3d800f977da013b9e91af9597ff17e500a9a..1cce3408cbab1b7d6aed376cda012fa0db428aeb 100644 (file)
@@ -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);
 
index 8ca8db9805b783e42d0c74d6f1d09e4b7227ef5f..9b1464b58d2357c75b2d4f7bf31382e758e9cca3 100644 (file)
     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;
 }
index 7c93e311a31b6278c27b97fb76768e47711ab228..27b08b09d28a438dafd4bb6ea23de854f8e560fd 100644 (file)
@@ -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'));
 }
index d35ed287594a2360f448c65764dd05a3ea74de76..e4516e4cd7befea02faac129f64d5bd3038a573f 100644 (file)
@@ -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();
     }