<commit_before><?php
/*
 * Copyright (c) 2012 <NAME>
 * 
 * See the file LICENSE.txt for copying permission.
 */
namespace Mouf\Html\Template\Menus;

use \Mouf\Html\HtmlElement\HtmlElementInterface;
use \Mouf\Html\Widgets\Menu\MenuItemInterface;

/**
 * This class is in charge of rendering a menu. It contains a menu and can transform it in HTML using the toHtml() method.
 * <p>The rendering is performed using &lt;ul&gt; and &lt;li&gt; tags.</p>
 * 
 * @Component
 */
class BasicMenuRenderer implements HtmlElementInterface {
	
	/**
	 * The menu to render
	 *
	 * @Property
	 * @Compulsory
	 * @var MenuInterface
	 */
	public $menu;
	
	/**
	 * The whole CSS class to apply to the UL element.
	 * 
	 * @Property
	 * @Compulsory
	 * @var string
	 */
	public $cssClass = "menu";
	
	/**
	 * Initialize the object, optionnally with the array of menu items to be displayed.
	 *
	 * @param array<MenuItemInterface> $menuItems
	 */
	public function __construct($menu = null) {
		$this->menu = $menu;
	}
	
	public function toHtml() {
		if ($this->menu && !$this->menu->isHidden()) {
			echo '<ul class="'.$this->cssClass.'">';
			
			$menuItems = $this->menu->getChildren();
			if (is_array($menuItems)) {
				foreach ($menuItems as $item) {
					$this->renderHtmlMenuItem($item);
				}
			}
				
			echo '</ul>';
		}
	}
	
	private function renderHtmlMenuItem(MenuItemInterface $menuItem) {
		if (!$menuItem->isHidden()) {
			echo '<li ';
			$menuCssClass = $menuItem->getCssClass();
			if (!empty($menuCssClass) || $menuItem->isActive() || $menuItem->isExtended()) {
				echo 'class="';
				echo $menuCssClass;
				if ($menuItem->isActive()) {
					echo ' active';
				}
				echo '"';
			}
			echo '>';
			$url = $menuItem->getLink();
			if ($url) {
				echo '<a href="'.$url.'" >';
			}
			echo $menuItem->getLabel();
			if ($url) {
				echo '</a>';
			}
			$children = $menuItem->getChildren();
			if ($children) {
				echo '<ul>';
				foreach ($children as $child) {
					/* @var $child MenuItemInterface */
					$this->renderHtmlMenuItem($child);
				}
				echo '</ul>';
			}
			
			echo '</li>';
		}
	}
	
}
?><commit_msg>Migration to Mouf2... continuing<commit_after><?php
/*
 * Copyright (c) 2012 <NAME>
 * 
 * See the file LICENSE.txt for copying permission.
 */
namespace Mouf\Html\Template\Menus;

use \Mouf\Html\HtmlElement\HtmlElementInterface;
use \Mouf\Html\Widgets\Menu\MenuItemInterface;

/**
 * This class is in charge of rendering a menu. It contains a menu and can transform it in HTML using the toHtml() method.
 * <p>The rendering is performed using &lt;ul&gt; and &lt;li&gt; tags.</p>
 * 
 * @Component
 */
class BasicMenuRenderer implements HtmlElementInterface {
	
	/**
	 * The menu to render
	 *
	 * @Property
	 * @Compulsory
	 * @var MenuInterface
	 */
	public $menu;
	
	/**
	 * The whole CSS class to apply to the UL element.
	 * 
	 * @Property
	 * @Compulsory
	 * @var string
	 */
	public $cssClass = "menu";
	
	/**
	 * Initialize the object, optionnally with the array of menu items to be displayed.
	 *
	 * @param array<MenuItemInterface> $menuItems
	 */
	public function __construct($menu = null) {
		$this->menu = $menu;
	}
	
	public function toHtml() {
		$menuItems = $this->menu->getChildren();
		if ($this->menu && !$this->menu->isHidden() && !empty($menuItems)) {
			echo '<ul class="'.$this->cssClass.'">';
			
			if (is_array($menuItems)) {
				foreach ($menuItems as $item) {
					$this->renderHtmlMenuItem($item);
				}
			}
				
			echo '</ul>';
		}
	}
	
	private function renderHtmlMenuItem(MenuItemInterface $menuItem) {
		if (!$menuItem->isHidden()) {
			echo '<li ';
			$menuCssClass = $menuItem->getCssClass();
			if (!empty($menuCssClass) || $menuItem->isActive() || $menuItem->isExtended()) {
				echo 'class="';
				echo $menuCssClass;
				if ($menuItem->isActive()) {
					echo ' active';
				}
				echo '"';
			}
			echo '>';
			$url = $menuItem->getLink();
			if ($url) {
				echo '<a href="'.$url.'" >';
			}
			echo $menuItem->getLabel();
			if ($url) {
				echo '</a>';
			}
			$children = $menuItem->getChildren();
			if ($children) {
				echo '<ul>';
				foreach ($children as $child) {
					/* @var $child MenuItemInterface */
					$this->renderHtmlMenuItem($child);
				}
				echo '</ul>';
			}
			
			echo '</li>';
		}
	}
	
}
?>
{'fraction_non_alphanumeric': 0.16554659498207885, 'fraction_numerical': 0.0020161290322580645, 'mean_word_length': 2.5436507936507935, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 63, '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': '5894563', 'n_tokens_mistral': 1744, 'n_tokens_neox': 1429, 'n_words': 362}