From 6dfb4ff2b31a3aa1aa5162677c3ebc6947094420 Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Wed, 21 Jun 2017 13:13:15 +0800 Subject: [PATCH 1/2] MDL-59285 tool_mobile: new setting for mobile app setup url --- admin/tool/mobile/lang/en/tool_mobile.php | 3 +++ admin/tool/mobile/settings.php | 3 +++ 2 files changed, 6 insertions(+) diff --git a/admin/tool/mobile/lang/en/tool_mobile.php b/admin/tool/mobile/lang/en/tool_mobile.php index 56e929a4bdecd..60e8c26ec4044 100644 --- a/admin/tool/mobile/lang/en/tool_mobile.php +++ b/admin/tool/mobile/lang/en/tool_mobile.php @@ -62,12 +62,15 @@ $string['loginintheembeddedbrowser'] = 'Via an embedded browser (for SSO plugins)'; $string['mainmenu'] = 'Main menu'; $string['mobileapp'] = 'Mobile app'; +$string['mobileappenabled'] = 'This moodle site has mobile app access enabled. You can use moodle mobile app to access the content of your courses and much more. Click here for more information'; $string['mobileappearance'] = 'Mobile appearance'; $string['mobileauthentication'] = 'Mobile authentication'; $string['mobilecssurl'] = 'CSS'; $string['mobilefeatures'] = 'Mobile features'; $string['mobilesettings'] = 'Mobile settings'; $string['pluginname'] = 'Moodle Mobile tools'; +$string['setuplink'] = 'Mobile setup link'; +$string['setuplink_desc'] = 'Link to documentation page to help users setup their mobile app.'; $string['smartappbanners'] = 'App Banners'; $string['pluginnotenabledorconfigured'] = 'Plugin not enabled or configured.'; $string['remoteaddons'] = 'Remote add-ons'; diff --git a/admin/tool/mobile/settings.php b/admin/tool/mobile/settings.php index 4f8630c95b649..8af64c66fdbe9 100644 --- a/admin/tool/mobile/settings.php +++ b/admin/tool/mobile/settings.php @@ -83,6 +83,9 @@ $temp->add(new admin_setting_configtext('tool_mobile/androidappid', new lang_string('androidappid', 'tool_mobile'), new lang_string('androidappid_desc', 'tool_mobile'), 'com.moodle.moodlemobile', PARAM_NOTAGS)); + $temp->add(new admin_setting_configtext('tool_mobile/setuplink', new lang_string('setuplink', 'tool_mobile'), + new lang_string('setuplink_desc', 'tool_mobile'), 'https://download.moodle.org/mobile', PARAM_URL)); + $ADMIN->add('mobileapp', $temp); // Features related settings. From 83f50acd53af0e712f2171540b078515a9ba7a2d Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Fri, 23 Jun 2017 14:10:03 +0800 Subject: [PATCH 2/2] MDL-59285 tool_mobile: add user profile page callback --- admin/tool/mobile/lang/en/tool_mobile.php | 3 +- admin/tool/mobile/lib.php | 76 +++++++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/admin/tool/mobile/lang/en/tool_mobile.php b/admin/tool/mobile/lang/en/tool_mobile.php index 60e8c26ec4044..e2234bc3dc07f 100644 --- a/admin/tool/mobile/lang/en/tool_mobile.php +++ b/admin/tool/mobile/lang/en/tool_mobile.php @@ -62,7 +62,8 @@ $string['loginintheembeddedbrowser'] = 'Via an embedded browser (for SSO plugins)'; $string['mainmenu'] = 'Main menu'; $string['mobileapp'] = 'Mobile app'; -$string['mobileappenabled'] = 'This moodle site has mobile app access enabled. You can use moodle mobile app to access the content of your courses and much more. Click here for more information'; +$string['mobileappconnected'] = 'Mobile app connected'; +$string['mobileappenabled'] = 'This site has mobile app access enabled. You can use mobile app to access the content of your courses and much more. Click here for more information'; $string['mobileappearance'] = 'Mobile appearance'; $string['mobileauthentication'] = 'Mobile authentication'; $string['mobilecssurl'] = 'CSS'; diff --git a/admin/tool/mobile/lib.php b/admin/tool/mobile/lib.php index de43b8190da7f..37f1043bde0ff 100644 --- a/admin/tool/mobile/lib.php +++ b/admin/tool/mobile/lib.php @@ -50,3 +50,79 @@ function tool_mobile_before_standard_html_head() { } return $output; } + +/** + * Generate the app download url to promote moodle mobile. + * + * @return moodle_url|void App download moodle_url object or return if setuplink is not set. + */ +function tool_mobile_create_app_download_url() { + global $CFG; + + $mobilesettings = get_config('tool_mobile'); + + if (empty($mobilesettings->setuplink)) { + return; + } + + $downloadurl = new moodle_url($mobilesettings->setuplink); + $downloadurl->param('version', $CFG->version); + $downloadurl->param('lang', current_language()); + + if (!empty($mobilesettings->iosappid)) { + $downloadurl->param('iosappid', $mobilesettings->iosappid); + } + + if (!empty($mobilesettings->androidappid)) { + $downloadurl->param('androidappid', $mobilesettings->androidappid); + } + + return $downloadurl; +} + +/** + * User profile page callback. + * + * Used add a section about the moodle mobile app. + * + * @param \core_user\output\myprofile\tree $tree My profile tree where the setting will be added. + * @param stdClass $user The user object. + * @param bool $iscurrentuser Is this the current user viewing + * @return void Return if the mobile web services setting is disabled or if not the current user. + */ +function tool_mobile_myprofile_navigation(\core_user\output\myprofile\tree $tree, $user, $iscurrentuser) { + global $CFG, $DB; + + if (empty($CFG->enablemobilewebservice)) { + return; + } + + if (!$iscurrentuser) { + return; + } + + if (!$url = tool_mobile_create_app_download_url()) { + return; + } + + $sql = "SELECT 1 + FROM {external_tokens} t, {external_services} s + WHERE t.externalserviceid = s.id + AND s.enabled = 1 + AND s.shortname IN ('moodle_mobile_app', 'local_mobile') + AND t.userid = ?"; + $userhastoken = $DB->record_exists_sql($sql, [$user->id]); + + $mobilecategory = new core_user\output\myprofile\category('mobile', get_string('mobileapp', 'tool_mobile'), + 'loginactivity'); + $tree->add_category($mobilecategory); + + if ($userhastoken) { + $mobilestr = get_string('mobileappconnected', 'tool_mobile'); + } else { + $mobilestr = get_string('mobileappenabled', 'tool_mobile', $url->out()); + } + + $node = new core_user\output\myprofile\node('mobile', 'mobileappnode', $mobilestr, null); + $tree->add_node($node); +}