News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Include reason for joining in profile.

Started by Jeff B, March 02, 2018, 01:02:08 PM

Previous topic - Next topic

Jeff B

I've used the reason for joining mod for many many years, and it has been most helpful. I realize I could use custom profile fields to do this now, but we have all those years of data in the join_reason field I want to keep and be able to refer back to.  Problem is, unless you go into phpmyadmin there is really no way to view it.  We like the way it displays now when approving members, so that is the reason for keeping the mod.

Anyhow, can someone help me with some code to include it in a user profile, so only admins can see it?  This is what I tried innitially, but the reason does not show up. I am guessing I need to define it somewhere?


echo '
<dt>', $txt['join_reason'], ': </dt>
<dd>', $context['member']['join_reason'], '</dd>';

Kindred

Why not just move the data from the reason field to a custom field?    That would basically take a single sql statement in phpmyadmin...
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Jeff B

If you add a custom profile field that is required on registration, does that then appear on the approve members page so it can be looked at like the mod does?  Or would you have to actually go to the profile and look at it? I was assuming not.   That is what I am trying to avoid. If we get multiple registration requests before they can be addressed, we can easily look at them all in one spot without having to go to each profile.  Its a large forum and all registrations are screened.  I think we've had almost 800 approved new members this year

Jeff B

I did run a test and added a custom profile field for registration. As I suspected, the data does not show up on the members waiting for approval. I think that what I seek is the best solution for me.  So with that... :)

I can fix an old truck but this is mostly beyond me.  :)

vii

Edit: Sorry, I forgot to mention, this is for adding a custom field. I know you were asking about something else before, but this was more straight-forward in my opinion, and it does what you were asking about after the first post, with the approval page and what not.
-

