This question has been answered by andytough. See the first response.
<?php
/** @var array $scriptProperties */
/* @var pdoFetch $pdoFetch */
if (!$modx->getService('pdoFetch')) {return 'You need to install pdoTools to use this snippet!';}
$pdoFetch = new pdoFetch($modx, $scriptProperties);
$pdoFetch->addTime('pdoTools loaded');
$modx->lexicon->load('bannery:default');
$modx->addPackage('bannery', MODX_CORE_PATH . 'components/bannery/model/');
if (!empty($tplOuter)) {$tplWrapper = $tplOuter;}
if (empty($outputSeparator)) {$outputSeparator = "\n";}
$class = 'byAd';
// Adding extra parameters into special place so we can put them in results
/** @var modSnippet $snippet */
$additionalPlaceholders = array();
if ($snippet = $modx->getObject('modSnippet', array('name' => 'BannerY'))) {
$properties = unserialize($snippet->properties);
foreach ($scriptProperties as $k => $v) {
if (!isset($properties[$k])) {
$additionalPlaceholders[$k] = $v;
}
}
}
// ---
$date = date('Y-m-d H:i:s');
$where = array(
"({$class}.start IS NULL OR {$class}.start <= '{$date}') AND ({$class}.end IS NULL OR {$class}.end >= '{$date}')"
);
if (empty($showInactive)) {
$where[$class.'.active'] = 1;
}
if (!empty($position)) {
$where['byAdPosition.position'] = $position;
}
elseif (!empty($positions)) {
$where['byAdPosition.position:IN'] = array_map('trim', explode(',', $positions));
}
if (empty($sortby)) {
$sortby = 'RAND()';
}
elseif ($sortby == 'idx' || $sortby == 'index') {
$sortby = 'byAdPosition.idx';
}
else {
$sortby = $class.'.'.$sortby;
}
$innerJoin = array(
'byAdPosition' => array(
'alias' => 'byAdPosition',
'on' => $class.'.id = byAdPosition.ad'
)
);
// Fields to select
$select = array(
$class => 'all',
'byAdPosition' => '`byAdPosition`.`id` as `adposition`, `byAdPosition`.`ad`'
);
// Add custom parameters
foreach (array('where','innerJoin','select') as $v) {
if (!empty($scriptProperties[$v])) {
$tmp = $modx->fromJSON($scriptProperties[$v]);
if (is_array($tmp)) {
$$v = array_merge($$v, $tmp);
}
}
unset($scriptProperties[$v]);
}
$pdoFetch->addTime('Conditions prepared');
$default = array(
'class' => $class,
'innerJoin' => $modx->toJSON($innerJoin),
'where' => $modx->toJSON($where),
'select' => $modx->toJSON($select),
'sortby' => $sortby,
'groupby' => $class.'.id',
'return' => 'data',
'disableConditions' => true,
);
$pdoFetch->setConfig(array_merge($default, $scriptProperties));
$rows = $pdoFetch->run();
$output = array();
$default_source = $modx->getOption('bannery_media_source', null, $modx->getOption('default_media_source'), true);
$sources = array();
foreach ($rows as $row) {
$source = !empty($row['source'])
? $row['source']
: $default_source;
if (!isset($sources[$row['source']])) {
/** @var modMediaSource $source */
if ($source = $modx->getObject('sources.modMediaSource', $source)) {
$source->initialize($modx->context->key);
}
$sources[$row['source']] = $source;
}
else {
$source = $sources[$row['source']];
}
if (!empty($source) && $source instanceof modMediaSource && !empty($row['image'])) {
$row['image'] = $source->getObjectUrl($row['image']);
}
$row['idx'] = $pdoFetch->idx++;
$tpl = $pdoFetch->defineChunk($row);
if (!empty($additionalPlaceholders)) {
$row = array_merge($additionalPlaceholders, $row);
}
$output[] = !empty($tpl)
? $pdoFetch->getChunk($tpl, $row, $pdoFetch->config['fastMode'])
: '<pre>'.$pdoFetch->getChunk('', $row).'</pre>';
}
if ($modx->user->hasSessionContext('mgr') && !empty($showLog)) {
$output['log'] = '<pre class="pdoUsersLog">' . print_r($pdoFetch->getTime(), 1) . '</pre>';
}
// Return output
if (!empty($toSeparatePlaceholders)) {
$modx->setPlaceholders($output, $toSeparatePlaceholders);
}
else {
$output = implode($outputSeparator, $output);
if (!empty($tplWrapper) && (!empty($wrapIfEmpty) || !empty($output))) {
$output = $pdoFetch->getChunk($tplWrapper, array('output' => $output), $pdoFetch->config['fastMode']);
}
if (!empty($toPlaceholder)) {
$modx->setPlaceholder($toPlaceholder, $output);
}
else {
return $output;
}
}<a target="_blank" href="[[++bannery_click]]/[[+adposition]]"><img style="width:300px !important;" src="[[+image]]" alt="[[+name]]"/></a>
<p><a target="_blank" href="[[++bannery_click]]/[[+adposition]]"><img src="[[+image]]" alt="[[+name]]"/></a></p>
<div class="main_left_ad">[[BannerY? &position=`3` &sortby=`RAND()` &limit=`1` tpl=`sidebyAd`]] </div>
<div class="main_right_ad">[[BannerY? &position=`4` &sortby=`RAND()` &limit=`1` tpl=`sidebyAd`]] </div>
.main_left_ad
{
float: left;
width: 200px;
height:20px;
/*border:solid 1px #0F0;*/
margin-left: -220px;
}
.main_right_ad
{
margin-right: -310px;
float: right;
width: 200px;
height:20px;
/*border:solid 1px #00F;*/
margin-right: -220px;
}
div.main_left_ad p a img
{
width: 300px !important;
}
div.main_right_ad p a img
{
width: 300px !important;
}
<div class="main_left_ad">[[BannerY? &position=`3` &sortby=`RAND()` &limit=`1` &tpl=`sidebyAd`]] </div> <div class="main_right_ad">[[BannerY? &position=`4` &sortby=`RAND()` &limit=`1` &tpl=`sidebyAd`]] </div>
I think you have left the ampersand out of your call for the tpl. It should read &tpl=
<div class="main_left_ad">[[BannerY? &position=`3` &sortby=`RAND()` &limit=`1` &tpl=`sidebyAd`]] </div> <div class="main_right_ad">[[BannerY? &position=`4` &sortby=`RAND()` &limit=`1` &tpl=`sidebyAd`]] </div>
I have not looked closely at your other code, so if this does not solve the problem post back here and people can have a proper look at it.