Custom Field SQL Query

Hmm thinking about it, we've over complicated this. There's actually loads of ways to do this.

In your PHP you can do this:

$userFieldValues = $userModel->getUserFieldValues(*InsertUserIdHere*);

You can then access that user's banner from $userFieldValues['banner']
But the *InsertUserIdHere* changes every hour, automatically.
Unless I can make it work with my addon, without messing up my addon, then it's not good, sadly. :(
 
Hmm thinking about it, we've over complicated this. There's actually loads of ways to do this.

In your PHP you can do this:

$userFieldValues = $userModel->getUserFieldValues(*InsertUserIdHere*);

You can then access that user's banner from $userFieldValues['banner']
Fatal error: Call to undefined method XenMoods_XFCP_Model_User::getUserFieldValues() in /home/<my username>/public_html/library/TwistedPromotion/TopUser/Model/XTopUser.php on line 22

Line 22 being: $userFieldValues = $userModel->getUserFieldValues($TT['user_id']);

Code:
<?php
class TwistedPromotion_TopUser_Model_XTopUser extends Xenforo_Model_User
{
        public static function TwistedPromotion_TopUserArray() {
                $db = XenForo_Application::get('db');
                $userModel = XenForo_Model::create('XenForo_Model_User');
                $TwistedPromotion_TopUser = array();
                $numShown = "1";
                $long = "3600";
 
$TTArray = $db->fetchAll( $db->limit( "SELECT u.username AS username, u.user_id, up.homepage AS homepage, COUNT( * ) AS totalPosts FROM xf_post AS p LEFT JOIN xf_user AS u ON ( u.user_id = p.user_id ) LEFT JOIN xf_user_profile AS up ON ( up.user_id = p.user_id ) WHERE post_date > UNIX_TIMESTAMP()-$long GROUP BY p.user_id ORDER BY totalPosts DESC", $numShown ));
                if(sizeof($TTArray) != 0) {
 
                foreach($TTArray as $TTX) {
                        $TTIds[] = $TTX['user_id'];
                }
                $userObjs = $userModel->getUsersByIds($TTIds,array());
                foreach($TTArray as $TT) {
                  if ($TT['user_id'])
      {
      $hrefx = XenForo_Link::buildPublicLink('toposters', $TT);
      $userFieldValues = $userModel->getUserFieldValues($TT['user_id']);
 
                  }
$TwistedPromotion_TopUser[] = array("user" => $userObjs[$TT['user_id']], "username" => $TT['username'], "totalPosts" => $TT['totalPosts'], "homepage" => $TT['homepage']);
 
                }
                }
 
                if(count($TwistedPromotion_TopUser))
    {
    return $TwistedPromotion_TopUser;
    }
                }
 
        }
Am particularly confused about the XenMoods bit as this has nothing to do with that. :confused:
 
Line 22 is wrong because of some bad info I gave you previously.

I think I advised you to use $userModel->getUserFieldValues()

But actually, the getUserFieldValues function is part of the User Field Model not the User Model.

So replace Line 22 with:

PHP:
$userFieldModel = XenForo_Model::create('XenForo_Model_UserField');
$userFieldValues = $userFieldModel->getUserFieldValues($TT['user_id']);
 
Line 22 is wrong because of some bad info I gave you previously.

I think I advised you to use $userModel->getUserFieldValues()

But actually, the getUserFieldValues function is part of the User Field Model not the User Model.

So replace Line 22 with:

PHP:
$userFieldModel = XenForo_Model::create('XenForo_Model_UserField');[/COLOR][/FONT][/SIZE][/COLOR][/FONT][/SIZE][/COLOR][/FONT][/SIZE]
[COLOR=#000000][SIZE=3][FONT=Times New Roman][COLOR=#000000][SIZE=3][FONT=Times New Roman][SIZE=3][FONT=Times New Roman][COLOR=#000000]$userFieldValues = $[/COLOR][/FONT][/SIZE][SIZE=4][FONT=Times New Roman][COLOR=#000000]userFieldModel[/COLOR][/FONT][/SIZE][SIZE=3][FONT=Times New Roman][COLOR=#000000]->getUserFieldValues($TT['user_id']);
???
DO i need font times new roman? :confused:
Also, in which of my files do I paste this?
My Model.php, Listener.php, or Controller?
 
I improvised and removed the font markup and put the code in XTopUser.php (the model file).
But when I use $userFieldValues['banner'] in templates it simply says: "$userFieldValues['banner']"
It doesn't actually show the banner it shows the command as if I'm asking it to display text. Advice?
 
No of course not. That was just an editor formatting issue.

I have fixed my post. Which file? As I said, Line 22 where the error was being thrown before. Replace it with the code from my previous post.
 
No of course not. That was just an editor formatting issue.

I have fixed my post. Which file? As I said, Line 22 where the error was being thrown before. Replace it with the code from my previous post.
I've put it in XTopUser.php (the model file)...same file I pasted the old code in.
I don't get any database errors so it appears that the addon accepts the code, right?
Well, when i now try to use $userFieldValues['banner'] from templates it doesn't.
It simply writes $userFieldValues['banner'] (the text), rather than the actual value.
 
In templates, variables are used in this syntax:

{$userFieldValues.banner}
Thanks. That makes sense. :)
However, this doesn't work.
I have a value entered in my banner field.
And I am the top poster of the last hour for this past hour, right?
Well, I use {$userFieldValues.banner}, nothing shows....nothing at all.
As if it's not fetching the data properly. :(
 
