• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Usermodel question

Wuebit

Well-known member
#1
Any idea why this is not working?

Code:
                $userModel = XenForo_Model::create('XenForo_Model_User');
                $identities = $userModel->getIdentities($hookParams['user']['user_id']);
Keep getting

Code:
undefined method XenForo_Model_User::getIdentities()
 

Chris D

XenForo developer
Staff member
#4
Do you not already have the user ID?
PHP:
$hookParams['user']['user_id']
Or are you after the full user record?

You can get the user's details using the getUserByUserId function in the user model.

I believe the getIdentities function was previously used to get a user's contact details. This has moved to custom fields that's why the getIdentities function no longer works.
 

Wuebit

Well-known member
#5
Do you not already have the user ID?
PHP:
$hookParams['user']['user_id']
Or are you after the full user record?

You can get the user's details using the getUserByUserId function in the user model.

I believe the getIdentities function was previously used to get a user's contact details. This has moved to custom fields that's why the getIdentities function no longer works.
Ah yes sorry Chris I am trying to get the users custom field (I need to get some kip I think or more coffee)

This is what I used to use.
Code:
$userModel = XenForo_Model::create('XenForo_Model_User');
                $identities = $userModel->getIdentities($hookParams['user']['user_id']);

                if (!empty($identities['twitter'])) {
                    $twitterId = $identities['twitter'];
                    $ourTemplate = $template->create('xen_profile_twitter_main');
                    $ourTemplate->setParam('twitter', $twitterId);
                    $contents .= $ourTemplate->render();
                }
 
Last edited:

Wuebit

Well-known member
#6
Chris would it be this than?

Code:
                $userModel = XenForo_Model::create('XenForo_Model_User');
                $identities = $userModel->getUserIdFromUser($hookParams['user']['user_id']);
It gives no errors but also nothing shows.
 

Daniel Hood

Well-known member
#8
Chris would it be this than?

Code:
                $userModel = XenForo_Model::create('XenForo_Model_User');
                $identities = $userModel->getUserIdFromUser($hookParams['user']['user_id']);
It gives no errors but also nothing shows.
Think you're looking for

PHP:
$userModel = XenForo_Model::create('XenForo_Model_User');
$identities = $userModel->getFullUserById($hookParams['user']['user_id']);
 

Wuebit

Well-known member
#10
Think you're looking for

PHP:
$userModel = XenForo_Model::create('XenForo_Model_User');
$identities = $userModel->getFullUserById($hookParams['user']['user_id']);
I still can't seem to get it to work tho.

PHP:
<?php

class Wuebit_Model_index
{
    public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
    {
        switch ($hookName)
        {
            case 'member_view_sidebar_middle2':
            {
                $userModel = XenForo_Model::create('XenForo_Model_User');
                $identities = $userModel->getFullUserById($hookParams['user']['user_id']);

                if (!empty($identities['twitter'])) {
                    $twitterId = $identities['twitter'];
                    $ourTemplate = $template->create('Wuebit_Twitter_Profile_Main');
                    $ourTemplate->setParam('twitter', $twitterId);
                    $contents .= $ourTemplate->render();
                }
                break;
            }
        }
    }
}
It seem's not to add the template on that hook.
 

Chris D

XenForo developer
Staff member
#11
Sorry it too me so long to respond.

I think you ought to start again from scratch.

There's a heck of a lot of new stuff in XenForo 1.2.

One such thing is Template Modifications which basically enable you to specify a template, find some code within it, and replace it with your own code. It's much easier and much more flexible. Template hooks are officially deprecated. And although technically they should still work, they aren't as favourable as the Template Modification system.

Also, as the contact information is now stored in custom fields, you don't even need any custom PHP to fetch them.

Once you've added your template code using a template modification, you can get the value of a user's Twitter account using:

Code:
{$user.customFields.twitter}
 

Wuebit

Well-known member
#12
Sorry it too me so long to respond.

I think you ought to start again from scratch.

There's a heck of a lot of new stuff in XenForo 1.2.

One such thing is Template Modifications which basically enable you to specify a template, find some code within it, and replace it with your own code. It's much easier and much more flexible. Template hooks are officially deprecated. And although technically they should still work, they aren't as favourable as the Template Modification system.

Also, as the contact information is now stored in custom fields, you don't even need any custom PHP to fetch them.

Once you've added your template code using a template modification, you can get the value of a user's Twitter account using:

Code:
{$user.customFields.twitter}
Wow oh wow that was SOO much easier lol thanks everyone.