I am exceedingly new to Drupal.
I need to set a user's created field value in the current session without saving it to the database, necessarily.
I have a website that reflects membership in a home builders' association with users who have been members of the association for many years, but are only being added to the website as users recently. Therefore, the site shows them as being members for a short time instead of for a long time.
I have added a custom field for when they joined the association, and I have had it where I can get that info and change the user info and save it to the database (in user-profile-item.tpl.php), but it only changes the info on subsequent database calls instead of for the current session. I've also tried changing the $user_profile variable in user-profile.tpl.php, but that did not change anything for the current session, either. I don't mind changing the database, but how do I update the created field value in the current session?
Website: http://certifiedmasterbuilder.com
This is what i tried :
global $user;
$user = user_load($user_profile['field_zip']['#object']->uid);
$join_date = field_get_items('user', $user, 'field_join_date')[0]['value']; $user->created = $join_date;
$user_save($user); // <-- This saves it to the database, but does not update the //current session value
// I tried this to update the current session, but it does not work
field_attach_update('user', $user);
entity_get_controller('user')->resetCache(array($user->uid));
I got it working by editing user-profile-item.tpl.php. I got the user profile we are viewing, retrieved the field value I want, checked to see if it contains a value which is different than the user's created date, then changed the $value variable to the formatted date:
$user = user_load(arg(1)); // Make sure the user object is fully loaded
$join_date = field_get_items('user', $user, 'field_join_date')[0]['value'];
if( $join_date > 0 && $user->created != $join_date )
{
$value = format_interval(REQUEST_TIME - $join_date);
}
My only question is if there is a better way to get the user id besides using arg(1). I heard that was not a very good way to do that.