(I answer myself to question b)
this function resolves it:
/* same as toPlaceholders, but naming in 1.2.3.4.. order, and not PK-based (as toPlaceholderS) */
function chronologicalPlaceholder($parentObj,$alias,$prefix) {
global $modx;
if (!isset($prefix)) {$prefix = $alias;} // default to use alias as placeholder prefix
$childs = $parentObj->getMany($alias); // get all children
sort($childs); //change array's keys to 0,1,2,etc...
array_unshift($childs,array()); // add empty one, simply so the numbering will start from 1 and not 0
$modx->toPlaceholders($childs,$prefix,"."); // generate modx placeholders for templates
return $childs; // return the array, needed for recursive placeholder (grandchildren relationship or more)
}
called like this:
/* add your schema */
$model_path = $modx->getOption('core_path', $properties, MODX_CORE_PATH).'components/yourName/model/';
$modx->addPackage('yourSchemaName',$model_path);
$memberSchemaDef = '{"Profile":{},"MemberLinks":{}}';
// and so on.... add all your salat here... note: doesn't support grandchildren or deeper (although looks like it should, by design...)
/* get extended user object */
$memberUser = $modx->getObjectGraph('memberUser', $memberSchemaDef , $userId);
if (!isset($memberUser)) {return;} // if empty? quit.
$modx->toPlaceholders($memberUser->Profile,'Profile'); // simple example, "profile" has 'one' relationship with modUser
chronologicalPlaceholder($memberUser,"MemberResidencies"); // has 'many' relationship with modUser (well actually to "memberUser" object that extends "modUser"
This will dump the placeholders in 1,2,3,4... order
btw, for grandchildren, i use this:
$skGroups = chronologicalPlaceholder($memberUser,"MemberSkillGroups");
foreach ($skGroups as $i => $skGroup) {
if (count($skGroup) > 0) { // has any professions?
chronologicalPlaceholder($skGroup,"Professions","MemberSkillGroups.".$i.".Profession");
}
}
(where the logic is: MemberUser [has many] MemberSkillGroups [has many] Professions)
for example, this would produce a placeholder that looks like this:
[MemberSkillGroups.1.Profession.2.name]
For my case, the custom user data is presented all around the site in fragments (in the user’s profile page - all info, in other places - just some info about him).
The above is very comfortable for template design, as it’s static name(unlike the toPlaceholders which names then based on the PK).
Good luck.