Skip to content

Instantly share code, notes, and snippets.

@nielsnuebel
Created February 7, 2018 13:48
Show Gist options
  • Save nielsnuebel/7850f0c51441886e706e3a969b1c4b0d to your computer and use it in GitHub Desktop.
Save nielsnuebel/7850f0c51441886e706e3a969b1c4b0d to your computer and use it in GitHub Desktop.
public static function getAjax()
{
$app = JFactory::getApplication();
// Get an instance of the generic articles model
$model = JModelLegacy::getInstance('Areas', 'KickDirectoryModel', array('ignore_request' => true));
$model->setState('filter.state', 1);
$items = $model->getItems();
// Load associations
$assoc = JLanguageAssociations::isEnabled();
$lang = JFactory::getLanguage();
$languages = JLanguageHelper::getLanguages();
foreach ($items as $item)
{
$item->link = JRoute::_('index.php?Itemid=' . $item->startid);
if (!$assoc)
{
continue;
}
$associations = MenusHelper::getAssociations($item->startid);
foreach ($languages as $language)
{
if($language->lang_code === $lang->getTag())
{
$itemid = $associations[$lang->getTag()];
$item->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $itemid);
break;
}
}
}
echo new JResponseJson($items, null, false);
$app->close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment