21
redheadedrod
Re: Looking to get current user information and some fields from user profile.

Ok, this is getting frustrating and I am about to bypass this and go directly to the database.

I decided to make a new function as below and not use the function as above.

The following function works right up until the lines where it actually is supposed to add or subtract a user from the user group. I have heavily commented this function to show what I am trying to do. I would greatly appreciate someone looking at it and seeing what I am missing.

$result returns a null which I would expect is a failure?

/** $id is the $id of the user from the roster database
*   $action true = add user to group  false = remove user from group
*   $xrosterList_users is list of registered users with the key being the UID and value being the UNAME
*   $key = contains the UID of the user obtained from the list of registered users
*   $xoopsModuleConfig['ugroup'] is the groupid of the group I am trying to add/remove user from
*   $result should equal true if it worked
*/
$xrosterhMember =& xoops_gethandler('member'); // Getting a handle for xoops_gethandler (doesn't seem to work if I put it IN the function)
function Groups_Add_n_Remove($id$action 0) {
  
$action = (int)$action 0// making sure it is an int.  1 = add user   0 = remove user
  
global $xrosterList_users$xoopsModuleConfig$xrosterhMember
  
$member=getMember($id1); // added the 1 to have getMember get a member no matter if activated or not and modified getMember accordingly
  
$key array_search($member['membername'], $xrosterList_users);  // gets UID of user if user is a registered user on the site
  
if ($key){ // makes sure the roster memeber is a registered site member
    
if ($action$result =& $xrosterhMember->addUserToGroup($xoopsModuleConfig['ugroup'], $key);  //  addUserToGroup('groupid', 'uid')
      
else  $result =& $xrosterhMember->removeUsersFromGroup($xoopsModuleConfig['ugroup'], array($key)); // removeUsersFromGroup('groupid', array('uid'))
  
}
}

22
redheadedrod
Re: Looking to get current user information and some fields from user profile.

I don't get it.. Not only does the above code not work... But when I try this... In the code by its self not in a function or anything...
$member_handler = &xoops_gethandler('member');
        
$member_handler->addUserToGroup(41);


It doesn't work.

I have even put a debug line in the code to see what is getting sent and it is getting the right stuff. Just not completing for some reason?

I print what is going on with the functions themselves in kernel/member.php.

If I do it from the control panel It gets the same 4 and 1 but completes successfully. I do it manually like above and it gets the 4 and 1 but doesn't complete ?

Still getting the above error message which I wonder if it is interfering?

And yes when I do this I remove the user from the group in the admin then let my code try to add it back in... But it doesn't add.. GRRRR

Rodney


23
redheadedrod
Re: Looking to get current user information and some fields from user profile.

Well I got it to work by accessing the database directly but I would rather NOT do it that way...

when I used queryf instead of query it worked in this code. Apparently the error was telling me it wasn't adding it but still would like to know what the error means any why I got it.

Here is the code that worked...


function Groups_Add_n_Remove($id$action 0) {
  
$action = (int)$action 0// making sure it is an int.  1 = add user   0 = remove user
  
global $xrosterList_users$xoopsModuleConfig$xrosterhMember;
  
$groupid=$xoopsModuleConfig['ugroup'];
  
$member=getMember($id1); // added the 1 to have getMember get a member no matter if activated or not and modified getMember accordingly
  
$key array_search($member['membername'], $xrosterList_users);  // gets UID of user if user is a registered user on the site
  
if ($key) {
    
$db =& Database::getInstance();
    
$result $db->query('SELECT linkid, groupid, uid FROM ' $db->prefix('groups_users_link') . ' WHERE uid=' $key ' AND groupid=' $groupid);
    
$row $db->fetchArray($result);
    
$linkid=$row['linkid'];
    if (!(isset(
$linkid)) && $action) {
          
$result $db->queryF('INSERT INTO ' $db->prefix('groups_users_link') . ' (groupid, uid)  VALUES (' $groupid ', ' $key .')');
    }
    if (isset(
$linkid) && !($action)) { 
          
$result $db->queryF('DELETE FROM ' $db->prefix('groups_users_link') . ' WHERE linkid='$linkid);  
    }        
  }
}

Login

Who's Online

369 user(s) are online (252 user(s) are browsing Support Forums)


Members: 0


Guests: 369


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits