primo commit
This commit is contained in:
@ -0,0 +1,208 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_newsfeeds
|
||||
*
|
||||
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Newsfeeds\Administrator\Helper;
|
||||
|
||||
use Joomla\CMS\Association\AssociationExtensionHelper;
|
||||
use Joomla\CMS\Language\Associations;
|
||||
use Joomla\CMS\Table\Table;
|
||||
use Joomla\Component\Newsfeeds\Site\Helper\AssociationHelper;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Content associations helper.
|
||||
*
|
||||
* @since 3.7.0
|
||||
*/
|
||||
class AssociationsHelper extends AssociationExtensionHelper
|
||||
{
|
||||
/**
|
||||
* The extension name
|
||||
*
|
||||
* @var array $extension
|
||||
*
|
||||
* @since 3.7.0
|
||||
*/
|
||||
protected $extension = 'com_newsfeeds';
|
||||
|
||||
/**
|
||||
* Array of item types
|
||||
*
|
||||
* @var array $itemTypes
|
||||
*
|
||||
* @since 3.7.0
|
||||
*/
|
||||
protected $itemTypes = ['newsfeed', 'category'];
|
||||
|
||||
/**
|
||||
* Has the extension association support
|
||||
*
|
||||
* @var boolean $associationsSupport
|
||||
*
|
||||
* @since 3.7.0
|
||||
*/
|
||||
protected $associationsSupport = true;
|
||||
|
||||
/**
|
||||
* Method to get the associations for a given item.
|
||||
*
|
||||
* @param integer $id Id of the item
|
||||
* @param string $view Name of the view
|
||||
*
|
||||
* @return array Array of associations for the item
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function getAssociationsForItem($id = 0, $view = null)
|
||||
{
|
||||
return AssociationHelper::getAssociations($id, $view);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the associated items for an item
|
||||
*
|
||||
* @param string $typeName The item type
|
||||
* @param int $id The id of item for which we need the associated items
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 3.7.0
|
||||
*/
|
||||
public function getAssociations($typeName, $id)
|
||||
{
|
||||
$type = $this->getType($typeName);
|
||||
|
||||
$context = $this->extension . '.item';
|
||||
$catidField = 'catid';
|
||||
|
||||
if ($typeName === 'category') {
|
||||
$context = 'com_categories.item';
|
||||
$catidField = '';
|
||||
}
|
||||
|
||||
// Get the associations.
|
||||
$associations = Associations::getAssociations(
|
||||
$this->extension,
|
||||
$type['tables']['a'],
|
||||
$context,
|
||||
$id,
|
||||
'id',
|
||||
'alias',
|
||||
$catidField
|
||||
);
|
||||
|
||||
return $associations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get item information
|
||||
*
|
||||
* @param string $typeName The item type
|
||||
* @param int $id The id of item for which we need the associated items
|
||||
*
|
||||
* @return Table|null
|
||||
*
|
||||
* @since 3.7.0
|
||||
*/
|
||||
public function getItem($typeName, $id)
|
||||
{
|
||||
if (empty($id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$table = null;
|
||||
|
||||
switch ($typeName) {
|
||||
case 'newsfeed':
|
||||
$table = Table::getInstance('NewsfeedTable', 'Joomla\\Component\\Newsfeeds\\Administrator\\Table\\');
|
||||
break;
|
||||
|
||||
case 'category':
|
||||
$table = Table::getInstance('Category');
|
||||
break;
|
||||
}
|
||||
|
||||
if (empty($table)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$table->load($id);
|
||||
|
||||
return $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about the type
|
||||
*
|
||||
* @param string $typeName The item type
|
||||
*
|
||||
* @return array Array of item types
|
||||
*
|
||||
* @since 3.7.0
|
||||
*/
|
||||
public function getType($typeName = '')
|
||||
{
|
||||
$fields = $this->getFieldsTemplate();
|
||||
$tables = [];
|
||||
$joins = [];
|
||||
$support = $this->getSupportTemplate();
|
||||
$title = '';
|
||||
|
||||
if (\in_array($typeName, $this->itemTypes)) {
|
||||
switch ($typeName) {
|
||||
case 'newsfeed':
|
||||
$fields['title'] = 'a.name';
|
||||
$fields['state'] = 'a.published';
|
||||
|
||||
$support['state'] = true;
|
||||
$support['acl'] = true;
|
||||
$support['checkout'] = true;
|
||||
$support['category'] = true;
|
||||
$support['save2copy'] = true;
|
||||
|
||||
$tables = [
|
||||
'a' => '#__newsfeeds',
|
||||
];
|
||||
$title = 'newsfeed';
|
||||
break;
|
||||
|
||||
case 'category':
|
||||
$fields['created_user_id'] = 'a.created_user_id';
|
||||
$fields['ordering'] = 'a.lft';
|
||||
$fields['level'] = 'a.level';
|
||||
$fields['catid'] = '';
|
||||
$fields['state'] = 'a.published';
|
||||
|
||||
$support['state'] = true;
|
||||
$support['acl'] = true;
|
||||
$support['checkout'] = true;
|
||||
$support['level'] = true;
|
||||
|
||||
$tables = [
|
||||
'a' => '#__categories',
|
||||
];
|
||||
|
||||
$title = 'category';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'fields' => $fields,
|
||||
'support' => $support,
|
||||
'tables' => $tables,
|
||||
'joins' => $joins,
|
||||
'title' => $title,
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,169 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Administrator
|
||||
* @subpackage com_newsfeeds
|
||||
*
|
||||
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Component\Newsfeeds\Administrator\Helper;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Helper\ContentHelper;
|
||||
use Joomla\Database\ParameterType;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Newsfeeds component helper.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
class NewsfeedsHelper extends ContentHelper
|
||||
{
|
||||
/**
|
||||
* Name of the extension
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public static $extension = 'com_newsfeeds';
|
||||
|
||||
/**
|
||||
* Adds Count Items for Category Manager.
|
||||
*
|
||||
* @param \stdClass[] &$items The banner category objects
|
||||
*
|
||||
* @return \stdClass[]
|
||||
*
|
||||
* @since 3.5
|
||||
*/
|
||||
public static function countItems(&$items)
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
$query->select(
|
||||
[
|
||||
$db->quoteName('published', 'state'),
|
||||
'COUNT(*) AS ' . $db->quoteName('count'),
|
||||
]
|
||||
)
|
||||
->from($db->quoteName('#__newsfeeds'))
|
||||
->where($db->quoteName('catid') . ' = :id')
|
||||
->bind(':id', $id, ParameterType::INTEGER)
|
||||
->group($db->quoteName('state'));
|
||||
$db->setQuery($query);
|
||||
|
||||
foreach ($items as $item) {
|
||||
$item->count_trashed = 0;
|
||||
$item->count_archived = 0;
|
||||
$item->count_unpublished = 0;
|
||||
$item->count_published = 0;
|
||||
|
||||
$id = (int) $item->id;
|
||||
$newfeeds = $db->loadObjectList();
|
||||
|
||||
foreach ($newfeeds as $newsfeed) {
|
||||
if ($newsfeed->state == 1) {
|
||||
$item->count_published = $newsfeed->count;
|
||||
}
|
||||
|
||||
if ($newsfeed->state == 0) {
|
||||
$item->count_unpublished = $newsfeed->count;
|
||||
}
|
||||
|
||||
if ($newsfeed->state == 2) {
|
||||
$item->count_archived = $newsfeed->count;
|
||||
}
|
||||
|
||||
if ($newsfeed->state == -2) {
|
||||
$item->count_trashed = $newsfeed->count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds Count Items for Tag Manager.
|
||||
*
|
||||
* @param \stdClass[] &$items The newsfeed tag objects
|
||||
* @param string $extension The name of the active view.
|
||||
*
|
||||
* @return \stdClass[]
|
||||
*
|
||||
* @since 3.6
|
||||
*/
|
||||
public static function countTagItems(&$items, $extension)
|
||||
{
|
||||
$db = Factory::getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
$parts = explode('.', $extension);
|
||||
$section = null;
|
||||
|
||||
if (\count($parts) > 1) {
|
||||
$section = $parts[1];
|
||||
}
|
||||
|
||||
$query->select(
|
||||
[
|
||||
$db->quoteName('published', 'state'),
|
||||
'COUNT(*) AS ' . $db->quoteName('count'),
|
||||
]
|
||||
)
|
||||
->from($db->quoteName('#__contentitem_tag_map', 'ct'));
|
||||
|
||||
if ($section === 'category') {
|
||||
$query->join('LEFT', $db->quoteName('#__categories', 'c'), $db->quoteName('ct.content_item_id') . ' = ' . $db->quoteName('c.id'));
|
||||
} else {
|
||||
$query->join('LEFT', $db->quoteName('#__newsfeeds', 'c'), $db->quoteName('ct.content_item_id') . ' = ' . $db->quoteName('c.id'));
|
||||
}
|
||||
|
||||
$query->where(
|
||||
[
|
||||
$db->quoteName('ct.tag_id') . ' = :id',
|
||||
$db->quoteName('ct.type_alias') . ' = :extension',
|
||||
]
|
||||
)
|
||||
->bind(':id', $id, ParameterType::INTEGER)
|
||||
->bind(':extension', $extension)
|
||||
->group($db->quoteName('state'));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
foreach ($items as $item) {
|
||||
$item->count_trashed = 0;
|
||||
$item->count_archived = 0;
|
||||
$item->count_unpublished = 0;
|
||||
$item->count_published = 0;
|
||||
|
||||
// Update ID used in database query.
|
||||
$id = (int) $item->id;
|
||||
$newsfeeds = $db->loadObjectList();
|
||||
|
||||
foreach ($newsfeeds as $newsfeed) {
|
||||
if ($newsfeed->state == 1) {
|
||||
$item->count_published = $newsfeed->count;
|
||||
}
|
||||
|
||||
if ($newsfeed->state == 0) {
|
||||
$item->count_unpublished = $newsfeed->count;
|
||||
}
|
||||
|
||||
if ($newsfeed->state == 2) {
|
||||
$item->count_archived = $newsfeed->count;
|
||||
}
|
||||
|
||||
if ($newsfeed->state == -2) {
|
||||
$item->count_trashed = $newsfeed->count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user