IdentifiableTree.class.php

Go to the documentation of this file.
00001 <?php
00002 /****************************************************************************
00003  *   Copyright (C) 2005-2007 by Konstantin V. Arkhipov, Anton E. Lebedevich *
00004  *                                                                          *
00005  *   This program is free software; you can redistribute it and/or modify   *
00006  *   it under the terms of the GNU Lesser General Public License as         *
00007  *   published by the Free Software Foundation; either version 3 of the     *
00008  *   License, or (at your option) any later version.                        *
00009  *                                                                          *
00010  ****************************************************************************/
00011 /* $Id: IdentifiableTree.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00018     abstract class IdentifiableTree
00019         extends IdentifiableObject
00020         implements Stringable
00021     {
00022         private $parent = null;
00023         
00024         public function getParent()
00025         {
00026             return $this->parent;
00027         }
00028         
00029         public function setParent(IdentifiableTree $parent)
00030         {
00031             Assert::brothers($this, $parent);
00032             
00033             $this->parent = $parent;
00034             
00035             return $this;
00036         }
00037         
00038         public function dropParent()
00039         {
00040             $this->parent = null;
00041             
00042             return $this;
00043         }
00044         
00045         public function getRoot()
00046         {
00047             $current = $this;
00048             $next = $this;
00049             
00050             while ($next) {
00051                 $current = $next;
00052                 $next = $next->getParent();
00053             }
00054             
00055             return $current;
00056         }
00057         
00058         public function toString($delimiter = ', ')
00059         {
00060             $ids = array($this->getId());
00061             
00062             $parent = $this;
00063             
00064             while ($parent = $parent->getParent())
00065                 $ids[] = $parent->getId();
00066             
00067             $ids = array_reverse($ids);
00068             
00069             return implode($delimiter, $ids);
00070         }
00071     }
00072 ?>

Generated on Sun Dec 9 21:56:23 2007 for onPHP by  doxygen 1.5.4