]> git.mjollnir.org Git - moodle.git/commitdiff
Refactor submission.php a bit to prepare for feedback form
authorDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 18:23:08 +0000 (18:23 +0000)
committerDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 18:23:08 +0000 (18:23 +0000)
mod/workshop/locallib.php
mod/workshop/submission.php
mod/workshop/submission_form.php

index 3117dbd7da1d792d6370a82cdcc85e4cde0d8525..4984c93245e0bf29640b777b3b05e2f764242de5 100644 (file)
@@ -645,11 +645,11 @@ class workshop {
     }
 
     /**
-     * @return moodle_url of the page to view own submission
+     * @return moodle_url of the page to view a submission, defaults to the own one
      */
-    public function submission_url() {
+    public function submission_url($id=null) {
         global $CFG;
-        return new moodle_url($CFG->wwwroot . '/mod/workshop/submission.php', array('cmid' => $this->cm->id));
+        return new moodle_url($CFG->wwwroot . '/mod/workshop/submission.php', array('cmid' => $this->cm->id, 'id' => $id));
     }
 
     /**
@@ -1480,6 +1480,33 @@ class workshop {
                 'post', '', null, $editable);
     }
 
+    /**
+     * Returns the mform the teachers use to put a feedback for the author on their submission
+     *
+     * @return workshop_feedbackauthor_form
+     */
+    public function get_feedbackauthor_form(moodle_url $actionurl, stdClass $submission, $editable=true) {
+        global $CFG;
+        require_once(dirname(__FILE__) . '/feedbackauthor_form.php');
+
+        $current = new stdClass();
+        $current->submissionid          = $submission->id;
+        $current->grade                 = $this->real_grade($assessment->grade);
+        $current->gradeover             = $this->real_grade($assessment->gradeover);
+        $current->feedbackauthor        = $assessment->feedbackreviewer;
+        $current->feedbackauthorformat  = $assessment->feedbackreviewerformat;
+        if (is_null($current->grade)) {
+            $current->grade = get_string('nullgrade', 'workshop');
+        }
+
+        // prepare wysiwyg editor
+        $current = file_prepare_standard_editor($current, 'feedbackauthor', array());
+
+        return new workshop_feedbackauthor_form($actionurl,
+                array('workshop' => $this, 'current' => $current, 'feedbackopts' => array()),
+                'post', '', null, $editable);
+    }
+
     ////////////////////////////////////////////////////////////////////////////////
     // Internal methods (implementation details)                                  //
     ////////////////////////////////////////////////////////////////////////////////
index a071624077aa6210b248d71e4f47f4717695bc37..2957235c9d2160d85fb3295ff9e3016c40a4178e 100644 (file)
@@ -26,7 +26,6 @@
 require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
 require_once(dirname(__FILE__).'/lib.php');
 require_once(dirname(__FILE__).'/locallib.php');
-require_once(dirname(__FILE__).'/submission_form.php');
 
 $cmid   = required_param('cmid', PARAM_INT);            // course module id
 $id     = optional_param('id', 0, PARAM_INT);           // submission id
@@ -56,8 +55,9 @@ if ($id) { // submission is specified
 }
 
 $ownsubmission  = $submission->authorid == $USER->id;
-$canviewall     = has_capability('mod/workshop:viewallsubmissions', $PAGE->context);
-$cansubmit      = has_capability('mod/workshop:submit', $PAGE->context);
+$canviewall     = has_capability('mod/workshop:viewallsubmissions', $workshop->context);
+$cansubmit      = has_capability('mod/workshop:submit', $workshop->context);
+$canoverride    = has_capability('mod/workshop:overridegrades', $workshop->context);
 $isreviewer     = $DB->record_exists('workshop_assessments', array('submissionid' => $submission->id, 'reviewerid' => $USER->id));
 
 if ($submission->id and ($ownsubmission or $canviewall or $isreviewer)) {
@@ -68,45 +68,50 @@ if ($submission->id and ($ownsubmission or $canviewall or $isreviewer)) {
     print_error('nopermissions');
 }
 
-$maxfiles       = $workshop->nattachments;
-$maxbytes       = $workshop->maxbytes;
-$contentopts    = array('trusttext' => true, 'subdirs' => false, 'maxfiles' => $maxfiles, 'maxbytes' => $maxbytes);
-$attachmentopts = array('subdirs' => true, 'maxfiles'=>$maxfiles, 'maxbytes'=>$maxbytes);
-$submission     = file_prepare_standard_editor($submission, 'content', $contentopts, $PAGE->context,
-                                    'workshop_submission_content', $submission->id);
-$submission     = file_prepare_standard_filemanager($submission, 'attachment', $attachmentopts, $PAGE->context,
-                                    'workshop_submission_attachment', $submission->id);
-$mform          = new workshop_submission_form(null, array('current' => $submission, 'cm' => $cm, 'workshop' => $workshop,
-                                    'contentopts' => $contentopts, 'attachmentopts' => $attachmentopts));
-
-if ($mform->is_cancelled()) {
-    redirect($workshop->view_url());
-
-} elseif ($cansubmit and $formdata = $mform->get_data()) {
-    $timenow = time();
-    if (empty($formdata->id)) {
-        $formdata->workshopid     = $workshop->id;
-        $formdata->example        = 0; // todo add examples support
-        $formdata->authorid       = $USER->id;
-        $formdata->timecreated    = $timenow;
-    }
-    $formdata->timemodified       = $timenow;
-    $formdata->title              = trim($formdata->title);
-    $formdata->content            = '';          // updated later
-    $formdata->contentformat      = FORMAT_HTML; // updated later
-    $formdata->contenttrust       = 0;           // updated later
-    if (empty($formdata->id)) {
-        $formdata->id = $DB->insert_record('workshop_submissions', $formdata);
-        // todo add to log
+if ($edit and $ownsubmission) {
+    require_once(dirname(__FILE__).'/submission_form.php');
+
+    $maxfiles       = $workshop->nattachments;
+    $maxbytes       = $workshop->maxbytes;
+    $contentopts    = array('trusttext' => true, 'subdirs' => false, 'maxfiles' => $maxfiles, 'maxbytes' => $maxbytes);
+    $attachmentopts = array('subdirs' => true, 'maxfiles' => $maxfiles, 'maxbytes' => $maxbytes);
+    $submission     = file_prepare_standard_editor($submission, 'content', $contentopts, $workshop->context,
+                                        'workshop_submission_content', $submission->id);
+    $submission     = file_prepare_standard_filemanager($submission, 'attachment', $attachmentopts, $workshop->context,
+                                        'workshop_submission_attachment', $submission->id);
+
+    $mform          = new workshop_submission_form($PAGE->url, array('current' => $submission, 'workshop' => $workshop,
+                                                    'contentopts' => $contentopts, 'attachmentopts' => $attachmentopts));
+
+    if ($mform->is_cancelled()) {
+        redirect($workshop->view_url());
+
+    } elseif ($cansubmit and $formdata = $mform->get_data()) {
+        $timenow = time();
+        if (empty($formdata->id)) {
+            $formdata->workshopid     = $workshop->id;
+            $formdata->example        = 0; // todo add examples support
+            $formdata->authorid       = $USER->id;
+            $formdata->timecreated    = $timenow;
+        }
+        $formdata->timemodified       = $timenow;
+        $formdata->title              = trim($formdata->title);
+        $formdata->content            = '';          // updated later
+        $formdata->contentformat      = FORMAT_HTML; // updated later
+        $formdata->contenttrust       = 0;           // updated later
+        if (empty($formdata->id)) {
+            $formdata->id = $DB->insert_record('workshop_submissions', $formdata);
+            // todo add to log
+        }
+        // save and relink embedded images and save attachments
+        $formdata = file_postupdate_standard_editor($formdata, 'content', $contentopts, $workshop->context,
+                                                      'workshop_submission_content', $formdata->id);
+        $formdata = file_postupdate_standard_filemanager($formdata, 'attachment', $attachmentopts, $workshop->context,
+                                                           'workshop_submission_attachment', $formdata->id);
+        // store the updated values or re-save the new submission (re-saving needed because URLs are now rewritten)
+        $DB->update_record('workshop_submissions', $formdata);
+        redirect($workshop->submission_url($formdata->id));
     }
-    // save and relink embedded images and save attachments
-    $formdata = file_postupdate_standard_editor($formdata, 'content', $contentopts, $PAGE->context,
-                                                  'workshop_submission_content', $formdata->id);
-    $formdata = file_postupdate_standard_filemanager($formdata, 'attachment', $attachmentopts, $PAGE->context,
-                                                       'workshop_submission_attachment', $formdata->id);
-    // store the updated values or re-save the new submission (re-saving needed because URLs are now rewritten)
-    $DB->update_record('workshop_submissions', $formdata);
-    redirect($workshop->view_url());
 }
 
 $PAGE->set_title($workshop->name);
index 5cd7945cdddba092b16c7018f1650a6e20198299..27703f6bcafac4fc670c8cc3d085bfff80c05964 100644 (file)
@@ -34,7 +34,6 @@ class workshop_submission_form extends moodleform {
 
         $current        = $this->_customdata['current'];
         $workshop       = $this->_customdata['workshop'];
-        $cm             = $this->_customdata['cm'];
         $contentopts    = $this->_customdata['contentopts'];
         $attachmentopts = $this->_customdata['attachmentopts'];
 
@@ -54,7 +53,8 @@ class workshop_submission_form extends moodleform {
         }
 
         $mform->addElement('hidden', 'id', $current->id);
-        $mform->addElement('hidden', 'cmid', $cm->id);
+        $mform->addElement('hidden', 'cmid', $workshop->cm->id);
+        $mform->addElement('hidden', 'edit', 1);
 
         $this->add_action_buttons();