Routing bug (fixed)

More
3 years 5 months ago - 3 years 5 months ago #469 by movs
movs created the topic: Routing bug (fixed)
Thank you for a very nice component,
I found a small bug in it and fixed,When i set up a module to the front page a found that a link to event still follows to "home page". I mean menu item. Untill i connected an event to the menu item, But I don't wont co connect every event to menu item. I only connected 1 menu item event category. So i fixed router (com_simple_calendar/helperroute.php) to check if any menu item connected to category of events.
Line 114: from
if ( isset($item->query['id'])  )
to:
if ( isset($item->query['id'])  || isset($item->query['catid']) )
and add line 224:
} elseif (isset($item->query['catid'])){
							$item->query['id'] = $item->query['catid'][0];


So compleate function is:
protected static function _findItem($needles = null)
	{
		$app		= JFactory::getApplication();
		$menus		= $app->getMenu('site');
		$language	= isset($needles['language']) ? $needles['language'] : '*';
		
		// Prepare the reverse lookup array.
		if (!isset(self::$lookup[$language]))
		{
			self::$lookup[$language] = array();

			$component	= JComponentHelper::getComponent('com_simplecalendar');

			$attributes = array('component_id');
			$values = array($component->id);

			if ($language != '*')
			{
				$attributes[] = 'language';
				$values[] = array($needles['language'], '*');
			}

			$items = $menus->getItems($attributes, $values);

			foreach ($items as $item)
			{
				if (isset($item->query) && isset($item->query['view']))
				{
					$view = $item->query['view'];
					if (!isset(self::$lookup[$language][$view]))
					{
						self::$lookup[$language][$view] = array();
					}
					if ( isset($item->query['id'])  || isset($item->query['catid']) )
					{

						// here it will become a bit tricky
						// language != * can override existing entries
						// language == * cannot override existing entries
						if ( is_array($item->query['id']) )
						{
							$item->query['id'] = $item->query['id'][0];

						} elseif (isset($item->query['catid'])){
							$item->query['id'] = $item->query['catid'][0];
						}
						if ( $item->query['id'] == '' )
						{
							$item->query['id'] = 0;
						}
						if (!isset(self::$lookup[$language][$view][$item->query['id']]) || $item->language != '*')
						{
							self::$lookup[$language][$view][$item->query['id']] = $item->id;
						}
					}
				}
			}
		}

		if ( $needles )
		{

			foreach ($needles as $view => $ids)
			{
				if ( isset(self::$lookup[$language][$view]) )
				{
					foreach ($ids as $id)
					{
						// Events list with category id (events of a single or multiple category)
						if ( isset(self::$lookup[$language][$view][(int) $id]) )
						{
							return self::$lookup[$language][$view][(int) $id];
						}
						// Events list without category id (all events)
						if ( isset(self::$lookup[$language][$view][0]) )
						{
							return self::$lookup[$language][$view][0];
						}
					}
				}
			}
		}

		$active = $menus->getActive();
		if ($active && ($active->language == '*' || !JLanguageMultilang::isEnabled()))
		{
			return $active->id;
		}

		// if not found, return language specific home link
		$default = $menus->getDefault($language);
		return !empty($default->id) ? $default->id : null;
	}


And in module mod_simplecalendar/helper.php line 147 cenged
from
$link = JRoute::_( SimpleCalendarHelperRoute::getEventRoute($row->slug, $row->catslug));
to
$link = JRoute::_( SimpleCalendarHelperRoute::getEventRoute($row->slug, $row->catid));

I did not tested it in multilangage site, may be I do it wrong, Correct me if so.
Last Edit: 3 years 5 months ago by movs.

Please Log in or Create an account to join the conversation.

More
3 years 5 months ago #473 by admin
admin replied the topic: Routing bug (fixed)
I will check that for completeness, but many many thanks for your help!
Fabrizio

Please Log in or Create an account to join the conversation.

Time to create page: 0.261 seconds
Powered by Kunena Forum