I have to admit, I thought this would be a quick one, but I am realizing now how much more complicated even generating just the member list is in SMF 2.0 (I've just done a bunch of SMF 1.1.21 coding in my spare time).


This is what I was able to do. Bare in mind that this is just what I was able to slap together in about 30 minutes:


1. Find this code in Sources/ManageMembers.php :


'ip' => array(
'header' => array(
'value' => $txt['ip_address'],
),
'data' => array(
'sprintf' => array(
'format' => '<a href="' . strtr($scripturl, array('%' => '%%')) . '?action=trackip;searchip=%1$s">%1$s</a>',
'params' => array(
'member_ip' => false,
),
),
),
'sort' => array(
'default' => 'INET_ATON(member_ip)',
'reverse' => 'INET_ATON(member_ip) DESC',
),
),



Add this as another entry in the array after it (you can add it somewhere else, but where you add it in this array determines where it will appear on the approve users list):

Important Note: You need to change the name of "cust_join_r" to whatever the custom col name of your custom profile field is. Otherwise it won't work.


// mod - add Reason for join custom profile field to approve list
'reason' => array(
'header' => array(
'value' => 'Reason for joining',
),
'data' => array(
'function' => create_function('$rowData', '
global $user_profile;

loadMemberData($rowData[\'id_member\'], false, \'profile\');

return $user_profile[$rowData[\'id_member\']][\'options\'][\'cust_join_r\'];
'),
'class' => 'windowbg',
),
'sort' => array(
'default' => 'join_reason',
'reverse' => 'join_reason DESC',
),
),
// end - end custom code


If you want to find the column name of your custom profile field, it's in the database table "custom_fields" (or rather: {$db_prefix}custom_fields). It would the text in the table column "col_name"


Attached is a screenshot of what the result looks like

Jeff B

That looks like it would work nicely!  Two more questions.  First, how would the sql statement be formed to copy the existing data from the the join_reason in the smf_members table to the new column in custom_fields table

and

How would you make the field required on registration?  It appears there are no options in the custom fields creation to require a field

vii

Well thinking about it more, you could move to the custom fields like talked about before, I could put together a quickie php script to copy the data from members.join_reason to the custom field

This is the page to add a custom field. There are a ton of options to customize it, including only letting an admin see. It should be plainly visible on this page: [your forum.com]index.php?action=admin;area=featuresettings;sa=profileedit

-

or you could just add the data to the profile field like in your first post. The reason it's not working, probably, is because the join_reason column is not actually be fetched from the db and put into the $context array. I'm not sure what mod you are using, so I can't be sure if it's actually fetching that data or not, but I presume not.

vii

If the join_reason column is indeed not being plucked from the database, then the fix would be to add it to the query in loadMemberData, which is in Sources/Load.php:

Find:


function loadMemberData($users, $is_name = false, $set = 'normal')


A couple dozen lines inside the loadMemberData function, you should find this:


elseif ($set == 'profile')
{
$select_columns = '
IFNULL(lo.log_time, 0) AS is_online, IFNULL(a.id_attach, 0) AS id_attach, a.filename, a.attachment_type,
mem.signature, mem.personal_text, mem.location, mem.gender, mem.avatar, mem.id_member, mem.member_name,
mem.real_name, mem.email_address, mem.hide_email, mem.date_registered, mem.website_title, mem.website_url,
mem.openid_uri, mem.birthdate, mem.icq, mem.aim, mem.yim, mem.msn, mem.posts, mem.last_login, mem.karma_good,
mem.karma_bad, mem.member_ip, mem.member_ip2, mem.lngfile, mem.id_group, mem.id_theme, mem.buddy_list,
mem.pm_ignore_list, mem.pm_email_notify, mem.pm_receive_from, mem.time_offset' . (!empty($modSettings['titlesEnable']) ? ', mem.usertitle' : '') . ',
mem.time_format, mem.secret_question, mem.is_activated, mem.additional_groups, mem.smiley_set, mem.show_online,
mem.total_time_logged_in, mem.id_post_group, mem.notify_announcements, mem.notify_regularity, mem.notify_send_body,
mem.notify_types, lo.url, mg.online_color AS member_group_color, IFNULL(mg.group_name, {string:blank_string}) AS member_group,
pg.online_color AS post_group_color, IFNULL(pg.group_name, {string:blank_string}) AS post_group, mem.ignore_boards, mem.warning,
CASE WHEN mem.id_group = 0 OR mg.stars = {string:blank_string} THEN pg.stars ELSE mg.stars END AS stars, mem.password_salt, mem.pm_prefs';


So maybe add it to the line that begins with mem.signature, like this:


mem.signature, mem.personal_text, mem.location, mem.gender, mem.avatar, mem.id_member, mem.member_name, mem.join_reason,


^(again, assuming, join_reason is the name of the db column. You need to be careful about this when editing sql queries)


It's my assumption that once you make the above modification, the join_reason column should be available to you in the $context code you provided in your very first post in this thread. If so, you can wrap a conditional statement around it that checks for admin privileges, so it only shows up for Administrators:


if ( allowedTo('admin_forum') ) {
echo '
<dt>', $txt['join_reason'], ': </dt>
<dd>', $context['member']['join_reason'], '</dd>';
}

Kindred

Custom fields are stored in the smf_themes table
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Jeff B

join_reason is definitely in smf_members  in my database.

vii

Quote from: Jeff B on March 02, 2018, 09:40:06 PM
join_reason is definitely in smf_members  in my database.

I wasn't asking if it was in the db table but rather if the loadMemberData was actually pulling it from the db. If you have a mod that adds their own columns to it, they usually have to add it to that function if they want it to be available to basic things like profiles and message view.

Check the db queries from loadMemberData like I was referring to in my last post, and add if it necessary as described.

Jeff B

I tried the edit to load.php and the data would still not propagate into the profile edits

vii

Quote from: Jeff B on March 02, 2018, 11:27:43 PM
I tried the edit to load.php and the data would still not propagate into the profile edits

Ok, I found out why. The loadMemberContext function in Load.php also needs to be modified. So in addition to adding "join_reason" to the sql query in loadMemberData, you need to do this in Load.php:

Find:


// What a monstrous array...
$memberContext[$user] = array(
'username' => $profile['member_name'],


Replace it with this:


// What a monstrous array...
$memberContext[$user] = array(
'username' => $profile['member_name'],
'join_reason' => !empty($profile['join_reason']) ? $profile['join_reason'] : '',



I added a test column to the members table called join_reason then followed all my own steps and I was able to successfully implement what you are trying to do. $context['member']['join_reason'] contained the data you are after.

Let me know how it goes.

aegersz

i came up with a batch solution to copy all join reasons from the mod to my new profile field via the DB.

it is documented in the mod comments and linked to my method.

it might help in someway.
The configuration of my Linux VPS (SMF 2.0 with 160+ mods & some assorted manual tweaks) can be found here and notes on my mods can be found here (warning: those links will take you to a drug related forum). My (House) music DJ dedication page is here

Jeff B

EUREKA!

One thing though to make it work,  I had to also add  mem.join_reason here as well, perhaps because I am using smfpack's socialprofile?:

if ($set == 'normal')
{
$select_columns = '
IFNULL(lo.log_time, 0) AS is_online, IFNULL(a.id_attach, 0) AS id_attach, a.filename, a.attachment_type,
mem.signature, mem.personal_text, mem.location, mem.gender, mem.avatar, mem.id_member, mem.member_name, mem.join_reason,


Thanks a ton!   However...  Can we go a step further?  My forum has been around 18 years.  The first couple thousand members did not have to give a reason for joining, so their column is empty. Is there an if statement we could include to assign text to appear if the field is empty?

vii

Re-modify Load.php:loadMemberContext


// What a monstrous array...
$memberContext[$user] = array(
'username' => $profile['member_name'],
'join_reason' => !empty($profile['join_reason']) ? $profile['join_reason'] : 'N/A',


If you wanted to be fancy about it, I suppose you could change N/A to <i>N/A</i> so you can differentiate between a rare instance where a user themselves inputs N/A and when the reason is actually not available.

Jeff B

Thank you!

  Now, if I wanted to get cute, and provide some random text via a random text script, can I put an include in there to direct to the script instead of the N/A?   If my php script was named randomtext.php for example...


Jeff B

I was able to accomplish that script part by myself.  THANK YOU!!

Jeff B

I'm going to mark this as solved.  I decided to use the new function publicly. Members can go in and see what members back to 2010 and see what the reasons were for joining. Members that joined prior to that, back to 2000, we are having fun with that. The member reason function if empty, returns a random text script with made up reasons for joining. I came up with about 75 bogus reasons that people joined and each time that part of the profile is viewed, a random reason is displayed with a disclaimer that is it is a random reason generated by the Forum.  Pretty fun and the members like it.

Example:
I have been around the forum since before they required a reason starting April 11th, 2010.
The Forestry Forum has generously generated a random reason for me!

I heard if I joined I could get Free Health care.

Example:

I have been around the forum since before they required a reason starting April 11th, 2010.
The Forestry Forum has generously generated a random reason for me!

I made a bet and I need someone to prove I'm right even if I'm not.

Example:

I have been around the forum since before they required a reason starting April 11th, 2010.
The Forestry Forum has generously generated a random reason for me!

I need someone to help me look for ticks.



Advertisement: