diff --git a/admin/tool/mobile/classes/api.php b/admin/tool/mobile/classes/api.php new file mode 100644 index 00000000000..c4ff3709567 --- /dev/null +++ b/admin/tool/mobile/classes/api.php @@ -0,0 +1,85 @@ +. + +/** + * Class for Moodle Mobile tools. + * + * @package tool_mobile + * @copyright 2016 Juan Leyva + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @since Moodle 3.1 + */ +namespace tool_mobile; + +use core_component; +use core_plugin_manager; + +/** + * API exposed by tool_mobile + * + * @copyright 2016 Juan Leyva + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @since Moodle 3.1 + */ +class api { + + /** + * Returns a list of Moodle plugins supporting the mobile app. + * + * @return array an array of objects containing the plugin information + */ + public static function get_plugins_supporting_mobile() { + global $CFG; + require_once($CFG->libdir . '/adminlib.php'); + + $pluginsinfo = []; + $plugintypes = core_component::get_plugin_types(); + + foreach ($plugintypes as $plugintype => $unused) { + // We need to include files here. + $pluginswithfile = core_component::get_plugin_list_with_file($plugintype, 'db' . DIRECTORY_SEPARATOR . 'mobile.php'); + foreach ($pluginswithfile as $plugin => $notused) { + $path = core_component::get_plugin_directory($plugintype, $plugin); + $component = $plugintype . '_' . $plugin; + $version = get_component_version($component); + + require_once("$path/db/mobile.php"); + foreach ($addons as $addonname => $addoninfo) { + $plugininfo = array( + 'component' => $component, + 'version' => $version, + 'addon' => $addonname, + 'dependencies' => !empty($addon['dependencies']) ? $addoninfo['dependencies'] : array(), + 'fileurl' => '', + 'filehash' => '', + 'filesize' => 0 + ); + + // All the mobile packages must be under the plugin mobile directory. + $package = $path . DIRECTORY_SEPARATOR . 'mobile' . DIRECTORY_SEPARATOR . $addonname . '.zip'; + if (file_exists($package)) { + $plugininfo['fileurl'] = $CFG->wwwroot . '' . str_replace($CFG->dirroot, '', $package); + $plugininfo['filehash'] = sha1_file($package); + $plugininfo['filesize'] = filesize($package); + } + $pluginsinfo[] = $plugininfo; + } + } + } + return $pluginsinfo; + } + +} diff --git a/admin/tool/mobile/classes/external.php b/admin/tool/mobile/classes/external.php new file mode 100644 index 00000000000..ca5fb71034e --- /dev/null +++ b/admin/tool/mobile/classes/external.php @@ -0,0 +1,98 @@ +. + +/** + * This is the external API for this tool. + * + * @package tool_mobile + * @copyright 2016 Juan Leyva + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace tool_mobile; + +require_once("$CFG->libdir/externallib.php"); + +use external_api; +use external_function_parameters; +use external_value; +use external_single_structure; +use external_multiple_structure; +use external_warnings; + +/** + * This is the external API for this tool. + * + * @copyright 2016 Juan Leyva + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class external extends external_api { + + /** + * Returns description of get_plugins_supporting_mobile() parameters. + * + * @return external_function_parameters + * @since Moodle 3.1 + */ + public static function get_plugins_supporting_mobile_parameters() { + return new external_function_parameters(array()); + } + + /** + * Returns a list of Moodle plugins supporting the mobile app. + * + * @return array an array of warnings and objects containing the plugin information + * @since Moodle 3.1 + */ + public static function get_plugins_supporting_mobile() { + return array( + 'plugins' => api::get_plugins_supporting_mobile(), + 'warnings' => array(), + ); + } + + /** + * Returns description of get_plugins_supporting_mobile() result value. + * + * @return external_description + * @since Moodle 3.1 + */ + public static function get_plugins_supporting_mobile_returns() { + return new external_single_structure( + array( + 'plugins' => new external_multiple_structure( + new external_single_structure( + array( + 'component' => new external_value(PARAM_COMPONENT, 'The plugin component name.'), + 'version' => new external_value(PARAM_NOTAGS, 'The plugin version number.'), + 'addon' => new external_value(PARAM_COMPONENT, 'The Mobile addon (package) name.'), + 'dependencies' => new external_multiple_structure( + new external_value(PARAM_COMPONENT, 'Mobile addon name.'), + 'The list of Mobile addons this addon depends on.' + ), + 'fileurl' => new external_value(PARAM_URL, 'The addon package url for download + or empty if it doesn\'t exist.'), + 'filehash' => new external_value(PARAM_RAW, 'The addon package hash or empty if it doesn\'t exist.'), + 'filesize' => new external_value(PARAM_INT, 'The addon package size or empty if it doesn\'t exist.') + ) + ) + ), + 'warnings' => new external_warnings(), + ) + ); + } + +} diff --git a/admin/tool/mobile/db/services.php b/admin/tool/mobile/db/services.php new file mode 100644 index 00000000000..f7ddd744765 --- /dev/null +++ b/admin/tool/mobile/db/services.php @@ -0,0 +1,37 @@ +. + +/** + * Moodle Mobile tools webservice definitions. + * + * + * @package tool_mobile + * @copyright 2016 Juan Leyva + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$functions = array( + + 'tool_mobile_get_plugins_supporting_mobile' => array( + 'classname' => 'tool_mobile\external', + 'methodname' => 'get_plugins_supporting_mobile', + 'description' => 'Returns a list of Moodle plugins supporting the mobile app.', + 'type' => 'read', + 'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE) + ) + +); + diff --git a/admin/tool/mobile/lang/en/tool_mobile.php b/admin/tool/mobile/lang/en/tool_mobile.php new file mode 100644 index 00000000000..56a13605089 --- /dev/null +++ b/admin/tool/mobile/lang/en/tool_mobile.php @@ -0,0 +1,25 @@ +. + +/** + * Strings for component 'tool_mobile', language 'en' + * + * @package tool_mobile + * @copyright 2016 Juan Leyva + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$string['pluginname'] = 'Moodle Mobile tools'; diff --git a/admin/tool/mobile/tests/externallib_test.php b/admin/tool/mobile/tests/externallib_test.php new file mode 100644 index 00000000000..166fe5dee04 --- /dev/null +++ b/admin/tool/mobile/tests/externallib_test.php @@ -0,0 +1,56 @@ +. + +/** + * Moodle Mobile admin tool external functions tests. + * + * @package tool_mobile + * @category external + * @copyright 2016 Juan Leyva + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @since Moodle 3.1 + */ + +defined('MOODLE_INTERNAL') || die(); + +global $CFG; + +require_once($CFG->dirroot . '/webservice/tests/helpers.php'); + +use tool_mobile\external; + +/** + * External learning plans webservice API tests. + * + * @package tool_mobile + * @copyright 2016 Juan Leyva + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @since Moodle 3.1 + */ +class tool_mobile_external_testcase extends externallib_advanced_testcase { + + /** + * Test get_plugins_supporting_mobile. + * This is a very basic test because currently there aren't plugins supporting Mobile in core. + */ + public function test_get_plugins_supporting_mobile() { + $result = external::get_plugins_supporting_mobile(); + $result = external_api::clean_returnvalue(external::get_plugins_supporting_mobile_returns(), $result); + $this->assertCount(0, $result['warnings']); + $this->assertCount(0, $result['plugins']); + } + +} diff --git a/admin/tool/mobile/version.php b/admin/tool/mobile/version.php new file mode 100644 index 00000000000..80283859cde --- /dev/null +++ b/admin/tool/mobile/version.php @@ -0,0 +1,28 @@ +. + +/** + * Plugin version info + * + * @package tool_mobile + * @copyright 2016 Juan Leyva + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); +$plugin->version = 2016032401; // The current plugin version (Date: YYYYMMDDXX). +$plugin->requires = 2016032400.00; // Requires this Moodle version. +$plugin->component = 'tool_mobile'; // Full name of the plugin (used for diagnostics). diff --git a/lib/classes/plugin_manager.php b/lib/classes/plugin_manager.php index 89efac92955..ace21df7ac6 100644 --- a/lib/classes/plugin_manager.php +++ b/lib/classes/plugin_manager.php @@ -1900,7 +1900,7 @@ class core_plugin_manager { 'tool' => array( 'assignmentupgrade', 'availabilityconditions', 'behat', 'capability', 'cohortroles', 'customlang', 'dbtransfer', 'filetypes', 'generator', 'health', 'innodb', 'installaddon', - 'langimport', 'log', 'lp', 'lpmigrate', 'messageinbound', 'multilangupgrade', 'monitor', + 'langimport', 'log', 'lp', 'lpmigrate', 'messageinbound', 'mobile', 'multilangupgrade', 'monitor', 'phpunit', 'profiling', 'recyclebin', 'replace', 'spamcleaner', 'task', 'templatelibrary', 'unittest', 'uploadcourse', 'uploaduser', 'unsuproles', 'xmldb' ),