<commit_before><?php
/**
 *  Author:<NAME> Copyright 2013
 *
 *  Description: Utility class to dynamically build menus 
 *               given the follow structure
 *	              
 *               Name, parent, child
 * 
 **/


class My_items
{
    private $name = "";
    private $parent = "";
    private $child = "";
    
   
    public function setName($fo)
    {
      $this->name = $fo;
    }
   
    public function setParent($id)
    {
       $this->parent = $id;
    }

    public function setChild($na)
    {
       $this->child= $na;
    }
    
    public function getName()
    {
       return $this->name;
    }
    
    public function getParent()
    {
       return $this->parent;
    }
    
    public function getChild()
    {
       return $this->child;
    }


}//End class declaration

/**
 *  @Description: To dynamically build a php menu
 *                using recursion.
 *
 **/

function buildNavigation($items, $parent = "0", $level = 0)
{
    $hasChildren = false;
    $outputHtml = '<ul>%s</ul>';
    $childrenHtml = '';

       
    foreach($items as $item)
    {
        if ($item->getParent() == $parent) 
        {           
            $hasChildren = true;
            $childrenHtml .= '<li>'. $item->getName();         
            $childrenHtml .= " $level".buildNavigation($items, $item->getChild(), $level+1);                  
            $childrenHtml .= '</li>';            
        }        
    }
 
    // Without children, we do not need the <ul> tag.
    if (!$hasChildren) 
    {
        $outputHtml = '';
        $level--;
    }

    // Returns the HTML
    return sprintf($outputHtml, $childrenHtml);
}



//declare an array of class objects
$metas = array();


$object = new My_items();
$object->setName("reloading");
$object->setParent("0");
$object->setChild("2");

$object1 = new My_items();
$object1->setName("compnents");
$object1->setParent("2");
$object1->setChild("19");

$object2 = new My_items();
$object2->setName("compndsdsents");
$object2->setParent("19");
$object2->setChild("20");

$object3 = new My_items();
$object3->setName("compndsdsents");
$object3->setParent("19");
$object3->setChild("23");


$metas[0] = $object;
$metas[1] = $object1;
$metas[2] = $object2;
$metas[3] = $object3;


print(buildNavigation($metas));





<commit_msg>Styled to accept bootstrap one level deep<commit_after><?php
/**
 *  Author:<NAME> Themes Copyright 2013
 *
 *  Description: Utility class to dynamically build menus 
 *               given the follow structure
 *	              
 *               Name, parent, child
 *
 * -Added bootstrap styling classes
 * -IMPORTANT Only works with one drop down menu
 * -Need to convert htmlentities to prevent bad output
 *   
 **/


class My_items
{
    private $name = "";
    private $parent = "";
    private $child = "";
    private $link = "#";
    
   
    public function setName($fo)
    {
      $this->name = $fo;
    }
   
    public function setParent($id)
    {
       $this->parent = $id;
    }

    public function setChild($na)
    {
       $this->child= $na;
    }
    
    public function setLink($li)
    {
       $this->link = $li;	
    }
    
    public function getName()
    {
       return $this->name;
    }
    
    public function getParent()
    {
       return $this->parent;
    }
    
    public function getChild()
    {
       return $this->child;
    }
    
    public function getLink()
    {
       return $this->link;	
    }


}//End class declaration

/**
 *  @Description: To dynamically build a php menu
 *                using recursion.
 *
 **/

function buildNavigation($items, $parent = "0", $level = 0)
{
    $hasChildren = false;
    $outputHtml = '<ul class="nav">%s</ul>';
    $childrenHtml = '';
    
    if($level == 1)
    {
       $outputHtml = '<ul class="dropdown-menu">%s</ul>';    	
    }
    if($level == 2)
    {
       $outputHtml = '<ul>%s</ul>';    	
    }

      
    foreach($items as $item)
    {
    	  
        if ($item->getParent() == $parent) 
        {           
				/*Special case for first drop down menu*/           
            if($level == 0) 
            { 
	            $hasChildren = true;
	            $childrenHtml .= '<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">'
	                             . $item->getName(). '<b class="caret"></b></a>';         
	            $childrenHtml .= buildNavigation($items, $item->getChild(), $level+1);                  
	            $childrenHtml .= '</li>'; 	
            }
            else
            {	
	            $hasChildren = true;
	            $childrenHtml .= '<li><a href="'.$item->getLink().'">'. $item->getName();         
	            $childrenHtml .= buildNavigation($items, $item->getChild(), $level+1);                  
	            $childrenHtml .= '</a></li>';  
            }          
        }        
    }
 
    // Without children, we do not need the <ul> tag.
    if (!$hasChildren) 
    {
        $outputHtml = '';
        $level--;
    }

    // Returns the HTML
    return sprintf($outputHtml, $childrenHtml);
    
}



//declare an array of class objects
$metas = array();


$object = new My_items();
$object->setName("reloading");
$object->setParent("0");
$object->setChild("2");

$object1 = new My_items();
$object1->setName("sublevel");
$object1->setParent("2");
$object1->setChild("19");

$object2 = new My_items();
$object2->setName("sublevel");
$object2->setParent("2");
$object2->setChild("22");




$metas[0] = $object;
$metas[1] = $object1;
$metas[2] = $object2;



print(buildNavigation($metas));


{'fraction_non_alphanumeric': 0.16454789615040286, 'fraction_numerical': 0.012712623097582811, 'mean_word_length': 1.9369085173501577, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3994701', 'n_tokens_mistral': 1804, 'n_tokens_neox': 1716, 'n_words': 381}