$criteria->prepare(); echo $criteria->toSQL();
$this->setDebug(true);
/* query code and execution here */ die();
//get params
$resource = $modx->getOption('id', $scriptProperties, $modx->resource->get('id'));
$direction = $modx->getOption('direction', $scriptProperties, false);
$tpl = $modx->getOption('tpl', $scriptProperties, false);
$linktxt = $modx->getOption('linktext', $scriptProperties, false);
if($res = $modx->getObject('modResource', $resource)) {
$menuindex = $res->get('menuindex');
$parentid = $res->get('parent');
$c = $modx->newQuery('modResource');
$c->limit(1);
switch($direction) {
case 'next':
case 'prev':
$c->where(array('id:!=' => $resource));
$c->where(array('parent' => $parentid));
$c->where(array('published' => true));
$c->where(array('deleted' => false));
break;
}
switch($direction) {
case 'next':
//$c->where(array('publishedon:<' => 'date('.$res->get('publishedon').')' ));
$c->where("[modResource].[publishedon] > CAST('" . $res->get('publishedon') . "' AS DATETIME) " , xPDOQuery::SQL_AND);
$c->sortby('publishedon','DESC');
break;
case 'prev':
//$c->where(array('publishedon:>' => 'date('.$res->get('publishedon').')' ));
$c->sortby('publishedon','ASC');
break;
}
//debug
//$c->prepare();
//return 'SQL: ' . $c->toSQL();
if($linkResource = $modx->getObject('modResource', $c)) {
// build placeholders
$placeholders = array(
'id' => $linkResource->get('id'),
'pagetitle' => (!empty($linktxt)) ? $linktxt : $linkResource->get('pagetitle'),
'longtitle' => (!empty($linktxt)) ? $linktxt : $linkResource->get('longtitle'),
'publishedon' => (!empty($linktxt)) ? $linktxt : $linkResource->get('publishedon'),
'menutitle' => (!empty($linktxt)) ? $linktxt : $linkResource->get('menutitle')
);
// parse chunk
$chunk = $modx->getObject('modChunk', array('name' => $tpl));
if(!$chunk) {
$useChunk = '<a href="[[~[[+id]]]]">[[+menutitle:isempty=`[[+pagetitle]]`]]</a>';
$chunk = $modx->newObject('modChunk');
$chunk->setCacheable(false);
$chunk->setContent($useChunk);
}
return $chunk->process($placeholders);
}else{
return 'no object found';
}
}
$c->sortby('publishedon', 'ASC');
$c->sortby('publishedon', 'DESC');