mirror of
https://github.com/moodle/moodle.git
synced 2025-02-19 23:55:54 +01:00
MDL-63522 course: Return more fields in get_course_content WS
We need those fields on the mobile app to be able to render the course view properly.
This commit is contained in:
parent
448bd578d8
commit
1206a4878c
@ -261,6 +261,9 @@ class core_course_external extends external_api {
|
|||||||
$module['modplural'] = $cm->modplural;
|
$module['modplural'] = $cm->modplural;
|
||||||
$module['modicon'] = $cm->get_icon_url()->out(false);
|
$module['modicon'] = $cm->get_icon_url()->out(false);
|
||||||
$module['indent'] = $cm->indent;
|
$module['indent'] = $cm->indent;
|
||||||
|
$module['onclick'] = $cm->onclick;
|
||||||
|
$module['afterlink'] = $cm->afterlink;
|
||||||
|
$module['customdata'] = json_encode($cm->customdata);
|
||||||
|
|
||||||
if (!empty($cm->showdescription) or $cm->modname == 'label') {
|
if (!empty($cm->showdescription) or $cm->modname == 'label') {
|
||||||
// We want to use the external format. However from reading get_formatted_content(), $cm->content format is always FORMAT_HTML.
|
// We want to use the external format. However from reading get_formatted_content(), $cm->content format is always FORMAT_HTML.
|
||||||
@ -408,6 +411,10 @@ class core_course_external extends external_api {
|
|||||||
'modplural' => new external_value(PARAM_TEXT, 'activity module plural name'),
|
'modplural' => new external_value(PARAM_TEXT, 'activity module plural name'),
|
||||||
'availability' => new external_value(PARAM_RAW, 'module availability settings', VALUE_OPTIONAL),
|
'availability' => new external_value(PARAM_RAW, 'module availability settings', VALUE_OPTIONAL),
|
||||||
'indent' => new external_value(PARAM_INT, 'number of identation in the site'),
|
'indent' => new external_value(PARAM_INT, 'number of identation in the site'),
|
||||||
|
'onclick' => new external_value(PARAM_RAW, 'Onclick action.', VALUE_OPTIONAL),
|
||||||
|
'afterlink' => new external_value(PARAM_RAW, 'After link info to be displayed.',
|
||||||
|
VALUE_OPTIONAL),
|
||||||
|
'customdata' => new external_value(PARAM_RAW, 'Custom data (JSON encoded).', VALUE_OPTIONAL),
|
||||||
'contents' => new external_multiple_structure(
|
'contents' => new external_multiple_structure(
|
||||||
new external_single_structure(
|
new external_single_structure(
|
||||||
array(
|
array(
|
||||||
|
@ -809,15 +809,24 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
|
|||||||
global $DB, $CFG;
|
global $DB, $CFG;
|
||||||
|
|
||||||
$CFG->allowstealth = 1; // Allow stealth activities.
|
$CFG->allowstealth = 1; // Allow stealth activities.
|
||||||
|
$CFG->enablecompletion = true;
|
||||||
|
$CFG->forum_allowforcedreadtracking = 1;
|
||||||
|
$course = self::getDataGenerator()->create_course(['numsections' => 4, 'enablecompletion' => 1]);
|
||||||
|
|
||||||
$course = self::getDataGenerator()->create_course(['numsections' => 4]);
|
|
||||||
$forumdescription = 'This is the forum description';
|
$forumdescription = 'This is the forum description';
|
||||||
$forum = $this->getDataGenerator()->create_module('forum',
|
$forum = $this->getDataGenerator()->create_module('forum',
|
||||||
array('course' => $course->id, 'intro' => $forumdescription),
|
array('course' => $course->id, 'intro' => $forumdescription, 'trackingtype' => 2),
|
||||||
array('showdescription' => true));
|
array('showdescription' => true, 'completion' => COMPLETION_TRACKING_MANUAL));
|
||||||
$forumcm = get_coursemodule_from_id('forum', $forum->cmid);
|
$forumcm = get_coursemodule_from_id('forum', $forum->cmid);
|
||||||
$data = $this->getDataGenerator()->create_module('data', array('assessed' => 1, 'scale' => 100, 'course' => $course->id));
|
// Add discussions to the tracking forced forum.
|
||||||
$datacm = get_coursemodule_from_instance('page', $data->id);
|
$record = new stdClass();
|
||||||
|
$record->course = $course->id;
|
||||||
|
$record->userid = 0;
|
||||||
|
$record->forum = $forum->id;
|
||||||
|
$discussionforce = $this->getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
|
||||||
|
$data = $this->getDataGenerator()->create_module('data',
|
||||||
|
array('assessed' => 1, 'scale' => 100, 'course' => $course->id, 'completion' => 2, 'completionentries' => 3));
|
||||||
|
$datacm = get_coursemodule_from_instance('data', $data->id);
|
||||||
$page = $this->getDataGenerator()->create_module('page', array('course' => $course->id));
|
$page = $this->getDataGenerator()->create_module('page', array('course' => $course->id));
|
||||||
$pagecm = get_coursemodule_from_instance('page', $page->id);
|
$pagecm = get_coursemodule_from_instance('page', $page->id);
|
||||||
// This is an stealth page (set by visibleoncoursepage).
|
// This is an stealth page (set by visibleoncoursepage).
|
||||||
@ -830,7 +839,8 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
|
|||||||
$tomorrow = time() + DAYSECS;
|
$tomorrow = time() + DAYSECS;
|
||||||
// Module with availability restrictions not met.
|
// Module with availability restrictions not met.
|
||||||
$url = $this->getDataGenerator()->create_module('url',
|
$url = $this->getDataGenerator()->create_module('url',
|
||||||
array('course' => $course->id, 'name' => 'URL: % & $ ../', 'section' => 2),
|
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' => '{"op":"&","c":[{"type":"date","d":">=","t":' . $tomorrow . '}],"showc":[true]}'));
|
||||||
$urlcm = get_coursemodule_from_instance('url', $url->id);
|
$urlcm = get_coursemodule_from_instance('url', $url->id);
|
||||||
// Module for the last section.
|
// Module for the last section.
|
||||||
@ -891,7 +901,8 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
|
|||||||
array('noclean' => true, 'para' => false, 'filter' => false));
|
array('noclean' => true, 'para' => false, 'filter' => false));
|
||||||
$this->assertEquals($formattedtext, $module['description']);
|
$this->assertEquals($formattedtext, $module['description']);
|
||||||
$this->assertEquals($forumcm->instance, $module['instance']);
|
$this->assertEquals($forumcm->instance, $module['instance']);
|
||||||
$testexecuted = $testexecuted + 1;
|
$this->assertContains('1 unread post', $module['afterlink']);
|
||||||
|
$testexecuted = $testexecuted + 2;
|
||||||
} else if ($module['id'] == $labelcm->id and $module['modname'] == 'label') {
|
} else if ($module['id'] == $labelcm->id and $module['modname'] == 'label') {
|
||||||
$cm = $modinfo->cms[$labelcm->id];
|
$cm = $modinfo->cms[$labelcm->id];
|
||||||
$formattedtext = format_text($cm->content, FORMAT_HTML,
|
$formattedtext = format_text($cm->content, FORMAT_HTML,
|
||||||
@ -899,9 +910,19 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
|
|||||||
$this->assertEquals($formattedtext, $module['description']);
|
$this->assertEquals($formattedtext, $module['description']);
|
||||||
$this->assertEquals($labelcm->instance, $module['instance']);
|
$this->assertEquals($labelcm->instance, $module['instance']);
|
||||||
$testexecuted = $testexecuted + 1;
|
$testexecuted = $testexecuted + 1;
|
||||||
|
} else if ($module['id'] == $datacm->id and $module['modname'] == 'data') {
|
||||||
|
$this->assertContains('customcompletionrules', $module['customdata']);
|
||||||
|
$testexecuted = $testexecuted + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->assertEquals(2, $testexecuted);
|
foreach ($sections[2]['modules'] as $module) {
|
||||||
|
if ($module['id'] == $urlcm->id and $module['modname'] == 'url') {
|
||||||
|
$this->assertContains('width=100,height=100', $module['onclick']);
|
||||||
|
$testexecuted = $testexecuted + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertEquals(5, $testexecuted);
|
||||||
$this->assertEquals(0, $sections[0]['section']);
|
$this->assertEquals(0, $sections[0]['section']);
|
||||||
|
|
||||||
$this->assertCount(5, $sections[0]['modules']);
|
$this->assertCount(5, $sections[0]['modules']);
|
||||||
|
@ -5,6 +5,10 @@ information provided here is intended especially for developers.
|
|||||||
|
|
||||||
* External function core_course_external::get_course_public_information now returns the roles and the primary role of course
|
* External function core_course_external::get_course_public_information now returns the roles and the primary role of course
|
||||||
contacts.
|
contacts.
|
||||||
|
* External function core_course_external::get_course_contents now return the following additional file fields:
|
||||||
|
- onclick (onclick javascript action code)
|
||||||
|
- afterlink (after link info to be displayed)
|
||||||
|
- customdata (module custom data (JSON encoded))
|
||||||
|
|
||||||
=== 3.5 ===
|
=== 3.5 ===
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user