getNode() public method

getter for node associated with this record
public getNode ( ) : Doctrine_Node
return Doctrine_Node false if component is not a Tree
Example #1
0
 /**
  * Creates root node from given record or from a new record.
  *
  * Note: When using a tree with multiple root nodes (hasManyRoots), you MUST pass in a
  * record to use as the root. This can either be a new/transient record that already has
  * the root id column set to some numeric value OR a persistent record. In the latter case
  * the records id will be assigned to the root id. You must use numeric columns for the id
  * and root id columns.
  *
  * @param object $record        instance of Doctrine_Record
  */
 public function createRoot(Doctrine_Record $record = null)
 {
     if ($this->getAttribute('hasManyRoots')) {
         if (!$record || !$record->exists() && $record->getNode()->getRootValue() <= 0 || $record->getTable()->isIdentifierComposite()) {
             throw new Doctrine_Tree_Exception("Node must have a root id set or must " . " be persistent and have a single-valued numeric primary key in order to" . " be created as a root node. Automatic assignment of a root id on" . " transient/new records is no longer supported.");
         }
         if ($record->exists() && $record->getNode()->getRootValue() <= 0) {
             // Default: root_id = id
             $identifier = $record->getTable()->getIdentifier();
             $record->getNode()->setRootValue($record->get($identifier));
         }
     }
     if (!$record) {
         $record = $this->table->create();
     }
     $record->set('lft', '1');
     $record->set('rgt', '2');
     $record->set('level', 0);
     $record->save();
     return $record;
 }
Example #2
0
 /**
  * determines if node is ancestor of subject node
  *
  * @return bool            
  */
 public function isAncestorOf(Doctrine_Record $subj)
 {
     return $subj->getNode()->getLeftValue() > $this->getLeftValue() && $subj->getNode()->getRightValue() < $this->getRightValue() && $subj->getNode()->getRootValue() == $this->getRootValue();
 }
Example #3
0
 /**
  * determines if node is child of or sibling to subject node
  *
  * @return bool            
  */
 public function isDescendantOfOrEqualTo(Doctrine_Record $subj)
 {
     return $this->getLeftValue() >= $subj->getNode()->getLeftValue() && $this->getRightValue() <= $subj->getNode()->getRightValue() && $this->getRootValue() == $subj->getNode()->getRootValue();
 }
Example #4
0
 /**
  * determines if node is valid
  *
  * @return bool            
  */
 public function isValidNode(Doctrine_Record $record = null)
 {
     if ($record === null) {
         return $this->getRightValue() > $this->getLeftValue();
     } else {
         return $record->getNode()->getRightValue() > $record->getNode()->getLeftValue();
     }
 }