Exemplo n.º 1
0
    public static function getUser($id = '')
    {
        if (array_key_exists($id, self::$_user)) {
            return self::$_user[$id];
        }
        $db = JFactory::getDBO();
        $original_id = $id;
        if ($id == '') {
            $id = JFactory::getUser()->id;
        }
        if ($id != 0) {
            $query = $db->getQuery(true);
            $query->select('
                km_u.id,  
				km_u.first_name,  
				km_u.last_name,  
				km_u.middle_name,  
                km_u.region_id, 
                km_u.phone, 
                km_u.watched, 
                km_u.favorites,
                km_u.settings,  
                u.id, 
                u.name, 
                u.username,
                u.email,  
                u.block, 
                u.sendEmail, 
                u.registerDate, 
                u.lastvisitDate, 
                u.activation, 
                u.params, 
                u.lastResetTime, 
                u.resetCount,
                ua.city,
                ua.zip,
                ua.street,
                ua.house,
                ua.floor,
                ua.flat,
                ua.coords,
                uf.filename AS logo
            ');
            $query->from('#__users AS u');
            $query->leftjoin('#__ksen_users AS km_u ON km_u.id=u.id');
            $query->leftjoin('#__ksen_files AS uf ON uf.owner_id=u.id');
            $query->leftjoin('#__ksen_user_addresses AS ua ON ua.user_id=u.id AND ua.default=1');
            $query->where('u.id=' . $id);
            $query = KSMedia::setItemMainImageToQuery($query, 'user', 'km_u.', 'ksen');
            $db->setQuery($query);
            $user = $db->loadObject();
            if (!$user) {
                $user = self::getEmptyUserObject();
            }
            $user->folder = 'users';
            $params = JComponentHelper::getParams('com_ksen');
            $user->small_img = KSMedia::resizeImage($user->filename, $user->folder, $params->get('admin_product_thumb_image_width', 36), $params->get('admin_product_thumb_image_heigth', 36), json_decode($user->params, true), 'com_ksen');
            $user->medium_img = KSMedia::resizeImage($user->filename, $user->folder, $params->get('admin_product_medium_image_width', 120), $params->get('admin_product_medium_image_heigth', 120), json_decode($user->params, true), 'com_ksen');
            if (!empty($item->social) && $user->email == $user->username . '@email.ru') {
                $user->email = '';
            }
            if (empty($user->groups)) {
                $user->groups = JFactory::getUser()->groups;
            } else {
                $user->groups = array();
            }
            if (!empty($user->watched)) {
                $user->watched = json_decode($user->watched);
            } else {
                $user->watched = array();
            }
            if (!empty($user->favorites)) {
                $user->favorites = json_decode($user->favorites);
            } else {
                $user->favorites = array();
            }
            if ($user->region_id == 0) {
                $session = JFactory::getSession();
                $user_region = $session->get('user_region', 0);
                $user->region_id = $user_region;
            }
            if ($user->phone == '') {
                $session = JFactory::getSession();
                $phone_code = $session->get('phone_code', '');
                $user->phone = $phone_code;
            }
            if (!is_object($user->settings)) {
                $user->settings = '{"catalog_layout":"' . $params->get('catalog_default_view', 'grid') . '"}';
                $user->settings = json_decode($user->settings);
            }
            $user->address = KSUsers::getDefaultAddress($id);
            KSUsers::setAvatarLogoInObject($user);
            KSUsers::setUserFields($user);
        } else {
            $user = self::getEmptyUserObject();
        }
        self::$_user[$original_id] = $user;
        return $user;
    }