Backend\Core\Engine\User::loadUser PHP 메소드

loadUser() 공개 메소드

Load a user
public loadUser ( integer $userId )
$userId integer The id of the user to load.
    public function loadUser($userId)
    {
        $userId = (int) $userId;
        // get database instance
        $db = BackendModel::getContainer()->get('database');
        // get user-data
        $userData = (array) $db->getRecord('SELECT u.id, u.email, u.is_god, us.session_id, us.secret_key, UNIX_TIMESTAMP(us.date) AS date
             FROM users AS u
             LEFT OUTER JOIN users_sessions AS us ON u.id = us.user_id AND us.session_id = ?
             WHERE u.id = ?
             LIMIT 1', array(\SpoonSession::getSessionId(), $userId));
        // if there is no data we have to destroy this object, I know this isn't a realistic situation
        if (empty($userData)) {
            throw new Exception('user (' . $userId . ') can\'t be loaded.');
        }
        // set properties
        $this->setUserId($userData['id']);
        $this->setEmail($userData['email']);
        $this->setSessionId($userData['session_id']);
        $this->setSecretKey($userData['secret_key']);
        $this->setLastloggedInDate($userData['date']);
        $this->isAuthenticated = true;
        $this->isGod = $userData['is_god'] == 'Y';
        $this->loadGroups($userData['id']);
        // get settings
        $settings = (array) $db->getPairs('SELECT us.name, us.value
             FROM users_settings AS us
             WHERE us.user_id = ?', array($userId));
        // loop settings and store them in the object
        foreach ($settings as $key => $value) {
            $this->settings[$key] = unserialize($value);
        }
        // nickname available?
        if (!isset($this->settings['nickname']) || $this->settings['nickname'] == '') {
            $this->setSetting('nickname', $this->settings['name'] . ' ' . $this->settings['surname']);
        }
    }