- md5
- 7fc6cd5e37b1e23ebfc59757d179e2ca
- sha1
- dbf031acd2ca6e80c7adebd890769622c3591b56
- sha256
- 5aee4515d13d87ab243e3f37f2dd41e5f0ff198ad868be8648127c1317d0a1f0
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
<?php
/**
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\CMS\Categories;
defined('JPATH_PLATFORM') or die;
/**
* Trait for component categories service.
*
* @since 4.0.0
*/
trait CategoriesServiceTrait
{
/**
* An array of categories.
*
* @var Categories[]
*
* @since 4.0.0
*/
private $categories;
/**
* Returns the category service.
*
* @param array $options The options
* @param string $section The section
*
* @return Categories
*
* @see Categories::setOptions()
*
* @since 4.0.0
* @throws SectionNotFoundException
*/
public function getCategories(array $options = [], $section = ''): Categories
{
if (!array_key_exists($section, $this->categories))
{
throw new SectionNotFoundException;
}
$categories = clone $this->categories[$section];
$categories->setOptions($options);
return $categories;
}
/**
* An array of categories where the key is the name of the section.
* If the component has no sections then the array must have at least
* an empty key.
*
* @param array $categories The categories
*
* @return void
*
* @since 4.0.0
*/
public function setCategories(array $categories)
{
$this->categories = $categories;
}
/**
* Adds Count Items for Category Manager.
*
* @param \stdClass[] $items The category objects
* @param string $section The section
*
* @return void
*
* @since 4.0.0
* @throws \Exception
*/
public function countItems(array $items, string $section)
{
$sectionTable = $this->getTableNameForSection($section);
if (!$sectionTable)
{
return;
}
$db = \JFactory::getDbo();
foreach ($items as $item)
{
$item->count_trashed = 0;
$item->count_archived = 0;
$item->count_unpublished = 0;
$item->count_published = 0;
$query = $db->getQuery(true);
$query->select('state, count(*) AS count')
->from($db->qn($sectionTable))
->where('catid = ' . (int) $item->id)
->group('state');
$db->setQuery($query);
$objects = $db->loadObjectList();
foreach ($objects as $object)
{
if ($object->state == 1)
{
$item->count_published = $object->count;
}
if ($object->state == 0)
{
$item->count_unpublished = $object->count;
}
if ($object->state == 2)
{
$item->count_archived = $object->count;
}
if ($object->state == -2)
{
$item->count_trashed = $object->count;
}
}
}
}
/**
* Adds Count Items for Tag Manager.
*
* @param \stdClass[] $items The content objects
* @param string $extension The name of the active view.
*
* @return void
*
* @since 4.0.0
*/
public function countTagItems(array $items, string $extension)
{
$parts = explode('.', $extension);
$section = null;
if (count($parts) > 1)
{
$section = $parts[1];
}
$sectionTable = $this->getTableNameForSection($section);
if (!$sectionTable)
{
return;
}
$db = \JFactory::getDbo();
$join = $db->qn($sectionTable) . ' AS c ON ct.content_item_id=c.id';
$state = 'state';
if ($section === 'category')
{
$join = $db->qn('#__categories') . ' AS c ON ct.content_item_id=c.id';
$state = 'published as state';
}
foreach ($items as $item)
{
$item->count_trashed = 0;
$item->count_archived = 0;
$item->count_unpublished = 0;
$item->count_published = 0;
$query = $db->getQuery(true);
$query->select($state . ', count(*) AS count')
->from($db->qn('#__contentitem_tag_map') . 'AS ct ')
->where('ct.tag_id = ' . (int) $item->id)
->where('ct.type_alias =' . $db->q($extension))
->join('LEFT', $join)
->group('state');
$db->setQuery($query);
$contents = $db->loadObjectList();
foreach ($contents as $content)
{
if ($content->state == 1)
{
$item->count_published = $content->count;
}
if ($content->state == 0)
{
$item->count_unpublished = $content->count;
}
if ($content->state == 2)
{
$item->count_archived = $content->count;
}
if ($content->state == -2)
{
$item->count_trashed = $content->count;
}
}
}
}
/**
* Returns the table for the count items functions for the given section.
*
* @param string $section The section
*
* @return string|null
*
* @since 4.0.0
*/
protected function getTableNameForSection(string $section = null)
{
return null;
}
}
No other release has this exact content. See every version of this file.