News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Getting user info

Started by thisisedy, April 20, 2014, 05:33:04 AM

Previous topic - Next topic

thisisedy

Hi ! How can i get some data from action=profile page of a logged in user to be displayed on every page(index.template file)  somewhere in header section (as a mini-profile card)?

I got avatar and username using :

echo '
<img src="', $context['user']['avatar']['href'], '" alt="', $txt['profile'], '" /> ', $context['user']['name'], ' ';
but i still need membergroup,current posts, etc  ::)


margarett

Try to
echo '<pre>';
print_r ($context['user']);
echo '</pre>';

And you can see what's in the structure :-)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

thisisedy

That's the way i did it to get avatar and name , but i have no clue how to get the rest .

thisisedy

Browsing the forum , i found about $user_info , which i globalized , but still no membergroup name output there , just ID's .

[groups] => Array
        (
            [0] => 1
            [1] => 4
        )


I can do this for admins :
if ($user_info['groups']['0'] == 1)
{
echo 'Admin';
}

but i got alot of custom membergroups . ;D Is there some array with all my group names ?

margarett

Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Kindred

that's right...   because membergroups are never identified int he user record by NAME...   if we did that, the system would have to re-write every user record if you changed any membergroup name...


So, the membergroups are referred to by ID and then JOINed to the membergroup table to pull the name
Сл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."

thisisedy

Quote from: margarett on April 21, 2014, 03:20:49 PM
For the membergroups maybe you can install this
http://custom.simplemachines.org/mods/index.php?mod=3805

Well , it's the same thing for me . Those aditional membergroups will display only in profile/topics view and i need the data on every page .

//Show additional groups, if the user has some attributed
if (!empty($modSettings['show_additional_groups']) && !empty($context['member']['additional_groups_full'])) {
echo '<dl>';
foreach($context['member']['additional_groups_full'] as $temp) {
echo '
<dt>', $txt['additional_membergroups'], ':</dt>
<dd>', $temp['group'], '</dd>';
}
echo '</dl>';
}

margarett

I'll give a look at it but I think it must be loaded everywhere...
Be right back :)
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

margarett

You are right, this data is not called at index because loadMemberData is not called here...

If you globalize $user_info, you have an array with all membergroups the user belongs to. You can add a query that fetches the group data of those, maybe... You'll be adding an extra query to each page load (not that much if you cache it...).
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Dragooon

You'll have to load the groups separately if you want to ensure that they are available on every page, since afaik they're loaded only on topic display, profile and certain admin areas (which can also be dodgy since they needn't be the current active user). What you want to do is query {db_prefix}membergroups table and load them by filtering their IDs from $use_info['groups'], preferably somewhere around the end of loadUserSettings function in Load.php

thisisedy

Quote from: Dragooon on April 23, 2014, 10:08:16 AM
You'll have to load the groups separately if you want to ensure that they are available on every page, since afaik they're loaded only on topic display, profile and certain admin areas (which can also be dodgy since they needn't be the current active user). What you want to do is query {db_prefix}membergroups table and load them by filtering their IDs from $use_info['groups'], preferably somewhere around the end of loadUserSettings function in Load.php

Can you please post the snippet when you got time ? I'm not that good in php  :-X

Dragooon

	
$request $smcFunc['db_query']('''
	
	
SELECT id_group, group_name
	
	
FROM {db_prefix}membergroups
	
	
WHERE id_group IN ({array_int:groups})'
,
	
	
array(
	
	
	
'groups' => $user_info['groups'],
	
	
)
	
);
	
$user_info['groupinfo'] = array();
	
while (
$group $smcFunc['db_fetch_assoc']($request))
	
	
$user_info['groupinfo'][$group['id_group']] = $group['group_name'];
	
$smcFunc['db_free_result']($request);


Place that at the end of Load.php -> loadUserSettings()

thisisedy

Works like a charm ; Thanks Dragooon !  ;D

Advertisement: