- md5
- f3fe687de103f6ea2436863300c8b40c
- sha1
- 3cdc06a51a6623da60a9e08216dc4cee7632519a
- sha256
- 090ec24911afd67038775c6367013e0b5d22f3bcc6b378be34dcd5eed3af679b
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
<?php
/**
* @package Joomla.Site
* @subpackage com_content
*
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Content\Site\Helper;
\defined('_JEXEC') or die;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Database\DatabaseInterface;
/**
* Content Component Query Helper
*
* @since 1.5
*/
class QueryHelper
{
/**
* Translate an order code to a field for primary category ordering.
*
* @param string $orderby The ordering code.
*
* @return string The SQL field(s) to order by.
*
* @since 1.5
*/
public static function orderbyPrimary($orderby)
{
switch ($orderby)
{
case 'alpha':
$orderby = 'c.path, ';
break;
case 'ralpha':
$orderby = 'c.path DESC, ';
break;
case 'order':
$orderby = 'c.lft, ';
break;
default:
$orderby = '';
break;
}
return $orderby;
}
/**
* Translate an order code to a field for secondary category ordering.
*
* @param string $orderby The ordering code.
* @param string $orderDate The ordering code for the date.
* @param DatabaseInterface $db The database
*
* @return string The SQL field(s) to order by.
*
* @since 1.5
*/
public static function orderbySecondary($orderby, $orderDate = 'created', DatabaseInterface $db = null)
{
$db = $db ?: Factory::getDbo();
$queryDate = self::getQueryDate($orderDate, $db);
switch ($orderby)
{
case 'date':
$orderby = $queryDate;
break;
case 'rdate':
$orderby = $queryDate . ' DESC ';
break;
case 'alpha':
$orderby = 'a.title';
break;
case 'ralpha':
$orderby = 'a.title DESC';
break;
case 'hits':
$orderby = 'a.hits DESC';
break;
case 'rhits':
$orderby = 'a.hits';
break;
case 'rorder':
$orderby = 'a.ordering DESC';
break;
case 'author':
$orderby = 'author';
break;
case 'rauthor':
$orderby = 'author DESC';
break;
case 'front':
$orderby = 'a.featured DESC, fp.ordering, ' . $queryDate . ' DESC ';
break;
case 'random':
$orderby = $db->getQuery(true)->rand();
break;
case 'vote':
$orderby = 'a.id DESC ';
if (PluginHelper::isEnabled('content', 'vote'))
{
$orderby = 'rating_count DESC ';
}
break;
case 'rvote':
$orderby = 'a.id ASC ';
if (PluginHelper::isEnabled('content', 'vote'))
{
$orderby = 'rating_count ASC ';
}
break;
case 'rank':
$orderby = 'a.id DESC ';
if (PluginHelper::isEnabled('content', 'vote'))
{
$orderby = 'rating DESC ';
}
break;
case 'rrank':
$orderby = 'a.id ASC ';
if (PluginHelper::isEnabled('content', 'vote'))
{
$orderby = 'rating ASC ';
}
break;
default:
$orderby = 'a.ordering';
break;
}
return $orderby;
}
/**
* Translate an order code to a field for primary category ordering.
*
* @param string $orderDate The ordering code.
* @param DatabaseInterface $db The database
*
* @return string The SQL field(s) to order by.
*
* @since 1.6
*/
public static function getQueryDate($orderDate, DatabaseInterface $db = null)
{
$db = $db ?: Factory::getDbo();
switch ($orderDate)
{
case 'modified' :
$queryDate = ' CASE WHEN a.modified = ' . $db->quote($db->getNullDate()) . ' THEN a.created ELSE a.modified END';
break;
// Use created if publish_up is not set
case 'published' :
$queryDate = ' CASE WHEN a.publish_up IS NULL THEN a.created ELSE a.publish_up END ';
break;
case 'unpublished' :
$queryDate = ' CASE WHEN a.publish_down IS NULL THEN a.created ELSE a.publish_down END ';
break;
case 'created' :
default :
$queryDate = ' a.created ';
break;
}
return $queryDate;
}
/**
* Get join information for the voting query.
*
* @param \Joomla\Registry\Registry $params An options object for the article.
*
* @return array A named array with "select" and "join" keys.
*
* @since 1.5
*
* @deprecated 5.0 Deprecated without replacement, not used in core
*/
public static function buildVotingQuery($params = null)
{
if (!$params)
{
$params = ComponentHelper::getParams('com_content');
}
$voting = $params->get('show_vote');
if ($voting)
{
// Calculate voting count
$select = ' , ROUND(v.rating_sum / v.rating_count) AS rating, v.rating_count';
$join = ' LEFT JOIN #__content_rating AS v ON a.id = v.content_id';
}
else
{
$select = '';
$join = '';
}
return array('select' => $select, 'join' => $join);
}
}
No other release has this exact content. See every version of this file.