XF 2.2 Member statistics not showing as number

mjda

Well-known member
I've added a new member statistics stat. The page is working just fine except for the value it's showing isn't showing as a number and I'm wondering how to change that.

Right now it's showing like 10123 and 7456, but I want it to show 10,123 and 7,456.

Obviously I'm missing something somewhere, but I can't figure this one out.
 
If it's being called in a template, use the number filter.

Code:
{$xf.visitor.message_count|number}
 
I didn't set that anywhere. I added the userSearcherOrder with this code:

Code:
public static function userSearcherOrders(\XF\Searcher\User $userSearcher, array &$sortOrders)
    {
        $sortOrders = array_replace($sortOrders, [
            'user_data' => \XF::phrase('user_data_phrase')
        ]);
    }

Then I added a new Member statistic with that as the search order.
 
Ahh, I just checked and the "Most media items" won't show as a number either if it's more than 1,000. Maybe this should be listed as a bug, or maybe this should be a suggestion to add an option to set what kind of data the value should be displayed as.
 
Can't you use numberFormat($value) in PHP?
I'm not sure where I'd use it in this case. The code I posted above is the only code that I had to add to get this to work.

I used the media gallery as an example for how to do it and, like I said, that addon's numbers aren't shown as numbers either. So, if someone on this forum had uploaded over 1,000 media items, their total number would show 1234 instead of 1,234 on the notable members page.

I'm assuming it'd be the same for over 1,000 resources too but I don't have the resource manager to test.
 
I removed my fix for this so folks wouldn't try using it. Check out the post right after this one to find a better way to fix this.
 
Last edited:
You can also accomplish this by extending \XF\Service\MemberStat\Preparer::prepareCacheResults() to run the results through \XF::language()->numberFormat() if the order matches your custom order. You can reference the original method to see how this is done for the pertinent core sort orders.
 
You can also accomplish this by extending \XF\Service\MemberStat\Preparer::prepareCacheResults() to run the results through \XF::language()->numberFormat() if the order matches your custom order. You can reference the original method to see how this is done for the pertinent core sort orders.
Thanks, a lot, for this @Jeremy P! This worked perfectly, and now I don't have to do all those template edits.

Might want to do this with the media gallery and resource manager (assuming it's not fixed), just in case folks have over 1,000 results to display. Looks kinda silly without the correct number format.
 
Back
Top Bottom