[ 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) 2017 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\Helper; 12 13 use Joomla\CMS\Factory; 14 use Joomla\CMS\Helper\ContentHelper; 15 use Joomla\Database\ParameterType; 16 17 // phpcs:disable PSR1.Files.SideEffects 18 \defined('_JEXEC') or die; 19 // phpcs:enable PSR1.Files.SideEffects 20 21 /** 22 * Newsfeeds component helper. 23 * 24 * @since 1.6 25 */ 26 class NewsfeedsHelper extends ContentHelper 27 { 28 /** 29 * Name of the extension 30 * 31 * @var string 32 */ 33 public static $extension = 'com_newsfeeds'; 34 35 /** 36 * Adds Count Items for Category Manager. 37 * 38 * @param \stdClass[] &$items The banner category objects 39 * 40 * @return \stdClass[] 41 * 42 * @since 3.5 43 */ 44 public static function countItems(&$items) 45 { 46 $db = Factory::getDbo(); 47 $query = $db->getQuery(true); 48 $query->select( 49 [ 50 $db->quoteName('published', 'state'), 51 'COUNT(*) AS ' . $db->quoteName('count'), 52 ] 53 ) 54 ->from($db->quoteName('#__newsfeeds')) 55 ->where($db->quoteName('catid') . ' = :id') 56 ->bind(':id', $id, ParameterType::INTEGER) 57 ->group($db->quoteName('state')); 58 $db->setQuery($query); 59 60 foreach ($items as $item) { 61 $item->count_trashed = 0; 62 $item->count_archived = 0; 63 $item->count_unpublished = 0; 64 $item->count_published = 0; 65 66 $id = (int) $item->id; 67 $newfeeds = $db->loadObjectList(); 68 69 foreach ($newfeeds as $newsfeed) { 70 if ($newsfeed->state == 1) { 71 $item->count_published = $newsfeed->count; 72 } 73 74 if ($newsfeed->state == 0) { 75 $item->count_unpublished = $newsfeed->count; 76 } 77 78 if ($newsfeed->state == 2) { 79 $item->count_archived = $newsfeed->count; 80 } 81 82 if ($newsfeed->state == -2) { 83 $item->count_trashed = $newsfeed->count; 84 } 85 } 86 } 87 88 return $items; 89 } 90 91 /** 92 * Adds Count Items for Tag Manager. 93 * 94 * @param \stdClass[] &$items The newsfeed tag objects 95 * @param string $extension The name of the active view. 96 * 97 * @return \stdClass[] 98 * 99 * @since 3.6 100 */ 101 public static function countTagItems(&$items, $extension) 102 { 103 $db = Factory::getDbo(); 104 $query = $db->getQuery(true); 105 $parts = explode('.', $extension); 106 $section = null; 107 108 if (count($parts) > 1) { 109 $section = $parts[1]; 110 } 111 112 $query->select( 113 [ 114 $db->quoteName('published', 'state'), 115 'COUNT(*) AS ' . $db->quoteName('count'), 116 ] 117 ) 118 ->from($db->quoteName('#__contentitem_tag_map', 'ct')); 119 120 if ($section === 'category') { 121 $query->join('LEFT', $db->quoteName('#__categories', 'c'), $db->quoteName('ct.content_item_id') . ' = ' . $db->quoteName('c.id')); 122 } else { 123 $query->join('LEFT', $db->quoteName('#__newsfeeds', 'c'), $db->quoteName('ct.content_item_id') . ' = ' . $db->quoteName('c.id')); 124 } 125 126 $query->where( 127 [ 128 $db->quoteName('ct.tag_id') . ' = :id', 129 $db->quoteName('ct.type_alias') . ' = :extension', 130 ] 131 ) 132 ->bind(':id', $id, ParameterType::INTEGER) 133 ->bind(':extension', $extension) 134 ->group($db->quoteName('state')); 135 136 $db->setQuery($query); 137 138 foreach ($items as $item) { 139 $item->count_trashed = 0; 140 $item->count_archived = 0; 141 $item->count_unpublished = 0; 142 $item->count_published = 0; 143 144 // Update ID used in database query. 145 $id = (int) $item->id; 146 $newsfeeds = $db->loadObjectList(); 147 148 foreach ($newsfeeds as $newsfeed) { 149 if ($newsfeed->state == 1) { 150 $item->count_published = $newsfeed->count; 151 } 152 153 if ($newsfeed->state == 0) { 154 $item->count_unpublished = $newsfeed->count; 155 } 156 157 if ($newsfeed->state == 2) { 158 $item->count_archived = $newsfeed->count; 159 } 160 161 if ($newsfeed->state == -2) { 162 $item->count_trashed = $newsfeed->count; 163 } 164 } 165 } 166 167 return $items; 168 } 169 }
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 |