Adding custom profile field to memberlist

Discussion forum for MOD Writers regarding MOD Development.
User avatar
beggers
Registered User
Posts: 1257
Joined: Fri Nov 23, 2001 8:19 pm
Location: Las Vegas

Re: Adding custom profile field to memberlist

Post by beggers »

Very userful info! I've been wondering how to do that. Thanks.
User avatar
redryder
Registered User
Posts: 64
Joined: Mon May 26, 2008 9:45 pm

Re: Adding custom profile field to memberlist

Post by redryder »

codejunkie wrote:On the line just before the double parenthesis and semi-colon I added

Code: Select all

		'FNAME'			=> 'Full Name',
		'SORT_FNAME'					=> 'Full Name',
Adding these two lines allows your template to be language independent again.
ok, up to, and including the above, i'm good with.

having trouble with the rest. actually, i 'think' the only part i'm having trouble with is the sorting portion.

previous to being pointed to this thread, i had already managed to add a custom profile field and have it show up on the memberlist as this image shows.
Image

the code changes from CodeJunkie has fixed my curly bracket issue already. :D

but here is where i seem to be confused . . .
codejunkie wrote:We can now change it to read as

Code: Select all

<th><a href="{U_SORT_FNAME}#memberlist">{L_FNAME}</a></th>
change what? where? i do not find that line in my membership_body file.


codejunkie wrote:Fortunately, we only need to modify one more file, memberlist.php, which is found in your root folder "/" of your installed phpbb forum.

Several places will need to be modified or added to. Starting at around line 900, I added

Code: Select all

		$sort_key_text['y'] = $user->lang['SORT_FNAME'];
		$sort_key_sql['y'] = 'fd.pf_fname';
The SORT_FNAME matches the previous edit to the common.php file. The pf_fname is a field name as found in the profile_fields_data table. The fd. is for a future abbreviation in a SQL statement.
i dropped that code in where it goes. pretty sure that 'that's' okay. i just changed FNAME to BIKE and fname to bike. anything i missed there?


codejunkie wrote:Now, scroll down to about line 1309 and look for

Code: Select all

// Get us some users :D
After that line and depending on how many custom fields you wanted to add, you need to add some type of conditional statement. Since I only wanted to add one new field / column to my memberlist page, I chose an if statement.

Code: Select all

if(isset($sort_key_sql['y'])) {
			$sql = "SELECT u.user_id
			        FROM " . USERS_TABLE . " u
			        $sql_from
			        LEFT JOIN " . PROFILE_FIELDS_DATA_TABLE . " fd ON (u.user_id = fd.user_id)
			        WHERE u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ")
			        $sql_where
			        ORDER BY $order_by";
		} else {
but from that 'if' statement on, is where i know i'm missing something.

the above piece of code, am i to literally just copy and paste that, as is, where you said too? does something in there need to be changed for my specific memberlist fields?


codejunkie wrote:Now, you need to add a closing bracket "}" after the previous SQL statement at about line 1325 to complete the if statement.

Code: Select all

}
i realize that the line numbers differ from style template to style template, but i'm still not sure where that closing bracket is supposed to go. tho, might be that once i'm clear on the above code itself, it'll be more obvious where to place the closing bracket.


codejunkie wrote:One more addition is needed to get your link to show up on the column for sorting. At around line 1470 or so I added

Code: Select all

'U_SORT_FNAME'		=> $sort_url . '&sk=y&sd=' . (($sort_key == 'y' && $sort_dir == 'a') ? 'd' : 'a'),
can this go anywhere within the 'U_SORT_' section?



thanks in advance for all the help with this . . i'm learning as i go! and while i really actually enjoy researching and figuring these things out on my own, as best i can, this is one thing i really need to get figured out as quickly as possible!

thanks again!

~ deanna ~
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53523
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}

Re: Adding custom profile field to memberlist

Post by Brf »

redryder wrote: i do not find that line in my membership_body file.
Of course not.
As it says, that is what you change your header line "to", not "from". That would be the part you said you "fixed the curly brackets" in.
codejunkie
Registered User
Posts: 26
Joined: Sun Jul 06, 2008 5:29 am

Re: Adding custom profile field to memberlist

Post by codejunkie »

redryder wrote:the code changes from CodeJunkie has fixed my curly bracket issue already. :D
That's good to know. ;)
redryder wrote: but here is where i seem to be confused . . .
codejunkie wrote:We can now change it to read as

Code: Select all

<th><a href="{U_SORT_FNAME}#memberlist">{L_FNAME}</a></th>
change what? where? i do not find that line in my membership_body file.
This bit of code is not currently in the memberlist.html file. That was what would have replaced the code brf used for your column header, which you state you have fixed already.
redryder wrote:
codejunkie wrote:Fortunately, we only need to modify one more file, memberlist.php, which is found in your root folder "/" of your installed phpbb forum.

Several places will need to be modified or added to. Starting at around line 900, I added

Code: Select all

		$sort_key_text['y'] = $user->lang['SORT_FNAME'];
		$sort_key_sql['y'] = 'fd.pf_fname';
The SORT_FNAME matches the previous edit to the common.php file. The pf_fname is a field name as found in the profile_fields_data table. The fd. is for a future abbreviation in a SQL statement.
i dropped that code in where it goes. pretty sure that 'that's' okay. i just changed FNAME to BIKE and fname to bike. anything i missed there?
As long as it is in the area of the other $sort_key_text[] variables, it should be fine.
redryder wrote:
codejunkie wrote:Now, scroll down to about line 1309 and look for

Code: Select all

// Get us some users :D
After that line and depending on how many custom fields you wanted to add, you need to add some type of conditional statement. Since I only wanted to add one new field / column to my memberlist page, I chose an if statement.

Code: Select all

if(isset($sort_key_sql['y'])) {
			$sql = "SELECT u.user_id
			        FROM " . USERS_TABLE . " u
			        $sql_from
			        LEFT JOIN " . PROFILE_FIELDS_DATA_TABLE . " fd ON (u.user_id = fd.user_id)
			        WHERE u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ")
			        $sql_where
			        ORDER BY $order_by";
		} else {
That is the SQL statement that is called when you select your new column for sorting. It goes right before the original SQL statement, which is found at line number 1298 in a clean memberlist.php file and right after the "//Get us some users :D" line. Here is the SQL code that it goes before.

Code: Select all

		$sql = "SELECT u.user_id
			FROM " . USERS_TABLE . " u
				$sql_from
			WHERE u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ")
				$sql_where
			ORDER BY $order_by";
redryder wrote: but from that 'if' statement on, is where i know i'm missing something.

the above piece of code, am i to literally just copy and paste that, as is, where you said too? does something in there need to be changed for my specific memberlist fields?
I don't think so. I think that code will work for you as is.
redryder wrote:
codejunkie wrote:Now, you need to add a closing bracket "}" after the previous SQL statement at about line 1325 to complete the if statement.

Code: Select all

}
i realize that the line numbers differ from style template to style template, but i'm still not sure where that closing bracket is supposed to go. tho, might be that once i'm clear on the above code itself, it'll be more obvious where to place the closing bracket.
That goes immediately after the SQL statement I just posted and before this code.

Code: Select all

		$result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
redryder wrote:
codejunkie wrote:One more addition is needed to get your link to show up on the column for sorting. At around line 1470 or so I added

Code: Select all

'U_SORT_FNAME'		=> $sort_url . '&sk=y&sd=' . (($sort_key == 'y' && $sort_dir == 'a') ? 'd' : 'a'),
can this go anywhere within the 'U_SORT_' section?
Yes, it can.
redryder wrote:


thanks in advance for all the help with this . . i'm learning as i go! and while i really actually enjoy researching and figuring these things out on my own, as best i can, this is one thing i really need to get figured out as quickly as possible!

thanks again!

~ deanna ~
Hopefully, this post will help you and others in the future. I'll try to upload a MODX for these changes later. This mod is my first one, EVER.
codejunkie
Registered User
Posts: 26
Joined: Sun Jul 06, 2008 5:29 am

Re: Adding custom profile field to memberlist

Post by codejunkie »

Link to MODX file for custom profile field sort on memberlist page.
User avatar
redryder
Registered User
Posts: 64
Joined: Mon May 26, 2008 9:45 pm

Re: Adding custom profile field to memberlist

Post by redryder »

codejunkie wrote:

Code: Select all

}
believe it or not, THAT was the only thing i had out of place and it was throwing everything off! so my column is showing, and sorting and is also in the drop down sort menu and i am one happy camper!

thank you SOOOOOO VERY MUCH!!!

codejunkie wrote:Hopefully, this post will help you and others in the future. I'll try to upload a MODX for these changes later. This mod is my first one, EVER.
oh i'm sure it will help many people!
User avatar
redryder
Registered User
Posts: 64
Joined: Mon May 26, 2008 9:45 pm

Re: Adding custom profile field to memberlist

Post by redryder »

ok, one more quick question . . . just for future reference . . . ;)

say i want to remove the post count column, not only from the memberlist page, but also from the sorting drop down menu . . . can i just remove those lines of code? turn them off? or is that even more involved than adding them in?

thanks so much!

~ deanna ~
codejunkie
Registered User
Posts: 26
Joined: Sun Jul 06, 2008 5:29 am

Re: Adding custom profile field to memberlist

Post by codejunkie »

redryder wrote:ok, one more quick question . . . just for future reference . . . ;)

say i want to remove the post count column, not only from the memberlist page, but also from the sorting drop down menu . . . can i just remove those lines of code? turn them off? or is that even more involved than adding them in?

thanks so much!

~ deanna ~
You could either comment out or delete the code in your memberlist_body.html file. The links would still work for sorting, but they would not be published and your members would need to manually surf to that url. If you wanted to go even further you could edit the memberlist.php file searching for 'd' where it points to the posts field, but the memberlist_body.html edit should do the job.
richard lee
Registered User
Posts: 73
Joined: Mon Mar 31, 2008 1:07 am

Re: Adding custom profile field to memberlist

Post by richard lee »

I used codiejunkie's code from the page 1-2 of this thread (rather than the MODX), and it works fine, but now I'm getting a couple of errors that may or may not be related:

UCP > Usergroups > Any Group:

Code: Select all

SQL ERROR [ mysql4 ]

Unknown column 'u.user_id' in 'on clause' [1054]

SQL

SELECT u.user_id FROM phpbb_users u , phpbb_user_group ug LEFT JOIN phpbb_profile_fields_data fd ON (u.user_id = fd.user_id) WHERE u.user_type IN (0, 3) AND ug.user_pending = 0 AND u.user_id = ug.user_id AND ug.group_id = 2 ORDER BY ug.group_leader DESC, u.user_regdate ASC LIMIT 25

BACKTRACE

FILE: includes/db/mysql.php
LINE: 158
CALL: dbal->sql_error()

FILE: includes/db/mysql.php
LINE: 205
CALL: dbal_mysql->sql_query()

FILE: includes/db/dbal.php
LINE: 157
CALL: dbal_mysql->_sql_query_limit()

FILE: memberlist.php
LINE: 1316
CALL: dbal->sql_query_limit()
Also, mass email doesn't work for most groups (though it does work for admins -- weird). We get

Code: Select all

[ADMIN NAME] [ADMIN IP] Sat Aug 09, 2008 8:13 pm E-mail error
» EMAIL/PHP/mail()
/adm/index.php
Any ideas what's going on? Can I fix this with or without doing the MODX version?
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53523
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}

Re: Adding custom profile field to memberlist

Post by Brf »

Some configurations of Mysql do not handle mixing implicit joins with explicit joins.
Try putting parenthesis here:

Code: Select all

FROM (phpbb_users u , phpbb_user_group ug) LEFT JOIN 
codejunkie
Registered User
Posts: 26
Joined: Sun Jul 06, 2008 5:29 am

Re: Adding custom profile field to memberlist

Post by codejunkie »

Just discovered this over the weekend. I have not had a chance to look into it further. I think, if you put an additional check in the if statement where the sql statement is assigned to check if the mode is not equal to group, then it should work. I don't have access to my initial testing on a fix at the moment.
richard lee
Registered User
Posts: 73
Joined: Mon Mar 31, 2008 1:07 am

Re: Adding custom profile field to memberlist

Post by richard lee »

Brf wrote:Some configurations of Mysql do not handle mixing implicit joins with explicit joins.
Try putting parenthesis here:

Code: Select all

FROM (phpbb_users u , phpbb_user_group ug) LEFT JOIN 
Does this just replace

Code: Select all

FROM " . USERS_TABLE . " u
                 $sql_from
                 LEFT JOIN
in the new "if" sql request?
richard lee
Registered User
Posts: 73
Joined: Mon Mar 31, 2008 1:07 am

Re: Adding custom profile field to memberlist

Post by richard lee »

codejunkie wrote:Just discovered this over the weekend. I have not had a chance to look into it further. I think, if you put an additional check in the if statement where the sql statement is assigned to check if the mode is not equal to group, then it should work. I don't have access to my initial testing on a fix at the moment.
wait, forget that previous question. Codiejunkie's extra condition

Code: Select all

if($mode != 'group' && isset($sort_key_sql['y'])) {
worked on the UCP Usergroups issue... except now it's throwing off table formatting. I get this when I search by group:

Image
codejunkie
Registered User
Posts: 26
Joined: Sun Jul 06, 2008 5:29 am

Re: Adding custom profile field to memberlist

Post by codejunkie »

richard lee wrote:
codejunkie wrote:Just discovered this over the weekend. I have not had a chance to look into it further. I think, if you put an additional check in the if statement where the sql statement is assigned to check if the mode is not equal to group, then it should work. I don't have access to my initial testing on a fix at the moment.
wait, forget that previous question. Codiejunkie's extra condition

Code: Select all

if($mode != 'group' && isset($sort_key_sql['y'])) {
I believe that is what I came up with.
richard lee wrote: worked on the UCP Usergroups issue... except now it's throwing off table formatting.
You'll need to modify the memberlist.html file from your assigned style. There is a line regarding colspan.
cpenticuff
Registered User
Posts: 7
Joined: Sat Sep 24, 2005 8:24 pm

Re: Adding custom profile field to memberlist

Post by cpenticuff »

I just happened to stumple on this post. I have read all the way through it but am still having trouble.

I am using the prosilver theme.
I have a custom profile field that appears as "Real Name" to the user and has a field id of "real_name."
I want this field to appear on the memberlist, but I don't want it to have it's own column. I want to add it to the WEBSITE, LOCATION column. Can anyone tell me how I would go about doing this?

Return to “[3.0.x] MOD Writers Discussion”