Jump to content

Profile Custom field Dependant Group sorting


Orlando Delcid

Recommended Posts

Create a plugin, and hook this class:

\IPS\core\modules\front\system\register

 

And then with something like this within your class:

/**
 * @var array
 */
public static $serverMapping = [];

/**
* Build Registration Form
*
* @return    \IPS\Helpers\Form
*/
public static function buildRegistrationForm()
{
    $form = call_user_func_array( 'parent::buildRegistrationForm', func_get_args() );
    $servers = array();
    foreach(\IPS\Db::i()->select('id, name', 'serverconsole_servers') as $_dbServer) {
        self::$serverMapping[$_dbServer['id']] = $_dbServer['name'];
    }
    $form->add(new \IPS\Helpers\Form\Select('serverconsole_registration_defaultserver',NULL,true, array('options' => self::$serverMapping)));
    return $form;
}


/**
 * Create Member
 *
 * @param    array $values Values from form
 * @return    \IPS\Member
 */
public static function _createMember( $values )
{
    $member = call_user_func_array( 'parent::_createMember', func_get_args() );
    
    if($values['serverconsole_registration_defaultserver']) {
        $serverName = self::$serverMapping[$values['serverconsole_registration_defaultserver']];
        
        //TODO: override membergroup, maybe with searching server name within the group?
    }

    return $member;
}

 

You would now only need to define the selection of the member group and set it for the member.
You could do that with an ID-Mapping as the groups have unique id's once created and it is only a personal plugin.

I recommend you having something to change it later in your accountsettings as exmaple.

Maybe it is even more recommend having multiselect and using secondary member groups.

Link to comment
Share on other sites

9 minutes ago, GriefCode said:

Create a plugin, and hook this class:


\IPS\core\modules\front\system\register

 

And then with something like this within your class:


/**
 * @var array
 */
public static $serverMapping = [];

/**
* Build Registration Form
*
* @return    \IPS\Helpers\Form
*/
public static function buildRegistrationForm()
{
    $form = call_user_func_array( 'parent::buildRegistrationForm', func_get_args() );
    $servers = array();
    foreach(\IPS\Db::i()->select('id, name', 'serverconsole_servers') as $_dbServer) {
        self::$serverMapping[$_dbServer['id']] = $_dbServer['name'];
    }
    $form->add(new \IPS\Helpers\Form\Select('serverconsole_registration_defaultserver',NULL,true, array('options' => self::$serverMapping)));
    return $form;
}


/**
 * Create Member
 *
 * @param    array $values Values from form
 * @return    \IPS\Member
 */
public static function _createMember( $values )
{
    $member = call_user_func_array( 'parent::_createMember', func_get_args() );
    
    if($values['serverconsole_registration_defaultserver']) {
        $serverName = self::$serverMapping[$values['serverconsole_registration_defaultserver']];
        
        //TODO: override membergroup, maybe with searching server name within the group?
    }

    return $member;
}

 

You would now only need to define the selection of the member group and set it for the member.
You could do that with an ID-Mapping as the groups have unique id's once created and it is only a personal plugin.

I recommend you having something to change it later in your accountsettings as exmaple.

Maybe it is even more recommend having multiselect and using secondary member groups.

Lol i have no idea how to get this done :/ i tried using rules application though using custom field and telling it to change class if string A == String B but that doesnt do anything 

Link to comment
Share on other sites

Just now, Orlando Delcid said:

Lol i have no idea how to get this done :/ i tried using rules application though using custom field and telling it to change class if string A == String B but that doesnt do anything 

Maybe when I got later some time I will create the plugin shortly as it is on 90% done with my given code :D 

Link to comment
Share on other sites

Had some trouble getting through it, but here is the plugin:
https://dev.grief.network/files/file/3-server-console-register/
I will not place it on the marketplace as I do not think it is something everyone want to use and is in some way special.
However, I have a list added to the general application on the marketplace to link these kind of plugins.

 

Sources are as always public:
https://github.com/Grief-Code/IPS-Server-Console-RegisterHook

 

Greetings

Server Console - Register.xml

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...