diff --git a/admin/tool/mobile/classes/api.php b/admin/tool/mobile/classes/api.php index 1dbe965f915..c111010b2ff 100644 --- a/admin/tool/mobile/classes/api.php +++ b/admin/tool/mobile/classes/api.php @@ -26,6 +26,7 @@ namespace tool_mobile; use core_component; use core_plugin_manager; +use context_system; /** * API exposed by tool_mobile @@ -82,4 +83,35 @@ class api { return $pluginsinfo; } + /** + * Returns a list of the site public settings, those not requiring authentication. + * + * @return array with the settings and warnings + */ + public static function get_site_public_settings() { + global $CFG, $SITE, $PAGE; + + $context = context_system::instance(); + // We need this to make work the format text functions. + $PAGE->set_context($context); + + $settings = array( + 'wwwroot' => $CFG->wwwroot, + 'httpswwwroot' => $CFG->httpswwwroot, + 'sitename' => external_format_string($SITE->fullname, $context->id, true), + 'guestlogin' => $CFG->guestloginbutton, + 'rememberusername' => $CFG->rememberusername, + 'authloginviaemail' => $CFG->authloginviaemail, + 'registerauth' => $CFG->registerauth, + 'forgottenpasswordurl' => $CFG->forgottenpasswordurl, + 'authinstructions' => format_text($CFG->auth_instructions), + 'authnoneenabled' => (int) is_enabled_auth('none'), + 'enablewebservices' => $CFG->enablewebservices, + 'enablemobilewebservice' => $CFG->enablemobilewebservice, + 'maintenanceenabled' => $CFG->maintenance_enabled, + 'maintenancemessage' => format_text($CFG->maintenance_message), + ); + return $settings; + } + } diff --git a/admin/tool/mobile/classes/external.php b/admin/tool/mobile/classes/external.php index ca5fb71034e..148f8a48016 100644 --- a/admin/tool/mobile/classes/external.php +++ b/admin/tool/mobile/classes/external.php @@ -95,4 +95,54 @@ class external extends external_api { ); } + /** + * Returns description of get_site_public_settings() parameters. + * + * @return external_function_parameters + * @since Moodle 3.2 + */ + public static function get_site_public_settings_parameters() { + return new external_function_parameters(array()); + } + + /** + * Returns a list of the site public settings, those not requiring authentication. + * + * @return array with the settings and warnings + * @since Moodle 3.2 + */ + public static function get_site_public_settings() { + $result = api::get_site_public_settings(); + $result['warnings'] = array(); + return $result; + } + + /** + * Returns description of get_site_public_settings() result value. + * + * @return external_description + * @since Moodle 3.2 + */ + public static function get_site_public_settings_returns() { + return new external_single_structure( + array( + 'wwwroot' => new external_value(PARAM_RAW, 'Site URL.'), + 'httpswwwroot' => new external_value(PARAM_RAW, 'Site https URL (if httpslogin is enabled).'), + 'sitename' => new external_value(PARAM_TEXT, 'Site name.'), + 'guestlogin' => new external_value(PARAM_INT, 'Whether guest login is enabled.'), + 'rememberusername' => new external_value(PARAM_INT, 'Values: 0 for No, 1 for Yes, 2 for optional.'), + 'authloginviaemail' => new external_value(PARAM_INT, 'Whether log in via email is enabled.'), + 'registerauth' => new external_value(PARAM_PLUGIN, 'Authentication method for user registration.'), + 'forgottenpasswordurl' => new external_value(PARAM_URL, 'Forgotten password URL.'), + 'authinstructions' => new external_value(PARAM_RAW, 'Authentication instructions.'), + 'authnoneenabled' => new external_value(PARAM_INT, 'Whether auth none is enabled.'), + 'enablewebservices' => new external_value(PARAM_INT, 'Whether Web Services are enabled.'), + 'enablemobilewebservice' => new external_value(PARAM_INT, 'Whether the Mobile service is enabled.'), + 'maintenanceenabled' => new external_value(PARAM_INT, 'Whether site maintenance is enabled.'), + 'maintenancemessage' => new external_value(PARAM_RAW, 'Maintenance message.'), + 'warnings' => new external_warnings(), + ) + ); + } + } diff --git a/admin/tool/mobile/db/services.php b/admin/tool/mobile/db/services.php index f7ddd744765..20c6c84b20b 100644 --- a/admin/tool/mobile/db/services.php +++ b/admin/tool/mobile/db/services.php @@ -31,6 +31,16 @@ $functions = array( 'description' => 'Returns a list of Moodle plugins supporting the mobile app.', 'type' => 'read', 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE) + ), + + 'tool_mobile_get_site_public_settings' => array( + 'classname' => 'tool_mobile\external', + 'methodname' => 'get_site_public_settings', + 'description' => 'Returns a list of the site public settings, those not requiring authentication.', + 'type' => 'read', + 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE), + 'ajax' => true, + 'loginrequired' => false, ) ); diff --git a/admin/tool/mobile/tests/externallib_test.php b/admin/tool/mobile/tests/externallib_test.php index 5a17c579208..0ee8fc34b59 100644 --- a/admin/tool/mobile/tests/externallib_test.php +++ b/admin/tool/mobile/tests/externallib_test.php @@ -54,4 +54,45 @@ class tool_mobile_external_testcase extends externallib_advanced_testcase { $this->assertTrue(is_array($result['plugins'])); } + public function test_get_site_public_settings() { + global $CFG, $SITE; + + $this->resetAfterTest(true); + $result = external::get_site_public_settings(); + $result = external_api::clean_returnvalue(external::get_site_public_settings_returns(), $result); + + // Test default values. + $context = context_system::instance(); + $expected = array( + 'wwwroot' => $CFG->wwwroot, + 'httpswwwroot' => $CFG->httpswwwroot, + 'sitename' => external_format_string($SITE->fullname, $context->id, true), + 'guestlogin' => $CFG->guestloginbutton, + 'rememberusername' => $CFG->rememberusername, + 'authloginviaemail' => $CFG->authloginviaemail, + 'registerauth' => $CFG->registerauth, + 'forgottenpasswordurl' => $CFG->forgottenpasswordurl, + 'authinstructions' => format_text($CFG->auth_instructions), + 'authnoneenabled' => (int) is_enabled_auth('none'), + 'enablewebservices' => $CFG->enablewebservices, + 'enablemobilewebservice' => $CFG->enablemobilewebservice, + 'maintenanceenabled' => $CFG->maintenance_enabled, + 'maintenancemessage' => format_text($CFG->maintenance_message), + 'warnings' => array() + ); + $this->assertEquals($expected, $result); + + // Change a value. + set_config('registerauth', 'email'); + $authinstructions = 'Something with html tags'; + set_config('auth_instructions', $authinstructions); + + $expected['registerauth'] = 'email'; + $expected['authinstructions'] = format_text($authinstructions); + + $result = external::get_site_public_settings(); + $result = external_api::clean_returnvalue(external::get_site_public_settings_returns(), $result); + $this->assertEquals($expected, $result); + } + } diff --git a/admin/tool/mobile/version.php b/admin/tool/mobile/version.php index 0efc6e12591..0c57e237651 100644 --- a/admin/tool/mobile/version.php +++ b/admin/tool/mobile/version.php @@ -23,6 +23,6 @@ */ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2016052300; // The current plugin version (Date: YYYYMMDDXX). +$plugin->version = 2016052301; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2016051900; // Requires this Moodle version. $plugin->component = 'tool_mobile'; // Full name of the plugin (used for diagnostics).