PDA

View Full Version : Make a user's ranks update? Plugin help.


drew010
06-26-2006, 07:23 AM
if ($foruminfo['forumid'] == 38)
{
$splitvotes = explode('|||', $pollinfo['votes']);
if ($splitvotes[0] >= 1)
{
$user = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE `userid`=".$db->sql_prepare($vbulletin->userinfo['userid']));
if ($user['membergroupids'] == '')
{
$membergroupids = $user['usergroupid'];
} else {
$membergroupids .= "," . $user['usergroupid'];
}
$groups = explode(",", $membergroupids);
if (!in_array(9, $groups))
{
if ($user['usergroupid'] == 4)
{
$user['usergroupid'] = 9;
} else {
if ($user['membergroupids'] == '')
{
$user['membergroupids'] = "9";
} else {
$user['membergroupids'] .= ",9";
}
}
}
$db->query("UPDATE " . TABLE_PREFIX . "user SET `usergroupid`=".$db->sql_prepare($user['usergroupid']).", `membergroupids`=".$db->sql_prepare($user['membergroupids']));
}
}

My problem? That updates the MySQL table, but each usergroup has a rank image, and it doesn't update the rank images until I save the user in the AdminCP..I know there are various update_counter functions and whatnot, is there anything to update a user's ranks?

Marco van Herwaarden
06-28-2006, 07:16 AM
If you are using vB3.5 or above, you really should consider using the DataManagers instead of directly altering the user table.

You can find some documentation on how to use them in our Tutorial section.

drew010
06-29-2006, 03:12 AM
I've done so - I still have the same problem.

Here's my updated code:

if ($foruminfo['forumid'] == 38)
{
$thread = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "thread WHERE `pollid`=".$pollinfo['pollid']);
if ($thread['postuserid'])
{
require_once(DIR . '/includes/functions_user.php');
$userdm =& datamanager_init('User', $vbulletin, ERRTYPE_SILENT);
$user = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE `userid`=".$db->sql_prepare($thread['postuserid']));
$userdm->set_existing($user);
$splitvotes = explode('|||', $pollinfo['votes']);
if ($vbulletin->GPC['optionnumber'] == 1)
{
$splitvotes[0] += 1;
}
if ($splitvotes[0]>= 1)
{
if ((!in_array('9', explode(',', $user['membergroupids']))) && ($user['usergroupid'] != '9'))
{
$membergroups = explode(',', $user['membergroupids']);
if ($user['usergroupid'] != '4')
{
$membergroups[] = $user['usergroupid'];
}
$user['usergroupid'] = '9';
$user['displaygroupid'] = '9';
$user['membergroupids'] = implode(',', $membergroups);
$userdm->set('usergroupid', $user['usergroupid']);
$userdm->set('membergroupids', $user['membergroupids']);
$userdm->save();
}
}
}
}

drew010
07-03-2006, 01:15 AM
Can NO-ONE help?