<?php
/**
 * ISO Project
 *
 * @category   Malf
 * @package    Malf_View
 * @subpackage Helper
 * @version    1.0
 */

/** Zend_View_Helper_Abstract.php */
require_once 'Zend/View/Helper/Abstract.php';

/**
 * Helper for transforming tree structure to table representation
 *
 * @subpackage Helper
 */
class Malf_View_Helper_TreeToRows extends Zend_View_Helper_Abstract
{
    /**
     * Generates rows from tree nodes.
     *
     * @access public
     *
     * @return array list of id for table output.
     */
    public function treeToRows($tree) {
    	$rows = $this->growRows($tree);
    	return $rows;
    }
    
    
    private function growRows($tree, $deep = 1)
    {
    	static $rows;
        
		foreach ($tree as $k => $v) {
			$rows[] = array('id' => $k, 'deep' => $deep);
			if (count($v) > 0) {
				$this->growRows($v, $deep + 1);
			}
		}

		return $rows;     			
    }
}
