]> git.mjollnir.org Git - moodle.git/commitdiff
Display "Edit submission" button at submission page
authorDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 17:50:03 +0000 (17:50 +0000)
committerDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 17:50:03 +0000 (17:50 +0000)
mod/workshop/lang/en_utf8/workshop.php
mod/workshop/locallib.php
mod/workshop/styles.php
mod/workshop/submission.php
mod/workshop/submission_form.php

index d3be7e0568acef7c16c4899f96246c44b6409b21..bcb896c912d4f5dfb20be535844794991f06de55 100644 (file)
@@ -26,7 +26,7 @@
 defined('MOODLE_INTERNAL') || die();
 
 $string['strategyhaschanged'] = 'The workshop grading strategy has changed since the form was opened for editing.';
-$string[''] = '';
+$string['editsubmission'] = 'Edit submission';
 $string[''] = '';
 $string[''] = '';
 $string[''] = '';
@@ -56,7 +56,7 @@ $string['allocationrandom'] = 'Random allocation';
 $string['allocationsettings'] = 'Allocation settings';
 $string['allocation'] = 'Submission allocation';
 $string['allocationview'] = 'View current allocations';
-$string['areadimensiondescription'] = 'Assessment dimensions';
+$string['areadimensiondescription'] = 'Assessment form fields';
 $string['areasubmissionattachment'] = 'Submission attachments';
 $string['areasubmissioncontent'] = 'Submission texts';
 $string['areyousuretodeallocate'] = 'Are you sure you want deallocate the selected assessment?';
index e40ba9519d5b2731ed9eb597a594419ce2614e20..f0571efd1b22c55f1f730c4f2c03815cd2414964 100644 (file)
@@ -600,4 +600,15 @@ class workshop {
         }
     }
 
+    /**
+     * Are users alloed to create/edit their submissions?
+     *
+     * TODO: this depends on the workshop phase, phase deadlines, submitting after deadlines possibility
+     *
+     * @return bool
+     */
+    public function submitting_allowed() {
+        return true;
+    }
+
 }
