Skip to content

Commit

Permalink
Improved menus and items language restriction based on current language.
Browse files Browse the repository at this point in the history
  • Loading branch information
prasanna-lmsace committed Sep 13, 2023
1 parent 1e8c1ed commit 1d8d7f6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
1 change: 0 additions & 1 deletion classes/smartmenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,6 @@ public static function build_smartmenu() {
* Verifies and handles changes in the session language.
* Clears cached smart menus and items when the user changes the language using the language menu.
*
* @param \theme_boost_union\cache\loader $cache
* @return void
*/
protected static function verify_lang_session_changes() {
Expand Down
22 changes: 10 additions & 12 deletions smartmenus/menulib.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ public function verify_access_restrictions() {
// Restriction by cohorts.
$this->restriction_bycohorts($query);

// REstriction by lanuages.
$this->restriction_bylanguage($query);
// Restriction by languages.
if (!$this->restriction_bylanguage()) {
return false;
}

// Restriction by date. Menu configured date is not started or already ended then hide the menu.
if (!$this->restriction_bydate()) {
Expand Down Expand Up @@ -188,24 +190,20 @@ public function restriction_bycohorts(&$query) {
}

/**
* Generate the queries and params to verify the user has the language which is contained in the current data.
* Verify the menu has restricted based on the current language.
*
* @param stdclass $query Array which contains elements for DB conditions, selectors and params.
* @return void
* @return bool True if the menu is avialble for this language, otherwise false menu will not shown to current user.
*/
public function restriction_bylanguage(&$query) {
global $DB;
public function restriction_bylanguage() {

$languages = $this->data->languages;
if (empty($languages)) {
return true;
}
list($insql, $inparam) = $DB->get_in_or_equal($languages, SQL_PARAMS_NAMED, 'la');
// Current language selected for this session.
$lang = current_language();

if (!empty($inparam)) {
$query->where[] = "u.lang $insql";
$query->params += $inparam;
}
return in_array($lang, $languages); // This menu or item is available for the current language.
}

/**
Expand Down

0 comments on commit 1d8d7f6

Please sign in to comment.