Permalink
Browse files

Merge branch 'MDL-60820-master-workshopsubmissiontypes' of git://gith…

…ub.com/mudrd8mz/moodle
  • Loading branch information...
dmonllao committed Sep 4, 2018
2 parents ffc4cc9 + 7d2ad71 commit 6a9867191632ad5e6c0fb9e8f379441ec938e142

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,99 @@
// 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/>.
/**
* Additional javascript for the Workshop module form.
*
* @module mod_workshop/modform
* @copyright The Open University 2018
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(['jquery'], function($) {
var submissionTypes = {
text: {
available: null,
required: null,
requiredHidden: null
},
file: {
available: null,
required: null,
requiredHidden: null
}
};
/**
* Determine whether one of the submission types has been marked as not available.
*
* If it has been marked not available, clear and disable its required checkbox. Then determine if the other submission
* type is available, and if it is, check and disable its required checkbox.
*
* @param {Object} checkUnavailable
* @param {Object} checkAvailable
*/
function checkAvailability(checkUnavailable, checkAvailable) {
if (!checkUnavailable.available.prop('checked')) {
checkUnavailable.required.prop('disabled', true);
checkUnavailable.required.prop('checked', false);
if (checkAvailable.available.prop('checked')) {
checkAvailable.required.prop('disabled', true);
checkAvailable.required.prop('checked', true);
// Also set the checkbox's hidden field to 1 so a 'required' value is submitted for the submission type.
checkAvailable.requiredHidden.val(1);
}
}
}
/**
* Enable the submission type's required checkbox and uncheck it.
*
* @param {Object} submissionType
*/
function enableRequired(submissionType) {
submissionType.required.prop('disabled', false);
submissionType.required.prop('checked', false);
submissionType.requiredHidden.val(0);
}
/**
* Check which submission types have been marked as available, and disable required checkboxes as necessary.
*/
function submissionTypeChanged() {
checkAvailability(submissionTypes.file, submissionTypes.text);
checkAvailability(submissionTypes.text, submissionTypes.file);
if (submissionTypes.text.available.prop('checked') && submissionTypes.file.available.prop('checked')) {
enableRequired(submissionTypes.text);
enableRequired(submissionTypes.file);
}
}
return /** @alias module:mod_workshop/modform */ {
/**
* Find all the required fields, set up event listeners, and set the initial state of required checkboxes.
*/
init: function() {
submissionTypes.text.available = $('#id_submissiontypetextavailable');
submissionTypes.text.required = $('#id_submissiontypetextrequired');
submissionTypes.text.requiredHidden = $('input[name="submissiontypetextrequired"][type="hidden"]');
submissionTypes.file.available = $('#id_submissiontypefileavailable');
submissionTypes.file.required = $('#id_submissiontypefilerequired');
submissionTypes.file.requiredHidden = $('input[name="submissiontypefilerequired"][type="hidden"]');
submissionTypes.text.available.on('change', submissionTypeChanged);
submissionTypes.file.available.on('change', submissionTypeChanged);
submissionTypeChanged();
}
};
});
@@ -369,7 +369,14 @@ function workshop_upgrade_transform_instance(stdClass $old) {
$new->name = $old->name;
$new->intro = $old->description;
$new->introformat = $old->format;
$new->nattachments = $old->nattachments;
if ($old->nattachments == 0) {
// Convert to the new method for disabling file submissions.
$new->submissiontypefile = WORKSHOP_SUBMISSION_TYPE_DISABLED;
$new->submissiontypetext = WORKSHOP_SUBMISSION_TYPE_REQUIRED;
$new->nattachments = 1;
} else {
$new->nattachments = $old->nattachments;
}
$new->maxbytes = $old->maxbytes;
$new->grade = $old->grade;
$new->gradinggrade = $old->gradinggrade;
@@ -409,4 +416,4 @@ function workshop_upgrade_transform_instance(stdClass $old) {
}
return $new;
}
}
@@ -53,8 +53,8 @@ protected function define_structure() {
'instructauthorsformat', 'instructreviewers',
'instructreviewersformat', 'timemodified', 'phase', 'useexamples',
'usepeerassessment', 'useselfassessment', 'grade', 'gradinggrade',
'strategy', 'evaluation', 'gradedecimals', 'nattachments', 'submissionfiletypes',
'latesubmissions', 'maxbytes', 'examplesmode', 'submissionstart',
'strategy', 'evaluation', 'gradedecimals', 'submissiontypetext', 'submissiontypefile', 'nattachments',
'submissionfiletypes', 'latesubmissions', 'maxbytes', 'examplesmode', 'submissionstart',
'submissionend', 'assessmentstart', 'assessmentend',
'conclusion', 'conclusionformat', 'overallfeedbackmode',
'overallfeedbackfiles', 'overallfeedbackfiletypes', 'overallfeedbackmaxbytes'));
@@ -111,6 +111,13 @@ protected function process_workshop($data) {
$data->assessmentstart = $this->apply_date_offset($data->assessmentstart);
$data->assessmentend = $this->apply_date_offset($data->assessmentend);
if ($data->nattachments == 0) {
// Convert to the new method for disabling file submissions.
$data->submissiontypefile = WORKSHOP_SUBMISSION_TYPE_DISABLED;
$data->submissiontypetext = WORKSHOP_SUBMISSION_TYPE_REQUIRED;
$data->nattachments = 1;
}
// insert the workshop record
$newitemid = $DB->insert_record('workshop', $data);
// immediately after inserting "activity" record, call this
@@ -145,10 +145,24 @@ protected static function define_properties() {
'description' => 'Number of digits that should be shown after the decimal point when displaying grades.',
'optional' => true,
),
'submissiontypetext' => array (
'type' => PARAM_INT,
'default' => 1,
'description' => 'Indicates whether text is required as part of each submission. ' .
'0 for no, 1 for optional, 2 for required.',
'optional' => true
),
'submissiontypefile' => array (
'type' => PARAM_INT,
'default' => 2,
'description' => 'Indicates whether a file upload is required as part of each submission. ' .
'0 for no, 1 for optional, 2 for required.',
'optional' => true
),
'nattachments' => array(
'type' => PARAM_INT,
'default' => 0,
'description' => 'Number of required submission attachments.',
'default' => 1,
'description' => 'Maximum number of submission attachments.',
'optional' => true,
),
'submissionfiletypes' => array(
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/workshop/db" VERSION="20180427" COMMENT="XMLDB file for Moodle mod/workshop"
<XMLDB PATH="mod/workshop/db" VERSION="20180626" COMMENT="XMLDB file for Moodle mod/workshop"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
@@ -25,7 +25,9 @@
<FIELD NAME="strategy" TYPE="char" LENGTH="30" NOTNULL="true" SEQUENCE="false" COMMENT="The type of the current grading strategy used in this workshop"/>
<FIELD NAME="evaluation" TYPE="char" LENGTH="30" NOTNULL="true" SEQUENCE="false" COMMENT="The recently used grading evaluation method"/>
<FIELD NAME="gradedecimals" TYPE="int" LENGTH="3" NOTNULL="false" DEFAULT="0" SEQUENCE="false" COMMENT="Number of digits that should be shown after the decimal point when displaying grades"/>
<FIELD NAME="nattachments" TYPE="int" LENGTH="3" NOTNULL="false" DEFAULT="0" SEQUENCE="false" COMMENT="Number of required submission attachments"/>
<FIELD NAME="submissiontypetext" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false" COMMENT="Can students enter text for their submissions? 0 for no, 1 for optional, 2 for required."/>
<FIELD NAME="submissiontypefile" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" SEQUENCE="false" COMMENT="Can students attach files for their submissions? 0 for no, 1 for optional, 2 for required."/>
<FIELD NAME="nattachments" TYPE="int" LENGTH="3" NOTNULL="false" DEFAULT="1" SEQUENCE="false" COMMENT="Maximum number of submission attachments"/>
<FIELD NAME="submissionfiletypes" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="comma separated list of file extensions"/>
<FIELD NAME="latesubmissions" TYPE="int" LENGTH="2" NOTNULL="false" DEFAULT="0" SEQUENCE="false" COMMENT="Allow submitting the work after the deadline"/>
<FIELD NAME="maxbytes" TYPE="int" LENGTH="10" NOTNULL="false" DEFAULT="100000" SEQUENCE="false" COMMENT="Maximum size of the one attached file"/>
@@ -133,4 +135,4 @@
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
</XMLDB>
@@ -68,5 +68,46 @@ function xmldb_workshop_upgrade($oldversion) {
// Automatically generated Moodle v3.5.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2018062600) {
// Define field submissiontypetext to be added to workshop.
$table = new xmldb_table('workshop');
$field = new xmldb_field('submissiontypetext', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'gradedecimals');
// Conditionally launch add field submissiontypetext.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
$field = new xmldb_field('submissiontypefile', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '2',
'submissiontypetext');
// Conditionally launch add field submissiontypefile.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Convert existing workshops with attachments disabled to use the new settings.
$workshops = $DB->get_records('workshop', ['nattachments' => 0]);
foreach ($workshops as $workshop) {
$update = (object) [
'id' => $workshop->id,
'submissiontypefile' => 0,
'submissiontypetext' => 2,
'nattachments' => 1
];
$DB->update_record('workshop', $update);
}
// Changing the default of field nattachments on table workshop to 1.
$field = new xmldb_field('nattachments', XMLDB_TYPE_INTEGER, '3', null, null, null, '1', 'submissiontypefile');
// Launch change of default for field nattachments.
$dbman->change_field_default($table, $field);
// Workshop savepoint reached.
upgrade_mod_savepoint(true, 2018062600, 'workshop');
}
return true;
}
@@ -204,6 +204,7 @@
$string['nattachments'] = 'Maximum number of submission attachments';
$string['noexamples'] = 'No examples yet in this workshop';
$string['noexamplesformready'] = 'You must define the assessment form before providing example submissions';
$string['nosubmissiontype'] = 'At least one submission type must be available';
$string['nogradeyet'] = 'No grade yet';
$string['nosubmissionfound'] = 'No submission found for this user';
$string['nosubmissions'] = 'No submissions yet in this workshop';
@@ -333,6 +334,12 @@
$string['submissionstartevent'] = '{$a} opens for submissions';
$string['submissionstartdatetime'] = 'Open for submissions from {$a->daydatetime} ({$a->distanceday})';
$string['submissiontitle'] = 'Title';
$string['submissiontypefileavailable'] = 'File attachment<span class="accesshide"> available</span>';
$string['submissiontypefilerequired'] = '<span class="accesshide">File attachment </span>Required';
$string['submissiontypetextavailable'] = 'Online text<span class="accesshide"> available</span>';
$string['submissiontypetextrequired'] = '<span class="accesshide">Online text </span>Required';
$string['submissiontypedisabled'] = 'This submission type is disabled for this workshop.';
$string['submissiontypes'] = 'Submission types';
$string['submissionsreport'] = 'Workshop submissions report';
$string['submittednotsubmitted'] = 'Submitted ({$a->submitted}) / not submitted ({$a->notsubmitted})';
$string['subplugintype_workshopallocation'] = 'Submissions allocation method';
@@ -34,6 +34,9 @@
define('WORKSHOP_EVENT_TYPE_SUBMISSION_CLOSE', 'closesubmission');
define('WORKSHOP_EVENT_TYPE_ASSESSMENT_OPEN', 'openassessment');
define('WORKSHOP_EVENT_TYPE_ASSESSMENT_CLOSE', 'closeassessment');
define('WORKSHOP_SUBMISSION_TYPE_DISABLED', 0);
define('WORKSHOP_SUBMISSION_TYPE_AVAILABLE', 1);
define('WORKSHOP_SUBMISSION_TYPE_REQUIRED', 2);
////////////////////////////////////////////////////////////////////////////////
// Moodle core API //
@@ -171,6 +171,12 @@ class workshop {
/** @var int maximum size of one file attached to the overall feedback */
public $overallfeedbackmaxbytes;
/** @var int Should the submission form show the text field? */
public $submissiontypetext;
/** @var int Should the submission form show the file attachment field? */
public $submissiontypefile;
/**
* @var workshop_strategy grading strategy instance
* Do not use directly, get the instance using {@link workshop::grading_strategy_instance()}
@@ -2870,9 +2876,39 @@ public function validate_submission_data($data) {
$errors['title'] = get_string('err_multiplesubmissions', 'mod_workshop');
}
}
// Get the workshop record by id or cmid, depending on whether we're creating or editing a submission.
if (empty($data['workshopid'])) {
$workshop = $DB->get_record_select('workshop', 'id = (SELECT instance FROM {course_modules} WHERE id = ?)',
[$data['cmid']]);
} else {
$workshop = $DB->get_record('workshop', ['id' => $data['workshopid']]);
}
if (isset($data['attachment_filemanager'])) {
$getfiles = file_get_drafarea_files($data['attachment_filemanager']);
$attachments = $getfiles->list;
} else {
$attachments = array();
}
$getfiles = file_get_drafarea_files($data['attachment_filemanager']);
if (empty($getfiles->list) and html_is_blank($data['content_editor']['text'])) {
if ($workshop->submissiontypefile == WORKSHOP_SUBMISSION_TYPE_REQUIRED) {
if (empty($attachments)) {
$errors['attachment_filemanager'] = get_string('err_required', 'form');
}
} else if ($workshop->submissiontypefile == WORKSHOP_SUBMISSION_TYPE_DISABLED && !empty($data['attachment_filemanager'])) {
$errors['attachment_filemanager'] = get_string('submissiontypedisabled', 'mod_workshop');
}
if ($workshop->submissiontypetext == WORKSHOP_SUBMISSION_TYPE_REQUIRED && html_is_blank($data['content_editor']['text'])) {
$errors['content_editor'] = get_string('err_required', 'form');
} else if ($workshop->submissiontypetext == WORKSHOP_SUBMISSION_TYPE_DISABLED && !empty($data['content_editor']['text'])) {
$errors['content_editor'] = get_string('submissiontypedisabled', 'mod_workshop');
}
// If neither type is explicitly required, one or the other must be submitted.
if ($workshop->submissiontypetext != WORKSHOP_SUBMISSION_TYPE_REQUIRED
&& $workshop->submissiontypefile != WORKSHOP_SUBMISSION_TYPE_REQUIRED
&& empty($attachments) && html_is_blank($data['content_editor']['text'])) {
$errors['content_editor'] = get_string('submissionrequiredcontent', 'mod_workshop');
$errors['attachment_filemanager'] = get_string('submissionrequiredfile', 'mod_workshop');
}
@@ -2939,8 +2975,10 @@ public function edit_submission($submission) {
$params['objectid'] = $submission->id;
// Save and relink embedded images and save attachments.
$submission = file_postupdate_standard_editor($submission, 'content', $this->submission_content_options(),
$this->context, 'mod_workshop', 'submission_content', $submission->id);
if ($this->submissiontypetext != WORKSHOP_SUBMISSION_TYPE_DISABLED) {
$submission = file_postupdate_standard_editor($submission, 'content', $this->submission_content_options(),
$this->context, 'mod_workshop', 'submission_content', $submission->id);
}
$submission = file_postupdate_standard_filemanager($submission, 'attachment', $this->submission_attachment_options(),
$this->context, 'mod_workshop', 'submission_attachment', $submission->id);
Oops, something went wrong.

0 comments on commit 6a98671

Please sign in to comment.