Skip to content

Commit

Permalink
Fixed lang selection issue
Browse files Browse the repository at this point in the history
  • Loading branch information
anayleeloolxp committed Apr 23, 2024
1 parent d034dc6 commit 541a360
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions js/local_leeloolxpcontentapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ require(["jquery"], function ($) {
let cmid = $("#leeloolxpcontentapi-js-vars").data("cmid");
let sectionid = $("#leeloolxpcontentapi-js-vars").data("sectionid");
let courseid = $("#leeloolxpcontentapi-js-vars").data("courseid");
let lang = $("#leeloolxpcontentapi-js-vars").data("lang");

var mootoolsresponseDe = JSON.parse(atob(mootoolsresponse));
if( lang != '' ){
mootoolsresponseDe.lang = lang;
}

mootoolsresponseDe.cmid = cmid;
mootoolsresponseDe.sectionid = sectionid;
mootoolsresponseDe.courseid = courseid;
Expand Down
17 changes: 15 additions & 2 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function local_leeloolxpcontentapi_before_footer() {
}

if ($mootoolsenable && $mootoolsleeloourl && $mootoolstoken) {
global $USER;
global $USER, $DB;
if (isloggedin() && !is_siteadmin($USER)) {

global $PAGE, $CFG;
Expand Down Expand Up @@ -69,7 +69,20 @@ function local_leeloolxpcontentapi_before_footer() {
if (isset($res_arr->status) && isset($res_arr->status) != '') {
if ($res_arr->status == 'success') {

echo '<div id="leeloolxpcontentapi-js-vars" data-mootoolsleeloourl="' . base64_encode($mootoolsleeloourl) . '" data-mootoolstoken="' . $mootoolstoken . '" data-cmid="' . $cmid . '" data-sectionid="' . $sectionid . '" data-courseid="' . $courseid . '" data-mootoolsloginresponse="' . base64_encode($mootoolsloginresponse) . '"></div>';
$user_lang = $DB->get_record_sql(
'SELECT u.lang AS preferred_language
FROM {user} u
WHERE u.id = :userid',
['userid' => $USER->id]
);

if ($user_lang) {
$preferred_language = $user_lang->preferred_language;
} else {
$preferred_language = "";
}

echo '<div id="leeloolxpcontentapi-js-vars" data-mootoolsleeloourl="' . base64_encode($mootoolsleeloourl) . '" data-mootoolstoken="' . $mootoolstoken . '" data-lang="' . $preferred_language . '" data-cmid="' . $cmid . '" data-sectionid="' . $sectionid . '" data-courseid="' . $courseid . '" data-mootoolsloginresponse="' . base64_encode($mootoolsloginresponse) . '"></div>';

$PAGE->requires->js(new moodle_url('/local/leeloolxpcontentapi/js/local_leeloolxpcontentapi.js'));
echo '<button id="local_leeloolxpcontentapi_button"><i class="icon fa fa-phone fa-fw"></i></button>';
Expand Down

0 comments on commit 541a360

Please sign in to comment.