<?php
// Allows for a specified User.
// User in this context is a User's personal Blog which uses its ID as its alias.
// This function may be called from any place, but just in case,
// we will use the results of the current User if the param is suspect.
$forUser = !empty($forUser)
? $forUser // The specified User
: $modx->resource->get('template') == 2
? $modx->resource->get('alias') // Use the Alias
: $modx->user->get('id'); // Fallback to User ID
// Initialize the rest of the necessary properties
$boxChunk = !empty($boxChunk)
? $boxChunk
: 'toLinkList';
$rowChunk = !empty($rowChunk)
? $rowChunk
: 'toBlogLink';
$limit = empty($limit) ? 10 : $limit;
// This is initialized with the System Setting, if it is not provided.
$debug = (!empty($debug))
? $debug
: $modx->getOption('debug');
// Single xPDO Query
$q = $modx->newQuery(
'modResource'
);
$q->innerJoin('modTemplateVarResource','TemplateVarResources');
// This limits it to a Context, making the result list smaller.
$q->where(array(
'modResource.context_key'=>projects,
'modResource.template'=>15,
'modResource.published'=>1,
'TemplateVarResources.tmplvarid'=>5
));
// Account for comma-delimited lists where id is first, last or only entry...
$values[] = array('TemplateVarResources.value'=>$forUser);
$values[] = array('OR:TemplateVarResources.value:LIKE' => '%,'.$forUser.'%');
$values[] = array('OR:TemplateVarResources.value:LIKE' => '%'.$forUser.',%');
$q->andCondition($values, null, 1);
// This makes the result set even smaller, and the query return much faster.
$q->select(array('id', 'pagetitle', 'introtext'));
$q->limit($limit);
$list = $modx->getCollection('modResource', $q);
if (!empty($debug))
$output .= 'Query complete: attempting to output results';
// We only work if we have a list.
if (!empty($list))
{ foreach ($list as $key => $project)
{ if (!empty($project))
{ $members = $project->getTVValue('Contributors');
if (!empty($members))
{ $members = explode(',', $members);
foreach($members as $key => $member)
{//Accounts for *# or #* results.
if (trim($member) == $forUser)
{ $output .= '<li>'
. $modx->getChunk(
$rowChunk,
array(
'id'=>$project->get('id'),
'text'=>$project->get('pagetitle'),
'desc'=>$project->get('introtext')
)
)
.'</li>';
// We only care if it matches once.
break;
}
elseif (!empty($debug))
$output .= '<li>Does not match:' . $member . '</li>'
}
}
elseif (!empty($debug))
$output .= '<li>Project has no members.</li>';
}
elseif (!empty($debug))
$output .= '<li>Query included an empty result. Consider revising</li>';
}
$output = $modx->getChunk($boxChunk, array('items'=>$output));
}
elseif (!empty($debug))
$output = 'There were no results to list for id:'.$forUser;
// If Placeholder is requested
if (empty($toPlaceholder))
return $output;
else
$modx->setPlaceholder($toPlaceholder, $output);
// Only return "sure" output. Better than mangling a User's page
return '';

but IMO, not using them causes worse problems.