Skip to content

Commit

Permalink
Merge branch 'MDL-67841-master' of git://github.com/jleyva/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
vmdef committed Sep 29, 2020
2 parents 0cd27ec + fada51a commit 8787cfe
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
1 change: 1 addition & 0 deletions admin/tool/mobile/lang/en/deprecated.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mobileappconnected,tool_mobile
4 changes: 3 additions & 1 deletion admin/tool/mobile/lang/en/tool_mobile.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
$string['minimumversion'] = 'If an app version is specified (3.8.0 or higher), any users using an older app version will be prompted to upgrade their app before being allowed access to the site.';
$string['minimumversion_key'] = 'Minimum app version required';
$string['mobileapp'] = 'Mobile app';
$string['mobileappconnected'] = 'Mobile app connected';
$string['mobileappenabled'] = 'This site has mobile app access enabled.<br /><a href="{$a}">Download the mobile app</a>.';
$string['mobileappearance'] = 'Mobile appearance';
$string['mobileappsubscription'] = 'Moodle app subscription';
Expand Down Expand Up @@ -144,3 +143,6 @@
$string['privacy:metadata:core_userkey'] = 'User\'s keys used to create auto-login key for the current user.';
$string['responsivemainmenuitems'] = 'Responsive menu items';
$string['viewqrcode'] = 'View QR code';

// Deprecated since Moodle 3.10.
$string['mobileappconnected'] = 'Mobile app connected';
42 changes: 31 additions & 11 deletions admin/tool/mobile/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,34 @@ function tool_mobile_create_app_download_url() {
}

/**
* Checks if the given user has a mobile token (has used recently the app).
* Return the user mobile app WebService access token.
*
* @param int $userid the user to check
* @return bool true if the user has a token, false otherwise.
* @param int $userid the user to return the token from
* @return stdClass|false the token or false if the token doesn't exists
* @since 3.10
*/
function tool_mobile_user_has_token($userid) {
function tool_mobile_get_token($userid) {
global $DB;

$sql = "SELECT 1
$sql = "SELECT t.*
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 = ?";

return $DB->record_exists_sql($sql, [$userid]);
return $DB->get_record_sql($sql, [$userid], IGNORE_MULTIPLE);
}

/**
* Checks if the given user has a mobile token (has used recently the app).
*
* @param int $userid the user to check
* @return bool true if the user has a token, false otherwise.
*/
function tool_mobile_user_has_token($userid) {

return !empty(tool_mobile_get_token($userid));
}

/**
Expand Down Expand Up @@ -162,17 +174,25 @@ function tool_mobile_myprofile_navigation(\core_user\output\myprofile\tree $tree
}

// Check if the user is using the app, encouraging him to use it otherwise.
$userhastoken = tool_mobile_user_has_token($user->id);
$usertoken = tool_mobile_get_token($user->id);
$mobilestrconnected = null;

if ($userhastoken) {
$mobilestrconnected = get_string('mobileappconnected', 'tool_mobile');
$mobilelastaccess = null;

if ($usertoken) {
$mobilestrconnected = get_string('lastsiteaccess');
if ($usertoken->lastaccess) {
$mobilelastaccess = userdate($usertoken->lastaccess) . "&nbsp; (" . format_time(time() - $usertoken->lastaccess) . ")";
} else {
// We should not reach this point.
$mobilelastaccess = get_string("never");
}
} else if ($url = tool_mobile_create_app_download_url()) {
$mobilestrconnected = get_string('mobileappenabled', 'tool_mobile', $url->out());
}

if ($mobilestrconnected) {
$newnodes[] = new core_user\output\myprofile\node('mobile', 'mobileappnode', $mobilestrconnected, null);
$newnodes[] = new core_user\output\myprofile\node('mobile', 'mobileappnode', $mobilestrconnected, null, null,
$mobilelastaccess);
}

// Add nodes, if any.
Expand Down

0 comments on commit 8787cfe

Please sign in to comment.