We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34193
    • 330 Posts
    Hi I’m trying to extend users I have followed the tutorial at http://rtfm.modx.com/display/revolution20/Extending+modUser below are my scheme, extuser.class.php and relevant system settings.

    What is now happening is when I create a user in the manager the class_key is being set as modUser, also if I create the user using code from the front end it is being set the same.

    Schema : (Shortened to relevant bit if you want more I can post)

    <?xml version="1.0" encoding="UTF-8"?>
    <model package="HCSpr" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" phpdoc-package="schoolmanagement" phpdoc-subpackage="model">
        <!-- inherit the modx user and extend it -->
        <object class="extUser" table="users" extends="modUser">
            <composite alias="Pupil_Details" class="pupil-details" local="id" foreign="User_ID_Child" cardinality="one" owner="local" />
            <composite alias="ParentOfChild" class="parent-child" local="id" foreign="User_ID_Child" cardinality="many" owner="local" />
            <composite alias="ChildOfParent" class="parent-child" local="id" foreign="User_ID_Parent" cardinality="many" owner="local" />
            <composite alias="AdditionalContactsforChild" class="child-additional-contacts" local="id" foreign="User_ID_Child" cardinality="many" owner="local" />
            <composite alias="PupilResults" class="pupil-results" local="id" foreign="User_ID_Child" cardinality="many" owner="local" />
        </object>
    


    extuser.class.php
     <?php
    /**
     * @package extendeduser
     * @subpackage user.mysql
     */
    class extUser extends modUser {
        function __construct(xPDO & $xpdo) {
            parent :: __construct($xpdo);
            $this->set('class_key','extUser');
        }
    }
    


    extension_packages = [{"HCSpr":{"path":"/opt/lampp/htdocs/HCSpr/core/components/HCSpr/model/"}}]

    Am I missing anything here.

      • 28215
      • 4,149 Posts
      How are you creating the user?
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 34193
        • 330 Posts
        Thanks I have tried creating the user through the manager and also using the code below
        $modx->addPackage('HCSpr','/opt/lampp/htdocs/HCSpr/core/components/HCSpr/model/', 'ut_');        /*added just incase it's needed */
        
        
        $response = $modx->runProcessor('security/user/create',array(
           'username' => $hook->getValue('firstname').$hook->getValue('surname'),
            'fullname' => $hook->getValue('firstname').' '.$hook->getValue('surname'),
            'address' => $hook->getValue('address1'),
            'county' => $hook->getValue('address2'),
            'city' => $hook->getValue('address3'),
            'zip' => $hook->getValue('postcode'),
            'phone' => $hook->getValue('phonenum'),
            'mobilephone' => $hook->getValue('mobilenum'),
            'email' => $hook->getValue('email'),
            'extended' => array(
              'title' => $hook->getValue('title'),),
            'newpassword' => TRUE,
            'passwordnotifymethod' => 'e',
            'passwordgenmethod' => 'g',
        ));
        if ($response->isError()) {
           if ($response->hasFieldErrors()) {
               $fieldErrors = $response->getAllErrors();
               $errorMessage = implode("\n",$fieldErrors);
           } else {
               $errorMessage = 'An error occurred: '.$response->getMessage();
           }
           $hook->addError('error_message',$errorMessage);
        return false;
        }
        return true;
        


          • 28215
          • 4,149 Posts
          You need to pass in the class_key to your params for the runProcessor call.
            shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
            • 34193
            • 330 Posts
            ok thanks I’ll add that in later. What about creating users within the manager don’t need it for this one but can possible see a situation where it might be needed in the future.

            I’m thinking Admin sets a user up in manger, and then they login to a front end to add the extended info, etc.

            Or can extended users only be added via a custom user creation.
              • 28215
              • 4,149 Posts
              I would think you’d be able to do it with a plugin:

              if ($modx->event->name == 'OnUserFormSave') {
                 if (!empty($scriptProperties['user'])) {
                    $scriptProperties['user']->set('class_key','myCustomUser');
                    $scriptProperties['user']->save();
              /* do other code here */
                 }
              }
              
                shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                • 34193
                • 330 Posts
                Quote from: splittingred at Feb 24, 2011, 09:31 AM

                You need to pass in the class_key to your params for the runProcessor call.

                hmmm ok can’t figure this out I’ve changed my runProcessor to

                $response = $modx->runProcessor('security/user/create',array(
                   'username' => $hook->getValue('firstname').$hook->getValue('surname'),
                    'fullname' => $hook->getValue('firstname').' '.$hook->getValue('surname'),
                    'address' => $hook->getValue('address1'),
                    'county' => $hook->getValue('address2'),
                    'city' => $hook->getValue('address3'),
                    'zip' => $hook->getValue('postcode'),
                    'phone' => $hook->getValue('phonenum'),
                    'mobilephone' => $hook->getValue('mobilenum'),
                    'email' => $hook->getValue('email'),
                    'extended' => array(
                      'title' => $hook->getValue('title'),),
                    'newpassword' => TRUE,
                    'passwordnotifymethod' => 'e',
                    'passwordgenmethod' => 'g',
                    'class_key' => 'extUser',
                


                but it still create the user with class_key being modUser..... looking at the code for create I see this
                $user = $modx->newObject('modUser');


                I tried changing this to extUser as a temp measure but that throw up all sorts of error’s but i’m wondering if it’s somthing to do with it.
                  • 34193
                  • 330 Posts
                  Quote from: peteedley at Feb 24, 2011, 11:56 AM


                  but it still create the user with class_key being modUser..... looking at the code for create I see this
                  $user = $modx->newObject('modUser');


                  I tried changing this to extUser as a temp measure but that throw up all sorts of error’s but i’m wondering if it’s somthing to do with it.

                  Actually ignore that, changing this value in create does work. So the question is do I file this as a bug. I can try and work on a way of setting this value dynamically to file as part of the bug but my coding skills arn’t the most refined.
                    • 34193
                    • 330 Posts
                    this seems to work

                    $user = (!empty($scriptProperties['class_key']) ? $modx->newObject($scriptProperties['class_key']) : $modx->newObject('modUser'));
                    


                    But will break on upgrade since I edited the core file.