I take offense to that.
Queries to get user info are somewhat ugly because the information for a single user is spread among several tables.

<?php
$output = array();
/* get the bobray user and his profile in a single query */
$user = $modx->getObjectGraph('modUser', '{"Profile":{}}', array('username' => 'bobray'));
/* get a userTpl chunk and pass the user and the core MODx profile attributes */
$output[] = $modx->getChunk('userTpl', array_merge($user->toArray(), $user->Profile->toArray()));
unset($user);
/* get all users/profiles except bobray in a single query and loop through them */
$users = $modx->getCollectionGraph('modUser', '{"Profile":{}}', array('username:!=' => 'bobray'));
foreach ($users as $user) {
/* get a userTpl chunk and pass the user and the core MODx profile attributes */
$output[] = $modx->getChunk('userTpl', array_merge($user->toArray(), $user->Profile->toArray()));
}
return implode("\n", $output);
?><?php
/* get custom profile data, along with the modx user and profile data for bobray in a single query */
$myProfile = $modx->getObjectGraph('myCustomProfileClass', '{"User":{"Profile":{}}}', array('User.username' => 'bobray'));
/* dump all the attributes */
var_dump(array_merge($myProfile->toArray(), $myProfile->User->toArray(), $myProfile->User->Profile->toArray()));
?>

) as class methods.
You don’t have to use JSON to represent your "graph" of related objects to query at the same time (what the get*Graph() methods do); the methods accept a JSON string OR a PHP array, so these are the same without the scary JSON:
...I think I’d have to spend a few weeks (or months) learning JSON format to understand it...
<?php
$user = $modx->getObjectGraph('modUser', array('Profile' => array()), array('username' => 'bobray'));
$myProfile = $modx->getObjectGraph('myCustomProfileClass', array('User' => array('Profile' => array())), array('User.username' => 'bobray'));
?>These are the objects you are getting; now just set() a column value and save():
...let alone figure out how to update user data the same way.
<?php
$myProfile = $modx->getObjectGraph('myCustomProfileClass', array('User' => array('Profile' => array())), array('User.username' => 'bobray'));
$myProfile->set('shipping_address', '123 ABC Blvd');
$myProfile->User->Profile->set('fullname', 'Bob Ray');
$myProfile->save();
?>You have one on the modX class; and returning the data using $user->toArray() gives you an array; and $user->toJSON() gives you JSON, etc.
I could go for a few convenience methods that used that code and returned an array of user data or filled-out user objects , though.
The $modx->user already has access to his Profile:
Maybe they could be tacked onto the $modx->user object (or a subclass of that object -- we could call it ’modObeseUser’) as class methods.
<?php
$modx->user->getOne('Profile');
var_dump($modx->user->Profile->toArray());
?>
I am thinking of starting on a REVO version of WebloginPE.
Has anyone any thoughts or ideas on this
Would you be interested in helping or joining such a project
You don’t have to use JSON to represent your "graph" of related objects to query at the same time (what the get*Graph() methods do); the methods accept a JSON string OR a PHP array, so these are the same without the scary JSON [...]
These are the objects you are getting; now just set() a column value and save():
<?php $myProfile = $modx->getObjectGraph('myCustomProfileClass', array('User' => array('Profile' => array())), array('User.username' => 'bobray')); $myProfile->set('shipping_address', '123 ABC Blvd'); $myProfile->User->Profile->set('fullname', 'Bob Ray'); $myProfile->save(); ?>


$user = $modx->getObjectGraph('modUser', array('Profile' => array()), array('username' => 'bobray'));$user->get('fullname'') // ??They are accessed indirectly via the hydrated related object, i.e.
After this:
$user = $modx->getObjectGraph('modUser', array('Profile' => array()), array('username' => 'bobray'));
are the profile fields grafted onto the user object, or accessed indirectly?
$user->get('fullname'') // ??
$user->Profile->get('fullname');When you call save on an object, any related objects that are loaded on that object (as the Profile is here) as also saved. So all you need to do is:
And can they be updated via the $user object or do you need to explicitly get a profile object to update them?
$user->set('username', 'newusername');
$user->Profile->set('fullname', 'New User');
$user->save();Basically, except the get*Graph() methods are more efficient since they get everything in a single query. Using the getOne()/getMany() methods after a getObject/getCollection executes a separate query to populate the related objects. Also note that once you hydrate a specific related object (or set of objects) using either method, subsequent calls to getOne()/getMany() without a specific criteria specified should return the already hydrated related object( s ) with no additional queries.
Is the code above the equivalent of $user=getObject(’modUser’, etc.) followed by $user->getOne(’Profile’)?