Merge branch 'MDL-54857-master' of git://github.com/jleyva/moodle
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 5 Jul 2016 22:03:39 +0000 (00:03 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 5 Jul 2016 22:03:39 +0000 (00:03 +0200)
admin/tool/mobile/classes/api.php
admin/tool/mobile/classes/external.php
admin/tool/mobile/db/services.php
admin/tool/mobile/tests/externallib_test.php
admin/tool/mobile/version.php

index 1dbe965..c111010 100644 (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;
+    }
+
 }
index ca5fb71..148f8a4 100644 (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(),
+            )
+        );
+    }
+
 }
index f7ddd74..20c6c84 100644 (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,
     )
 
 );
index 5a17c57..0ee8fc3 100644 (file)
@@ -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);
+    }
+
 }
index 0efc6e1..0c57e23 100644 (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).