Object relational mapping - Hierarchical data - Introduction - Node interface.php 2.25 KB
Newer Older
hansbrix's avatar
hansbrix committed
1 2


3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
The node interface, for inserting and manipulating nodes within the tree, is accessed on a record level. A full implementation of this interface will be as follows:



<code type="php">
interface Doctrine_Node_Interface {

    /**
     * insert node into tree
     */
    public function insertAsParentOf(Doctrine_Record $dest);

    public function insertAsPrevSiblingOf(Doctrine_Record $dest);

    public function insertAsNextSiblingOf(Doctrine_Record $dest);

    public function insertAsFirstChildOf(Doctrine_Record $dest);

    public function insertAsLastChildOf(Doctrine_Record $dest);

    public function addChild(Doctrine_Record $record);

    /**
     * moves node (if has children, moves branch)
     *
     */  
    public function moveAsPrevSiblingOf(Doctrine_Record $dest);

    public function moveAsNextSiblingOf(Doctrine_Record $dest);

    public function moveAsFirstChildOf(Doctrine_Record $dest);

    public function moveAsLastChildOf(Doctrine_Record $dest);

    /**
     * node information
     */
    public function getPrevSibling();

    public function getNextSibling();

    public function getSiblings($includeNode = false);

    public function getFirstChild();

    public function getLastChild();

    public function getChildren();

    public function getDescendants();

    public function getParent();

    public function getAncestors();

    public function getPath($seperator = ' > ', $includeNode = false);

    public function getLevel();

    public function getNumberChildren();

    public function getNumberDescendants();

    /**
     * node checks
     */
    public function hasPrevSibling();

    public function hasNextSibling();

    public function hasChildren();

    public function hasParent();

    public function isLeaf();

    public function isRoot();

    public function isEqualTo(Doctrine_Record $subj);

    public function isDescendantOf(Doctrine_Record $subj);

    public function isDescendantOfOrEqualTo(Doctrine_Record $subj);

    public function isValidNode();

    /**
     * deletes node and it's descendants
     */
    public function delete();
}

// if your model acts as tree you can retrieve the associated node object as follows
$record = $manager->getTable('Model')->find($pk);
$nodeObj = $record->getNode();
</code>