Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/workshop/submission.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 $cmid   = required_param('cmid', PARAM_INT);            // course module id
00031 $id     = optional_param('id', 0, PARAM_INT);           // submission id
00032 $edit   = optional_param('edit', false, PARAM_BOOL);    // open for editing?
00033 $assess = optional_param('assess', false, PARAM_BOOL);  // instant assessment required
00034 
00035 $cm     = get_coursemodule_from_id('workshop', $cmid, 0, false, MUST_EXIST);
00036 $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
00037 
00038 require_login($course, false, $cm);
00039 if (isguestuser()) {
00040     print_error('guestsarenotallowed');
00041 }
00042 
00043 $workshop = $DB->get_record('workshop', array('id' => $cm->instance), '*', MUST_EXIST);
00044 $workshop = new workshop($workshop, $cm, $course);
00045 
00046 $PAGE->set_url($workshop->submission_url(), array('cmid' => $cmid, 'id' => $id));
00047 
00048 if ($edit) {
00049     $PAGE->url->param('edit', $edit);
00050 }
00051 
00052 if ($id) { // submission is specified
00053     $submission = $workshop->get_submission_by_id($id);
00054     $workshop->log('view submission', $workshop->submission_url($submission->id), $submission->id);
00055 
00056 } else { // no submission specified
00057     if (!$submission = $workshop->get_submission_by_author($USER->id)) {
00058         $submission = new stdclass();
00059         $submission->id = null;
00060         $submission->authorid = $USER->id;
00061         $submission->example = 0;
00062         $submission->grade = null;
00063         $submission->gradeover = null;
00064         $submission->published = null;
00065         $submission->feedbackauthor = null;
00066         $submission->feedbackauthorformat = editors_get_preferred_format();
00067     }
00068 }
00069 
00070 $ownsubmission  = $submission->authorid == $USER->id;
00071 $canviewall     = has_capability('mod/workshop:viewallsubmissions', $workshop->context);
00072 $cansubmit      = has_capability('mod/workshop:submit', $workshop->context);
00073 $canallocate    = has_capability('mod/workshop:allocate', $workshop->context);
00074 $canpublish     = has_capability('mod/workshop:publishsubmissions', $workshop->context);
00075 $canoverride    = (($workshop->phase == workshop::PHASE_EVALUATION) and has_capability('mod/workshop:overridegrades', $workshop->context));
00076 $userassessment = $workshop->get_assessment_of_submission_by_user($submission->id, $USER->id);
00077 $isreviewer     = !empty($userassessment);
00078 $editable       = ($cansubmit and $ownsubmission);
00079 $ispublished    = ($workshop->phase == workshop::PHASE_CLOSED
00080                     and $submission->published == 1
00081                     and has_capability('mod/workshop:viewpublishedsubmissions', $workshop->context));
00082 
00083 if (empty($submission->id) and !$workshop->creating_submission_allowed($USER->id)) {
00084     $editable = false;
00085 }
00086 if ($submission->id and !$workshop->modifying_submission_allowed($USER->id)) {
00087     $editable = false;
00088 }
00089 
00090 if ($editable and $workshop->useexamples and $workshop->examplesmode == workshop::EXAMPLES_BEFORE_SUBMISSION
00091         and !has_capability('mod/workshop:manageexamples', $workshop->context)) {
00092     // check that all required examples have been assessed by the user
00093     $examples = $workshop->get_examples_for_reviewer($USER->id);
00094     foreach ($examples as $exampleid => $example) {
00095         if (is_null($example->grade)) {
00096             $editable = false;
00097             break;
00098         }
00099     }
00100 }
00101 $edit = ($editable and $edit);
00102 
00103 $seenaspublished = false; // is the submission seen as a published submission?
00104 
00105 if ($submission->id and ($ownsubmission or $canviewall or $isreviewer)) {
00106     // ok you can go
00107 } elseif ($submission->id and $ispublished) {
00108     // ok you can go
00109     $seenaspublished = true;
00110 } elseif (is_null($submission->id) and $cansubmit) {
00111     // ok you can go
00112 } else {
00113     print_error('nopermissions', 'error', $workshop->view_url(), 'view or create submission');
00114 }
00115 
00116 if ($assess and $submission->id and !$isreviewer and $canallocate and $workshop->assessing_allowed($USER->id)) {
00117     require_sesskey();
00118     $assessmentid = $workshop->add_allocation($submission, $USER->id);
00119     redirect($workshop->assess_url($assessmentid));
00120 }
00121 
00122 if ($edit) {
00123     require_once(dirname(__FILE__).'/submission_form.php');
00124 
00125     $maxfiles       = $workshop->nattachments;
00126     $maxbytes       = $workshop->maxbytes;
00127     $contentopts    = array(
00128                         'trusttext' => true,
00129                         'subdirs'   => false,
00130                         'maxfiles'  => $maxfiles,
00131                         'maxbytes'  => $maxbytes,
00132                         'context'   => $workshop->context
00133                       );
00134 
00135     $attachmentopts = array('subdirs' => true, 'maxfiles' => $maxfiles, 'maxbytes' => $maxbytes);
00136     $submission     = file_prepare_standard_editor($submission, 'content', $contentopts, $workshop->context,
00137                                         'mod_workshop', 'submission_content', $submission->id);
00138     $submission     = file_prepare_standard_filemanager($submission, 'attachment', $attachmentopts, $workshop->context,
00139                                         'mod_workshop', 'submission_attachment', $submission->id);
00140 
00141     $mform          = new workshop_submission_form($PAGE->url, array('current' => $submission, 'workshop' => $workshop,
00142                                                     'contentopts' => $contentopts, 'attachmentopts' => $attachmentopts));
00143 
00144     if ($mform->is_cancelled()) {
00145         redirect($workshop->view_url());
00146 
00147     } elseif ($cansubmit and $formdata = $mform->get_data()) {
00148         if ($formdata->example == 0) {
00149             // this was used just for validation, it must be set to zero when dealing with normal submissions
00150             unset($formdata->example);
00151         } else {
00152             throw new coding_exception('Invalid submission form data value: example');
00153         }
00154         $timenow = time();
00155         if (is_null($submission->id)) {
00156             $formdata->workshopid     = $workshop->id;
00157             $formdata->example        = 0;
00158             $formdata->authorid       = $USER->id;
00159             $formdata->timecreated    = $timenow;
00160             $formdata->feedbackauthorformat = editors_get_preferred_format();
00161         }
00162         $formdata->timemodified       = $timenow;
00163         $formdata->title              = trim($formdata->title);
00164         $formdata->content            = '';          // updated later
00165         $formdata->contentformat      = FORMAT_HTML; // updated later
00166         $formdata->contenttrust       = 0;           // updated later
00167         $formdata->late               = 0x0;         // bit mask
00168         if (!empty($workshop->submissionend) and ($workshop->submissionend < time())) {
00169             $formdata->late = $formdata->late | 0x1;
00170         }
00171         if ($workshop->phase == workshop::PHASE_ASSESSMENT) {
00172             $formdata->late = $formdata->late | 0x2;
00173         }
00174         if (is_null($submission->id)) {
00175             $submission->id = $formdata->id = $DB->insert_record('workshop_submissions', $formdata);
00176             $workshop->log('add submission', $workshop->submission_url($submission->id), $submission->id);
00177         } else {
00178             $workshop->log('update submission', $workshop->submission_url($submission->id), $submission->id);
00179             if (empty($formdata->id) or empty($submission->id) or ($formdata->id != $submission->id)) {
00180                 throw new moodle_exception('err_submissionid', 'workshop');
00181             }
00182         }
00183         // save and relink embedded images and save attachments
00184         $formdata = file_postupdate_standard_editor($formdata, 'content', $contentopts, $workshop->context,
00185                                                       'mod_workshop', 'submission_content', $submission->id);
00186         $formdata = file_postupdate_standard_filemanager($formdata, 'attachment', $attachmentopts, $workshop->context,
00187                                                            'mod_workshop', 'submission_attachment', $submission->id);
00188         if (empty($formdata->attachment)) {
00189             // explicit cast to zero integer
00190             $formdata->attachment = 0;
00191         }
00192         // store the updated values or re-save the new submission (re-saving needed because URLs are now rewritten)
00193         $DB->update_record('workshop_submissions', $formdata);
00194         redirect($workshop->submission_url($formdata->id));
00195     }
00196 }
00197 
00198 // load the form to override grade and/or publish the submission and process the submitted data eventually
00199 if (!$edit and ($canoverride or $canpublish)) {
00200     $options = array(
00201         'editable' => true,
00202         'editablepublished' => $canpublish,
00203         'overridablegrade' => $canoverride);
00204     $feedbackform = $workshop->get_feedbackauthor_form($PAGE->url, $submission, $options);
00205     if ($data = $feedbackform->get_data()) {
00206         $data = file_postupdate_standard_editor($data, 'feedbackauthor', array(), $workshop->context);
00207         $record = new stdclass();
00208         $record->id = $submission->id;
00209         if ($canoverride) {
00210             $record->gradeover = $workshop->raw_grade_value($data->gradeover, $workshop->grade);
00211             $record->gradeoverby = $USER->id;
00212             $record->feedbackauthor = $data->feedbackauthor;
00213             $record->feedbackauthorformat = $data->feedbackauthorformat;
00214         }
00215         if ($canpublish) {
00216             $record->published = !empty($data->published);
00217         }
00218         $DB->update_record('workshop_submissions', $record);
00219         redirect($workshop->view_url());
00220     }
00221 }
00222 
00223 $PAGE->set_title($workshop->name);
00224 $PAGE->set_heading($course->fullname);
00225 if ($edit) {
00226     $PAGE->navbar->add(get_string('mysubmission', 'workshop'), $workshop->submission_url(), navigation_node::TYPE_CUSTOM);
00227     $PAGE->navbar->add(get_string('editingsubmission', 'workshop'));
00228 } elseif ($ownsubmission) {
00229     $PAGE->navbar->add(get_string('mysubmission', 'workshop'));
00230 } else {
00231     $PAGE->navbar->add(get_string('submission', 'workshop'));
00232 }
00233 
00234 // Output starts here
00235 $output = $PAGE->get_renderer('mod_workshop');
00236 echo $output->header();
00237 echo $output->heading(format_string($workshop->name), 2);
00238 
00239 // show instructions for submitting as thay may contain some list of questions and we need to know them
00240 // while reading the submitted answer
00241 if (trim($workshop->instructauthors)) {
00242     $instructions = file_rewrite_pluginfile_urls($workshop->instructauthors, 'pluginfile.php', $PAGE->context->id,
00243         'mod_workshop', 'instructauthors', 0, workshop::instruction_editors_options($PAGE->context));
00244     print_collapsible_region_start('', 'workshop-viewlet-instructauthors', get_string('instructauthors', 'workshop'));
00245     echo $output->box(format_text($instructions, $workshop->instructauthorsformat, array('overflowdiv'=>true)), array('generalbox', 'instructions'));
00246     print_collapsible_region_end();
00247 }
00248 
00249 // if in edit mode, display the form to edit the submission
00250 
00251 if ($edit) {
00252     $mform->display();
00253     echo $output->footer();
00254     die();
00255 }
00256 
00257 // else display the submission
00258 
00259 if ($submission->id) {
00260     if ($seenaspublished) {
00261         $showauthor = has_capability('mod/workshop:viewauthorpublished', $workshop->context);
00262     } else {
00263         $showauthor = has_capability('mod/workshop:viewauthornames', $workshop->context);
00264     }
00265     echo $output->render($workshop->prepare_submission($submission, $showauthor));
00266 } else {
00267     echo $output->box(get_string('noyoursubmission', 'workshop'));
00268 }
00269 
00270 if ($editable) {
00271     if ($submission->id) {
00272         $btnurl = new moodle_url($PAGE->url, array('edit' => 'on', 'id' => $submission->id));
00273         $btntxt = get_string('editsubmission', 'workshop');
00274     } else {
00275         $btnurl = new moodle_url($PAGE->url, array('edit' => 'on'));
00276         $btntxt = get_string('createsubmission', 'workshop');
00277     }
00278     echo $output->single_button($btnurl, $btntxt, 'get');
00279 }
00280 
00281 if ($submission->id and !$edit and !$isreviewer and $canallocate and $workshop->assessing_allowed($USER->id)) {
00282     $url = new moodle_url($PAGE->url, array('assess' => 1));
00283     echo $output->single_button($url, get_string('assess', 'workshop'), 'post');
00284 }
00285 
00286 if (($workshop->phase == workshop::PHASE_CLOSED) and ($ownsubmission or $canviewall)) {
00287     if (!empty($submission->gradeoverby) and strlen(trim($submission->feedbackauthor)) > 0) {
00288         echo $output->render(new workshop_feedback_author($submission));
00289     }
00290 }
00291 
00292 // and possibly display the submission's review(s)
00293 
00294 if ($isreviewer) {
00295     // user's own assessment
00296     $strategy   = $workshop->grading_strategy_instance();
00297     $mform      = $strategy->get_assessment_form($PAGE->url, 'assessment', $userassessment, false);
00298     $options    = array(
00299         'showreviewer'  => true,
00300         'showauthor'    => $showauthor,
00301         'showform'      => !is_null($userassessment->grade),
00302         'showweight'    => true,
00303     );
00304     $assessment = $workshop->prepare_assessment($userassessment, $mform, $options);
00305     $assessment->title = get_string('assessmentbyyourself', 'workshop');
00306 
00307     if ($workshop->assessing_allowed($USER->id)) {
00308         if (is_null($userassessment->grade)) {
00309             $assessment->add_action($workshop->assess_url($assessment->id), get_string('assess', 'workshop'));
00310         } else {
00311             $assessment->add_action($workshop->assess_url($assessment->id), get_string('reassess', 'workshop'));
00312         }
00313     }
00314     if ($canoverride) {
00315         $assessment->add_action($workshop->assess_url($assessment->id), get_string('assessmentsettings', 'workshop'));
00316     }
00317 
00318     echo $output->render($assessment);
00319 
00320     if ($workshop->phase == workshop::PHASE_CLOSED) {
00321         if (strlen(trim($userassessment->feedbackreviewer)) > 0) {
00322             echo $output->render(new workshop_feedback_reviewer($userassessment));
00323         }
00324     }
00325 }
00326 
00327 if (has_capability('mod/workshop:viewallassessments', $workshop->context) or ($ownsubmission and $workshop->assessments_available())) {
00328     // other assessments
00329     $strategy       = $workshop->grading_strategy_instance();
00330     $assessments    = $workshop->get_assessments_of_submission($submission->id);
00331     $showreviewer   = has_capability('mod/workshop:viewreviewernames', $workshop->context);
00332     foreach ($assessments as $assessment) {
00333         if ($assessment->reviewerid == $USER->id) {
00334             // own assessment has been displayed already
00335             continue;
00336         }
00337         if (is_null($assessment->grade) and !has_capability('mod/workshop:viewallassessments', $workshop->context)) {
00338             // students do not see peer-assessment that are not graded yet
00339             continue;
00340         }
00341         $mform      = $strategy->get_assessment_form($PAGE->url, 'assessment', $assessment, false);
00342         $options    = array(
00343             'showreviewer'  => $showreviewer,
00344             'showauthor'    => $showauthor,
00345             'showform'      => !is_null($assessment->grade),
00346             'showweight'    => true,
00347         );
00348         $displayassessment = $workshop->prepare_assessment($assessment, $mform, $options);
00349         if ($canoverride) {
00350             $displayassessment->add_action($workshop->assess_url($assessment->id), get_string('assessmentsettings', 'workshop'));
00351         }
00352         echo $output->render($displayassessment);
00353 
00354         if ($workshop->phase == workshop::PHASE_CLOSED and has_capability('mod/workshop:viewallassessments', $workshop->context)) {
00355             if (strlen(trim($assessment->feedbackreviewer)) > 0) {
00356                 echo $output->render(new workshop_feedback_reviewer($assessment));
00357             }
00358         }
00359     }
00360 }
00361 
00362 if (!$edit and $canoverride) {
00363     // display a form to override the submission grade
00364     $feedbackform->display();
00365 }
00366 
00367 echo $output->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations