Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/workshop/exassessment.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00027 require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
00028 require_once(dirname(__FILE__).'/locallib.php');
00029 
00030 $asid       = required_param('asid', PARAM_INT);  // assessment id
00031 $assessment = $DB->get_record('workshop_assessments', array('id' => $asid), '*', MUST_EXIST);
00032 $example    = $DB->get_record('workshop_submissions', array('id' => $assessment->submissionid, 'example' => 1), '*', MUST_EXIST);
00033 $workshop   = $DB->get_record('workshop', array('id' => $example->workshopid), '*', MUST_EXIST);
00034 $course     = $DB->get_record('course', array('id' => $workshop->course), '*', MUST_EXIST);
00035 $cm         = get_coursemodule_from_instance('workshop', $workshop->id, $course->id, false, MUST_EXIST);
00036 
00037 require_login($course, false, $cm);
00038 if (isguestuser()) {
00039     print_error('guestsarenotallowed');
00040 }
00041 $workshop = new workshop($workshop, $cm, $course);
00042 
00043 $PAGE->set_url($workshop->exassess_url($assessment->id));
00044 $PAGE->set_title($workshop->name);
00045 $PAGE->set_heading($course->fullname);
00046 $PAGE->navbar->add(get_string('assessingexample', 'workshop'));
00047 $currenttab = 'assessment';
00048 
00049 $canmanage  = has_capability('mod/workshop:manageexamples', $workshop->context);
00050 $isreviewer = ($USER->id == $assessment->reviewerid);
00051 
00052 if ($isreviewer or $canmanage) {
00053     // such a user can continue
00054 } else {
00055     print_error('nopermissions', 'error', $workshop->view_url(), 'assess example submission');
00056 }
00057 
00058 // only the reviewer is allowed to modify the assessment
00059 if (($canmanage and $assessment->weight == 1) or ($isreviewer and $workshop->assessing_examples_allowed())) {
00060     $assessmenteditable = true;
00061 } else {
00062     $assessmenteditable = false;
00063 }
00064 
00065 // load the grading strategy logic
00066 $strategy = $workshop->grading_strategy_instance();
00067 
00068 // load the assessment form and process the submitted data eventually
00069 $mform = $strategy->get_assessment_form($PAGE->url, 'assessment', $assessment, $assessmenteditable);
00070 if ($mform->is_cancelled()) {
00071     redirect($workshop->view_url());
00072 } elseif ($assessmenteditable and ($data = $mform->get_data())) {
00073     if ($canmanage) {
00074         if (is_null($assessment->grade)) {
00075             $workshop->log('add reference assessment', $workshop->exassess_url($assessment->id), $assessment->submissionid);
00076         } else {
00077             $workshop->log('update reference assessment', $workshop->exassess_url($assessment->id), $assessment->submissionid);
00078         }
00079     } else {
00080         if (is_null($assessment->grade)) {
00081             $workshop->log('add example assessment', $workshop->exassess_url($assessment->id), $assessment->submissionid);
00082         } else {
00083             $workshop->log('update example assessment', $workshop->exassess_url($assessment->id), $assessment->submissionid);
00084         }
00085     }
00086     $rawgrade = $strategy->save_assessment($assessment, $data);
00087     if ($canmanage) {
00088         // remember the last one who edited the reference assessment
00089         $DB->set_field('workshop_assessments', 'reviewerid', $USER->id, array('id' => $assessment->id));
00090     }
00091     if (!is_null($rawgrade) and isset($data->saveandclose)) {
00092         if ($canmanage) {
00093             redirect($workshop->view_url());
00094         } else {
00095             redirect($workshop->excompare_url($example->id, $assessment->id));
00096         }
00097     } else {
00098         // either it is not possible to calculate the $rawgrade
00099         // or the reviewer has chosen "Save and continue"
00100         redirect($PAGE->url);
00101     }
00102 }
00103 
00104 // output starts here
00105 $output = $PAGE->get_renderer('mod_workshop');      // workshop renderer
00106 echo $output->header();
00107 echo $output->heading(get_string('assessedexample', 'workshop'), 2);
00108 
00109 $example = $workshop->get_example_by_id($example->id);     // reload so can be passed to the renderer
00110 echo $output->render($workshop->prepare_example_submission(($example)));
00111 
00112 // show instructions for assessing as thay may contain important information
00113 // for evaluating the assessment
00114 if (trim($workshop->instructreviewers)) {
00115     $instructions = file_rewrite_pluginfile_urls($workshop->instructreviewers, 'pluginfile.php', $PAGE->context->id,
00116         'mod_workshop', 'instructreviewers', 0, workshop::instruction_editors_options($PAGE->context));
00117     print_collapsible_region_start('', 'workshop-viewlet-instructreviewers', get_string('instructreviewers', 'workshop'));
00118     echo $output->box(format_text($instructions, $workshop->instructreviewersformat, array('overflowdiv'=>true)), array('generalbox', 'instructions'));
00119     print_collapsible_region_end();
00120 }
00121 
00122 // extend the current assessment record with user details
00123 $assessment = $workshop->get_assessment_by_id($assessment->id);
00124 
00125 if ($canmanage and $assessment->weight == 1) {
00126     $options = array(
00127         'showreviewer'  => false,
00128         'showauthor'    => false,
00129         'showform'      => true,
00130     );
00131     $assessment = $workshop->prepare_example_reference_assessment($assessment, $mform, $options);
00132     $assessment->title = get_string('assessmentreference', 'workshop');
00133     echo $output->render($assessment);
00134 
00135 } else if ($isreviewer) {
00136     $options = array(
00137         'showreviewer'  => true,
00138         'showauthor'    => false,
00139         'showform'      => true,
00140     );
00141     $assessment = $workshop->prepare_example_assessment($assessment, $mform, $options);
00142     $assessment->title = get_string('assessmentbyyourself', 'workshop');
00143     echo $output->render($assessment);
00144 
00145 } else if ($canmanage) {
00146     $options = array(
00147         'showreviewer'  => true,
00148         'showauthor'    => false,
00149         'showform'      => true,
00150         'showweight'    => false,
00151     );
00152     $assessment = $workshop->prepare_example_assessment($assessment, $mform, $options);
00153     echo $output->render($assessment);
00154 }
00155 
00156 echo $output->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations