]> git.mjollnir.org Git - moodle.git/commitdiff
Initial draft of submission support
authorDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 17:38:29 +0000 (17:38 +0000)
committerDavid Mudrak <david.mudrak@gmail.com>
Mon, 4 Jan 2010 17:38:29 +0000 (17:38 +0000)
mod/workshop/db/install.xml
mod/workshop/editgradingform.php
mod/workshop/lang/en_utf8/workshop.php
mod/workshop/submission.php [new file with mode: 0644]
mod/workshop/submission_form.php [new file with mode: 0644]
mod/workshop/view.php

index 08276eeecfc1ad935057993f8e11269612a5e249..dffd618068aec12785767e2f11d945d23867097f 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="mod/workshop/db" VERSION="20090601" COMMENT="XMLDB file for Moodle mod/workshop"
+<XMLDB PATH="mod/workshop/db" VERSION="20090605" COMMENT="XMLDB file for Moodle mod/workshop"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
 >
         <FIELD NAME="example" TYPE="int" LENGTH="2" NOTNULL="false" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Is this submission an example from teacher" PREVIOUS="workshopid" NEXT="userid"/>
         <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="The author of the submission" PREVIOUS="example" NEXT="timecreated"/>
         <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="Timestamp when the work was submitted for the first time" PREVIOUS="userid" NEXT="timemodified"/>
-        <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="Timestamp when the submission has been updated" PREVIOUS="timecreated" NEXT="grade"/>
-        <FIELD NAME="grade" TYPE="number" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" DECIMALS="5" COMMENT="Grade for the submission calculated as average of the peer-assessments. The grade is a number from interval 0..100. If NULL then the grade for submission has not been aggregated yet." PREVIOUS="timemodified" NEXT="gradeover"/>
+        <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="Timestamp when the submission has been updated" PREVIOUS="timecreated" NEXT="title"/>
+        <FIELD NAME="title" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The submission title" PREVIOUS="timemodified" NEXT="data"/>
+        <FIELD NAME="data" TYPE="text" LENGTH="big" NOTNULL="false" SEQUENCE="false" COMMENT="Submission text" PREVIOUS="title" NEXT="dataformat"/>
+        <FIELD NAME="dataformat" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="The format of submission text" PREVIOUS="data" NEXT="datatrust"/>
+        <FIELD NAME="datatrust" TYPE="int" LENGTH="3" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="The trust mode of the data" PREVIOUS="dataformat" NEXT="attachment"/>
+        <FIELD NAME="attachment" TYPE="int" LENGTH="2" NOTNULL="false" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="Used by File API file_postupdate_standard_filemanager" PREVIOUS="datatrust" NEXT="grade"/>
+        <FIELD NAME="grade" TYPE="number" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" DECIMALS="5" COMMENT="Grade for the submission calculated as average of the peer-assessments. The grade is a number from interval 0..100. If NULL then the grade for submission has not been aggregated yet." PREVIOUS="attachment" NEXT="gradeover"/>
         <FIELD NAME="gradeover" TYPE="number" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" DECIMALS="5" COMMENT="Grade for the submission manually overridden by a teacher. Grade is always from interval 0..100. If NULL then the grade is not overriden." PREVIOUS="grade" NEXT="gradeoverby"/>
         <FIELD NAME="gradeoverby" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="The id of the user who has overridden the grade for submission." PREVIOUS="gradeover" NEXT="gradinggrade"/>
         <FIELD NAME="gradinggrade" TYPE="number" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" DECIMALS="5" COMMENT="Grade for the assessment calculated by the module. The grade is a number from interval 0..100. If NULL then the grade for assessment has not been aggregated yet." PREVIOUS="gradeoverby" NEXT="teachercomment"/>
index 642775eb13aca596189dd80a0b2582a4ccf646a7..8f3914d7e285c30878ad82c2f63229fa86ee8e14 100644 (file)
 require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
 require_once(dirname(__FILE__).'/lib.php');
 
-$id = optional_param('id', 0, PARAM_INT); // course_module ID, or
-$a  = optional_param('a', 0, PARAM_INT);  // workshop instance ID
-
-if ($id) {
-    if (! $cm = get_coursemodule_from_id('workshop', $id)) {
-        error('Course Module ID was incorrect');
-    }
-
-    if (! $course = $DB->get_record('course', array('id' => $cm->course))) {
-        error('Course is misconfigured');
-    }
-
-    if (! $workshop = $DB->get_record('workshop', array('id' => $cm->instance))) {
-        error('Course module is incorrect');
-    }
-
-} else if ($a) {
-    if (! $workshop = $DB->get_record('workshop', array('id' => $a))) {
-        error('Course module is incorrect');
-    }
-    if (! $course = $DB->get_record('course', array('id' => $workshop->course))) {
-        error('Course is misconfigured');
-    }
-    if (! $cm = get_coursemodule_from_instance('workshop', $workshop->id, $course->id)) {
-        error('Course Module ID was incorrect');
-    }
-
-} else {
-    error('You must specify a course_module ID or an instance ID');
+$cmid = required_param('cmid', PARAM_INT);            // course module id
+        
+if (!$cm = get_coursemodule_from_id('workshop', $cmid)) {
+    print_error('invalidcoursemodule');
+}   
+        
+if (!$course = $DB->get_record('course', array('id' => $cm->course))) {
+    print_error('coursemisconf');
+}   
+
+require_login($course, false, $cm);
+
+$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+
+if (isguestuser()) {
+    print_error('guestnoedit', 'workshop', "$CFG->wwwroot/mod/workshop/view.php?id=$cmid");
 }
 
-require_login($course, true, $cm);
-
-add_to_log($course->id, "workshop", "editgradingform", "editgradingform.php?id=$cm->id", "$workshop->id");
+if (!$workshop = $DB->get_record('workshop', array('id' => $cm->instance))) {
+    print_error('invalidid', 'workshop');
+}
 
 // where should the user be sent after closing the editing form
 $returnurl = "{$CFG->wwwroot}/mod/workshop/view.php?id={$cm->id}";
 // the URL of this editing form
-$selfurl   = "{$CFG->wwwroot}/mod/workshop/editgradingform.php?id={$cm->id}";
+$selfurl   = "{$CFG->wwwroot}/mod/workshop/editgradingform.php?cmid={$cm->id}";
 
 // load the grading strategy logic
 $strategylib = dirname(__FILE__) . '/grading/' . $workshop->strategy . '/strategy.php';
index ac22488f448aef3451fea7e0dc0918f05e9162e5..f91dffb23ad5d426687f5821070d394902ca97e3 100644 (file)
@@ -95,7 +95,7 @@ $string['nsassessments'] = 'Number of required assessments of other users\' work
 $string['releasegrades'] = 'Push final grades into the gradebook';
 $string['requirepassword'] = 'Require password';
 $string['saveandclose'] = 'Save and close';
-$string['saveandcontinue'] = 'Save and continue';
+$string['saveandcontinue'] = 'Save and continue editing';
 $string['strategyaccumulative'] = 'Accumulative grading';
 $string['strategyerrorbanded'] = 'Error banded grading';
 $string['strategy'] = 'Grading strategy';
diff --git a/mod/workshop/submission.php b/mod/workshop/submission.php
new file mode 100644 (file)
index 0000000..b4bd15c
--- /dev/null
@@ -0,0 +1,136 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/  
+// 
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+
+/**
+ * Submit an assignment or edit the already submitted work
+ *
+ * @package   mod-workshop
+ * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
+require_once(dirname(__FILE__).'/lib.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
+
+if (!$cm = get_coursemodule_from_id('workshop', $cmid)) {
+    print_error('invalidcoursemodule');
+}
+
+if (!$course = $DB->get_record('course', array('id' => $cm->course))) {
+    print_error('coursemisconf');
+}
+
+require_login($course, false, $cm);
+
+$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+
+if (isguestuser()) {
+    print_error('guestnoedit', 'workshop', "$CFG->wwwroot/mod/workshop/view.php?id=$cmid");
+}
+
+if (!$workshop = $DB->get_record('workshop', array('id' => $cm->instance))) {
+    print_error('invalidid', 'workshop');
+}
+
+if ($id) { // if submission is specified
+    if (!$submission = $DB->get_record('workshop_submissions', array('id' => $id, 'workshopid' => $workshop->id))) {
+        print_error('invalidsubmissionid', 'workshop');
+    }
+    // todo check access rights
+
+} else { // new submission
+    //require_capability('mod/workshop:submit', $context);
+    $submission = new object();
+    $submission->id = null;
+}
+
+$maxfiles = $workshop->nattachments;
+$maxbytes = $workshop->maxbytes;
+
+$dataoptions = array('trusttext' => true, 'subdirs' => false, 'maxfiles' => $maxfiles, 'maxbytes' => $maxbytes);
+$attachmentoptions = array('subdirs' => false, 'maxfiles'=>$maxfiles, 'maxbytes'=>$maxbytes);
+
+$submission = file_prepare_standard_editor($submission, 'data', $dataoptions, $context, 'workshop_submission', $submission->id);
+$submission = file_prepare_standard_filemanager($submission, 'attachment', $attachmentoptions, $context,
+                                                'workshop_attachment', $submission->id);
+
+$submission->cmid = $cm->id;
+
+// create form and set initial data
+$mform = new workshop_submission_form(null, array('current' => $submission, 'cm' => $cm, 'workshop'=>$workshop,
+                                                 'dataoptions' => $dataoptions, 'attachmentoptions'=>$attachmentoptions));
+
+if ($mform->is_cancelled()){
+    if ($id){
+        redirect("view.php?id=$cm->id");
+    } else {
+        redirect("view.php?id=$cm->id");
+    }
+
+} else if ($submission = $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;
+    }
+
+    $submission->timemodified       = $timenow;
+    $submission->title              = trim($submission->title);
+    $submission->data               = '';          // updated later
+    $submission->dataformat         = FORMAT_HTML; // updated later
+    $submission->datatrust          = 0;           // updated later
+
+    if (empty($submission->id)) {
+        //new submission
+        $submission->id = $DB->insert_record('workshop_submissions', $submission);
+        // todo add to log
+
+    } else {
+        //existing submission
+        $DB->update_record('workshop_submissions', $submission);
+        // todo add to log
+    }
+
+    // save and relink embedded images and save attachments
+    $submission = file_postupdate_standard_editor($submission, 'data', $dataoptions, $context, 'workshop_submission', $submission->id);
+    $submission = file_postupdate_standard_filemanager($submission, 'attachment', $attachmentoptions, $context, 'workshop_attachment', $submission->id);
+
+    // store the updated value values
+    $DB->update_record('workshop_submissions', $submission);
+
+    redirect("view.php?id=$cm->id");
+}
+
+$stredit = empty($submission->id) ? get_string('addsubmission', 'workshop') : get_string('edit');
+
+$navigation = build_navigation($stredit, $cm);
+print_header_simple(format_string($workshop->name), "", $navigation, "", "", true, "", navmenu($course, $cm));
+
+print_heading(format_string($workshop->name));
+
+$mform->display();
+
+print_footer($course);
diff --git a/mod/workshop/submission_form.php b/mod/workshop/submission_form.php
new file mode 100644 (file)
index 0000000..8991652
--- /dev/null
@@ -0,0 +1,70 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/  
+// 
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+
+/**
+ * Submit an assignment or edit the already submitted work
+ *
+ * @package   mod-workshop
+ * @copyright 2009 David Mudrak <david.mudrak@gmail.com>
+ * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+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'];
+        $dataoptions        = $this->_customdata['dataoptions'];
+        $attachmentoptions  = $this->_customdata['attachmentoptions'];
+
+        $mform->addElement('header', 'general', get_string('submission', 'workshop'));
+
+        $mform->addElement('text', 'title', get_string('submissiontitle', 'workshop'));
+        $mform->setType('title', PARAM_TEXT);
+        $mform->addRule('title', null, 'required', null, 'client');
+
+        $mform->addElement('editor', 'data_editor', get_string('submissiondata', 'workshop'), null, $dataoptions);
+        $mform->setType('data_editor', PARAM_RAW);
+
+        $mform->addElement('filemanager', 'attachment_filemanager', get_string('submissionattachment', 'workshop'), 
+                            null, $attachmentoptions);
+
+        $mform->addElement('hidden', 'id');
+        $mform->addElement('hidden', 'cmid');
+
+        $this->add_action_buttons();
+
+        $this->set_data($current);
+    }
+
+
+    function validation($data, $files) {
+        global $CFG, $USER, $DB;
+
+        $errors = parent::validation($data, $files);
+        return $errors;
+    }
+}
index 7f7c79799f100e6110270d02f4b758a0dc6fe255..4638e27fe29d2b354e8be8d5538e236b5874cff0 100644 (file)
@@ -82,7 +82,9 @@ print_header_simple(format_string($workshop->name), '', $navigation, '', '', tru
 
 /// Print the main part of the page
 
-echo "<a href=\"editgradingform.php?id={$cm->id}\">Edit grading form</a>";
+echo "<a href=\"editgradingform.php?cmid={$cm->id}\">Edit grading form</a>";
+echo " | ";
+echo "<a href=\"submission.php?cmid={$cm->id}\">My submission</a>";
 
 /// Finish the page
 print_footer($course);