PDA

View Full Version : removing specific data from membergroupids


Bobbo
06-16-2010, 05:58 PM
I've got a plugin that extends many of the VB permissions out to an external datasource.

One of the things I am trying to do is make updates to the membergroupids column of the user table based on logic in my plugin.

I'm unsure how exactly to read the contents of membergroupids for a user and strip out only a single id number without changing the rest. So for example is user A has membergroupids set to 9,10, 11 and my plugin determines that this user should no longer have access to 10, I want to update that value to be 9,11.

Does anyone have some insight on an easy method to accomplish this?

Thanks!

Bobbo :rolleyes:

Bobbo
06-22-2010, 12:18 PM
Anyone have some thoughts on this one?

I think what I am trying to do is update the array, but if I try to unset one of the values using a foreach statement it doesnt work.

I suspect someone with more php knowledge than myself would know how to do this.

I'd really appreciate any help.

Thanks.

B

Bobbo
06-25-2010, 07:13 PM
Ok, I think I got this one licked...

I can tell the interest level by the high level of responses... lol. ;-)

Anyhow, I'm doing something like this.


eval('$getids = array ('.$vbulletin->userinfo['membergroupids'].');');
$dropid = "12"; //in my real code, this value is determined by an external MS SQL lookup
for($i=0;$i<count($getids);$i++) {
if($getids[$i] == $dropid) {
unset($getids[$i]);
}
}
$idupdate = implode(",", $getids);
$vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "user SET membergroupids = '" . $idupdate . "' WHERE email = '" . $username . "' LIMIT 1 ");


So basically, i'm reading the contents of the membergroupids into an array, reading through the array until I find a usergroup id match, I then unset that array element, implode the array into a variable, and write it back to the database.

Seems to work really well. Not sure if there are any 'gotchas' or reasons why this would be a problem. If anyone has any feedback, I'd apprecaite it.

Maybe it will help someone else...

Bobbo