Skip to content

Instantly share code, notes, and snippets.

@nielsnuebel
Created July 3, 2015 08:43
Show Gist options
  • Save nielsnuebel/cfbc79da25adc7003ada to your computer and use it in GitHub Desktop.
Save nielsnuebel/cfbc79da25adc7003ada to your computer and use it in GitHub Desktop.
<?php
/**
* @package Joomla.Site
* @subpackage com_weblinks
*
* @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
/**
* Weblinks Component Route Helper
*
* @static
* @package Joomla.Site
* @subpackage com_weblinks
* @since 1.5
*/
abstract class NNProductsHelperRoute
{
/**
* @param integer The route of the category
*/
public static function getCategoryRoute($id)
{
$needles = array(
'category' => array((int) $id,'catid')
);
//Create the link
$link = 'index.php?option=com_nnproducts&view=category&catid=' . $id;
if ($item = self::_findItem($needles))
{
$link .= '&Itemid='.$item;
}
return $link;
}
/**
* @param integer The route of the product
*/
public static function getProductRoute($id)
{
$needles = array(
'product' => array((int) $id,'id')
);
//Create the link
$link = 'index.php?option=com_nnproducts&view=product&id=' . $id;
if ($item = self::_findItem($needles))
{
$link .= '&Itemid='.$item;
}
return $link;
}
/**
* @param integer The route of the product
*/
public static function getRecipesRoute()
{
$needles = array(
'recipes' => array('recipes','view')
);
//Create the link
$link = 'index.php?option=com_nnproducts&view=recipes';
if ($item = self::_findItem($needles))
{
$link .= '&Itemid='.$item;
}
return $link;
}
/**
* @param integer The route of the product
*/
public static function getSearchRoute()
{
$needles = array(
'search' => array('search','view')
);
//Create the link
$link = 'index.php?option=com_nnproducts&view=search';
if ($item = self::_findItem($needles))
{
$link .= '&Itemid='.$item;
}
return $link;
}
/**
* @param integer The route of the product
*/
public static function getNewSearchRoute()
{
$needles = array(
'search' => array('search','view')
);
//Create the link
$link = 'index.php?option=com_nnproducts&view=search&task=resetfilter';
if ($item = self::_findItem($needles))
{
$link .= '&Itemid='.$item;
}
return $link;
}
/**
* @param integer The route of the product
*/
public static function getChildrenSearchRoute()
{
$needles = array(
'recipes' => array('recipes','view')
);
//Create the link
$link = 'index.php?option=com_nnproducts&view=recipes&task=childrens';
if ($item = self::_findItem($needles))
{
$link .= '&Itemid='.$item;
}
return $link;
}
/**
* @param integer The route of the product
*/
public static function getProductSearchRoute($id)
{
$needles = array(
'recipes' => array('recipes','view')
);
//Create the link
$link = 'index.php?option=com_nnproducts&view=recipes&task=product&id=' . $id;
if ($item = self::_findItem($needles))
{
$link .= '&Itemid='.$item;
}
return $link;
}
/**
* @param integer The route of the product
*/
public static function getRecipeRoute($id)
{
$needles = array(
'recipe' => array((int) $id,'id')
);
//Create the link
$link = 'index.php?option=com_nnproducts&view=recipe&id=' . $id;
if ($item = self::_findItem($needles))
{
$link .= '&Itemid='.$item;
}
else
{
$needles = array(
'recipes' => array('recipes','view')
);
if ($item = self::_findItem($needles))
{
$link .= '&Itemid='.$item;
}
}
return $link;
}
protected static function _findItem($needles)
{
$component =& JComponentHelper::getComponent('com_nnproducts');
$app = JFactory::getApplication();
$menus = $app->getMenu('site');
$items = $menus->getItems('component_id', $component->id);
$match = null;
foreach($needles as $needle => $id)
{
foreach($items as $item)
{
if ((@$item->query['view'] == $needle) && ($item->query[$id[1]] == $id[0])) {
$match = $item->id;
break;
}
}
if(isset($match)) {
break;
}
}
return $match;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment