File: D:/HostingSpaces/SBogers10/tops.komma.pro/wwwroot/lib/content/submenu.class.php
<?php
/**
* submenu.class.php
* Created by Komma Mediadesign.
* Author: mike
* Date: 10/04/14
*/
class Submenu
{
private $_name;
/*
* Filter array
*/
private $_items;
/*
* Filters that have sub filter
*/
private $_hasSubItem;
/*
* Sub filter array
*/
private $_subItem;
private $_lang = array();
private $_urls = array();
private $_pages = array();
public function __construct()
{
// Set language and url for conversion
$Translator = new Translator(URL_LANG);
$this->_lang = $Translator->get();
$this->_urls = $Translator->getUrls();
$this->_pages = $Translator->getPages();
}
public function set($name, $item, $hasSub=array(), $sub=array())
{
$this->_name = $name;
$this->_items = $item;
$this->_hasSubItem = $hasSub;
$this->_subItem = $sub;
}
/*
* Create mobile menu
*/
public function create($singleList = false)
{
$output = '<ul>';
if($this->_name == 'filters')
{
$output .= '<li class="main';
if( ! defined('URL_SUB')) $output .= ' active';
$output .= '"><a class="title" href="'. LANG_ROOT . $this->_urls[$this->_name] . '/">' . $this->_lang['survey'] . '</a>';
}
if($this->_name == 'uses')
{
$output .= '<li class="main';
if( ! defined('URL_SUB')) $output .= ' active';
$output .= '"><a class="title" href="'. LANG_ROOT . $this->_urls[$this->_name] . '/">' . $this->_lang['general'] . '</a>';
}
// Generate list
foreach($this->_items as $item)
{
// Get URL
$itemUrl = $this->_pages[$item];
// if isset language
if(isset($this->_lang[$item]))
{
// Defined language for this filter
$title = $this->_lang[$item];
}
else
{
// Default title
$title = str_replace('-',' ',$itemUrl);
$title = ucfirst($title);
}
// Add main title to list
$output .= '<li class="main';
if(defined('URL_SUB') && URL_SUB == $itemUrl) $output .= ' active';
$output .= '"><a class="title" href="'. LANG_ROOT . $this->_urls[$this->_name] . '/' . $itemUrl . '">' . $title . '</a>';
// Check for submenu
if( in_array($item,$this->_hasSubItem))
{
if( ! $singleList) $output .= '<ul>';
$output .= '<li';
if(defined('URL_SUB') && URL_SUB == $itemUrl && ! defined('URL_SUB2')) $output .= ' class="active"';
$output .= '><a href="'. LANG_ROOT . $this->_urls[$this->_name] . '/' . $itemUrl . '">' . $this->_lang['general'] . '</a></li>';
// Add sub filters
foreach($this->_subItem[$item] as $subFilter)
{
//var_dump($subFilter);
// Get URL
$subFilterUrl = $this->_pages[$subFilter];
// if isset language
if(isset($this->_lang[$subFilter]))
{
// Defined language for this filter
$subTitle = $this->_lang[$subFilter];
}
else
{
// Default title
$subTitle = str_replace('-',' ',$subFilterUrl);
$subTitle = ucfirst($subTitle);
}
$output .= '<li';
if(defined('URL_SUB2') && URL_SUB2 == $subFilterUrl) $output .= ' class="active"';
$output .= '><a href="'. LANG_ROOT . $this->_urls[$this->_name] . '/' . $itemUrl . '/' . $subFilterUrl . '">' . $subTitle . '</a></li>';
}
if( ! $singleList) $output .= '</ul>';
}
$output .= '</li>';
}
// Close list
$output .= '</ul>';
return $output;
}
/*
* Create mobile menu
*/
public function createMobile()
{
$output = '<span class="title"><span class="dd_arrow"></span>' . $this->_lang[$this->_name] . '</span>';
$output .= '<ul>';
// Generate list
foreach($this->_items as $item)
{
// Get URL
$itemUrl = $this->_pages[$item];
// if isset language
if(isset($this->_lang[$item]))
{
// Defined language for this filter
$title = $this->_lang[$item];
}
else
{
// Default title
$title = str_replace('-',' ',$itemUrl);
$title = ucwords($title);
}
$hasSubmenu = in_array($item,$this->_hasSubItem);
// Add main title to list
$classes = array();
if(defined('URL_SUB') && URL_SUB == $itemUrl) $classes[] = 'active';
if($hasSubmenu) $classes[] = 'mb_dropdown';
$output .= '<li';
if( ! empty($classes))
{
$output .= ' class="';
foreach($classes as $key => $class)
{
if($key != 0) $output .= ' ';
$output .= $class;
}
$output .= '"';
}
$output .= '>';
if($hasSubmenu)
{
$output .= '<span class="title"><span class="dd_arrow"></span>' . $title . '</span>';
}
else
{
$output .= '<a class="title" href="'. LANG_ROOT . $this->_urls[$this->_name] . '/' . $itemUrl . '">' . $title . '</a>';
}
// Check for submenu
if( $hasSubmenu )
{
$output .= '<ul>';
// Add sub filters
foreach($this->_subItem[$item] as $subFilter)
{
// Get URL
$subFilterUrl = $this->_pages[$subFilter];
// if isset language
if(isset($this->_lang[$subFilter]))
{
// Defined language for this filter
$subTitle = $this->_lang[$subFilter];
}
else
{
// Default title
$subTitle = str_replace('-',' ',$subFilterUrl);
$subTitle = ucwords($subTitle);
}
if($subFilter == 'index') $subTitle = 'Algemeen';
$output .= '<li';
if(defined('URL_SUB2') && URL_SUB2 == $subFilterUrl) $output .= ' class="active"';
$output .= '><a class="title" href="'. LANG_ROOT . $this->_urls[$this->_name] . '/' . $itemUrl . '/' . $subFilterUrl . '">' . $subTitle . '</a></li>';
}
$output .= '</ul>';
}
$output .= '</li>';
}
// Close list
$output .= '</ul>';
return $output;
}
}