[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Administrator 5 * @subpackage com_categories 6 * 7 * @copyright (C) 2012 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Categories\Administrator\Service\HTML; 12 13 use Joomla\CMS\Factory; 14 use Joomla\CMS\Language\LanguageHelper; 15 use Joomla\CMS\Language\Text; 16 use Joomla\CMS\Layout\LayoutHelper; 17 use Joomla\CMS\Router\Route; 18 use Joomla\Component\Categories\Administrator\Helper\CategoriesHelper; 19 use Joomla\Database\ParameterType; 20 use Joomla\Utilities\ArrayHelper; 21 22 // phpcs:disable PSR1.Files.SideEffects 23 \defined('_JEXEC') or die; 24 // phpcs:enable PSR1.Files.SideEffects 25 26 /** 27 * Administrator category HTML 28 * 29 * @since 3.2 30 */ 31 class AdministratorService 32 { 33 /** 34 * Render the list of associated items 35 * 36 * @param integer $catid Category identifier to search its associations 37 * @param string $extension Category Extension 38 * 39 * @return string The language HTML 40 * 41 * @since 3.2 42 * @throws \Exception 43 */ 44 public function association($catid, $extension = 'com_content') 45 { 46 // Defaults 47 $html = ''; 48 49 // Get the associations 50 if ($associations = CategoriesHelper::getAssociations($catid, $extension)) { 51 $associations = ArrayHelper::toInteger($associations); 52 53 // Get the associated categories 54 $db = Factory::getDbo(); 55 $query = $db->getQuery(true) 56 ->select( 57 [ 58 $db->quoteName('c.id'), 59 $db->quoteName('c.title'), 60 $db->quoteName('l.sef', 'lang_sef'), 61 $db->quoteName('l.lang_code'), 62 $db->quoteName('l.image'), 63 $db->quoteName('l.title', 'language_title'), 64 ] 65 ) 66 ->from($db->quoteName('#__categories', 'c')) 67 ->whereIn($db->quoteName('c.id'), array_values($associations)) 68 ->where($db->quoteName('c.id') . ' != :catid') 69 ->bind(':catid', $catid, ParameterType::INTEGER) 70 ->join( 71 'LEFT', 72 $db->quoteName('#__languages', 'l'), 73 $db->quoteName('c.language') . ' = ' . $db->quoteName('l.lang_code') 74 ); 75 $db->setQuery($query); 76 77 try { 78 $items = $db->loadObjectList('id'); 79 } catch (\RuntimeException $e) { 80 throw new \Exception($e->getMessage(), 500, $e); 81 } 82 83 if ($items) { 84 $languages = LanguageHelper::getContentLanguages(array(0, 1)); 85 $content_languages = array_column($languages, 'lang_code'); 86 87 foreach ($items as &$item) { 88 if (in_array($item->lang_code, $content_languages)) { 89 $text = $item->lang_code; 90 $url = Route::_('index.php?option=com_categories&task=category.edit&id=' . (int) $item->id . '&extension=' . $extension); 91 $tooltip = '<strong>' . htmlspecialchars($item->language_title, ENT_QUOTES, 'UTF-8') . '</strong><br>' 92 . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8'); 93 $classes = 'badge bg-secondary'; 94 95 $item->link = '<a href="' . $url . '" class="' . $classes . '">' . $text . '</a>' 96 . '<div role="tooltip" id="tip-' . (int) $catid . '-' . (int) $item->id . '">' . $tooltip . '</div>'; 97 } else { 98 // Display warning if Content Language is trashed or deleted 99 Factory::getApplication()->enqueueMessage(Text::sprintf('JGLOBAL_ASSOCIATIONS_CONTENTLANGUAGE_WARNING', $item->lang_code), 'warning'); 100 } 101 } 102 } 103 104 $html = LayoutHelper::render('joomla.content.associations', $items); 105 } 106 107 return $html; 108 } 109 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |