[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Site 5 * @subpackage mod_tags_popular 6 * 7 * @copyright (C) 2013 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\Module\TagsPopular\Site\Helper; 12 13 use Joomla\CMS\Component\ComponentHelper; 14 use Joomla\CMS\Factory; 15 use Joomla\CMS\Helper\ContentHelper; 16 use Joomla\Database\ParameterType; 17 18 // phpcs:disable PSR1.Files.SideEffects 19 \defined('_JEXEC') or die; 20 // phpcs:enable PSR1.Files.SideEffects 21 22 /** 23 * Helper for mod_tags_popular 24 * 25 * @since 3.1 26 */ 27 abstract class TagsPopularHelper 28 { 29 /** 30 * Get list of popular tags 31 * 32 * @param \Joomla\Registry\Registry &$params module parameters 33 * 34 * @return mixed 35 * 36 * @since 3.1 37 */ 38 public static function getList(&$params) 39 { 40 $db = Factory::getDbo(); 41 $user = Factory::getUser(); 42 $groups = $user->getAuthorisedViewLevels(); 43 $timeframe = $params->get('timeframe', 'alltime'); 44 $maximum = (int) $params->get('maximum', 5); 45 $order_value = $params->get('order_value', 'title'); 46 $nowDate = Factory::getDate()->toSql(); 47 $nullDate = $db->getNullDate(); 48 49 $query = $db->getQuery(true) 50 ->select( 51 [ 52 'MAX(' . $db->quoteName('tag_id') . ') AS ' . $db->quoteName('tag_id'), 53 'COUNT(*) AS ' . $db->quoteName('count'), 54 'MAX(' . $db->quoteName('t.title') . ') AS ' . $db->quoteName('title'), 55 'MAX(' . $db->quoteName('t.access') . ') AS ' . $db->quoteName('access'), 56 'MAX(' . $db->quoteName('t.alias') . ') AS ' . $db->quoteName('alias'), 57 'MAX(' . $db->quoteName('t.params') . ') AS ' . $db->quoteName('params'), 58 'MAX(' . $db->quoteName('t.language') . ') AS ' . $db->quoteName('language'), 59 ] 60 ) 61 ->group($db->quoteName(['tag_id', 't.title', 't.access', 't.alias'])) 62 ->from($db->quoteName('#__contentitem_tag_map', 'm')) 63 ->whereIn($db->quoteName('t.access'), $groups); 64 65 // Only return published tags 66 $query->where($db->quoteName('t.published') . ' = 1 '); 67 68 // Filter by Parent Tag 69 $parentTags = $params->get('parentTag', []); 70 71 if ($parentTags) { 72 $query->whereIn($db->quoteName('t.parent_id'), $parentTags); 73 } 74 75 // Filter on category state 76 $query->join( 77 'INNER', 78 $db->quoteName('#__ucm_content', 'ucm'), 79 $db->quoteName('m.content_item_id') . ' = ' . $db->quoteName('ucm.core_content_item_id') . 80 ' AND ' . $db->quoteName('m.type_id') . ' = ' . $db->quoteName('ucm.core_type_id') 81 ); 82 83 $query->join( 84 'INNER', 85 $db->quoteName('#__categories', 'cat'), 86 $db->quoteName('ucm.core_catid') . ' = ' . $db->quoteName('cat.id') 87 ); 88 89 $query->where($db->quoteName('cat.published') . ' > 0'); 90 91 // Optionally filter on language 92 $language = ComponentHelper::getParams('com_tags')->get('tag_list_language_filter', 'all'); 93 94 if ($language !== 'all') { 95 if ($language === 'current_language') { 96 $language = ContentHelper::getCurrentLanguage(); 97 } 98 99 $query->whereIn($db->quoteName('t.language'), [$language, '*'], ParameterType::STRING); 100 } 101 102 if ($timeframe !== 'alltime') { 103 $query->where($db->quoteName('tag_date') . ' > ' . $query->dateAdd($db->quote($nowDate), '-1', strtoupper($timeframe))); 104 } 105 106 $query->join('INNER', $db->quoteName('#__tags', 't'), $db->quoteName('tag_id') . ' = ' . $db->quoteName('t.id')) 107 ->join( 108 'INNER', 109 $db->quoteName('#__ucm_content', 'c'), 110 $db->quoteName('m.core_content_id') . ' = ' . $db->quoteName('c.core_content_id') 111 ); 112 113 $query->where($db->quoteName('m.type_alias') . ' = ' . $db->quoteName('c.core_type_alias')); 114 115 // Only return tags connected to published and authorised items 116 $query->where($db->quoteName('c.core_state') . ' = 1') 117 ->where( 118 '(' . $db->quoteName('c.core_access') . ' IN (' . implode(',', $query->bindArray($groups)) . ')' 119 . ' OR ' . $db->quoteName('c.core_access') . ' = 0)' 120 ) 121 ->where( 122 '(' . $db->quoteName('c.core_publish_up') . ' IS NULL' 123 . ' OR ' . $db->quoteName('c.core_publish_up') . ' = :nullDate2' 124 . ' OR ' . $db->quoteName('c.core_publish_up') . ' <= :nowDate2)' 125 ) 126 ->where( 127 '(' . $db->quoteName('c.core_publish_down') . ' IS NULL' 128 . ' OR ' . $db->quoteName('c.core_publish_down') . ' = :nullDate3' 129 . ' OR ' . $db->quoteName('c.core_publish_down') . ' >= :nowDate3)' 130 ) 131 ->bind([':nullDate2', ':nullDate3'], $nullDate) 132 ->bind([':nowDate2', ':nowDate3'], $nowDate); 133 134 // Set query depending on order_value param 135 if ($order_value === 'rand()') { 136 $query->order($query->rand()); 137 } else { 138 $order_direction = $params->get('order_direction', 1) ? 'DESC' : 'ASC'; 139 140 if ($params->get('order_value', 'title') === 'title') { 141 // Backup bound parameters array of the original query 142 $bounded = $query->getBounded(); 143 144 if ($maximum > 0) { 145 $query->setLimit($maximum); 146 } 147 148 $query->order($db->quoteName('count') . ' DESC'); 149 $equery = $db->getQuery(true) 150 ->select( 151 $db->quoteName( 152 [ 153 'a.tag_id', 154 'a.count', 155 'a.title', 156 'a.access', 157 'a.alias', 158 'a.language', 159 ] 160 ) 161 ) 162 ->from('(' . (string) $query . ') AS ' . $db->quoteName('a')) 163 ->order($db->quoteName('a.title') . ' ' . $order_direction); 164 165 $query = $equery; 166 167 // Rebind parameters 168 foreach ($bounded as $key => $obj) { 169 $query->bind($key, $obj->value, $obj->dataType); 170 } 171 } else { 172 $query->order($db->quoteName($order_value) . ' ' . $order_direction); 173 } 174 } 175 176 if ($maximum > 0) { 177 $query->setLimit($maximum); 178 } 179 180 $db->setQuery($query); 181 182 try { 183 $results = $db->loadObjectList(); 184 } catch (\RuntimeException $e) { 185 $results = array(); 186 Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); 187 } 188 189 return $results; 190 } 191 }
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 |