Ok. I see why it won't work anyway without looking at the other files.

Your model file is returning:

PHP:
return $TwistedPromotion_TopUser;

Working backwards, $TwistedPromotion_TopUser is this:

PHP:
$TwistedPromotion_TopUser[] = array("user" => $userObjs[$TT['user_id']], "username" => $TT['username'], "totalPosts" => $TT['totalPosts'], "homepage" => $TT['homepage']);

So there's no way your $userFieldValues variable is going to be returned.

You should add the $userFieldValues to that TopUser array, like so:

PHP:
$TwistedPromotion_TopUser[] = array("user" => $userObjs[$TT['user_id']], "username" => $TT['username'], "totalPosts" => $TT['totalPosts'], "homepage" => $TT['homepage'], "userFieldValues" => $userFieldValues);

In your controller you're then passing the returned data as a param: {$TwistedPromotion_TopUser}

With that in mind, the banner user field value will be {$TwistedPromotion_TopUser.userFieldValues.banner}
 
Ok. I see why it won't work anyway without looking at the other files.

Your model file is returning:

PHP:
return $TwistedPromotion_TopUser;

Working backwards, $TwistedPromotion_TopUser is this:

PHP:
$TwistedPromotion_TopUser[] = array("user" => $userObjs[$TT['user_id']], "username" => $TT['username'], "totalPosts" => $TT['totalPosts'], "homepage" => $TT['homepage']);

So there's no way your $userFieldValues variable is going to be returned.

You should add the $userFieldValues to that TopUser array, like so:

PHP:
$TwistedPromotion_TopUser[] = array("user" => $userObjs[$TT['user_id']], "username" => $TT['username'], "totalPosts" => $TT['totalPosts'], "homepage" => $TT['homepage'], "userFieldValues" => $userFieldValues);

In your controller you're then passing the returned data as a param: {$TwistedPromotion_TopUser}

With that in mind, the banner user field value will be {$TwistedPromotion_TopUser.userFieldValues.banner}
Still not working. :(
{$TwistedPromotion_TopUser.userFieldValues.banner} returns nothing.
 
Directly above
PHP:
return $TwistedPromotion_TopUser;

Add :
PHP:
Zend_Debug::dump($TwistedPromotion_TopUser);

That will output the contents of that variable at the top of the page.
 
The banner is there...

Can you paste the template here? There's something missing or wrong somewhere.
 
Code:
<xen:if is="{$TwistedPromotion_TopUser}">
<div class="section staffOnline avatarList">
  <div class="secondaryContent">
    <h3>{xen:phrase twistedpromotion_topuser}</h3>
    <ol>
    <xen:foreach loop="$TwistedPromotion_TopUser" value="$XTopUser">
    <li>
    <xen:avatar user="$XTopUser.user" size="s" text="{$XTopUser.username} ({xen:number $XTopUser.totalPosts})" class="Tooltip" title="{$XTopUser.username}" />
    <xen:username user="$XTopUser.user" rich="true" />
    <xen:if is="{$XTopUser.homepage} == ''">
<i>has not set their homepage.</i><br />
<a href="http://www.twistedpromotion.com/account/personal-details">Click to set your homepage.</a>
<xen:else />
Visit {$XTopUser.username}'s website:<br />
<a href="{$XTopUser.homepage}" target="_blank">{$XTopUser.homepage}</a>
</xen:if>
{$TwistedPromotion_TopUser.userFieldValues.banner}
    </li>
    </xen:foreach>
    </ol>
  </div>
  </div>
</xen:if>
 
Top Bottom