Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Assigning roles using a database

Hey all, bit of a newby to this framework and couldn't find a topic covering this.
I was wondering if you could assign a role to a user based off of a database using PHP, e.g. a user named John Doe belongs to John Doe Ltd who are non-members. Can I assign him the role of Non-Member from a database so I don't have to click on him and assign the role manually?

Tagged:

Comments

  • Options
    rasteronrasteron forum.rastercode.com ✭✭
    edited February 2015

    you could try under GDN_UserRole table, with UserID and RoleID field that looks like role flags or constants. If you can take a look at applications/dashboard/settings/structure.php I think that is one example defined there.

  • Options
    R_JR_J Ex-Fanboy Munich Admin
    edited February 2015

    You should avoid writing directly to the database. You better create a short plugin that does exactly what you need. It doesn't need to be sophisticated:

    <?php defined('APPLICATION') or die;
    
    $PluginInfo['Aah'] = array(
        'Name' => 'Aah!',
        'Description' => 'Just a barebone plugin for messing around.',
        'Version' => '0.1',
        'Author' => 'YOU!'
    );
    
    class AahPlugin extends Gdn_Plugin {
        public function setup() {
          // whatever code you put in here will be executed when you enable the plugin
        }
    }
    

    I have not put any code in there, because I'm not quite sure what you try to achieve: if the user is not a member, you will not have him in the user database...

    But in order to give a user a special role, you would need something like this:

    $UserModel = new UserModel();
    $UserRoles =  $UserModel->GetRoles($UserID);
    $UserRoles[] = ? // <- RoleID to add;
    $RecordActivity = false; // set to true if you want this to be shown on the activity stream
    $UserModel->SaveRoles($UserID, $UserRoles, $RecordActivity)
    
Sign In or Register to comment.