/** * Indicates whether a particular user can use skins on their pages or not. This is in * lib/web.php instead of lib/skin.php so that we can use it while generating the main nav. * @param int $userid The Id of the user to check. Null checks the current user. * @param bool $managesiteskin = true if admins try to manage the site skin * @param bool $issiteview = true if admins try to use skins for site views * @return bool */ function can_use_skins($userid = null, $managesiteskin = false, $issiteview = false) { global $USER; if (!get_config('skins')) { return false; } // Site Admins can access site skin if ($USER->get('admin') && ($managesiteskin || $issiteview)) { return true; } // A user can belong to multiple institutions. If any of their institutions allow it, then // let them use skins! $results = get_configs_user_institutions('skins', $userid); foreach ($results as $r) { if ($r) { return true; } } return false; }
/** * Find out a user's institution sort order for comments on artefacts within view page. * If they belong to one institution that has specified a sort order, then this will * be that institution's comment sort. * If they belong to multiple institutions then the arbitrarily "first" institution's * sort order will be used. * * @param int $userid Which user to check (defaults to $USER) * @return string Sort order - either 'earliest', 'latest'. */ function get_user_institution_comment_sort_order($userid = null) { $instsorts = get_configs_user_institutions('commentsortorder', $userid); $sortorder = null; // Every user belongs to at least one institution foreach ($instsorts as $sort) { // If the user belongs to multiple institutions, arbitrarily use the sort // from the first one that has specified a sort. if (!empty($sort)) { $sortorder = $sort; break; } } return $sortorder; }
/** * Find out if a user's pages should allow threaded replies. * @param string $userid * @return boolean */ function get_user_institution_comment_threads($userid = null) { $instthreads = get_configs_user_institutions('commentthreaded', $userid); // If they belong to even one institution that allows threaded comments, let them use them. foreach ($instthreads as $inst => $threads) { if (!empty($threads)) { return true; } } return false; }
/** * Find out a user's institution language. If they belong to one institution that has specified * a language, then this will be that institution's language. If they belong to multiple * institutions that have specified languages, it will be the arbitrarily "first" institution. * If they belong to no institution that has specified a language, it will return null. * * @param int $userid Which user to check (defaults to $USER) * @param string $sourceinst If provided, the source institution for the language will be * returned here by reference * @return string A language, or 'default' */ function get_user_institution_language($userid = null, &$sourceinst = null) { global $USER; if ($userid == null) { $userid = $USER->id; } $instlangs = get_configs_user_institutions('lang', $userid); // Every user belongs to at least one institution foreach ($instlangs as $name => $lang) { $sourceinst = $name; $instlang = $lang; // If the user belongs to multiple institutions, arbitrarily use the language // from the first one that has specified a language. if (!empty($instlang) && $instlang != 'default' && language_installed($instlang)) { break; } } if (!$instlang) { $instlang = 'default'; } return $instlang; }