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

This commit is contained in:
Eloy Lafuente (stronk7)
2016-07-06 00:03:39 +02:00
5 changed files with 134 additions and 1 deletions
+32
View File
@@ -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;
}
}
+50
View File
@@ -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(),
)
);
}
}
+10
View File
@@ -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,
)
);
@@ -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 <b>html tags</b>';
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);
}
}
+1 -1
View File
@@ -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).