Permalink
Browse files

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

  • Loading branch information...
dmonllao committed Apr 11, 2018
2 parents 0ca25fe + cf58a2d commit a5db58f4f215a2fddcd87b616e06d37ed9ff0567
@@ -2458,6 +2458,15 @@ protected static function get_course_structure($onlypublicdata = true) {
),
'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 @@ public static function get_courses_by_field($field = '', $value = '') {
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(
@@ -1261,6 +1261,17 @@ public function section_action($section, $action, $sr) {
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();
}
}
/**
@@ -478,4 +478,14 @@ public function has_view_page() {
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();
}
}
@@ -120,4 +120,15 @@ public function course_format_options($foreditform = false) {
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();
}
}
@@ -399,6 +399,17 @@ public function section_action($section, $action, $sr) {
$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();
}
}
/**
@@ -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.
@@ -565,6 +565,17 @@ public static function update_end_date($courseid) {
}
}
}
/**
* 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();
}
}
/**
@@ -2045,7 +2045,8 @@ public function test_get_courses_by_field() {
$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 @@ public function test_get_courses_by_field() {
$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 @@ public function test_get_courses_by_field() {
$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'];

0 comments on commit a5db58f

Please sign in to comment.