- md5
- 8c2d3e7d9a707a9b1ab13da36824b6e0
- sha1
- ae021dc902f18739d5ead310be00cb4c91eb38bd
- sha256
- c65dcd244f3db47e997e0e25b98a75fe705ec41cb440ce620e1d85ea432b9e33
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
<?php
/**
* @package Joomla.Administrator
* @subpackage com_content
*
* @copyright (C) 2008 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Content\Administrator\Model;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Associations;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Table\Category;
use Joomla\Component\Content\Administrator\Extension\ContentComponent;
use Joomla\Database\ParameterType;
use Joomla\Database\QueryInterface;
use Joomla\Registry\Registry;
use Joomla\Utilities\ArrayHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Methods supporting a list of article records.
*
* @since 1.6
*/
class ArticlesModel extends ListModel
{
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
* @param ?MVCFactoryInterface $factory The factory.
*
* @since 1.6
* @see \Joomla\CMS\MVC\Controller\BaseController
*/
public function __construct($config = [], ?MVCFactoryInterface $factory = null)
{
if (empty($config['filter_fields'])) {
$config['filter_fields'] = [
'id', 'a.id',
'title', 'a.title',
'alias', 'a.alias',
'checked_out', 'a.checked_out',
'checked_out_time', 'a.checked_out_time',
'catid', 'a.catid', 'category_title',
'state', 'a.state',
'access', 'a.access', 'access_level',
'created', 'a.created',
'modified', 'a.modified',
'created_by', 'a.created_by',
'created_by_alias', 'a.created_by_alias',
'ordering', 'a.ordering',
'featured', 'a.featured',
'featured_up', 'fp.featured_up',
'featured_down', 'fp.featured_down',
'language', 'a.language',
'hits', 'a.hits',
'publish_up', 'a.publish_up',
'publish_down', 'a.publish_down',
'published', 'a.published',
'author_id',
'category_id',
'level',
'tag',
'rating_count', 'rating',
'stage', 'wa.stage_id',
'ws.title',
'fp.ordering',
];
if (Associations::isEnabled()) {
$config['filter_fields'][] = 'association';
}
}
parent::__construct($config, $factory);
}
/**
* Get the filter form
*
* @param array $data data
* @param boolean $loadData load current data
*
* @return \Joomla\CMS\Form\Form|null The Form object or null if the form can't be found
*
* @since 3.2
*/
public function getFilterForm($data = [], $loadData = true)
{
$form = parent::getFilterForm($data, $loadData);
$params = ComponentHelper::getParams('com_content');
if (!$params->get('workflow_enabled')) {
$form->removeField('stage', 'filter');
}
return $form;
}
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @param string $ordering An optional ordering field.
* @param string $direction An optional direction (asc|desc).
*
* @return void
*
* @since 1.6
*/
protected function populateState($ordering = 'a.id', $direction = 'desc')
{
$app = Factory::getApplication();
$input = $app->getInput();
$forcedLanguage = $input->get('forcedLanguage', '', 'cmd');
// Adjust the context to support modal layouts.
if ($layout = $input->get('layout')) {
$this->context .= '.' . $layout;
}
// Adjust the context to support forced languages.
if ($forcedLanguage) {
$this->context .= '.' . $forcedLanguage;
}
// Required content filters for the administrator menu
$this->getUserStateFromRequest($this->context . '.filter.category_id', 'filter_category_id');
$this->getUserStateFromRequest($this->context . '.filter.level', 'filter_level');
$this->getUserStateFromRequest($this->context . '.filter.featured', 'filter_featured');
$this->getUserStateFromRequest($this->context . '.filter.author_id', 'filter_author_id');
$this->getUserStateFromRequest($this->context . '.filter.tag', 'filter_tag', '');
$this->getUserStateFromRequest($this->context . '.filter.access', 'filter_access');
$this->getUserStateFromRequest($this->context . '.filter.language', 'filter_language', '');
$this->getUserStateFromRequest($this->context . '.filter.checked_out', 'filter_checked_out', '');
// List state information.
parent::populateState($ordering, $direction);
// Force a language
if (!empty($forcedLanguage)) {
$this->setState('filter.language', $forcedLanguage);
$this->setState('filter.forcedLanguage', $forcedLanguage);
}
}
/**
* Method to get a store id based on model configuration state.
*
* This is necessary because the model is used by the component and
* different modules that might need different sets of data or different
* ordering requirements.
*
* @param string $id A prefix for the store id.
*
* @return string A store id.
*
* @since 1.6
*/
protected function getStoreId($id = '')
{
// Compile the store id.
$id .= ':' . $this->getState('filter.search');
$id .= ':' . serialize($this->getState('filter.access'));
$id .= ':' . $this->getState('filter.published');
$id .= ':' . $this->getState('filter.featured');
$id .= ':' . serialize($this->getState('filter.category_id'));
$id .= ':' . serialize($this->getState('filter.author_id'));
$id .= ':' . $this->getState('filter.language');
$id .= ':' . serialize($this->getState('filter.tag'));
$id .= ':' . $this->getState('filter.checked_out');
$id .= ':' . $this->getState('filter.date_filtering');
$id .= ':' . $this->getState('filter.date_field');
$id .= ':' . $this->getState('filter.start_date_range');
$id .= ':' . $this->getState('filter.end_date_range');
$id .= ':' . $this->getState('filter.relative_date');
return parent::getStoreId($id);
}
/**
* Build an SQL query to load the list data.
*
* @return QueryInterface
*
* @since 1.6
*/
protected function getListQuery()
{
// Create a new query object.
$db = $this->getDatabase();
$query = $db->createQuery();
$user = $this->getCurrentUser();
$params = ComponentHelper::getParams('com_content');
// Select the required fields from the table.
$query->select(
$this->getState(
'list.select',
[
$db->quoteName('a.id'),
$db->quoteName('a.asset_id'),
$db->quoteName('a.title'),
$db->quoteName('a.alias'),
$db->quoteName('a.checked_out'),
$db->quoteName('a.checked_out_time'),
$db->quoteName('a.catid'),
$db->quoteName('a.state'),
$db->quoteName('a.access'),
$db->quoteName('a.created'),
$db->quoteName('a.created_by'),
$db->quoteName('a.created_by_alias'),
$db->quoteName('a.modified'),
$db->quoteName('a.ordering'),
$db->quoteName('a.featured'),
$db->quoteName('a.language'),
$db->quoteName('a.hits'),
$db->quoteName('a.publish_up'),
$db->quoteName('a.publish_down'),
$db->quoteName('a.introtext'),
$db->quoteName('a.fulltext'),
$db->quoteName('a.note'),
$db->quoteName('a.images'),
$db->quoteName('a.metakey'),
$db->quoteName('a.metadesc'),
$db->quoteName('a.metadata'),
$db->quoteName('a.version'),
]
)
)
->select(
[
$db->quoteName('fp.featured_up'),
$db->quoteName('fp.featured_down'),
$db->quoteName('l.title', 'language_title'),
$db->quoteName('l.image', 'language_image'),
$db->quoteName('uc.name', 'editor'),
$db->quoteName('ag.title', 'access_level'),
$db->quoteName('c.title', 'category_title'),
$db->quoteName('c.created_user_id', 'category_uid'),
$db->quoteName('c.level', 'category_level'),
$db->quoteName('c.published', 'category_published'),
$db->quoteName('parent.title', 'parent_category_title'),
$db->quoteName('parent.id', 'parent_category_id'),
$db->quoteName('parent.created_user_id', 'parent_category_uid'),
$db->quoteName('parent.level', 'parent_category_level'),
$db->quoteName('ua.name', 'author_name'),
$db->quoteName('wa.stage_id', 'stage_id'),
$db->quoteName('ws.title', 'stage_title'),
$db->quoteName('ws.workflow_id', 'workflow_id'),
$db->quoteName('w.title', 'workflow_title'),
]
)
->from($db->quoteName('#__content', 'a'))
->where($db->quoteName('wa.extension') . ' = ' . $db->quote('com_content.article'))
->join('LEFT', $db->quoteName('#__languages', 'l'), $db->quoteName('l.lang_code') . ' = ' . $db->quoteName('a.language'))
->join('LEFT', $db->quoteName('#__content_frontpage', 'fp'), $db->quoteName('fp.content_id') . ' = ' . $db->quoteName('a.id'))
->join('LEFT', $db->quoteName('#__users', 'uc'), $db->quoteName('uc.id') . ' = ' . $db->quoteName('a.checked_out'))
->join('LEFT', $db->quoteName('#__viewlevels', 'ag'), $db->quoteName('ag.id') . ' = ' . $db->quoteName('a.access'))
->join('LEFT', $db->quoteName('#__categories', 'c'), $db->quoteName('c.id') . ' = ' . $db->quoteName('a.catid'))
->join('LEFT', $db->quoteName('#__categories', 'parent'), $db->quoteName('parent.id') . ' = ' . $db->quoteName('c.parent_id'))
->join('LEFT', $db->quoteName('#__users', 'ua'), $db->quoteName('ua.id') . ' = ' . $db->quoteName('a.created_by'))
->join('INNER', $db->quoteName('#__workflow_associations', 'wa'), $db->quoteName('wa.item_id') . ' = ' . $db->quoteName('a.id'))
->join('INNER', $db->quoteName('#__workflow_stages', 'ws'), $db->quoteName('ws.id') . ' = ' . $db->quoteName('wa.stage_id'))
->join('INNER', $db->quoteName('#__workflows', 'w'), $db->quoteName('w.id') . ' = ' . $db->quoteName('ws.workflow_id'));
if (PluginHelper::isEnabled('content', 'vote')) {
$query->select(
[
'COALESCE(NULLIF(ROUND(' . $db->quoteName('v.rating_sum') . ' / ' . $db->quoteName('v.rating_count') . ', 0), 0), 0)'
. ' AS ' . $db->quoteName('rating'),
'COALESCE(NULLIF(' . $db->quoteName('v.rating_count') . ', 0), 0) AS ' . $db->quoteName('rating_count'),
]
)
->join('LEFT', $db->quoteName('#__content_rating', 'v'), $db->quoteName('a.id') . ' = ' . $db->quoteName('v.content_id'));
}
// Join over the associations.
if (Associations::isEnabled()) {
$subQuery = $db->createQuery()
->select('COUNT(' . $db->quoteName('asso1.id') . ') > 1')
->from($db->quoteName('#__associations', 'asso1'))
->join('INNER', $db->quoteName('#__associations', 'asso2'), $db->quoteName('asso1.key') . ' = ' . $db->quoteName('asso2.key'))
->where(
[
$db->quoteName('asso1.id') . ' = ' . $db->quoteName('a.id'),
$db->quoteName('asso1.context') . ' = ' . $db->quote('com_content.item'),
]
);
$query->select('(' . $subQuery . ') AS ' . $db->quoteName('association'));
}
// Filter by access level.
$access = $this->getState('filter.access');
if (is_numeric($access)) {
$access = (int) $access;
$query->where($db->quoteName('a.access') . ' = :access')
->bind(':access', $access, ParameterType::INTEGER);
} elseif (\is_array($access)) {
$access = ArrayHelper::toInteger($access);
$query->whereIn($db->quoteName('a.access'), $access);
}
// Filter by featured.
$featured = $this->getState('filter.featured');
$defaultOrdering = 'a.id';
if (is_numeric($featured) && \in_array($featured, [0, 1])) {
$featured = (int) $featured;
$query->where($db->quoteName('a.featured') . ' = :featured')
->bind(':featured', $featured, ParameterType::INTEGER);
if ($featured) {
$query->select($db->quoteName('fp.ordering'));
$defaultOrdering = 'fp.ordering';
}
}
// Filter by access level on categories.
if (!$user->authorise('core.admin')) {
$groups = $user->getAuthorisedViewLevels();
$query->whereIn($db->quoteName('a.access'), $groups);
$query->whereIn($db->quoteName('c.access'), $groups);
}
// Filter by published state
$workflowStage = (string) $this->getState('filter.stage');
if ($params->get('workflow_enabled') && is_numeric($workflowStage)) {
$workflowStage = (int) $workflowStage;
$query->where($db->quoteName('wa.stage_id') . ' = :stage')
->bind(':stage', $workflowStage, ParameterType::INTEGER);
}
$published = (string) $this->getState('filter.published');
if ($published !== '*') {
if (is_numeric($published)) {
$state = (int) $published;
$query->where($db->quoteName('a.state') . ' = :state')
->bind(':state', $state, ParameterType::INTEGER);
} elseif (!is_numeric($workflowStage)) {
$query->whereIn(
$db->quoteName('a.state'),
[
ContentComponent::CONDITION_PUBLISHED,
ContentComponent::CONDITION_UNPUBLISHED,
]
);
}
}
// Filter by categories and by level
$categoryId = $this->getState('filter.category_id', []);
$level = (int) $this->getState('filter.level');
if (!\is_array($categoryId)) {
$categoryId = $categoryId ? [$categoryId] : [];
}
// Case: Using both categories filter and by level filter
if (\count($categoryId)) {
$categoryId = ArrayHelper::toInteger($categoryId);
$categoryTable = new Category($db);
$subCatItemsWhere = [];
foreach ($categoryId as $key => $filter_catid) {
$categoryTable->load($filter_catid);
// Because values to $query->bind() are passed by reference, using $query->bindArray() here instead to prevent overwriting.
$valuesToBind = [$categoryTable->lft, $categoryTable->rgt];
if ($level) {
$valuesToBind[] = $level + $categoryTable->level - 1;
}
// Bind values and get parameter names.
$bounded = $query->bindArray($valuesToBind);
$categoryWhere = $db->quoteName('c.lft') . ' >= ' . $bounded[0] . ' AND ' . $db->quoteName('c.rgt') . ' <= ' . $bounded[1];
if ($level) {
$categoryWhere .= ' AND ' . $db->quoteName('c.level') . ' <= ' . $bounded[2];
}
$subCatItemsWhere[] = '(' . $categoryWhere . ')';
}
$query->where('(' . implode(' OR ', $subCatItemsWhere) . ')');
} elseif ($level = (int) $level) {
// Case: Using only the by level filter
$query->where($db->quoteName('c.level') . ' <= :level')
->bind(':level', $level, ParameterType::INTEGER);
}
// Filter by author
$authorId = $this->getState('filter.author_id');
if (is_numeric($authorId)) {
$authorId = (int) $authorId;
if ($authorId === 0) {
// Only show deleted authors' articles
$subQuery = $db->createQuery()
->select($db->quoteName('id'))
->from($db->quoteName('#__users'));
$query->where($db->quoteName('a.created_by') . ' NOT IN (' . $subQuery . ')');
} else {
$type = $this->getState('filter.author_id.include', true) ? ' = ' : ' <> ';
$query->where($db->quoteName('a.created_by') . $type . ':authorId')
->bind(':authorId', $authorId, ParameterType::INTEGER);
}
} elseif (\is_array($authorId)) {
// Check to see if by_me is in the array
$keyByMe = array_search('by_me', $authorId);
if ($keyByMe !== false) {
// Replace by_me with the current user id in the array
$authorId[$keyByMe] = $user->id;
}
$authorId = ArrayHelper::toInteger($authorId);
if (\in_array(0, $authorId)) {
// Remove 0 from array and handle deleted users with OR condition
$authorId = array_filter($authorId);
// Subquery for deleted users
$subQuery = $db->createQuery()
->select($db->quoteName('id'))
->from($db->quoteName('#__users'));
// Build WHERE with both conditions
$query->where('(' .
$db->quoteName('a.created_by') . ' NOT IN (' . $subQuery . ')' .
(!empty($authorId)
? ' OR ' . $db->quoteName('a.created_by') . ' IN (' . implode(',', $query->bindArray($authorId)) . ')'
: '') .
')');
} else {
$query->whereIn($db->quoteName('a.created_by'), $authorId);
}
}
// Filter by search in title.
$search = $this->getState('filter.search');
if (!empty($search)) {
if (stripos($search, 'id:') === 0) {
$search = (int) substr($search, 3);
$query->where($db->quoteName('a.id') . ' = :search')
->bind(':search', $search, ParameterType::INTEGER);
} elseif (stripos($search, 'author:') === 0) {
$search = '%' . substr($search, 7) . '%';
$query->where('(' . $db->quoteName('ua.name') . ' LIKE :search1 OR ' . $db->quoteName('ua.username') . ' LIKE :search2)')
->bind([':search1', ':search2'], $search);
} elseif (stripos($search, 'content:') === 0) {
$search = '%' . substr($search, 8) . '%';
$query->where('(' . $db->quoteName('a.introtext') . ' LIKE :search1 OR ' . $db->quoteName('a.fulltext') . ' LIKE :search2)')
->bind([':search1', ':search2'], $search);
} elseif (stripos($search, 'checkedout:') === 0) {
$search = '%' . substr($search, 11) . '%';
$query->where('(' . $db->quoteName('uc.name') . ' LIKE :search1 OR ' . $db->quoteName('uc.username') . ' LIKE :search2)'
. ' AND ' . $db->quoteName('a.checked_out') . ' IS NOT NULL')
->bind([':search1', ':search2'], $search);
} else {
$search = '%' . str_replace(' ', '%', trim($search)) . '%';
$query->where(
'(' . $db->quoteName('a.title') . ' LIKE :search1 OR ' . $db->quoteName('a.alias') . ' LIKE :search2'
. ' OR ' . $db->quoteName('a.note') . ' LIKE :search3)'
)
->bind([':search1', ':search2', ':search3'], $search);
}
}
// Filter on the language.
if ($language = $this->getState('filter.language')) {
$query->where($db->quoteName('a.language') . ' = :language')
->bind(':language', $language);
}
// Filter by checked out status.
$checkedOut = $this->getState('filter.checked_out');
if (is_numeric($checkedOut)) {
if ($checkedOut == -1) {
// Only checked out articles
$query->where($db->quoteName('a.checked_out') . ' > 0');
} elseif ($checkedOut == 0) {
// Only not checked out articles (checked_out is 0 or NULL)
$query->where('(' . $db->quoteName('a.checked_out') . ' = 0 OR ' . $db->quoteName('a.checked_out') . ' IS NULL)');
} else {
// Checked out by specific user
$checkedOut = (int) $checkedOut;
$query->where($db->quoteName('a.checked_out') . ' = :checkedOutUser')
->bind(':checkedOutUser', $checkedOut, ParameterType::INTEGER);
}
}
// Filter by a single or group of tags.
$tag = $this->getState('filter.tag');
// Run simplified query when filtering by one tag.
if (\is_array($tag) && \count($tag) === 1) {
$tag = $tag[0];
}
if ($tag && \is_array($tag)) {
$tag = ArrayHelper::toInteger($tag);
$includeNone = false;
if (\in_array(0, $tag)) {
$tag = array_filter($tag);
$includeNone = true;
}
$subQuery = $db->createQuery()
->select('DISTINCT ' . $db->quoteName('content_item_id'))
->from($db->quoteName('#__contentitem_tag_map'))
->where(
[
$db->quoteName('tag_id') . ' IN (' . implode(',', $query->bindArray($tag)) . ')',
$db->quoteName('type_alias') . ' = ' . $db->quote('com_content.article'),
]
);
$query->join(
$includeNone ? 'LEFT' : 'INNER',
'(' . $subQuery . ') AS ' . $db->quoteName('tagmap'),
$db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id')
);
if ($includeNone) {
$subQuery2 = $db->createQuery()
->select('DISTINCT ' . $db->quoteName('content_item_id'))
->from($db->quoteName('#__contentitem_tag_map'))
->where($db->quoteName('type_alias') . ' = ' . $db->quote('com_content.article'));
$query->join(
'LEFT',
'(' . $subQuery2 . ') AS ' . $db->quoteName('tagmap2'),
$db->quoteName('tagmap2.content_item_id') . ' = ' . $db->quoteName('a.id')
)
->where(
'(' . $db->quoteName('tagmap.content_item_id') . ' IS NOT NULL OR '
. $db->quoteName('tagmap2.content_item_id') . ' IS NULL)'
);
}
} elseif (is_numeric($tag)) {
$tag = (int) $tag;
if ($tag === 0) {
$subQuery = $db->createQuery()
->select('DISTINCT ' . $db->quoteName('content_item_id'))
->from($db->quoteName('#__contentitem_tag_map'))
->where($db->quoteName('type_alias') . ' = ' . $db->quote('com_content.article'));
// Only show articles without tags
$query->join(
'LEFT',
'(' . $subQuery . ') AS ' . $db->quoteName('tagmap'),
$db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id')
)
->where($db->quoteName('tagmap.content_item_id') . ' IS NULL');
} else {
$query->join(
'INNER',
$db->quoteName('#__contentitem_tag_map', 'tagmap'),
$db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id')
)
->where(
[
$db->quoteName('tagmap.tag_id') . ' = :tag',
$db->quoteName('tagmap.type_alias') . ' = ' . $db->quote('com_content.article'),
]
)
->bind(':tag', $tag, ParameterType::INTEGER);
}
}
// Filter by date after modified date.
$modifiedStartDateTime = $this->getState('filter.modified_start');
if (!empty($modifiedStartDateTime)) {
$query->where($db->quoteName('a.modified') . ' >= :startDate')
->bind(':startDate', $modifiedStartDateTime);
}
// Filter by date before modified date.
$modifiedEndDateTime = $this->getState('filter.modified_end');
if (!empty($modifiedEndDateTime)) {
$query->where($db->quoteName('a.modified') . ' <= :endDate')
->bind(':endDate', $modifiedEndDateTime);
}
// Filter by Date Range or Relative Date
$dateFiltering = $this->getState('filter.date_filtering', 'off');
$dateField = $this->getState('filter.date_field', 'a.created');
// Validate the date field to prevent SQL injection
$validDateFields = ['a.created', 'a.modified', 'a.publish_up'];
if (!\in_array($dateField, $validDateFields)) {
$dateField = 'a.created';
}
switch ($dateFiltering) {
case 'range':
$startDateRange = $this->getState('filter.start_date_range', '');
$endDateRange = $this->getState('filter.end_date_range', '');
if ($startDateRange || $endDateRange) {
$query->where($db->quoteName($dateField) . ' IS NOT NULL');
if ($startDateRange) {
$query->where($db->quoteName($dateField) . ' >= :startDateRange')
->bind(':startDateRange', $startDateRange);
}
if ($endDateRange) {
$query->where($db->quoteName($dateField) . ' <= :endDateRange')
->bind(':endDateRange', $endDateRange);
}
}
break;
case 'relative':
$relativeDate = (int) $this->getState('filter.relative_date', 0);
if ($relativeDate > 0) {
$nowDate = Factory::getDate()->toSql();
$query->where(
$db->quoteName($dateField) . ' IS NOT NULL AND '
. $db->quoteName($dateField) . ' >= ' . $query->dateAdd($db->quote($nowDate), -1 * $relativeDate, 'DAY')
);
}
break;
case 'off':
default:
break;
}
// Add the list ordering clause.
$orderCol = $this->state->get('list.ordering', $defaultOrdering);
$orderDirn = $this->state->get('list.direction', 'DESC');
if ($orderCol === 'a.ordering' || $orderCol === 'category_title') {
$ordering = [
$db->quoteName('c.title') . ' ' . $db->escape($orderDirn),
$db->quoteName('a.ordering') . ' ' . $db->escape($orderDirn),
];
} else {
$ordering = $db->escape($orderCol) . ' ' . $db->escape($orderDirn);
}
$query->order($ordering);
return $query;
}
/**
* Method to get all transitions at once for all articles
*
* @return array|boolean
*
* @since 4.0.0
*/
public function getTransitions()
{
// Get a storage key.
$store = $this->getStoreId('getTransitions');
// Try to load the data from internal storage.
if (isset($this->cache[$store])) {
return $this->cache[$store];
}
$db = $this->getDatabase();
$user = $this->getCurrentUser();
$items = $this->getItems();
if ($items === false) {
return false;
}
$stage_ids = ArrayHelper::getColumn($items, 'stage_id');
$stage_ids = ArrayHelper::toInteger($stage_ids);
$stage_ids = array_values(array_unique(array_filter($stage_ids)));
$workflow_ids = ArrayHelper::getColumn($items, 'workflow_id');
$workflow_ids = ArrayHelper::toInteger($workflow_ids);
$workflow_ids = array_values(array_unique(array_filter($workflow_ids)));
$this->cache[$store] = [];
try {
if (\count($stage_ids) || \count($workflow_ids)) {
Factory::getLanguage()->load('com_workflow', JPATH_ADMINISTRATOR);
$query = $db->createQuery();
$query ->select(
[
$db->quoteName('t.id', 'value'),
$db->quoteName('t.title', 'text'),
$db->quoteName('t.from_stage_id'),
$db->quoteName('t.to_stage_id'),
$db->quoteName('s.id', 'stage_id'),
$db->quoteName('s.title', 'stage_title'),
$db->quoteName('t.workflow_id'),
]
)
->from($db->quoteName('#__workflow_transitions', 't'))
->innerJoin(
$db->quoteName('#__workflow_stages', 's'),
$db->quoteName('t.to_stage_id') . ' = ' . $db->quoteName('s.id')
)
->where(
[
$db->quoteName('t.published') . ' = 1',
$db->quoteName('s.published') . ' = 1',
]
)
->order($db->quoteName('t.ordering'));
$where = [];
if (\count($stage_ids)) {
$where[] = $db->quoteName('t.from_stage_id') . ' IN (' . implode(',', $query->bindArray($stage_ids)) . ')';
}
if (\count($workflow_ids)) {
$where[] = '(' . $db->quoteName('t.from_stage_id') . ' = -1 AND ' . $db->quoteName('t.workflow_id') . ' IN (' . implode(',', $query->bindArray($workflow_ids)) . '))';
}
$query->where('((' . implode(') OR (', $where) . '))');
$transitions = $db->setQuery($query)->loadAssocList();
foreach ($transitions as $key => $transition) {
if (!$user->authorise('core.execute.transition', 'com_content.transition.' . (int) $transition['value'])) {
unset($transitions[$key]);
}
$transitions[$key]['text'] = Text::_($transition['text']);
}
$this->cache[$store] = $transitions;
}
} catch (\RuntimeException $e) {
$this->setError($e->getMessage());
return false;
}
return $this->cache[$store];
}
/**
* Method to get a list of articles.
* Overridden to add item type alias.
*
* @return mixed An array of data items on success, false on failure.
*
* @since 4.0.0
*/
public function getItems()
{
$items = parent::getItems();
foreach ($items as $item) {
$item->typeAlias = 'com_content.article';
if (isset($item->metadata)) {
$registry = new Registry($item->metadata);
$item->metadata = $registry->toArray();
}
}
return $items;
}
}
The same content is in 29 releases, Joomla 6.1.0-alpha3 to 6.2.1-rc1. See them all, or every version of this file.