function getChildren( VF_Level $entity ) { if($this->getSchema()->isGlobal($entity->getType()) && $this->getSchema()->getRootLevel() != $entity->getType()) { throw new Exception('ambiguous operation'); } if( $entity->getNextLevel() == '' ) { throw new Exception( 'this type doesnt have children' ); } $nextLevelsTable = $this->getSchema()->levelTable($entity->getNextLevel()); $q = $this->getReadAdapter()->select() ->from(array('l'=>$nextLevelsTable)) ->joinLeft(array('d'=>$this->getSchema()->definitionTable()), 'l.id = d.' . $entity->getNextLevel() . '_id', array()) ->where('d.' . $entity->getType() . '_id = ?', $entity->getId() ) ->order('title') ->group('l.id'); $r = $this->query( $q ); $children = array(); foreach( $r->fetchAll( Zend_Db::FETCH_OBJ ) as $row ) { $child = $entity->createEntity( $entity->getNextLevel() ); $child->setId( $row->id ); $child->setTitle( $row->title ); $children[] = $child; } return $children; }