Code snippets for symfony 1.x

Navigation

Nested Set Navigation Component Module (PART 3)

NestedSet Model for Navigation

model scheme

enhanced nested set model class

enhanced module action class

navigation list tabular cell template

Features:

TEMPLATES

NestedSet Action Controls

Look at module action class for further information.

/apps/backend/modules/navigation/templates/_list_td_tabular.php
 
 
 
 
// delete action for node enabled if it has parent
<?php if($navigation->getParent()>0): ?>
<?php echo link_to(__('delete'), 'navigation/delete?component_id='.$navigation->getComponentId(), array ('post' => true,'confirm' => __('Are you sure?'),));?>
<?php endif; ?>
 
// edit node
<?php echo link_to(__('edit'), 'navigation/edit?component_id='.$navigation->getComponentId());?>
 
 
// tree actions if node level greater zero
<?php if($navigation->hasChilds()>0 && $navigation->isLevel() > 0): ?>
 
// perform tree delete action
<?php echo link_to(__('delete tree'), 'navigation/deleteDescendants?component_id='.$navigation->getComponentId(), array ('post' => true,'confirm' => __('Are you sure?')));?>
<?php if($navigation->hasChilds() > 0):?>
 
// allow tree copy action if node has children
<?php echo link_to(__('copy tree'), 'navigation/copyDescendants?component_id='.$navigation->getComponentId().'&root_id='.$navigation->selfRoot(), array ('post' => true,'confirm' => __('Are you sure?')));?>
<?php endif; ?>
<?php endif; ?>
 
// move operations
<?php if($navigation->isLevel() > 0): ?>
<?php
    // if a node's root has a successor then move to previous root
    if($navigation->nextRoot()){
        echo link_to(__('moveRootPrev'), 'navigation/moveRootPrev?component_id='. $navigation->getComponentId().'&root_id='.$navigation->selfRoot(), array('class' => 'moveRootPrev'));
    }
    // if a node's root has a predecessor then move to next root
    if($navigation->prevRoot()){
        echo link_to(__('moveRootNext'), 'navigation/moveRootNext?component_id='.$navigation->getComponentId().'&root_id='.$navigation->selfRoot(), array('class' => 'moveRootNext'));
    }
?>
<?php endif; ?>
 
// self-explaining
<?php echo link_to(__('insertAsFirstChildOf'), 'navigation/insertAsFirstChildOf?component_id='. $navigation->getComponentId(), array('class' => 'insertAsFirstChildOf'));?>
<?php echo link_to(__('insertAsLastChildOf'), 'navigation/insertAsLastChildOf?component_id='.$navigation->getComponentId(), array('class' => 'insertAsLastChildOf'));?>
if($navigation->isLevel() > 0){
    echo link_to(__('insertAsPrevSiblingOf'), 'navigation/insertAsPrevSiblingOf?component_id='.$navigation->getComponentId(), array('class' => 'insertAsPrevSiblingOf'));
    echo link_to(__('insertAsNextSiblingOf'), 'navigation/insertAsNextSiblingOf?component_id='.$navigation->getComponentId(), array('class' => 'insertAsNextSiblingOf'));
}
?>
<?php if($navigation->getParent()>0): ?>
    // move to parent node and place before
    if($navigation->isLevel()>1){
        echo link_to(__('moveLeftUp'), 'navigation/moveLeftUp?component_id='. $navigation->getComponentId(), array('class' => 'moveLeftUp'));
    }
 
    // move to parent node and place after
    if($navigation->isLevel()>1){
        echo link_to(__('moveLeftDown'), 'navigation/moveLeftDown?component_id='.$navigation->getComponentId(), array('class' => 'moveLeftDown'));
    }
 
    // place as predecessor's child
    if ( $navigation->isLevel() > 0 && $navigation->prevSibling() ) {
        echo link_to(__('moveRightPrev'), 'navigation/moveRightPrev?component_id='.$navigation->getComponentId(), array('class' => 'moveRightPrev'));
    }
 
    // place as successor's child
    if ( $navigation->isLevel() > 0 && $navigation->nextSibling() ){
        echo link_to(__('moveRightNext'), 'navigation/moveRightNext?component_id='.$navigation->getComponentId(), array('class' => 'moveRightNext'));
    }
?>
 
if($navigation->isLevel()>0){
    if($navigation->prevSibling()){
        echo link_to(__('moveToPrevSiblingOf'), 'navigation/moveToPrevSiblingOf?component_id='.$navigation->getComponentId(),array('class' => 'moveUp'));
    }
 
    if($navigation->nextSibling()){
        echo link_to(__('moveToNextSiblingOf'), 'navigation/moveToNextSiblingOf?component_id='.$navigation->getComponentId(), array('class' => 'moveDown'));
    }
}
?>
 

Enjoy it.

by Thomas Schäfer on 2008-03-19, tagged model  navigation  nested  set