Back to PhocaDownloadRoute class

Method _findItem

protected static
_findItem
(mixed $needles, mixed $notCheckId = 0, mixed $component = 'com_phocadownload')

Method _findItem - Source code

/*
	function getSectionRoute($sectionid, $sectionidAlias = '')
	{
		$needles = array(
			'section' => (int) $sectionid,
			'sections' => ''
		);

		if ($sectionidAlias != '') {
			$sectionid = $sectionid . ':' . $sectionidAlias;
		}

		//Create the link
		$link = 'index.php?option=com_phocadownload&view=section&id='.$sectionid;

		if($item = self::_findItem($needles)) {
			if(isset($item->query['layout'])) {
				$link .= '&layout='.$item->query['layout'];
			}
			$link .= '&Itemid='.$item->id;
		}

		return $link;
	}

	function getSectionsRoute()
	{
		$needles = array(
			'sections' => ''
		);

		//Create the link
		$link = 'index.php?option=com_phocadownload&view=sections';

		if($item = self::_findItem($needles)) {
			if(isset($item->query['layout'])) {
				$link .= '&layout='.$item->query['layout'];
			}
			if (isset($item->id)) {
				$link .= '&Itemid='.$item->id;
			}
		}

		return $link;
	}*/
protected static function _findItem($needles, $notCheckId = 0, $component = 'com_phocadownload')
{
    $app = Factory::getApplication();
    $menus = $app->getMenu('site', array());
    $items = $menus->getItems('component', $component);
    // Don't check ID for specific views
    $notCheckIdArray = array('categories');
    if (!$items) {
        return $app->input->get('Itemid', 0, '', 'int');
        //return null;
    }
    $match = null;
    foreach ($needles as $needle => $id) {
        if ($notCheckId == 0) {
            foreach ($items as $item) {
                if (@$item->query['view'] == $needle && (in_array($needle, $notCheckIdArray) || @$item->query['id'] == $id)) {
                    $match = $item;
                    break;
                }
            }
        } else {
            foreach ($items as $item) {
                if (@$item->query['view'] == $needle) {
                    $match = $item;
                    break;
                }
            }
        }
        if (isset($match)) {
            break;
        }
    }
    return $match;
}