Merge branch 'MDL-61198-master' of git://github.com/jleyva/moodle

This commit is contained in:
David Monllao 2018-04-11 18:23:59 +02:00
commit a5db58f4f2
8 changed files with 94 additions and 6 deletions

View File

@ -2458,6 +2458,15 @@ class core_course_external extends external_api {
),
'Course filters', VALUE_OPTIONAL
),
'courseformatoptions' => new external_multiple_structure(
new external_single_structure(
array(
'name' => new external_value(PARAM_RAW, 'Course format option name.'),
'value' => new external_value(PARAM_RAW, 'Course format option value.'),
)
),
'Additional options for particular course format.', VALUE_OPTIONAL
),
);
$coursestructure = array_merge($coursestructure, $extra);
}
@ -3084,6 +3093,14 @@ class core_course_external extends external_api {
if (isset($coursesdata[$course->id]['lang'])) {
$coursesdata[$course->id]['lang'] = clean_param($coursesdata[$course->id]['lang'], PARAM_LANG);
}
$courseformatoptions = course_get_format($course)->get_config_for_external();
foreach ($courseformatoptions as $key => $value) {
$coursesdata[$course->id]['courseformatoptions'][] = array(
'name' => $key,
'value' => $value
);
}
}
return array(

View File

@ -1261,6 +1261,17 @@ abstract class format_base {
return ['modules' => $modules];
}
/**
* Return the plugin config settings for external functions,
* in some cases the configs will need formatting or be returned only if the current user has some capabilities enabled.
*
* @return array the list of configs
* @since Moodle 3.5
*/
public function get_config_for_external() {
return array();
}
}
/**

View File

@ -478,4 +478,14 @@ class format_singleactivity extends format_base {
return false;
}
/**
* Return the plugin configs for external functions.
*
* @return array the list of configuration settings
* @since Moodle 3.5
*/
public function get_config_for_external() {
// Return everything (nothing to hide).
return $this->get_format_options();
}
}

View File

@ -120,4 +120,15 @@ class format_social extends format_base {
public function allow_stealth_module_visibility($cm, $section) {
return true;
}
/**
* Return the plugin configs for external functions.
*
* @return array the list of configuration settings
* @since Moodle 3.5
*/
public function get_config_for_external() {
// Return everything (nothing to hide).
return $this->get_format_options();
}
}

View File

@ -399,6 +399,17 @@ class format_topics extends format_base {
$rv['section_availability'] = $renderer->section_availability($this->get_section($section));
return $rv;
}
/**
* Return the plugin configs for external functions.
*
* @return array the list of configuration settings
* @since Moodle 3.5
*/
public function get_config_for_external() {
// Return everything (nothing to hide).
return $this->get_format_options();
}
}
/**

View File

@ -2,6 +2,12 @@ This files describes API changes for course formats
Overview of this plugin type at http://docs.moodle.org/dev/Course_formats
=== 3.5 ===
* Course formats should overwrite get_config_for_external function to return the course format settings viewable by the
current user.
If the course format does not have any setting that could be considerated private (like a private/access key/token),
is ok to return all the settigns via the get_format_options function.
=== 3.3 ===
* Javascript code for editing activities and sections was moved to an AMD module, course/rest.php is no longer
responsible for editing actions, instead it is done in web services. Carefully test all editing actions during upgrade.

View File

@ -565,6 +565,17 @@ class format_weeks extends format_base {
}
}
}
/**
* Return the plugin configs for external functions.
*
* @return array the list of configuration settings
* @since Moodle 3.5
*/
public function get_config_for_external() {
// Return everything (nothing to hide).
return $this->get_format_options();
}
}
/**

View File

@ -2045,7 +2045,8 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
$category1 = self::getDataGenerator()->create_category();
$category2 = self::getDataGenerator()->create_category(array('parent' => $category1->id));
$course1 = self::getDataGenerator()->create_course(array('category' => $category1->id, 'shortname' => 'c1'));
$course1 = self::getDataGenerator()->create_course(
array('category' => $category1->id, 'shortname' => 'c1', 'format' => 'topics'));
$course2 = self::getDataGenerator()->create_course(array('visible' => 0, 'category' => $category2->id, 'idnumber' => 'i2'));
$student1 = self::getDataGenerator()->create_user();
@ -2061,15 +2062,25 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
$this->assertCount(3, $result['courses']);
// Expect to receive all the fields.
$this->assertCount(37, $result['courses'][0]);
$this->assertCount(37, $result['courses'][1]);
$this->assertCount(37, $result['courses'][2]);
$this->assertCount(38, $result['courses'][1]); // One more field because is not the site course.
$this->assertCount(38, $result['courses'][2]); // One more field because is not the site course.
$result = core_course_external::get_courses_by_field('id', $course1->id);
$result = external_api::clean_returnvalue(core_course_external::get_courses_by_field_returns(), $result);
$this->assertCount(1, $result['courses']);
$this->assertEquals($course1->id, $result['courses'][0]['id']);
// Expect to receive all the fields.
$this->assertCount(37, $result['courses'][0]);
$this->assertCount(38, $result['courses'][0]);
// Check default values for course format topics.
$this->assertCount(2, $result['courses'][0]['courseformatoptions']);
foreach ($result['courses'][0]['courseformatoptions'] as $option) {
if ($option['name'] == 'hiddensections') {
$this->assertEquals(0, $option['value']);
} else {
$this->assertEquals('coursedisplay', $option['name']);
$this->assertEquals(0, $option['value']);
}
}
$result = core_course_external::get_courses_by_field('id', $course2->id);
$result = external_api::clean_returnvalue(core_course_external::get_courses_by_field_returns(), $result);
@ -2112,14 +2123,14 @@ class core_course_externallib_testcase extends externallib_advanced_testcase {
$result = external_api::clean_returnvalue(core_course_external::get_courses_by_field_returns(), $result);
$this->assertCount(2, $result['courses']);
$this->assertCount(30, $result['courses'][0]);
$this->assertCount(30, $result['courses'][1]);
$this->assertCount(31, $result['courses'][1]); // One field more (course format options), not present in site course.
$result = core_course_external::get_courses_by_field('id', $course1->id);
$result = external_api::clean_returnvalue(core_course_external::get_courses_by_field_returns(), $result);
$this->assertCount(1, $result['courses']);
$this->assertEquals($course1->id, $result['courses'][0]['id']);
// Expect to receive all the files that a student can see.
$this->assertCount(30, $result['courses'][0]);
$this->assertCount(31, $result['courses'][0]);
// Check default filters.
$filters = $result['courses'][0]['filters'];