<?php 
namespace backend\components;

use \Yii;
	
	
	
class LTEAdminMenu extends \dmstr\widgets\Menu{
		
		
		
		
		/**
		 * Checks whether a menu item is active.
		 * This is done by checking if [[route]] and [[params]] match that specified in the `url` option of the menu item.
		 * When the `url` option of a menu item is specified in terms of an array, its first element is treated
		 * as the route for the item and the rest of the elements are the associated parameters.
		 * Only when its route and parameters match [[route]] and [[params]], respectively, will a menu item
		 * be considered active.
		 * @param array $item the menu item to be checked
		 * @return boolean whether the menu item is active
		 */
		protected function isItemActive($item)
		{
			
			if (isset($item['target_url']) && is_array($item['target_url'])  ) {
				foreach ($item['target_url'] as $target){
					$route = $target;
					if ($route[0] !== '/' && Yii::$app->controller) {
						$route = Yii::$app->controller->module->getUniqueId() . '/' . $route;
					}
					$arrayRoute = explode('/', ltrim($route, '/'));
					$arrayThisRoute = explode('/', $this->route);
					if ($arrayRoute[0] !== $arrayThisRoute[0]) {
						continue;
					}
					if (isset($arrayRoute[1]) && $arrayRoute[1] !== $arrayThisRoute[1]) {
						continue;
					}
					if (isset($arrayRoute[2]) && $arrayRoute[2] !== $arrayThisRoute[2]) {
						continue;
					}
				return true;
				}
				return false;
			}else if (isset($item['url']) && is_array($item['url']) && isset($item['url'][0])) {
				$route = $item['url'][0];
				if ($route[0] !== '/' && Yii::$app->controller) {
					$route = Yii::$app->controller->module->getUniqueId() . '/' . $route;
				}
				$arrayRoute = explode('/', ltrim($route, '/'));
				$arrayThisRoute = explode('/', $this->route);
				if ($arrayRoute[0] !== $arrayThisRoute[0]) {
					return false;
				}
				if (isset($arrayRoute[1]) && $arrayRoute[1] !== $arrayThisRoute[1]) {
					return false;
				}
				if (isset($arrayRoute[2]) && $arrayRoute[2] !== $arrayThisRoute[2]) {
					return false;
				}
// 				unset($item['url']['#']);
// 				if (count($item['url']) > 1) {
// 					foreach (array_splice($item['url'], 1) as $name => $value) {
// 						if ($value !== null && (!isset($this->params[$name]) || $this->params[$name] != $value)) {
// 							return false;
// 						}
// 					}
// 				}
				return true;
			}
			return false;
		}
		
	}


?>