Custom profile fields in Who is online and Memberlist

Started by HunterP, July 08, 2012, 12:46:19 PM

Previous topic - Next topic

HunterP


Hi there,

Running 2.02 and having setup some custom profile fields, I'd like to show some of them in the Memberlist as well Who Is Online. It's no point to add the columns, but I'd like to know how to retrieve this information out of the DB. Is there possibly already a MOD for this? If not, hopefully someone can help me out with the query.

HunterP


Arantor

There is a very old mod for putting them on the memberlist, but it's 2.0 RC1.2 - though it might help you figure out what you need.

No-one has wanted to put things on Who's Online and honestly I'm not sure it's a big deal anyway, because anyone who wants to see it will go to the profile (but it usually makes more sense on the memberlist, especially if they're IM type icons)

HunterP

Quote from: Arantor on July 10, 2012, 10:30:56 AM
There is a very old mod for putting them on the memberlist, but it's 2.0 RC1.2 - though it might help you figure out what you need.

Couldn't find it there, do you have a hint?

Quote from: Arantor on July 10, 2012, 10:30:56 AM
No-one has wanted to put things on Who's Online and honestly I'm not sure it's a big deal anyway, because anyone who wants to see it will go to the profile (but it usually makes more sense on the memberlist, especially if they're IM type icons)

The additional information I want to show does make sense. At least for me it does :)

HunterP

Quote from: HunterP on July 10, 2012, 11:22:19 AM
Quote from: Arantor on July 10, 2012, 10:30:56 AM
There is a very old mod for putting them on the memberlist, but it's 2.0 RC1.2 - though it might help you figure out what you need.

Couldn't find it there, do you have a hint?

Ok, probably this one?

http://custom.simplemachines.org/mods/index.php?mod=1520

live627

Yep - that's the one! It needs refit to use Curve, though.

HunterP

Quote from: live627 on July 10, 2012, 07:50:56 PM
Yep - that's the one! It needs refit to use Curve, though.

Already got it working, thanks :)

HunterP


Can anyone tell me why the number of messages sort correctly, like :

0
1
2
10

But the custom fields sort like if they are treated als alphanumeric :

0
1
10
2

In fact, these fields are only numeric. Any ideas on this?

Sorck

Quote from: HunterP on July 11, 2012, 02:04:08 PM

Can anyone tell me why the number of messages sort correctly, like :

0
1
2
10

But the custom fields sort like if they are treated als alphanumeric :

0
1
10
2

In fact, these fields are only numeric. Any ideas on this?
SMF stores them as a string rather than as an integer therefore when sorting them it will do so alphabetically.

It would be possible to adjust SMF to sort those columns properly but it would only work in MySQL I think.

http://www.kreci.net/web-development/sort-varchar-as-int-in-mysql-query/ for some information. http://dev.mysql.com/doc/refman/5.0/en/cast-functions.html#function_cast covers the MySQL docs for the function. I'm not sure how efficient this will be though...

HunterP

Sounds interesting, but I can't find ORDER anywhere, I did find this piece of code :

// Build up sort queries.
if ($row['field_type'] != 'check')
$context['custom_profile_fields']['sort'][$curField] = array(
'down' => 'LENGTH(t' . $curField . '.value) > 0 ASC, IFNULL(t' . $curField . '.value, 1=1) DESC, t' . $curField . '.value DESC',
'up' => 'LENGTH(t' . $curField . '.value) > 0 DESC, IFNULL(t' . $curField . '.value, 1=1) ASC, t' . $curField . '.value ASC'
);
else
$context['custom_profile_fields']['sort'][$curField] = array(
'down' => 't' . $curField . '.value DESC',
'up' => 't' . $curField . '.value ASC'
);

// Did they make a magical selection?
if (isset($_REQUEST['sort']) && $_REQUEST['sort'] == $curField)
{
$context['custom_profile_fields']['join'] = 'LEFT JOIN {db_prefix}themes AS t' . $curField . ' ON (t' . $curField . '.variable = {string:t' . $curField . '} AND t' . $curField . '.id_theme = 1 AND t' . $curField . '.id_member = mem.id_member)';
$context['custom_profile_fields']['parameters']['t' . $curField] = $row['col_name'];
}
}


Any suggestions how to modify this?

Arantor

That's the order code right there.

Except there's no way to reorder it efficiently how you want.

HunterP

Quote from: Sorck on July 11, 2012, 02:18:10 PM
SMF stores them as a string rather than as an integer therefore when sorting them it will do so alphabetically.

So if they would be stored as INT, they would be sorted correctly?

Arantor

Except that you CANNOT store them as an int. The same table where they are stored uses a text column and I guarantee you if you change that column to int you will break SMF irretrievably (since, for example, the same column stores the theme URL and path, and converting that to int will leave you with 0 for the theme path and then it will simply fail to load everything)

HunterP

Quote from: Arantor on July 20, 2012, 12:09:21 PM
Except that you CANNOT store them as an int. The same table where they are stored uses a text column and I guarantee you if you change that column to int you will break SMF irretrievably (since, for example, the same column stores the theme URL and path, and converting that to int will leave you with 0 for the theme path and then it will simply fail to load everything)

That's not my question, as I was planning to add these fields into smf_members.

If I add new columns as INT to smf_members, will I be able to sort them correctly?

Arantor

Probably, assuming you also want to go through all the mess of adding them to the profile code.

HunterP

Quote from: Arantor on July 20, 2012, 02:12:53 PM
Probably, assuming you also want to go through all the mess of adding them to the profile code.

Mess? Done it before on a different forum, but these were text items, so wasn't sure whether it could solve my sorting problem. Any chance that I can copy the custom profile fields (TEXT) into the new fields (INT), maybe with casting?

Arantor

Oh, trust me, setting up new profile fields actually in the profile, that use the SMF members table is nothing short of a mess to implement. It's the one reason why CPF was even implemented in the first place.

You could probably do it with casting and a LOT of work (one query per user) though I'm curious as to what's so important that users are actually going to sort by it in the first place.

HunterP

Quote from: Arantor on July 20, 2012, 06:29:42 PM
Oh, trust me, setting up new profile fields actually in the profile, that use the SMF members table is nothing short of a mess to implement. It's the one reason why CPF was even implemented in the first place.

Well, reading isn't my best thing, that's why I manually added some fields to the profiles on an other forum, which works like a charm, so I don't really see the problem? Anyway, recently I've set up a new forum and suddenly discovered the CPF. This would indeed have made things a bit easier on the first forum, but maybe I'm also going to add extra columns for this forum too.

Quote from: Arantor on July 20, 2012, 06:29:42 PM
You could probably do it with casting and a LOT of work (one query per user) though I'm curious as to what's so important that users are actually going to sort by it in the first place.

It's not important Pete, I just like things to be as perfect as possible. If that takes some extra blood, sweat and coding, so be it :)

Arantor

It's not just about being perfect, there's also the small matters of maintainability and upgradability to contend with - if you later upgrade to 2.1 you have to redo all this work >_>

HunterP

Quote from: Arantor on July 20, 2012, 06:42:33 PM
It's not just about being perfect, there's also the small matters of maintainability and upgradability to contend with - if you later upgrade to 2.1 you have to redo all this work >_>

Will an upgrade make additional columns disappear, or might my mod not be compatible with 2.1 ? I don't understand... Most of my changes are put in a little modification, to make life a bit easier after upgrades...

Advertisement: