Commit 76724712 authored by Mark Johnson's avatar Mark Johnson
Browse files

MDL-64123 webservices: Add valueused to completion data

parent 33a388ef
......@@ -268,7 +268,8 @@ class core_completion_external extends external_api {
'state' => $activitycompletiondata->completionstate,
'timecompleted' => $activitycompletiondata->timemodified,
'tracking' => $activity->completion,
'overrideby' => $activitycompletiondata->overrideby
'overrideby' => $activitycompletiondata->overrideby,
'valueused' => core_availability\info::completion_value_used($course, $activity->id)
);
}
......@@ -302,6 +303,8 @@ class core_completion_external extends external_api {
0 means none, 1 manual, 2 automatic'),
'overrideby' => new external_value(PARAM_INT, 'The user id who has overriden the status, or null',
VALUE_OPTIONAL),
'valueused' => new external_value(PARAM_BOOL, 'Whether the completion status affects the availability
of another activity.', VALUE_OPTIONAL),
), 'Activity'
), 'List of activities status'
),
......
......@@ -103,12 +103,14 @@ class core_completion_externallib_testcase extends externallib_advanced_testcase
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1,
'groupmode' => SEPARATEGROUPS,
'groupmodeforce' => 1));
availability_completion\condition::wipe_static_cache();
$data = $this->getDataGenerator()->create_module('data', array('course' => $course->id),
array('completion' => 1));
$forum = $this->getDataGenerator()->create_module('forum', array('course' => $course->id),
array('completion' => 1));
$assign = $this->getDataGenerator()->create_module('assign', array('course' => $course->id));
$availability = '{"op":"&","c":[{"type":"completion","cm":' . $forum->cmid .',"e":1}],"showc":[true]}';
$assign = $this->getDataGenerator()->create_module('assign', ['course' => $course->id], ['availability' => $availability]);
$page = $this->getDataGenerator()->create_module('page', array('course' => $course->id),
array('completion' => 1, 'visible' => 0));
......@@ -146,10 +148,12 @@ class core_completion_externallib_testcase extends externallib_advanced_testcase
$activitiesfound++;
$this->assertEquals(COMPLETION_COMPLETE, $status['state']);
$this->assertEquals(COMPLETION_TRACKING_MANUAL, $status['tracking']);
$this->assertTrue($status['valueused']);
} else if ($status['cmid'] == $data->cmid and $status['modname'] == 'data' and $status['instance'] == $data->id) {
$activitiesfound++;
$this->assertEquals(COMPLETION_INCOMPLETE, $status['state']);
$this->assertEquals(COMPLETION_TRACKING_MANUAL, $status['tracking']);
$this->assertFalse($status['valueused']);
}
}
$this->assertEquals(2, $activitiesfound);
......
This files describes API changes in /completion/* - completion,
information provided here is intended especially for developers.
=== 3.7 ===
* External function core_completion_external::get_activities_completion_status new returns the following additional field:
- valueused (indicates whether the completion state affects the availability of other content)
=== 2.9 ===
* A completed and failed activity counts as a completed activity for
......
......@@ -277,7 +277,8 @@ class core_course_external extends external_api {
$module['completiondata'] = array(
'state' => $completiondata->completionstate,
'timecompleted' => $completiondata->timemodified,
'overrideby' => $completiondata->overrideby
'overrideby' => $completiondata->overrideby,
'valueused' => core_availability\info::completion_value_used($course, $cm->id)
);
}
......@@ -440,6 +441,8 @@ class core_course_external extends external_api {
'timecompleted' => new external_value(PARAM_INT, 'Timestamp for completion status.'),
'overrideby' => new external_value(PARAM_INT, 'The user id who has overriden the
status.'),
'valueused' => new external_value(PARAM_BOOL, 'Whether the completion status affects
the availability of another activity.', VALUE_OPTIONAL),
), 'Module completion data.', VALUE_OPTIONAL
),
'contents' => new external_multiple_structure(
......
......@@ -833,14 +833,16 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
$labeldescription = 'This is a very long label to test if more than 50 characters are returned.
So bla bla bla bla <b>bold bold bold</b> bla bla bla bla.';
$label = $this->getDataGenerator()->create_module('label', array('course' => $course->id,
'intro' => $labeldescription));
'intro' => $labeldescription, 'completion' => COMPLETION_TRACKING_MANUAL));
$labelcm = get_coursemodule_from_instance('label', $label->id);
$tomorrow = time() + DAYSECS;
// Module with availability restrictions not met.
$availability = '{"op":"&","c":[{"type":"date","d":">=","t":' . $tomorrow . '},'
.'{"type":"completion","cm":' . $label->cmid .',"e":1}],"showc":[true,true]}';
$url = $this->getDataGenerator()->create_module('url',
array('course' => $course->id, 'name' => 'URL: % & $ ../', 'section' => 2, 'display' => RESOURCELIB_DISPLAY_POPUP,
'popupwidth' => 100, 'popupheight' => 100),
array('availability' => '{"op":"&","c":[{"type":"date","d":">=","t":' . $tomorrow . '}],"showc":[true]}'));
array('availability' => $availability));
$urlcm = get_coursemodule_from_instance('url', $url->id);
// Module for the last section.
$this->getDataGenerator()->create_module('url',
......@@ -1152,6 +1154,7 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
$this->resetAfterTest(true);
list($course, $forumcm, $datacm, $pagecm, $labelcm, $urlcm) = $this->prepare_get_course_contents_test();
availability_completion\condition::wipe_static_cache();
// Test activity not completed yet.
$result = core_course_external::get_course_contents($course->id, array(
......@@ -1165,6 +1168,7 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
$this->assertEquals(0, $result[0]['modules'][0]["completiondata"]['state']);
$this->assertEquals(0, $result[0]['modules'][0]["completiondata"]['timecompleted']);
$this->assertEmpty($result[0]['modules'][0]["completiondata"]['overrideby']);
$this->assertFalse($result[0]['modules'][0]["completiondata"]['valueused']);
// Set activity completed.
core_completion_external::update_activity_completion_status_manually($forumcm->id, true);
......@@ -1178,6 +1182,20 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
$this->assertNotEmpty($result[0]['modules'][0]["completiondata"]['timecompleted']);
$this->assertEmpty($result[0]['modules'][0]["completiondata"]['overrideby']);
// Test activity with completion value that is used in an availability condition.
$result = core_course_external::get_course_contents($course->id, array(
array("name" => "modname", "value" => "label"), array("name" => "modid", "value" => $labelcm->instance)));
// We need to execute the return values cleaning process to simulate the web service server.
$result = external_api::clean_returnvalue(core_course_external::get_course_contents_returns(), $result);
$this->assertCount(1, $result[0]['modules']);
$this->assertEquals("label", $result[0]['modules'][0]["modname"]);
$this->assertEquals(COMPLETION_TRACKING_MANUAL, $result[0]['modules'][0]["completion"]);
$this->assertEquals(0, $result[0]['modules'][0]["completiondata"]['state']);
$this->assertEquals(0, $result[0]['modules'][0]["completiondata"]['timecompleted']);
$this->assertEmpty($result[0]['modules'][0]["completiondata"]['overrideby']);
$this->assertTrue($result[0]['modules'][0]["completiondata"]['valueused']);
// Disable completion.
$CFG->enablecompletion = 0;
$result = core_course_external::get_course_contents($course->id, array(
......@@ -2826,4 +2844,4 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
$this->assertCount(1, $result);
$this->assertEquals($courses[0]->id, array_shift($result)->id);
}
}
\ No newline at end of file
}
This files describes API changes in /course/*,
information provided here is intended especially for developers.
=== 3.7 ===
* External function core_course_external::get_course_contents new returns the following additional completiondata field:
- valueused (indicates whether the completion state affects the availability of other content)
=== 3.6 ===
* External function core_course_external::get_course_public_information now returns the roles and the primary role of course
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment