|
Moodle
2.2.1
http://www.collinsharper.com
|
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 00038 require_once(dirname(dirname(dirname(__FILE__))).'/config.php'); 00039 require_once(dirname(__FILE__).'/locallib.php'); 00040 00041 $asid = required_param('asid', PARAM_INT); // assessment id 00042 $assessment = $DB->get_record('workshop_assessments', array('id' => $asid), '*', MUST_EXIST); 00043 $submission = $DB->get_record('workshop_submissions', array('id' => $assessment->submissionid, 'example' => 0), '*', MUST_EXIST); 00044 $workshop = $DB->get_record('workshop', array('id' => $submission->workshopid), '*', MUST_EXIST); 00045 $course = $DB->get_record('course', array('id' => $workshop->course), '*', MUST_EXIST); 00046 $cm = get_coursemodule_from_instance('workshop', $workshop->id, $course->id, false, MUST_EXIST); 00047 00048 require_login($course, false, $cm); 00049 if (isguestuser()) { 00050 print_error('guestsarenotallowed'); 00051 } 00052 $workshop = new workshop($workshop, $cm, $course); 00053 00054 $PAGE->set_url($workshop->assess_url($assessment->id)); 00055 $PAGE->set_title($workshop->name); 00056 $PAGE->set_heading($course->fullname); 00057 $PAGE->navbar->add(get_string('assessingsubmission', 'workshop')); 00058 00059 $canviewallassessments = has_capability('mod/workshop:viewallassessments', $workshop->context); 00060 $canviewallsubmissions = has_capability('mod/workshop:viewallsubmissions', $workshop->context); 00061 $cansetassessmentweight = has_capability('mod/workshop:allocate', $workshop->context); 00062 $canoverridegrades = has_capability('mod/workshop:overridegrades', $workshop->context); 00063 $isreviewer = ($USER->id == $assessment->reviewerid); 00064 $isauthor = ($USER->id == $submission->authorid); 00065 00066 if ($isreviewer or $isauthor or ($canviewallassessments and $canviewallsubmissions)) { 00067 // such a user can continue 00068 } else { 00069 print_error('nopermissions', 'error', $workshop->view_url(), 'view this assessment'); 00070 } 00071 00072 if ($isauthor and !$isreviewer and !$canviewallassessments and $workshop->phase != workshop::PHASE_CLOSED) { 00073 // authors can see assessments of their work at the end of workshop only 00074 print_error('nopermissions', 'error', $workshop->view_url(), 'view assessment of own work before workshop is closed'); 00075 } 00076 00077 // only the reviewer is allowed to modify the assessment 00078 if ($isreviewer and $workshop->assessing_allowed($USER->id)) { 00079 $assessmenteditable = true; 00080 } else { 00081 $assessmenteditable = false; 00082 } 00083 00084 // check that all required examples have been assessed by the user 00085 if ($assessmenteditable and $workshop->useexamples and $workshop->examplesmode == workshop::EXAMPLES_BEFORE_ASSESSMENT 00086 and !has_capability('mod/workshop:manageexamples', $workshop->context)) { 00087 // the reviewer must have submitted their own submission 00088 $reviewersubmission = $workshop->get_submission_by_author($assessment->reviewerid); 00089 if (!$reviewersubmission) { 00090 // no money, no love 00091 $assessmenteditable = false; 00092 echo $output->header(); 00093 echo $output->heading(get_string('exampleneedsubmission', 'workshop'), 2); 00094 echo $output->footer(); 00095 exit; 00096 } else { 00097 $examples = $workshop->get_examples_for_reviewer($assessment->reviewerid); 00098 foreach ($examples as $exampleid => $example) { 00099 if (is_null($example->grade)) { 00100 $assessmenteditable = false; 00101 echo $output->header(); 00102 echo $output->heading(get_string('exampleneedassessed', 'workshop'), 2); 00103 echo $output->footer(); 00104 exit; 00105 } 00106 } 00107 } 00108 } 00109 00110 // load the grading strategy logic 00111 $strategy = $workshop->grading_strategy_instance(); 00112 00113 if (is_null($assessment->grade) and !$assessmenteditable) { 00114 $mform = null; 00115 } else { 00116 // load the assessment form and process the submitted data eventually 00117 $mform = $strategy->get_assessment_form($PAGE->url, 'assessment', $assessment, $assessmenteditable, 00118 array('editableweight' => $cansetassessmentweight)); 00119 $mform->set_data(array('weight' => $assessment->weight)); // other values are set by subplugins 00120 if ($mform->is_cancelled()) { 00121 redirect($workshop->view_url()); 00122 } elseif ($assessmenteditable and ($data = $mform->get_data())) { 00123 if (is_null($assessment->grade)) { 00124 $workshop->log('add assessment', $workshop->assess_url($assessment->id), $assessment->submissionid); 00125 } else { 00126 $workshop->log('update assessment', $workshop->assess_url($assessment->id), $assessment->submissionid); 00127 } 00128 $rawgrade = $strategy->save_assessment($assessment, $data); 00129 if (isset($data->weight) and $cansetassessmentweight) { 00130 $DB->set_field('workshop_assessments', 'weight', $data->weight, array('id' => $assessment->id)); 00131 } 00132 if (!is_null($rawgrade) and isset($data->saveandclose)) { 00133 redirect($workshop->view_url()); 00134 } else { 00135 // either it is not possible to calculate the $rawgrade 00136 // or the reviewer has chosen "Save and continue" 00137 redirect($PAGE->url); 00138 } 00139 } 00140 } 00141 00142 // load the form to override gradinggrade and/or set weight and process the submitted data eventually 00143 if ($canoverridegrades or $cansetassessmentweight) { 00144 $options = array( 00145 'editable' => true, 00146 'editableweight' => $cansetassessmentweight, 00147 'overridablegradinggrade' => $canoverridegrades); 00148 $feedbackform = $workshop->get_feedbackreviewer_form($PAGE->url, $assessment, $options); 00149 if ($data = $feedbackform->get_data()) { 00150 $data = file_postupdate_standard_editor($data, 'feedbackreviewer', array(), $workshop->context); 00151 $record = new stdclass(); 00152 $record->id = $assessment->id; 00153 if ($cansetassessmentweight) { 00154 $record->weight = $data->weight; 00155 } 00156 if ($canoverridegrades) { 00157 $record->gradinggradeover = $workshop->raw_grade_value($data->gradinggradeover, $workshop->gradinggrade); 00158 $record->gradinggradeoverby = $USER->id; 00159 $record->feedbackreviewer = $data->feedbackreviewer; 00160 $record->feedbackreviewerformat = $data->feedbackreviewerformat; 00161 } 00162 $DB->update_record('workshop_assessments', $record); 00163 redirect($workshop->view_url()); 00164 } 00165 } 00166 00167 // output starts here 00168 $output = $PAGE->get_renderer('mod_workshop'); // workshop renderer 00169 echo $output->header(); 00170 echo $output->heading(get_string('assessedsubmission', 'workshop'), 2); 00171 00172 $submission = $workshop->get_submission_by_id($submission->id); // reload so can be passed to the renderer 00173 echo $output->render($workshop->prepare_submission($submission, has_capability('mod/workshop:viewauthornames', $workshop->context))); 00174 00175 // show instructions for assessing as they may contain important information 00176 // for evaluating the assessment 00177 if (trim($workshop->instructreviewers)) { 00178 $instructions = file_rewrite_pluginfile_urls($workshop->instructreviewers, 'pluginfile.php', $PAGE->context->id, 00179 'mod_workshop', 'instructreviewers', 0, workshop::instruction_editors_options($PAGE->context)); 00180 print_collapsible_region_start('', 'workshop-viewlet-instructreviewers', get_string('instructreviewers', 'workshop')); 00181 echo $output->box(format_text($instructions, $workshop->instructreviewersformat, array('overflowdiv'=>true)), array('generalbox', 'instructions')); 00182 print_collapsible_region_end(); 00183 } 00184 00185 // extend the current assessment record with user details 00186 $assessment = $workshop->get_assessment_by_id($assessment->id); 00187 00188 if ($isreviewer) { 00189 $options = array( 00190 'showreviewer' => true, 00191 'showauthor' => has_capability('mod/workshop:viewauthornames', $workshop->context), 00192 'showform' => $assessmenteditable or !is_null($assessment->grade), 00193 'showweight' => true, 00194 ); 00195 $assessment = $workshop->prepare_assessment($assessment, $mform, $options); 00196 $assessment->title = get_string('assessmentbyyourself', 'workshop'); 00197 echo $output->render($assessment); 00198 00199 } else { 00200 $options = array( 00201 'showreviewer' => has_capability('mod/workshop:viewreviewernames', $workshop->context), 00202 'showauthor' => has_capability('mod/workshop:viewauthornames', $workshop->context), 00203 'showform' => $assessmenteditable or !is_null($assessment->grade), 00204 'showweight' => true, 00205 ); 00206 $assessment = $workshop->prepare_assessment($assessment, $mform, $options); 00207 echo $output->render($assessment); 00208 } 00209 00210 if (!$assessmenteditable and $canoverridegrades) { 00211 $feedbackform->display(); 00212 } 00213 00214 echo $output->footer();