$doc = $this->modx->getPageInfo($id, 0, 'type,published,hidemenu,deleted' );
$resource = $this->modx->getObject('modResource', $id);
$doc = $resource->get('type,published,hidemenu,deleted'); function GetTVArray()
{
// Gets an array of all template variables
$table = $this->modx->getFullTableName('site_tmplvars');
$tvs = $this->modx->db->select('name', $table);
// TODO: make it so that it only pulls those that apply to the current template
$dbfields = array();
while ( $dbfield = $this->modx->db->getRow( $tvs ) )
{
$dbfields[] = $dbfield['name'];
}
return $dbfields;
}
$doc = $this->modx->getPageInfo($id, 0, 'type,published,hidemenu,deleted' );
$resource = $this->modx->getObject('modResource', $id); $doc = $resource->get('type,published,hidemenu,deleted');
$doc = $resource->get(array('type','published','hidemenu','deleted'));
/* assuming you have the ID of the template */
$c = $modx->newQuery('modTemplateVar');
$c->innerJoin('modTemplateVarTemplate','TemplateVarTemplates');
$c->where(array(
'TemplateVarTemplates.templateid' => $templateId,
));
$c->sortby('TemplateVarTemplates.rank','ASC');
$tvs = $modx->getObject('modTemplateVar',$c);
$names = array();
foreach ($tvs as $tv) {
$names[] = $tv->get('name');
}
$names = array_unique($names);
$siblings = $this->modx->getAllChildren($parentId, 'menuindex', 'ASC', 'id');
$c = $modx->newQuery('modResource');
$c->where(array(
'parent' => $parentId,
));
$c->sortby('menuindex','ASC');
$siblings = $modx->resource->getMany('Children',$c); function GetSiblingId( $id )
{
global $modx;
// Gets the next sibling.
// Returns -1 if one doesn't exist
$siblingId = -1;
// If the document is the document root, then it has no siblings
if ( $id == 0 )
{
return -1;
}
// Get the parent document id
$parentId = $this->GetParentId( $id );
// Get the immediate siblings (and the current document)
$c = $modx->newQuery('modResource');
$c->where(array(
'parent' => $parentId,
));
$c->sortby('menuindex','ASC');
$siblings = $modx->resource->getMany(array('Children','id'),$c);
echo "GetSiblingId: ";
print_r($siblings);
// Calculate the number of siblings
$nSiblings = count( $siblings ) - 1;
$currentIndex = -1;
// Find the current document in the list of siblings
foreach ( $siblings as $index => $sibling )
{
if ( $sibling['id'] == $id )
{
$currentIndex = $index;
break;
}
}
if ($currentIndex == -1)
{
return $siblingId;
}
switch ( $this->rel )
{
case 'prev':
if ( $currentIndex > 0 )
{
$siblingId = $siblings[$currentIndex-1]['id'];
return $siblingId;
}
break;
case 'next':
if ( $currentIndex < $nSiblings )
{
$siblingId = $siblings[$currentIndex+1]['id'];
return $siblingId;
}
break;
default:
return $siblingId;
}
return $siblingId;
} function GetParentId( $id )
{
// Gets the id of the parent.
// If the document is the root, and so has no parent, -1 is returned
if ( $id <= 0 ) {
return -1;
}
$resource = $this->modx->getObject('modResource', $id);
$currentDoc = $resource->get('parent');
return $currentDoc['parent'];
}
Thanks for your answer!
I tried to convert the rest of the snippet but got the following error on line 596:
Fatal error: Call to a member function newQuery() on a non-object in /public_html/assets/snippets/navigator/navigator.php on line 596
On line 596 I replaced the EVO code
$siblings = $this->modx->getAllChildren($parentId, 'menuindex', 'ASC', 'id');
with this REVO code
$c = $modx->newQuery('modResource'); $c->where(array( 'parent' => $parentId, )); $c->sortby('menuindex','ASC'); $siblings = $modx->resource->getMany('Children',$c);
Anyone seeing my mistake?
I attached the snippet-code if anyone is interested in helping me. I’ve commented every change I made in the script.
$parent = $modx->resource->getOne('Parent);
$siblings = $parent->getMany('Children',$c);$modx->getCollection('modResource',$c);
Hi,
I’d be really interesting if you got this to work? I am relatively new to ModX so even though I just followed the thread and tried to debug it, I didn’t get it to work. Anyone?
Thanks