[ 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_contact 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\Contact\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 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 * Contact HTML helper class. 28 * 29 * @since 1.6 30 */ 31 class AdministratorService 32 { 33 /** 34 * Get the associated language flags 35 * 36 * @param integer $contactid The item id to search associations 37 * 38 * @return string The language HTML 39 * 40 * @throws \Exception 41 */ 42 public function association($contactid) 43 { 44 // Defaults 45 $html = ''; 46 47 // Get the associations 48 if ($associations = Associations::getAssociations('com_contact', '#__contact_details', 'com_contact.item', $contactid)) { 49 foreach ($associations as $tag => $associated) { 50 $associations[$tag] = (int) $associated->id; 51 } 52 53 // Get the associated contact items 54 $db = Factory::getDbo(); 55 $query = $db->getQuery(true) 56 ->select( 57 [ 58 $db->quoteName('c.id'), 59 $db->quoteName('c.name', 'title'), 60 $db->quoteName('l.sef', 'lang_sef'), 61 $db->quoteName('lang_code'), 62 $db->quoteName('cat.title', 'category_title'), 63 $db->quoteName('l.image'), 64 $db->quoteName('l.title', 'language_title'), 65 ] 66 ) 67 ->from($db->quoteName('#__contact_details', '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 ->whereIn($db->quoteName('c.id'), array_values($associations)) 71 ->where($db->quoteName('c.id') . ' != :id') 72 ->bind(':id', $contactid, ParameterType::INTEGER); 73 $db->setQuery($query); 74 75 try { 76 $items = $db->loadObjectList('id'); 77 } catch (\RuntimeException $e) { 78 throw new \Exception($e->getMessage(), 500, $e); 79 } 80 81 if ($items) { 82 $languages = LanguageHelper::getContentLanguages(array(0, 1)); 83 $content_languages = array_column($languages, 'lang_code'); 84 85 foreach ($items as &$item) { 86 if (in_array($item->lang_code, $content_languages)) { 87 $text = $item->lang_code; 88 $url = Route::_('index.php?option=com_contact&task=contact.edit&id=' . (int) $item->id); 89 $tooltip = '<strong>' . htmlspecialchars($item->language_title, ENT_QUOTES, 'UTF-8') . '</strong><br>' 90 . htmlspecialchars($item->title, ENT_QUOTES, 'UTF-8') . '<br>' . Text::sprintf('JCATEGORY_SPRINTF', $item->category_title); 91 $classes = 'badge bg-secondary'; 92 93 $item->link = '<a href="' . $url . '" class="' . $classes . '">' . $text . '</a>' 94 . '<div role="tooltip" id="tip-' . (int) $contactid . '-' . (int) $item->id . '">' . $tooltip . '</div>'; 95 } else { 96 // Display warning if Content Language is trashed or deleted 97 Factory::getApplication()->enqueueMessage(Text::sprintf('JGLOBAL_ASSOCIATIONS_CONTENTLANGUAGE_WARNING', $item->lang_code), 'warning'); 98 } 99 } 100 } 101 102 $html = LayoutHelper::render('joomla.content.associations', $items); 103 } 104 105 return $html; 106 } 107 108 /** 109 * Show the featured/not-featured icon. 110 * 111 * @param integer $value The featured value. 112 * @param integer $i Id of the item. 113 * @param boolean $canChange Whether the value can be changed or not. 114 * 115 * @return string The anchor tag to toggle featured/unfeatured contacts. 116 * 117 * @since 1.6 118 */ 119 public function featured($value, $i, $canChange = true) 120 { 121 // Array of image, task, title, action 122 $states = array( 123 0 => array('unfeatured', 'contacts.featured', 'COM_CONTACT_UNFEATURED', 'JGLOBAL_ITEM_FEATURE'), 124 1 => array('featured', 'contacts.unfeatured', 'JFEATURED', 'JGLOBAL_ITEM_UNFEATURE'), 125 ); 126 $state = ArrayHelper::getValue($states, (int) $value, $states[1]); 127 $icon = $state[0] === 'featured' ? 'star featured' : 'circle'; 128 $onclick = 'onclick="return Joomla.listItemTask(\'cb' . $i . '\',\'' . $state[1] . '\')"'; 129 $tooltipText = Text::_($state[3]); 130 131 if (!$canChange) { 132 $onclick = 'disabled'; 133 $tooltipText = Text::_($state[2]); 134 } 135 136 $html = '<button type="submit" class="tbody-icon' . ($value == 1 ? ' active' : '') . '"' 137 . ' aria-labelledby="cb' . $i . '-desc" ' . $onclick . '>' 138 . '<span class="icon-' . $icon . '" aria-hidden="true"></span>' 139 . '</button>' 140 . '<div role="tooltip" id="cb' . $i . '-desc">' . $tooltipText . '</div>'; 141 142 return $html; 143 } 144 }
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 |