<?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>
<?php
/**
* @package extendeduser
* @subpackage user.mysql
*/
class extUser extends modUser {
function __construct(xPDO & $xpdo) {
parent :: __construct($xpdo);
$this->set('class_key','extUser');
}
}
$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;
if ($modx->event->name == 'OnUserFormSave') {
if (!empty($scriptProperties['user'])) {
$scriptProperties['user']->set('class_key','myCustomUser');
$scriptProperties['user']->save();
/* do other code here */
}
}
You need to pass in the class_key to your params for the runProcessor call.
$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',
$user = $modx->newObject('modUser');
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.
$user = (!empty($scriptProperties['class_key']) ? $modx->newObject($scriptProperties['class_key']) : $modx->newObject('modUser'));