Merge branch 'wip-MDL-23919-master' of https://github.com/marinaglancy/moodle

This commit is contained in:
Andrew Nicols 2017-04-06 09:02:36 +08:00
commit 3e57763833
2 changed files with 20 additions and 14 deletions

View File

@ -4166,21 +4166,24 @@ function data_update_completion_state($data, $course, $cm) {
* to the function name. This is why there are unused parameters.
*
* @since Moodle 3.3
* @param object $course Course
* @param object $cm course-module
* @param stdClass $course Course
* @param cm_info|stdClass $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 data_get_completion_state($course, $cm, $userid, $type) {
global $DB;
global $DB, $PAGE;
$result = $type; // Default return value
// Get data details.
$data = $DB->get_record('data', array('id' => $cm->instance), '*', MUST_EXIST);
if (isset($PAGE->cm->id) && $PAGE->cm->id == $cm->id) {
$data = $PAGE->activityrecord;
} else {
$data = $DB->get_record('data', array('id' => $cm->instance), '*', MUST_EXIST);
}
// If completion option is enabled, evaluate it and return true/false.
if ($data->completionentries) {
$data = $DB->get_record('data', array('id' => $cm->instance));
$numentries = data_numentries($data);
$numentries = data_numentries($data, $userid);
// Check the number of entries required against the number of entries already made.
if ($numentries >= $data->completionentries) {
$result = true;

View File

@ -4,14 +4,14 @@ Feature: Set entries required as a completion condition for a data item
As a teacher
I need to set entries required to mark the database activity as completed
Scenario:
Scenario: Two entries required to complete the activity
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@example.com |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
| fullname | shortname | enablecompletion |
| Course 1 | C1 | 1 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
@ -19,11 +19,6 @@ Scenario:
And I log in as "teacher1"
And I follow "C1"
And I turn editing mode on
And I navigate to "Edit settings" in current page administration
And I set the following fields to these values:
| Enable completion tracking | Yes |
And I press "Save and display"
#Two entries required to complete the activity
And I add a "Database" to section "1" and I fill the form with:
| Name | Test database name |
| Description | Test database description |
@ -56,4 +51,12 @@ Scenario:
And I log in as "teacher1"
And I follow "C1"
Then "Student 1" user has completed "Test database name" activity
And I follow "Course 1"
And I follow "Test database name"
And I navigate to "Edit settings" in current page administration
And I press "Unlock completion"
And I set the field "completionentries" to "1"
And I press "Save and display"
And I follow "C1"
Then "Student 1" user has completed "Test database name" activity
And I log out