Skip to content

Commit

Permalink
MDL-59285 tool_mobile: add user profile page callback
Browse files Browse the repository at this point in the history
  • Loading branch information
lameze committed Jun 28, 2017
1 parent 6dfb4ff commit 83f50ac
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
3 changes: 2 additions & 1 deletion admin/tool/mobile/lang/en/tool_mobile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="{$a}">here</a> 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 <a href="{$a}">here</a> for more information';
$string['mobileappearance'] = 'Mobile appearance';
$string['mobileauthentication'] = 'Mobile authentication';
$string['mobilecssurl'] = 'CSS';
Expand Down
76 changes: 76 additions & 0 deletions admin/tool/mobile/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 83f50ac

Please sign in to comment.