From cc90f74b1877609b3a875b47c67eaf73f299d2c4 Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Fri, 27 Feb 2015 15:17:04 +0100 Subject: [PATCH 1/2] MDL-49333 webservices: Return additional info in core_get_site_info --- webservice/externallib.php | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/webservice/externallib.php b/webservice/externallib.php index 26e81a5c66b..da4ce3e719a 100644 --- a/webservice/externallib.php +++ b/webservice/externallib.php @@ -160,6 +160,23 @@ class core_webservice_external extends external_api { // Mobile CSS theme and alternative login url. $siteinfo['mobilecssurl'] = $CFG->mobilecssurl; + // Retrieve some advanced features. Only enable/disable ones (bool). + $advancedfeatures = array("usecomments", "usetags", "enablenotes", "messaging", "enableblogs", + "enablecompletion", "enablebadges"); + foreach ($advancedfeatures as $feature) { + if (isset($CFG->{$feature})) { + $siteinfo['advancedfeatures'][] = array( + 'name' => $feature, + 'value' => (int) $CFG->{$feature} + ); + } + } + // Special case mnet_dispatcher_mode. + $siteinfo['advancedfeatures'][] = array( + 'name' => 'mnet_dispatcher_mode', + 'value' => ($CFG->mnet_dispatcher_mode == 'strict') ? 1 : 0 + ); + return $siteinfo; } @@ -200,7 +217,18 @@ class core_webservice_external extends external_api { VALUE_OPTIONAL), 'release' => new external_value(PARAM_TEXT, 'Moodle release number', VALUE_OPTIONAL), 'version' => new external_value(PARAM_TEXT, 'Moodle version number', VALUE_OPTIONAL), - 'mobilecssurl' => new external_value(PARAM_URL, 'Mobile custom CSS theme', VALUE_OPTIONAL) + 'mobilecssurl' => new external_value(PARAM_URL, 'Mobile custom CSS theme', VALUE_OPTIONAL), + 'advancedfeatures' => new external_multiple_structure( + new external_single_structure( + array( + 'name' => new external_value(PARAM_ALPHANUMEXT, 'feature name'), + 'value' => new external_value(PARAM_INT, 'feature value. Usually 1 means enabled.') + ), + 'Advanced features availability' + ), + 'Advanced features availability', + VALUE_OPTIONAL + ) ) ); } From 14ae63be25c0ad9fcad8a3239ae5f3f4fec1c05e Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Fri, 27 Feb 2015 15:17:21 +0100 Subject: [PATCH 2/2] MDL-49333 webservices: Additional unit tests for core_get_site_info --- webservice/tests/externallib_test.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/webservice/tests/externallib_test.php b/webservice/tests/externallib_test.php index 92399af0c32..801679d123d 100644 --- a/webservice/tests/externallib_test.php +++ b/webservice/tests/externallib_test.php @@ -100,6 +100,19 @@ class core_webservice_externallib_testcase extends externallib_advanced_testcase $this->assertEquals($function['version'], $siteinfo['version']); $this->assertEquals(1, $siteinfo['downloadfiles']); $this->assertEquals(1, $siteinfo['uploadfiles']); + + foreach ($siteinfo['advancedfeatures'] as $feature) { + if ($feature['name'] == 'mnet_dispatcher_mode') { + if ($CFG->mnet_dispatcher_mode == 'off') { + $this->assertEquals(0, $feature['value']); + } else { + $this->assertEquals(1, $feature['value']); + } + } else { + $this->assertEquals($CFG->{$feature['name']}, $feature['value']); + } + } + } }