Skip to content

Commit a5db58f

Browse files
author
David Monllao
committed
Merge branch 'MDL-61198-master' of git://github.com/jleyva/moodle
2 parents 0ca25fe + cf58a2d commit a5db58f

File tree

8 files changed

+94
-6
lines changed

8 files changed

+94
-6
lines changed

course/externallib.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2458,6 +2458,15 @@ protected static function get_course_structure($onlypublicdata = true) {
24582458
),
24592459
'Course filters', VALUE_OPTIONAL
24602460
),
2461+
'courseformatoptions' => new external_multiple_structure(
2462+
new external_single_structure(
2463+
array(
2464+
'name' => new external_value(PARAM_RAW, 'Course format option name.'),
2465+
'value' => new external_value(PARAM_RAW, 'Course format option value.'),
2466+
)
2467+
),
2468+
'Additional options for particular course format.', VALUE_OPTIONAL
2469+
),
24612470
);
24622471
$coursestructure = array_merge($coursestructure, $extra);
24632472
}
@@ -3084,6 +3093,14 @@ public static function get_courses_by_field($field = '', $value = '') {
30843093
if (isset($coursesdata[$course->id]['lang'])) {
30853094
$coursesdata[$course->id]['lang'] = clean_param($coursesdata[$course->id]['lang'], PARAM_LANG);
30863095
}
3096+
3097+
$courseformatoptions = course_get_format($course)->get_config_for_external();
3098+
foreach ($courseformatoptions as $key => $value) {
3099+
$coursesdata[$course->id]['courseformatoptions'][] = array(
3100+
'name' => $key,
3101+
'value' => $value
3102+
);
3103+
}
30873104
}
30883105

30893106
return array(

course/format/lib.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,17 @@ public function section_action($section, $action, $sr) {
12611261

12621262
return ['modules' => $modules];
12631263
}
1264+
1265+
/**
1266+
* Return the plugin config settings for external functions,
1267+
* in some cases the configs will need formatting or be returned only if the current user has some capabilities enabled.
1268+
*
1269+
* @return array the list of configs
1270+
* @since Moodle 3.5
1271+
*/
1272+
public function get_config_for_external() {
1273+
return array();
1274+
}
12641275
}
12651276

12661277
/**

course/format/singleactivity/lib.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,4 +478,14 @@ public function has_view_page() {
478478
return false;
479479
}
480480

481+
/**
482+
* Return the plugin configs for external functions.
483+
*
484+
* @return array the list of configuration settings
485+
* @since Moodle 3.5
486+
*/
487+
public function get_config_for_external() {
488+
// Return everything (nothing to hide).
489+
return $this->get_format_options();
490+
}
481491
}

course/format/social/lib.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,15 @@ public function course_format_options($foreditform = false) {
120120
public function allow_stealth_module_visibility($cm, $section) {
121121
return true;
122122
}
123+
124+
/**
125+
* Return the plugin configs for external functions.
126+
*
127+
* @return array the list of configuration settings
128+
* @since Moodle 3.5
129+
*/
130+
public function get_config_for_external() {
131+
// Return everything (nothing to hide).
132+
return $this->get_format_options();
133+
}
123134
}

course/format/topics/lib.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,17 @@ public function section_action($section, $action, $sr) {
399399
$rv['section_availability'] = $renderer->section_availability($this->get_section($section));
400400
return $rv;
401401
}
402+
403+
/**
404+
* Return the plugin configs for external functions.
405+
*
406+
* @return array the list of configuration settings
407+
* @since Moodle 3.5
408+
*/
409+
public function get_config_for_external() {
410+
// Return everything (nothing to hide).
411+
return $this->get_format_options();
412+
}
402413
}
403414

404415
/**

course/format/upgrade.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ This files describes API changes for course formats
22

33
Overview of this plugin type at http://docs.moodle.org/dev/Course_formats
44

5+
=== 3.5 ===
6+
* Course formats should overwrite get_config_for_external function to return the course format settings viewable by the
7+
current user.
8+
If the course format does not have any setting that could be considerated private (like a private/access key/token),
9+
is ok to return all the settigns via the get_format_options function.
10+
511
=== 3.3 ===
612
* Javascript code for editing activities and sections was moved to an AMD module, course/rest.php is no longer
713
responsible for editing actions, instead it is done in web services. Carefully test all editing actions during upgrade.

course/format/weeks/lib.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,17 @@ public static function update_end_date($courseid) {
565565
}
566566
}
567567
}
568+
569+
/**
570+
* Return the plugin configs for external functions.
571+
*
572+
* @return array the list of configuration settings
573+
* @since Moodle 3.5
574+
*/
575+
public function get_config_for_external() {
576+
// Return everything (nothing to hide).
577+
return $this->get_format_options();
578+
}
568579
}
569580

570581
/**

course/tests/externallib_test.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,7 +2045,8 @@ public function test_get_courses_by_field() {
20452045

20462046
$category1 = self::getDataGenerator()->create_category();
20472047
$category2 = self::getDataGenerator()->create_category(array('parent' => $category1->id));
2048-
$course1 = self::getDataGenerator()->create_course(array('category' => $category1->id, 'shortname' => 'c1'));
2048+
$course1 = self::getDataGenerator()->create_course(
2049+
array('category' => $category1->id, 'shortname' => 'c1', 'format' => 'topics'));
20492050
$course2 = self::getDataGenerator()->create_course(array('visible' => 0, 'category' => $category2->id, 'idnumber' => 'i2'));
20502051

20512052
$student1 = self::getDataGenerator()->create_user();
@@ -2061,15 +2062,25 @@ public function test_get_courses_by_field() {
20612062
$this->assertCount(3, $result['courses']);
20622063
// Expect to receive all the fields.
20632064
$this->assertCount(37, $result['courses'][0]);
2064-
$this->assertCount(37, $result['courses'][1]);
2065-
$this->assertCount(37, $result['courses'][2]);
2065+
$this->assertCount(38, $result['courses'][1]); // One more field because is not the site course.
2066+
$this->assertCount(38, $result['courses'][2]); // One more field because is not the site course.
20662067

20672068
$result = core_course_external::get_courses_by_field('id', $course1->id);
20682069
$result = external_api::clean_returnvalue(core_course_external::get_courses_by_field_returns(), $result);
20692070
$this->assertCount(1, $result['courses']);
20702071
$this->assertEquals($course1->id, $result['courses'][0]['id']);
20712072
// Expect to receive all the fields.
2072-
$this->assertCount(37, $result['courses'][0]);
2073+
$this->assertCount(38, $result['courses'][0]);
2074+
// Check default values for course format topics.
2075+
$this->assertCount(2, $result['courses'][0]['courseformatoptions']);
2076+
foreach ($result['courses'][0]['courseformatoptions'] as $option) {
2077+
if ($option['name'] == 'hiddensections') {
2078+
$this->assertEquals(0, $option['value']);
2079+
} else {
2080+
$this->assertEquals('coursedisplay', $option['name']);
2081+
$this->assertEquals(0, $option['value']);
2082+
}
2083+
}
20732084

20742085
$result = core_course_external::get_courses_by_field('id', $course2->id);
20752086
$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() {
21122123
$result = external_api::clean_returnvalue(core_course_external::get_courses_by_field_returns(), $result);
21132124
$this->assertCount(2, $result['courses']);
21142125
$this->assertCount(30, $result['courses'][0]);
2115-
$this->assertCount(30, $result['courses'][1]);
2126+
$this->assertCount(31, $result['courses'][1]); // One field more (course format options), not present in site course.
21162127

21172128
$result = core_course_external::get_courses_by_field('id', $course1->id);
21182129
$result = external_api::clean_returnvalue(core_course_external::get_courses_by_field_returns(), $result);
21192130
$this->assertCount(1, $result['courses']);
21202131
$this->assertEquals($course1->id, $result['courses'][0]['id']);
21212132
// Expect to receive all the files that a student can see.
2122-
$this->assertCount(30, $result['courses'][0]);
2133+
$this->assertCount(31, $result['courses'][0]);
21232134

21242135
// Check default filters.
21252136
$filters = $result['courses'][0]['filters'];

0 commit comments

Comments
 (0)