Need help on converting Display Additional Membergroups on Profile mod to 2.0

Started by Yağız..., September 19, 2009, 01:49:21 PM

Previous topic - Next topic

Yağız...

Default code:

// Begin modification - Additional membergroups on profile
// Let's start with an empty array
$user_profile[$row['ID_MEMBER']]['additionalGroups2'] = array();

// Any additional membergroups for this user?
if (isset($row['additionalGroups']) && $row['additionalGroups'] != '')
{
// There is? Great! Get the names of the groups
$result_groups = db_query("
SELECT groupName
FROM {$db_prefix}membergroups
WHERE ID_GROUP IN (" . $row['additionalGroups'] . ')
ORDER BY groupName ASC', __FILE__, __LINE__);

// Loop through all the groups...
while ($row_groups = mysql_fetch_assoc($result_groups))
// ... and add them to the user's list
$user_profile[$row['ID_MEMBER']]['additionalGroups2'][] = $row_groups['groupName'];

mysql_free_result($result_groups);
}
// End modification

The code that i converted to SMF 2.0:
// Begin modification - Additional membergroups on profile
// Let's start with an empty array
$user_profile[$row['id_member']]['additional_groups2'] = array();

// Any additional membergroups for this user?
if (isset($row['additional_groups']) && $row['additional_groups'] != '')
{
// There is? Great! Get the names of the groups
$result_groups = $smcFunc['db_query']('', '
SELECT group_name
FROM {db_prefix}membergroups
WHERE id_group IN (' . count($row['additional_groups']) == 1 ? '{string:groups}' : '{array_string:groups}' . ')
ORDER BY group_name ASC',
array(
'groups' => $row['additional_groups'],
)
);

// Loop through all the groups...
while ($row_groups = $smcFunc['db_fetch_assoc']($result_groups))
// ... and add them to the user's list
$user_profile[$row['id_member']]['additional_groups2'][] = $row_groups['group_name'];

$smcFunc['db_free_result']($result_groups);
}
// End modification


I'm getting this error on profile page: Wrong value type sent to the database. Array of strings expected. (groups)

User has 1 additional group.

Özgür

I think problem is
count($row['additional_groups']) == 1
Can you try echo $row['additional_groups']  and see results ?
And why you use the count, you must use !empty() (:
So Long

Yağız...

Quote from: [Daydreamer] on September 19, 2009, 03:55:49 PM
I think problem is
count($row['additional_groups']) == 1
Can you try echo $row['additional_groups']  and see results ?
And why you use the count, you must use !empty() (:
No, because I need to get the count of additionl groups, not to check if it's empty or not :)

Özgür

Hmm. But if $row['additional_groups'] is empty? if = 1 use the string, if not 1 use the array_string. But if empty ? =)
So Long

Yağız...

Quote from: [Daydreamer] on September 19, 2009, 05:20:12 PM
Hmm. But if $row['additional_groups'] is empty? if = 1 use the string, if not 1 use the array_string. But if empty ? =)
Hmm, you can be right :) I'll try to it and write the result there.

Arantor

Um, I think part of the problem is that array_string is - as the name implies - an array of strings. Membergroups when they are already extracted are not in an array_string type; they are in a simple string.
Holder of controversial views, all of which my own.


Yağız...

Solved :)
// Begin modification - Additional membergroups on profile
// Let's start with an empty array
$user_profile[$row['id_member']]['additional_groups2'] = array();

// Any additional membergroups for this user?
if (isset($row['additional_groups']) && $row['additional_groups'] != '')
{
// There is? Great! Get the names of the groups
$result_groups = $smcFunc['db_query']('', '
SELECT group_name
FROM {db_prefix}membergroups
WHERE id_group IN ({array_int:groups})
ORDER BY group_name ASC',
array(
'groups' => explode(',', $row['additional_groups']),
)
);

// Loop through all the groups...
while ($row_groups = $smcFunc['db_fetch_assoc']($result_groups))
// ... and add them to the user's list
$user_profile[$row['id_member']]['additional_groups2'][] = $row_groups['group_name'];

$smcFunc['db_free_result']($result_groups);
}
// End modification

Alpay

Rc 1.x Version

Quote from: [SiNaN] on September 23, 2009, 06:16:17 AM
Display.php

Code (Find) Select
SELECT id_msg, id_member, approved
FROM {db_prefix}messages
WHERE id_topic = {int:current_topic}' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : (!empty($modSettings['db_mysql_group_by_fix']) ? '' : '
GROUP BY id_msg') . '
HAVING (approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR id_member = {int:current_member}') . ')') . '
ORDER BY id_msg ' . ($ascending ? '' : 'DESC') . ($context['messages_per_page'] == -1 ? '' : '


Code (Replace) Select
SELECT m.id_msg, m.id_member, m.approved, mem.additional_groups
FROM {db_prefix}messages AS m
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
WHERE m.id_topic = {int:current_topic}' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : (!empty($modSettings['db_mysql_group_by_fix']) ? '' : '
GROUP BY m.id_msg') . '
HAVING (m.approved = {int:is_approved}' . ($user_info['is_guest'] ? '' : ' OR m.id_member = {int:current_member}') . ')') . '
ORDER BY m.id_msg ' . ($ascending ? '' : 'DESC') . ($context['messages_per_page'] == -1 ? '' : '


Code (Find) Select
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if (!empty($row['id_member']))
$posters[] = $row['id_member'];


Code (Replace) Select
$context['add_groups'] = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if (!empty($row['id_member']))
{
$posters[] = $row['id_member'];
if (!empty($row['additional_groups']))
$context['add_groups'][$row['id_member']] = $row['additional_groups'];
}


Code (Find) Select
// If there _are_ messages here... (probably an error otherwise :!)

Code (Replace) Select
if (!empty($context['add_groups']))
{
$groups = array();
foreach ($context['add_groups'] as $group)
$groups += explode(',', $group);

$request = $smcFunc['db_query']('', '
SELECT id_group, group_name
FROM {db_prefix}membergroups
WHERE id_group IN ({array_int:groups})
LIMIT {int:limit}',
array(
'groups' => array_unique($groups),
'limit' => count($groups),
)
);
$context['all_groups'] = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$context['all_groups'][$row['id_group']] = $row['group_name'];
$smcFunc['db_free_result']($request);
}

// If there _are_ messages here... (probably an error otherwise :!)


Code (Find) Select
$memberContext[$message['id_member']]['is_topic_starter'] = $message['id_member'] == $context['topic_starter_id'];

Code (Replace) Select
$memberContext[$message['id_member']]['is_topic_starter'] = $message['id_member'] == $context['topic_starter_id'];

if (!empty($context['add_groups'][$message['id_member']]) && !isset($memberContext[$message['id_member']]['additional_groups']))
{
$m_groups = explode(',', $context['add_groups'][$message['id_member']]);
foreach ($m_groups as $group)
$memberContext[$message['id_member']]['additional_groups'][] = $context['all_groups'][$group];
}


Display.template.php

Code (Find) Select
// Don't show these things for guests.

Code (Replace) Select
if (!empty($message['member']['additional_groups']))
foreach ($message['member']['additional_groups'] as $add_group)
echo '
<li>', $add_group, '</li>';

// Don't show these things for guests.


Alpay

There are a few problems..

1.
Wrong value type sent to the database. Array of integers expected. (groups)
Function: loadMemberData

File: /home/omerkoro/public_html/forum/Sources/Display.php
Line: 1109

==>1109:   );

2.
Quote from: mrtrc266 on November 10, 2009, 12:21:47 PM
After doing this edit my error log gets flooded with the following...

8: Undefined index:  42
File: /home/content/f/e/l/feltfanatics/html/worldteampoker/Sources/Display.php
Line: 1136                           

Which point to here
==>1136:                 $memberContext[$message['id_member']]['additional_groups'][] = $context['all_groups'][$group];


Any ideas?

Thanks in advance.

Advertisement: