Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: Gargoyle - syyskuu 22, 2013, 03:17:23 IP

Otsikko: Trying to add a bit of info to display.template
Kirjoitti: Gargoyle - syyskuu 22, 2013, 03:17:23 IP
I am trying to display a bit of text for a specific member group in display template. This is the bit of code I am trying at the moment.

if (in_array(15, $message['member']['group']))
echo '
Supporting Member
';


The structure has changed a bit since the 1.x.x series and I cannot find the calls to the database to know how I need to word this, edit, add, etc... Guidance here would be appreciated.

Thanks!
Otsikko: Re: Trying to add a bit of info to display.template
Kirjoitti: Arantor - syyskuu 22, 2013, 03:23:20 IP
What, exactly, are you trying to do? Display a name if the user has group 15 as any kind of group (not just primary)?

As per 1.1.x, primary group is the only thing loaded, you might find it in $message['member']['group_id'] rather than group (which is the group's *name*)

Secondary groups are not ever loaded for topic display purposes.
Otsikko: Re: Trying to add a bit of info to display.template
Kirjoitti: Gargoyle - syyskuu 22, 2013, 03:42:00 IP
Yes I am trying to display the bit of text if group 15 is *any* group. Secondary or primary.

I remember having to add a bit of code to load the secondary groups into display before so I understand that. Was just easier for me to find the database calls in 1.1.x then it is now.

I am sure you know where I would need to go load that info... Any chance you could push me off a cliff?? I mean in the right direction?

Thanks!!

I tried using group_id but I am getting the same results... Still not calling the info. Hoping I can just find where the database fields get loaded and add a bit of code to load that info as well.
Otsikko: Re: Trying to add a bit of info to display.template
Kirjoitti: Arantor - syyskuu 22, 2013, 03:45:37 IP
LainaaI remember having to add a bit of code to load the secondary groups into display before so I understand that. Was just easier for me to find the database calls in 1.1.x then it is now.

You mean, despite the fact that the code is basically the same since 1.0 let alone 1.1... you still need to add it to the list of things added in loadMemberData and pulled through in loadMemberContext (*EXACTLY* as you would have in 1.1, in fact the only actual difference is that the database field is called additional_groups rather than additionalGroups)
Otsikko: Re: Trying to add a bit of info to display.template
Kirjoitti: Gargoyle - syyskuu 22, 2013, 04:18:45 IP
Yeah....

So I looked quite a bit. Tried a few things and really didnt get anywhere. All the code I see in front of me looks nothing like I used to see in 1.1

Although you have done so much more with this code than I have its not even measurable. I will continue to look around later on. I am pretty lost as this is the first time I have tried to actually massage this code in a few years.

Thanks for the tips and info. Just feeling over whelmed. But seriously thanks! You've helped a lot already and I am sure I will get it. :-)
Otsikko: Re: Trying to add a bit of info to display.template
Kirjoitti: Arantor - syyskuu 22, 2013, 04:28:55 IP
I'm not sure what the problem is, seriously... the code change you want to do is ALMOST IDENTICAL. The only real difference is in your mind and, to a point the template - but that's not really as big a difference as you seem to believe.


Step 1: Get actually get the data from the database.

loadMemberData, in Load.php
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,


Just add mem.additional_groups, (not forgetting the comma) to that.

Related snippet of code from 1.1.x:
if ($set == 'normal')
{
$select_columns = "
IFNULL(lo.logTime, 0) AS isOnline, IFNULL(a.ID_ATTACH, 0) AS ID_ATTACH, a.filename, a.attachmentType,
mem.signature, mem.personalText, mem.location, mem.gender, mem.avatar, mem.ID_MEMBER, mem.memberName,


Oh look how similar it is.

Step 2: Export it into $message['member'] so we can use it.

loadMemberContext, in Load.php
'group' => $profile['member_group'],
'group_color' => $profile['member_group_color'],
'group_id' => $profile['id_group'],


(this is part of a much, much larger list but this works)

Add:
'additional_groups' => !empty($profile['additional_groups']) ? explode(',', $profile['additional_groups']) : array(),

Related segment in 1.1.x...

'group' => $profile['member_group'],
'group_color' => $profile['member_group_color'],
'group_id' => $profile['ID_GROUP'],


Again, near enough identical. It's in the same function in roughly the same place down the list.


Step 3: Actually do the display in the template.

// Show the member's primary group (like 'Administrator') if they have one.
if (!empty($message['member']['group']))
echo '
<li class="membergroup">', $message['member']['group'], '</li>';


Now, I assume you're trying to put it directly under that in which case:
if ($message['member']['group_id'] == 15 || in_array(15, $message['member']['additional_groups']))
echo '
<li class="additional_group">Supporting Member</li>';


Now, I realise the code changed since 1.1 days however the equivalent piece of code from 1.1's Display.template.php:
// Show the member's primary group (like 'Administrator') if they have one.
if (isset($message['member']['group']) && $message['member']['group'] != '')
echo '
', $message['member']['group'], '<br />';


Even the comment is the same, just the check is very slightly different and the formatting changed but otherwise it's the same basic thing going on.

So, I'm sorry but the argument about it being very different is nonsense, because it really isn't.
Otsikko: Re: Trying to add a bit of info to display.template
Kirjoitti: Gargoyle - syyskuu 22, 2013, 04:43:18 IP
WOW!!!  Talk about a humbling experience...

Step 1 I had... Step 2... Not even close. And I would have never gotten that on my own. So thank you for that. Step 3 makes me feel like a nub.. (which I am but still). I have been away from it for so long I have forgotten so much about what to look for and structure of the indentation.

So you are absolutely correct... Code is really close and my mind wont let me see it.

Thank you for taking the time.