mirror of
https://github.com/moodle/moodle.git
synced 2025-04-20 16:04:25 +02:00
Merge branch 'MDL-48944_m32v4' of https://github.com/sbourget/moodle
This commit is contained in:
commit
c145e290a3
@ -39,7 +39,7 @@ class backup_survey_activity_structure_step extends backup_activity_structure_st
|
||||
// Define each element separated
|
||||
$survey = new backup_nested_element('survey', array('id'), array(
|
||||
'name', 'intro', 'introformat', 'template',
|
||||
'questions', 'days', 'timecreated', 'timemodified'));
|
||||
'questions', 'days', 'timecreated', 'timemodified', 'completionsubmit'));
|
||||
|
||||
$answers = new backup_nested_element('answers');
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="mod/survey/db" VERSION="20120122" COMMENT="XMLDB file for Moodle mod/survey"
|
||||
<XMLDB PATH="mod/survey/db" VERSION="20160615" COMMENT="XMLDB file for Moodle mod/survey"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
@ -16,6 +16,7 @@
|
||||
<FIELD NAME="intro" TYPE="text" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="intro text field format"/>
|
||||
<FIELD NAME="questions" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
|
||||
<FIELD NAME="completionsubmit" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="If this field is set to 1, then the activity will be automatically marked as 'complete' once the user submits the survey."/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
|
||||
|
@ -22,8 +22,8 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
function xmldb_survey_upgrade($oldversion) {
|
||||
global $CFG;
|
||||
|
||||
global $DB;
|
||||
$dbman = $DB->get_manager(); // Loads ddl manager and xmldb classes.
|
||||
// Moodle v2.8.0 release upgrade line.
|
||||
// Put any upgrade step following this.
|
||||
|
||||
@ -35,6 +35,20 @@ function xmldb_survey_upgrade($oldversion) {
|
||||
|
||||
// Moodle v3.1.0 release upgrade line.
|
||||
// Put any upgrade step following this.
|
||||
if ($oldversion < 2016061400) {
|
||||
|
||||
// Define field completionsubmit to be added to survey.
|
||||
$table = new xmldb_table('survey');
|
||||
$field = new xmldb_field('completionsubmit', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'questions');
|
||||
|
||||
// Conditionally launch add field completionsubmit.
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// Survey savepoint reached.
|
||||
upgrade_mod_savepoint(true, 2016061400, 'survey');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -82,6 +82,7 @@ $string['attls9short'] = 'argue with authors';
|
||||
$string['cannotfindanswer'] = 'There are no answers for this survey yet.';
|
||||
$string['cannotfindquestion'] = 'Question doesn\'t exist';
|
||||
$string['cannotfindsurveytmpt'] = 'No survey templates found!';
|
||||
$string['completionsubmit'] = 'Student must submit to this activity to complete it';
|
||||
$string['ciqintro'] = 'While thinking about recent events in this class, answer the questions below.';
|
||||
$string['ciqname'] = 'Critical incidents';
|
||||
$string['ciq1'] = 'At what moment in class were you most engaged as a learner?';
|
||||
|
@ -785,6 +785,7 @@ function survey_supports($feature) {
|
||||
case FEATURE_GROUPINGS: return true;
|
||||
case FEATURE_MOD_INTRO: return true;
|
||||
case FEATURE_COMPLETION_TRACKS_VIEWS: return true;
|
||||
case FEATURE_COMPLETION_HAS_RULES: return true;
|
||||
case FEATURE_GRADE_HAS_GRADE: return false;
|
||||
case FEATURE_GRADE_OUTCOMES: return false;
|
||||
case FEATURE_BACKUP_MOODLE2: return true;
|
||||
@ -1008,6 +1009,13 @@ function survey_save_answers($survey, $answersrawdata, $course, $context) {
|
||||
$DB->insert_records("survey_answers", $answerstoinsert);
|
||||
}
|
||||
|
||||
// Update completion state.
|
||||
$cm = get_coursemodule_from_instance('survey', $survey->id, $course->id);
|
||||
$completion = new completion_info($course);
|
||||
if (isloggedin() && !isguestuser() && $completion->is_enabled($cm) && $survey->completionsubmit) {
|
||||
$completion->update_state($cm, COMPLETION_COMPLETE);
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'context' => $context,
|
||||
'courseid' => $course->id,
|
||||
@ -1016,3 +1024,29 @@ function survey_save_answers($survey, $answersrawdata, $course, $context) {
|
||||
$event = \mod_survey\event\response_submitted::create($params);
|
||||
$event->trigger();
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the automatic completion state for this survey based on the condition
|
||||
* in feedback settings.
|
||||
*
|
||||
* @param object $course Course
|
||||
* @param object $cm Course-module
|
||||
* @param int $userid User ID
|
||||
* @param bool $type Type of comparison (or/and; can be used as return value if no conditions)
|
||||
* @return bool True if completed, false if not, $type if conditions not set.
|
||||
*/
|
||||
function survey_get_completion_state($course, $cm, $userid, $type) {
|
||||
global $DB;
|
||||
|
||||
// Get survey details.
|
||||
$survey = $DB->get_record('survey', array('id' => $cm->instance), '*', MUST_EXIST);
|
||||
|
||||
// If completion option is enabled, evaluate it and return true/false.
|
||||
if ($survey->completionsubmit) {
|
||||
$params = array('userid' => $userid, 'survey' => $survey->id);
|
||||
return $DB->record_exists('survey_answers', $params);
|
||||
} else {
|
||||
// Completion option is not enabled so just return $type.
|
||||
return $type;
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,46 @@ class mod_survey_mod_form extends moodleform_mod {
|
||||
$this->add_action_buttons();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return submitted data if properly submitted or returns NULL if validation fails or
|
||||
* if there is no submitted data.
|
||||
*
|
||||
* @return stdClass submitted data; NULL if not valid or not submitted or cancelled
|
||||
*/
|
||||
public function get_data() {
|
||||
$data = parent::get_data();
|
||||
if (!$data) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!empty($data->completionunlocked)) {
|
||||
// Turn off completion settings if the checkboxes aren't ticked.
|
||||
$autocompletion = !empty($data->completion) &&
|
||||
$data->completion == COMPLETION_TRACKING_AUTOMATIC;
|
||||
if (!$autocompletion || empty($data->completionsubmit)) {
|
||||
$data->completionsubmit = 0;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add completion rules to form.
|
||||
* @return array
|
||||
*/
|
||||
public function add_completion_rules() {
|
||||
$mform =& $this->_form;
|
||||
$mform->addElement('checkbox', 'completionsubmit', '', get_string('completionsubmit', 'survey'));
|
||||
return array('completionsubmit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable completion rules
|
||||
* @param stdclass $data
|
||||
* @return array
|
||||
*/
|
||||
public function completion_rule_enabled($data) {
|
||||
return !empty($data['completionsubmit']);
|
||||
}
|
||||
}
|
||||
|
||||
|
46
mod/survey/tests/behat/survey_completion.feature
Normal file
46
mod/survey/tests/behat/survey_completion.feature
Normal file
@ -0,0 +1,46 @@
|
||||
@mod @mod_survey
|
||||
Feature: A teacher can use activity completion to track a student progress
|
||||
In order to use activity completion
|
||||
As a teacher
|
||||
I need to set survey activities and enable activity completion
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||
And the following "courses" exist:
|
||||
| fullname | shortname | category | enablecompletion |
|
||||
| Course 1 | C1 | 0 | 1 |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
And I log in as "teacher1"
|
||||
And I follow "Course 1"
|
||||
And I turn editing mode on
|
||||
|
||||
Scenario: Require survey view
|
||||
Given I add a "Survey" to section "1" and I fill the form with:
|
||||
| Name | Test survey name |
|
||||
| Survey type | Critical incidents |
|
||||
| Description | Test survey description |
|
||||
| Completion tracking | Show activity as complete when conditions are met |
|
||||
| id_completionview | 1 |
|
||||
And I turn editing mode off
|
||||
And the "Test survey name" "survey" activity with "auto" completion should be marked as not complete
|
||||
When I follow "Test survey name"
|
||||
And I follow "Course 1"
|
||||
Then the "Test survey name" "survey" activity with "auto" completion should be marked as complete
|
||||
|
||||
Scenario: Require survey submission
|
||||
Given I add a "Survey" to section "1" and I fill the form with:
|
||||
| Name | Test survey name |
|
||||
| Survey type | Critical incidents |
|
||||
| Description | Test survey description |
|
||||
| Completion tracking | Show activity as complete when conditions are met |
|
||||
| id_completionsubmit | 1 |
|
||||
And I turn editing mode off
|
||||
And the "Test survey name" "survey" activity with "auto" completion should be marked as not complete
|
||||
When I follow "Test survey name"
|
||||
And I press "Click here to continue"
|
||||
And I follow "Course 1"
|
||||
Then the "Test survey name" "survey" activity with "auto" completion should be marked as complete
|
@ -24,7 +24,7 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2016052300; // The current module version (Date: YYYYMMDDXX)
|
||||
$plugin->version = 2016061400; // The current module version (Date: YYYYMMDDXX)
|
||||
$plugin->requires = 2016051900; // Requires this Moodle version
|
||||
$plugin->component = 'mod_survey'; // Full name of the plugin (used for diagnostics)
|
||||
$plugin->cron = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user