[ 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_content 6 * 7 * @copyright (C) 2007 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\Content\Administrator\Service\HTML; 12 13 use Joomla\CMS\Factory; 14 use Joomla\CMS\Language\Associations; 15 use Joomla\CMS\Language\LanguageHelper; 16 use Joomla\CMS\Language\Text; 17 use Joomla\CMS\Layout\LayoutHelper; 18 use Joomla\CMS\Router\Route; 19 use Joomla\Database\ParameterType; 20 21 // phpcs:disable PSR1.Files.SideEffects 22 \defined('_JEXEC') or die; 23 // phpcs:enable PSR1.Files.SideEffects 24 25 /** 26 * Content HTML helper 27 * 28 * @since 3.0 29 */ 30 class AdministratorService 31 { 32 /** 33 * Render the list of associated items 34 * 35 * @param integer $articleid The article item id 36 * 37 * @return string The language HTML 38 * 39 * @throws \Exception 40 */ 41 public function association($articleid) 42 { 43 // Defaults 44 $html = ''; 45 46 // Get the associations 47 if ($associations = Associations::getAssociations('com_content', '#__content', 'com_content.item', $articleid)) { 48 foreach ($associations as $tag => $associated) { 49 $associations[$tag] = (int) $associated->id; 50 } 51 52 // Get the associated menu items 53 $db = Factory::getDbo(); 54 $query = $db->getQuery(true) 55 ->select( 56 [ 57 'c.*', 58 $db->quoteName('l.sef', 'lang_sef'), 59 $db->quoteName('l.lang_code'), 60 $db->quoteName('cat.title', 'category_title'), 61 $db->quoteName('l.image'), 62 $db->quoteName('l.title', 'language_title'), 63 ] 64 ) 65 ->from($db->quoteName('#__content', 'c')) 66 ->join('LEFT', $db->quoteName('#__categories', 'cat'), $db->quoteName('cat.id') . ' = ' . $db->quoteName('c.catid')) 67 ->join('LEFT', $db->quoteName('#__languages', 'l'), $db->quoteName('c.language') . ' = ' . $db->quoteName('l.lang_code')) 68 ->whereIn($db->quoteName('c.id'), array_values($associations)) 69 ->where($db->quoteName('c.id') . ' != :articleId') 70 ->bind(':articleId', $articleid, ParameterType::INTEGER); 71 72 $db->setQuery($query); 73 74 try { 75 $items = $db->loadObjectList('id'); 76 } catch (\RuntimeException $e) { 77 throw new \Exception($e->getMessage(), 500, $e); 78 } 79 80 if ($items) { 81 $languages = LanguageHelper::getContentLanguages(array(0, 1)); 82 $content_languages = array_column($languages, 'lang_code'); 83 84 foreach ($items as &$item) { 85 if (in_array($item->lang_code, $content_languages)) { 86 $text = $item->lang_code; 87 $url = Route::_('index.php?option=com_content&task=article.edit&id=' . (int) $item->id); 88 $tooltip = '<strong>' . htmlspecialchars($item->language_title, ENT_QUOTES, 'UTF-8') . '</strong><br>' 89 . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '<br>' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title); 90 $classes = 'badge bg-secondary'; 91 92 $item->link = '<a href="' . $url . '" class="' . $classes . '">' . $text . '</a>' 93 . '<div role="tooltip" id="tip-' . (int) $articleid . '-' . (int) $item->id . '">' . $tooltip . '</div>'; 94 } else { 95 // Display warning if Content Language is trashed or deleted 96 Factory::getApplication()->enqueueMessage(Text::sprintf('JGLOBAL_ASSOCIATIONS_CONTENTLANGUAGE_WARNING', $item->lang_code), 'warning'); 97 } 98 } 99 } 100 101 $html = LayoutHelper::render('joomla.content.associations', $items); 102 } 103 104 return $html; 105 } 106 }
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 |