| Server IP : 54.36.91.62 / Your IP : 216.73.217.94 Web Server : Apache System : Linux webm013.cluster127.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64 User : coopiak ( 151928) PHP Version : 8.3.23 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/coopiak/amisdesseniors-fr/vesoul/components/com_djcatalog2/helpers/ |
Upload File : |
<?php
/**
* @package DJ-Catalog2
* @copyright Copyright (C) DJ-Extensions.com, All rights reserved.
* @license http://www.gnu.org/licenses GNU/GPL
* @author url: http://dj-extensions.com
* @author email contact@dj-extensions.com
*/
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Associations;
use Joomla\CMS\Language\Multilanguage;
abstract class DJCatalog2HelperAssociation
{
/**
* Method to get the associations for a given item
*
* @param integer $id Id of the item (helloworld id or catid, depending on view)
* @param string $view Name of the view ('helloworld' or 'category')
*
* @return array Array of associations for the item
*/
public static function getAssociations($id = 0, $view = null)
{
$input = Factory::getApplication()->input;
$view = $view === null ? $input->get('view') : $view;
$id = empty($id) ? $input->getInt('id') : $id;
$pid = empty($id) ? $input->getInt('pid') : $id;
$cid = $input->getInt('cid', 0);
$pcid = $input->getInt('pcid', 0);
if ($view === 'item') {
if ($id) {
$user = Factory::getUser();
$groups = implode(',', $user->getAuthorisedViewLevels());
$db = Factory::getDbo();
$advClausuleItem = array();
$advClausuleItem[] = 'c2.access IN (' . $groups . ')';
$advClausuleItem[] = 'c2.language != ' . $db->quote(Factory::getApplication()->getLanguage()->getTag());
$advClausuleItem[] = 'c2.published = 1';
$queryCategory = $db->getQuery(true)
->select($db->quoteName(['cat_id']))
->from($db->quoteName('#__djc2_items'))
->where([
$db->quoteName('id') . ' = ' . $db->quote($id),
]);
$db->setQuery($queryCategory);
$catItem = $db->loadObject();
$associationsItem = Associations::getAssociations('com_djcatalog2', '#__djc2_items', 'com_djcatalog2.item', $id, 'id', 'alias', '', $advClausuleItem);
$associationsCategory = Associations::getAssociations('com_djcatalog2', '#__djc2_categories', 'com_djcatalog2.category', $catItem->cat_id, 'id', 'alias', '');
$return = array();
foreach ($associationsItem as $tag => $item) {
$cid = isset($associationsCategory[$tag]) ? $associationsCategory[$tag]->id : 0;
$link = DJCatalog2HelperRoute::getItemRoute($item->id, $cid);
if ($item->language && $item->language !== '*' && Multilanguage::isEnabled()) {
$link .= '&lang=' . $item->language;
}
require_once JPATH_SITE . '/components/com_djcatalog2/router.php';
parse_str(parse_url($link, PHP_URL_QUERY), $query);
// 🔹 Pełne id:alias
$idFull = $query['id'] ?? '';
$cidFull = $query['cid'] ?? '';
// 🔹 Znajdź Itemid pozycji menu z widokiem "items" i odpowiednim językiem
$app = \Joomla\CMS\Factory::getApplication();
$menu = $app->getMenu();
$db = \Joomla\CMS\Factory::getDbo();
$langTag = $item->language !== '*' ? $item->language : '*';
$queryMenu = $db->getQuery(true)
->select($db->quoteName(['id', 'language', 'link', 'alias']))
->from($db->quoteName('#__menu'))
->where([
$db->quoteName('link') . ' LIKE ' . $db->quote('%view=items%'),
$db->quoteName('published') . ' = 1'
])
->order('FIELD(language, ' . $db->quote($langTag) . ', "'.$item->language.'") DESC');
$db->setQuery($queryMenu);
$menuItem = $db->loadObject();
if ($menuItem) {
$query['Itemid'] = (int) $menuItem->id;
} else {
// fallback: spróbuj użyć aktywnego menu, albo bez Itemid
$query['Itemid'] = null;
}
$query = [
'option' => 'com_djcatalog2',
'view' => 'item',
'id' => $idFull,
'cid' => $cidFull,
'Itemid' => $menuItem ? $menuItem->id : null
];
if (!empty($query['cid']) && $query['view'] === 'item') {
// Force router to build full path with category
$query['force_category'] = false;
}
$djRouter = new \DJCatalog2Router();
$segments = $djRouter->build($query);
if ($menuItem) {
$menuAlias = trim($menuItem->alias ?? '', '/');
if ($menuAlias) {
array_unshift($segments, $menuAlias);
}
}
$path = implode('/', $segments);
$sefUrl = '/' . substr($item->language, 0, 2) . '/' . $path;
$return[$tag] = $sefUrl;
}
return $return;
}
} else if ($view === 'producer') {
if ($pid) {
$user = Factory::getUser();
$groups = implode(',', $user->getAuthorisedViewLevels());
$db = Factory::getDbo();
$advClausuleItem = array();
//$advClausuleItem[] = 'c2.access IN (' . $groups . ')';
$advClausuleItem[] = 'c2.language != ' . $db->quote(Factory::getApplication()->getLanguage()->getTag());
$advClausuleItem[] = 'c2.published = 1';
$associationsItem = Associations::getAssociations('com_djcatalog2', '#__djc2_producers', 'com_djcatalog2.producer', $pid, 'id', 'alias', '', $advClausuleItem);
$associationsCategory = Associations::getAssociations('com_djcatalog2', '#__djc2_producer_categories', 'com_djcatalog2.producercategory', $pcid, 'id', 'alias', '');
$return = array();
foreach ($associationsItem as $tag => $item) {
$cid = ((isset($associationsCategory[$tag])) ? $associationsCategory[$tag]->id : 0);
$link = DJCatalog2HelperRoute::getProducerRoute($item->id);
if ($item->language && $item->language !== '*' && Multilanguage::isEnabled()) {
$link .= '&lang=' . $item->language;
}
$return[$tag] = $link;
}
return $return;
}
}
if ($view === 'items') {
if ($cid) {
$user = Factory::getUser();
$groups = implode(',', $user->getAuthorisedViewLevels());
$db = Factory::getDbo();
$advClausule = [];
$advClausule[] = 'c2.access IN (' . $groups . ')';
$advClausule[] = 'c2.language != ' . $db->quote(Factory::getApplication()->getLanguage()->getTag());
$advClausule[] = 'c2.published = 1';
// Pobierz asocjacje dla kategorii
$associationsCategory = Associations::getAssociations(
'com_djcatalog2',
'#__djc2_categories',
'com_djcatalog2.category',
$cid,
'id',
'alias',
'',
$advClausule
);
$return = [];
foreach ($associationsCategory as $tag => $cat) {
// Utwórz podstawowy link
$link = DJCatalog2HelperRoute::getCategoryRoute($cat->id);
if ($cat->language && $cat->language !== '*' && Multilanguage::isEnabled()) {
$link .= '&lang=' . $cat->language;
}
require_once JPATH_SITE . '/components/com_djcatalog2/router.php';
parse_str(parse_url($link, PHP_URL_QUERY), $query);
$cidFull = $query['cid'] ?? '';
// Znajdź Itemid menu z widokiem "items" w danym języku
$app = Factory::getApplication();
$menu = $app->getMenu();
$langTag = $cat->language !== '*' ? $cat->language : '*';
$queryMenu = $db->getQuery(true)
->select($db->quoteName(['id', 'language', 'link', 'alias']))
->from($db->quoteName('#__menu'))
->where([
$db->quoteName('link') . ' LIKE ' . $db->quote('%view=items%'),
$db->quoteName('published') . ' = 1'
])
->order('FIELD(language, ' . $db->quote($langTag) . ', "'.$cat->language.'") DESC');
$db->setQuery($queryMenu);
$menuItem = $db->loadObject();
$query = [
'option' => 'com_djcatalog2',
'view' => 'items',
'cid' => $cidFull,
'Itemid' => $menuItem ? (int) $menuItem->id : null,
];
// Zbuduj SEF URL
$djRouter = new \DJCatalog2Router();
$segments = $djRouter->build($query);
// Dodaj alias menu (np. /tapijten)
if (!empty($menuItem) && !empty($menuItem->alias)) {
$menuAlias = trim($menuItem->alias, '/');
if ($menuAlias && (!isset($segments[0]) || $segments[0] !== $menuAlias)) {
array_unshift($segments, $menuAlias);
}
}
// Sklej pełną ścieżkę
$path = implode('/', $segments);
$sefUrl = '/'.substr($cat->language, 0, 2) . '/' . $path;
$return[$tag] = $sefUrl;
}
return $return;
}
} else if ($view === 'producers') {
$associations = Associations::getAssociations('com_djcatalog2', '#__djc2_producer_categories', 'com_djcatalog2.producercategory', $pcid, 'id', 'alias', '');
$return = array();
foreach ($associations as $tag => $item) {
$link = DJCatalog2HelperRoute::getProducerCategoryRoute($item->id);
if ($item->language && $item->language !== '*' && Multilanguage::isEnabled()) {
$link .= '&lang=' . $item->language;
}
$return[$tag] = $link;
}
return $return;
}
return array();
}
}