当前位置: 首页>>代码示例>>PHP>>正文


PHP check_user_preferences_loaded函数代码示例

本文整理汇总了PHP中check_user_preferences_loaded函数的典型用法代码示例。如果您正苦于以下问题:PHP check_user_preferences_loaded函数的具体用法?PHP check_user_preferences_loaded怎么用?PHP check_user_preferences_loaded使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了check_user_preferences_loaded函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __fav_user_login

 public function __fav_user_login($user)
 {
     global $CFG, $USER;
     // regenerate session id and delete old session,
     // this helps prevent session fixation attacks from the same domain
     session_regenerate_id(true);
     // let enrol plugins deal with new enrolments if necessary
     enrol_check_plugins($user);
     // check enrolments, load caps and setup $USER object
     session_set_user($user);
     // reload preferences from DB
     unset($USER->preference);
     check_user_preferences_loaded($USER);
     // update login times
     update_user_login_times();
     // extra session prefs init
     set_login_session_preferences();
     if (isguestuser()) {
         // no need to continue when user is THE guest
         return $USER;
     }
     return $USER;
 }
开发者ID:vinoth4891,项目名称:clinique,代码行数:23,代码来源:favorites.php

示例2: test_check_user_preferences_loaded

 public function test_check_user_preferences_loaded()
 {
     global $DB;
     $this->resetAfterTest();
     $otheruser = $this->getDataGenerator()->create_user();
     $otheruserid = $otheruser->id;
     $DB->delete_records('user_preferences', array('userid' => $otheruserid));
     set_cache_flag('userpreferenceschanged', $otheruserid, null);
     $user = new stdClass();
     $user->id = $otheruserid;
     // Load.
     check_user_preferences_loaded($user);
     $this->assertTrue(isset($user->preference));
     $this->assertTrue(is_array($user->preference));
     $this->assertArrayHasKey('_lastloaded', $user->preference);
     $this->assertCount(1, $user->preference);
     // Add preference via direct call.
     $DB->insert_record('user_preferences', array('name' => 'xxx', 'value' => 'yyy', 'userid' => $user->id));
     // No cache reload yet.
     check_user_preferences_loaded($user);
     $this->assertCount(1, $user->preference);
     // Forced reloading of cache.
     unset($user->preference);
     check_user_preferences_loaded($user);
     $this->assertCount(2, $user->preference);
     $this->assertSame('yyy', $user->preference['xxx']);
     // Add preference via direct call.
     $DB->insert_record('user_preferences', array('name' => 'aaa', 'value' => 'bbb', 'userid' => $user->id));
     // Test timeouts and modifications from different session.
     set_cache_flag('userpreferenceschanged', $user->id, 1, time() + 1000);
     $user->preference['_lastloaded'] = $user->preference['_lastloaded'] - 20;
     check_user_preferences_loaded($user);
     $this->assertCount(2, $user->preference);
     check_user_preferences_loaded($user, 10);
     $this->assertCount(3, $user->preference);
     $this->assertSame('bbb', $user->preference['aaa']);
     set_cache_flag('userpreferenceschanged', $user->id, null);
 }
开发者ID:miguelangelUvirtual,项目名称:uEducon,代码行数:38,代码来源:moodlelib_test.php

示例3: get_complete_user_data

/**
 * Get a complete user record, which includes all the info in the user record.
 *
 * Intended for setting as $USER session variable
 *
 * @param string $field The user field to be checked for a given value.
 * @param string $value The value to match for $field.
 * @param int $mnethostid
 * @return mixed False, or A {@link $USER} object.
 */
function get_complete_user_data($field, $value, $mnethostid = null)
{
    global $CFG, $DB;
    if (!$field || !$value) {
        return false;
    }
    // Build the WHERE clause for an SQL query.
    $params = array('fieldval' => $value);
    $constraints = "{$field} = :fieldval AND deleted <> 1";
    // If we are loading user data based on anything other than id,
    // we must also restrict our search based on mnet host.
    if ($field != 'id') {
        if (empty($mnethostid)) {
            // If empty, we restrict to local users.
            $mnethostid = $CFG->mnet_localhost_id;
        }
    }
    if (!empty($mnethostid)) {
        $params['mnethostid'] = $mnethostid;
        $constraints .= " AND mnethostid = :mnethostid";
    }
    // Get all the basic user data.
    if (!($user = $DB->get_record_select('user', $constraints, $params))) {
        return false;
    }
    // Get various settings and preferences.
    // Preload preference cache.
    check_user_preferences_loaded($user);
    // Load course enrolment related stuff.
    $user->lastcourseaccess = array();
    // During last session.
    $user->currentcourseaccess = array();
    // During current session.
    if ($lastaccesses = $DB->get_records('user_lastaccess', array('userid' => $user->id))) {
        foreach ($lastaccesses as $lastaccess) {
            $user->lastcourseaccess[$lastaccess->courseid] = $lastaccess->timeaccess;
        }
    }
    $sql = "SELECT g.id, g.courseid\n              FROM {groups} g, {groups_members} gm\n             WHERE gm.groupid=g.id AND gm.userid=?";
    // This is a special hack to speedup calendar display.
    $user->groupmember = array();
    if (!isguestuser($user)) {
        if ($groups = $DB->get_records_sql($sql, array($user->id))) {
            foreach ($groups as $group) {
                if (!array_key_exists($group->courseid, $user->groupmember)) {
                    $user->groupmember[$group->courseid] = array();
                }
                $user->groupmember[$group->courseid][$group->id] = $group->id;
            }
        }
    }
    // Add the custom profile fields to the user record.
    $user->profile = array();
    if (!isguestuser($user)) {
        require_once $CFG->dirroot . '/user/profile/lib.php';
        profile_load_custom_fields($user);
    }
    // Rewrite some variables if necessary.
    if (!empty($user->description)) {
        // No need to cart all of it around.
        $user->description = true;
    }
    if (isguestuser($user)) {
        // Guest language always same as site.
        $user->lang = $CFG->lang;
        // Name always in current language.
        $user->firstname = get_string('guestuser');
        $user->lastname = ' ';
    }
    return $user;
}
开发者ID:lucaboesch,项目名称:moodle,代码行数:81,代码来源:moodlelib.php

示例4: test_check_user_preferences_loaded

 public function test_check_user_preferences_loaded()
 {
     global $DB;
     if (!($otheruserid = $this->get_fake_preference_test_userid())) {
         $this->fail('Can not find unused user id for the preferences test');
         return;
     }
     $DB->delete_records('user_preferences', array('userid' => $otheruserid));
     set_cache_flag('userpreferenceschanged', $otheruserid, NULL);
     $user = new stdClass();
     $user->id = $otheruserid;
     // load
     check_user_preferences_loaded($user);
     $this->assertTrue(isset($user->preference));
     $this->assertTrue(is_array($user->preference));
     $this->assertTrue(isset($user->preference['_lastloaded']));
     $this->assertEqual(count($user->preference), 1);
     // add preference via direct call
     $DB->insert_record('user_preferences', array('name' => 'xxx', 'value' => 'yyy', 'userid' => $user->id));
     // no cache reload yet
     check_user_preferences_loaded($user);
     $this->assertEqual(count($user->preference), 1);
     // forced reloading of cache
     unset($user->preference);
     check_user_preferences_loaded($user);
     $this->assertEqual(count($user->preference), 2);
     $this->assertEqual($user->preference['xxx'], 'yyy');
     // add preference via direct call
     $DB->insert_record('user_preferences', array('name' => 'aaa', 'value' => 'bbb', 'userid' => $user->id));
     // test timeouts and modifications from different session
     set_cache_flag('userpreferenceschanged', $user->id, 1, time() + 1000);
     $user->preference['_lastloaded'] = $user->preference['_lastloaded'] - 20;
     check_user_preferences_loaded($user);
     $this->assertEqual(count($user->preference), 2);
     check_user_preferences_loaded($user, 10);
     $this->assertEqual(count($user->preference), 3);
     $this->assertEqual($user->preference['aaa'], 'bbb');
     set_cache_flag('userpreferenceschanged', $user->id, null);
 }
开发者ID:richheath,项目名称:moodle,代码行数:39,代码来源:testmoodlelib.php

示例5: get_user_preferences

/**
 * Used to fetch user preference(s)
 *
 * If no arguments are supplied this function will return
 * all of the current user preferences as an array.
 *
 * If a name is specified then this function
 * attempts to return that particular preference value.  If
 * none is found, then the optional value $default is returned,
 * otherwise NULL.
 *
 * @global object
 * @global object
 * @param string $name Name of the key to use in finding a preference value
 * @param string $default Value to be returned if the $name key is not set in the user preferences
 * @param int $otheruserid A moodle user ID
 * @return string
 */
function get_user_preferences($name = NULL, $default = NULL, $otheruserid = NULL)
{
    global $USER, $DB;
    if (empty($otheruserid) || !empty($USER->id) && $USER->id == $otheruserid) {
        check_user_preferences_loaded();
        if (empty($name)) {
            return $USER->preference;
            // All values
        } else {
            if (array_key_exists($name, $USER->preference)) {
                return $USER->preference[$name];
                // The single value
            } else {
                return $default;
                // Default value (or NULL)
            }
        }
    } else {
        if (empty($name)) {
            return $DB->get_records_menu('user_preferences', array('userid' => $otheruserid), '', 'name,value');
            // All values
        } else {
            if ($value = $DB->get_field('user_preferences', 'value', array('userid' => $otheruserid, 'name' => $name))) {
                return $value;
                // The single value
            } else {
                return $default;
                // Default value (or NULL)
            }
        }
    }
}
开发者ID:ajv,项目名称:Offline-Caching,代码行数:50,代码来源:moodlelib.php


注:本文中的check_user_preferences_loaded函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。