<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of FMenu
 *
 * @author HP
 */
Yii::import('zii.widgets.CMenu');

class FMenu extends CMenu {

    /**
     * Checks whether a menu item is active.
     * This is done by checking if the currently requested URL is generated by the 'url' option
     * of the menu item. Note that the GET parameters not specified in the 'url' option will be ignored.
     * @param array $item the menu item to be checked
     * @param string $route the route of the current request
     * @return boolean whether the menu item is active
     */
    protected function isItemActive($item, $route) {
        if (isset($item['url']) && is_array($item['url']) && !strcasecmp(trim($item['url'][0], '/'), $route)) {
            unset($item['url']['#']);
            if (count($item['url']) > 1) {
                foreach (array_splice($item['url'], 1) as $name => $value) {
                    if (!isset($_GET[$name]) || $_GET[$name] != $value)
                        return false;
                }
            }
            return true;
        }
        else {
            if (isset($item['url'])) {
                $requestUri = Yii::app()->request->requestUri;
                if ($requestUri == $item['url']) {
                    return true;
                }
            }
        }
        return false;
    }

}
