[ 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_newsfeeds 6 * 7 * @copyright (C) 2009 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\Newsfeeds\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 * Utility class for creating HTML Grids. 27 * 28 * @since 1.5 29 */ 30 class AdministratorService 31 { 32 /** 33 * Get the associated language flags 34 * 35 * @param int $newsfeedid The item id to search associations 36 * 37 * @return string The language HTML 38 * 39 * @throws \Exception Throws a 500 Exception on Database failure 40 */ 41 public function association($newsfeedid) 42 { 43 // Defaults 44 $html = ''; 45 46 // Get the associations 47 if ($associations = Associations::getAssociations('com_newsfeeds', '#__newsfeeds', 'com_newsfeeds.item', $newsfeedid)) { 48 foreach ($associations as $tag => $associated) { 49 $associations[$tag] = (int) $associated->id; 50 } 51 52 // Get the associated newsfeed items 53 $db = Factory::getDbo(); 54 $query = $db->getQuery(true); 55 $query 56 ->select( 57 [ 58 $db->quoteName('c.id'), 59 $db->quoteName('c.name', 'title'), 60 $db->quoteName('cat.title', 'category_title'), 61 $db->quoteName('l.sef', 'lang_sef'), 62 $db->quoteName('l.lang_code'), 63 $db->quoteName('l.image'), 64 $db->quoteName('l.title', 'language_title'), 65 ] 66 ) 67 ->from($db->quoteName('#__newsfeeds', 'c')) 68 ->join('LEFT', $db->quoteName('#__categories', 'cat'), $db->quoteName('cat.id') . ' = ' . $db->quoteName('c.catid')) 69 ->join('LEFT', $db->quoteName('#__languages', 'l'), $db->quoteName('c.language') . ' = ' . $db->quoteName('l.lang_code')) 70 ->where( 71 [ 72 $db->quoteName('c.id') . ' IN (' . implode(',', $query->bindArray(array_values($associations))) . ')', 73 $db->quoteName('c.id') . ' != :id', 74 ] 75 ) 76 ->bind(':id', $newsfeedid, ParameterType::INTEGER); 77 $db->setQuery($query); 78 79 try { 80 $items = $db->loadObjectList('id'); 81 } catch (\RuntimeException $e) { 82 throw new \Exception($e->getMessage(), 500); 83 } 84 85 if ($items) { 86 $languages = LanguageHelper::getContentLanguages(array(0, 1)); 87 $content_languages = array_column($languages, 'lang_code'); 88 89 foreach ($items as &$item) { 90 if (in_array($item->lang_code, $content_languages)) { 91 $text = $item->lang_code; 92 $url = Route::_('index.php?option=com_newsfeeds&task=newsfeed.edit&id=' . (int) $item->id); 93 $tooltip = '<strong>' . htmlspecialchars($item->language_title, ENT_QUOTES, 'UTF-8') . '</strong><br>' 94 . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '<br>' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title); 95 $classes = 'badge bg-secondary'; 96 97 $item->link = '<a href="' . $url . '" class="' . $classes . '">' . $text . '</a>' 98 . '<div role="tooltip" id="tip-' . (int) $newsfeedid . '-' . (int) $item->id . '">' . $tooltip . '</div>'; 99 } else { 100 // Display warning if Content Language is trashed or deleted 101 Factory::getApplication()->enqueueMessage(Text::sprintf('JGLOBAL_ASSOCIATIONS_CONTENTLANGUAGE_WARNING', $item->lang_code), 'warning'); 102 } 103 } 104 } 105 106 $html = LayoutHelper::render('joomla.content.associations', $items); 107 } 108 109 return $html; 110 } 111 }
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 |