index c80a38f2880aaebf9edf89aa29ca448fc30a66cf..2c4a0db55f0ccb638f1defa305548bf25126b1ea 100644 (file)
@@ -3,6 +3,7 @@
  */
 .submission-full {
     border: 1px solid #ddd;
+    margin: 0px 0px 1em 0px;
 }
 
 .submission-full .header {
index a676db763e32582eda84b1c62c07d3a7835ef57d..fb1780f622da1fac7f2ac2bf8602418c1a936945 100644 (file)
@@ -16,7 +16,7 @@
 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
 /**
- * Submit an assignment or edit the already submitted work
+ * Submit own assignment or edit the already submitted own work
  *
  * @package   mod-workshop
  * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
@@ -28,11 +28,12 @@ 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
+$cmid   = required_param('cmid', PARAM_INT);            // course module id
+$id     = optional_param('id', 0, PARAM_INT);           // submission id
+$edit   = optional_param('edit', false, PARAM_BOOL);    // open for editing?
 
-$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);
 require_capability('mod/workshop:submit', $PAGE->context);
@@ -49,61 +50,82 @@ if ($id) { // submission is specified
     if (!$submission = $workshop->get_submission_by_author($USER->id)) {
         $submission = new object();
         $submission->id = null;
+        $submission->userid = $USER->id;
     }
 }
-unset($id); // not needed anymore
-
-$maxfiles           = $workshop->nattachments;
-$maxbytes           = $workshop->maxbytes;
-$contentoptions     = array('trusttext' => true, 'subdirs' => false, 'maxfiles' => $maxfiles, 'maxbytes' => $maxbytes);
-$attachmentoptions  = array('subdirs' => false, 'maxfiles'=>$maxfiles, 'maxbytes'=>$maxbytes);
-$submission         = file_prepare_standard_editor($submission, 'content', $contentoptions, $PAGE->context,
-                                                   'workshop_submission_content', $submission->id);
-$submission         = file_prepare_standard_filemanager($submission, 'attachment', $attachmentoptions, $PAGE->context,
-                                                        'workshop_submission_attachment', $submission->id);
-// create form and set initial data
-$mform = new workshop_submission_form(null, array('current' => $submission, 'cm' => $cm, 'workshop' => $workshop,
-                                    'contentoptions' => $contentoptions, 'attachmentoptions' => $attachmentoptions));
+
+if ($submission->userid !== $USER->id) {
+    print_error('nopermissiontoviewpage', 'error', $workshop->view_url());
+}
+
+$maxfiles       = $workshop->nattachments;
+$maxbytes       = $workshop->maxbytes;
+$contentopts    = array('trusttext' => true, 'subdirs' => false, 'maxfiles' => $maxfiles, 'maxbytes' => $maxbytes);
+$attachmentopts = array('subdirs' => false, '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("view.php?id=$cm->id");
-} else if ($submission = $mform->get_data()) {
+    redirect($workshop->view_url());
+
+} elseif ($formdata = $mform->get_data()) {
     $timenow = time();
-    if (empty($submission->id)) {
-        $submission->workshopid     = $workshop->id;
-        $submission->example        = 0; // todo add examples support
-        $submission->userid         = $USER->id;
-        $submission->timecreated    = $timenow;
+    if (empty($formdata->id)) {
+        $formdata->workshopid     = $workshop->id;
+        $formdata->example        = 0; // todo add examples support
+        $formdata->userid         = $USER->id;
+        $formdata->timecreated    = $timenow;
     }
-    $submission->timemodified       = $timenow;
-    $submission->title              = trim($submission->title);
-    $submission->content            = '';          // updated later
-    $submission->contentformat      = FORMAT_HTML; // updated later
-    $submission->contenttrust       = 0;           // updated later
-    if (empty($submission->id)) {
-        $submission->id = $DB->insert_record('workshop_submissions', $submission);
+    $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
-    $submission = file_postupdate_standard_editor($submission, 'content', $contentoptions, $PAGE->context,
-                                                  'workshop_submission_content', $submission->id);
-    $submission = file_postupdate_standard_filemanager($submission, 'attachment', $attachmentoptions, $PAGE->context,
-                                                       'workshop_submission_attachment', $submission->id);
-    // store the updated values or re-save the new submission
-    $DB->update_record('workshop_submissions', $submission);
-    redirect("view.php?id=$cm->id");
+    $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());
 }
 
-// Output starts here
 $PAGE->set_url('mod/workshop/submission.php', array('cmid' => $cm->id));
 $PAGE->set_title($workshop->name);
 $PAGE->set_heading($course->fullname);
 
+// Output starts here
 $stredit    = empty($submission->id) ? get_string('editingsubmission', 'workshop') : get_string('edit');
 $navigation = build_navigation($stredit, $cm);
-// todo $menu       = navmenu($course, $cm);
-
 echo $OUTPUT->header($navigation);
 echo $OUTPUT->heading(format_string($workshop->name), 2);
-$mform->display();
+
+if ($edit) {
+    $mform->display();
+    echo $OUTPUT->footer();
+    die();
+}
+
+if (!empty($submission->id)) {
+    $wsoutput = $PAGE->theme->get_renderer('mod_workshop', $PAGE);
+    echo $wsoutput->submission_full($submission, true, $USER);
+}
+
+if ($workshop->submitting_allowed()) {
+    $editbutton                 = new html_form();
+    $editbutton->method         = 'get';
+    $editbutton->button->text   = get_string('editsubmission', 'workshop');
+    $editbutton->url            = new moodle_url($PAGE->url, array('edit' => 'on', 'id' => $submission->id));
+    echo $OUTPUT->button($editbutton);
+}
+
 echo $OUTPUT->footer();
index aab37f75dd701ebe8bdae6e003b196c7b4d60c51..5cd7945cdddba092b16c7018f1650a6e20198299 100644 (file)
 
 defined('MOODLE_INTERNAL') || die();
 
-require_once ($CFG->dirroot.'/lib/formslib.php');
+require_once($CFG->dirroot . '/lib/formslib.php');
 
 class workshop_submission_form extends moodleform {
 
     function definition() {
-
         $mform = $this->_form;
 
-        $current            = $this->_customdata['current'];
-        $workshop           = $this->_customdata['workshop'];
-        $cm                 = $this->_customdata['cm'];
-        $contentoptions     = $this->_customdata['contentoptions'];
-        $attachmentoptions  = $this->_customdata['attachmentoptions'];
+        $current        = $this->_customdata['current'];
+        $workshop       = $this->_customdata['workshop'];
+        $cm             = $this->_customdata['cm'];
+        $contentopts    = $this->_customdata['contentopts'];
+        $attachmentopts = $this->_customdata['attachmentopts'];
 
         $mform->addElement('header', 'general', get_string('submission', 'workshop'));
 
@@ -45,13 +44,13 @@ class workshop_submission_form extends moodleform {
         $mform->setType('title', PARAM_TEXT);
         $mform->addRule('title', null, 'required', null, 'client');
 
-        $mform->addElement('editor', 'content_editor', get_string('submissioncontent', 'workshop'), null, $contentoptions);
+        $mform->addElement('editor', 'content_editor', get_string('submissioncontent', 'workshop'), null, $contentopts);
         $mform->setType('content', PARAM_RAW);
 
         if ($workshop->nattachments > 0) {
             $mform->addElement('static', 'filemanagerinfo', get_string('nattachments', 'workshop'), $workshop->nattachments);
             $mform->addElement('filemanager', 'attachment_filemanager', get_string('submissionattachment', 'workshop'),
-                                null, $attachmentoptions);
+                                null, $attachmentopts);
         }
 
         $mform->addElement('hidden', 'id', $current->id);