Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core Enhancement 3 - Merge Featured into Articles #11

Open
wants to merge 16 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Update link to featured
UPDATE `#__menu`
SET `link` = 'index.php?option=com_content&view=articles&featured=1'
WHERE `link` = 'index.php?option=com_content&view=featured';
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Update link to featured
UPDATE "#__menu"
SET "link" = 'index.php?option=com_content&view=articles&featured=1'
WHERE "link" = 'index.php?option=com_content&view=featured';
26 changes: 13 additions & 13 deletions administrator/components/com_content/forms/filter_articles.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<form>
<field
name="featured"
type="list"
label="JFEATURED"
filtermode="selector"
onchange="Joomla.resetFilters(this)"
validate="options"
addfieldprefix="Joomla\Component\Content\Administrator\Field"
>
<option value="">JALL</option>
<option value="0">COM_CONTENT_FILTER_FEATURED_NO</option>
<option value="1">COM_CONTENT_FILTER_FEATURED_YES</option>
</field>
<fields name="filter">
<field
name="search"
Expand All @@ -10,19 +23,6 @@
hint="JSEARCH_FILTER"
/>

<field
name="featured"
type="list"
label="JFEATURED"
onchange="this.form.submit();"
default=""
validate="options"
>
<option value="">COM_CONTENT_SELECT_FEATURED</option>
<option value="0">COM_CONTENT_FILTER_FEATURED_NO</option>
<option value="1">COM_CONTENT_FILTER_FEATURED_YES</option>
</field>

<field
name="stage"
type="workflowstage"
Expand Down
2 changes: 1 addition & 1 deletion administrator/components/com_content/presets/content.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
title="COM_CONTENT_MENUS_FEATURED"
type="component"
element="com_content"
link="index.php?option=com_content&amp;view=featured"
link="index.php?option=com_content&amp;view=articles&amp;featured=1"
class="class:featured"
/>
</menuitem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,60 @@ public function getQuickiconContent()

echo new JsonResponse($result);
}

/**
* Removes an item.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function delete()
{
$articlesModel = $this->getModel('articles');
$featured = $articlesModel->isFeatured();

if ($featured === "1")
{
// Check for request forgeries
$this->checkToken();

$user = $this->app->getIdentity();
$ids = $this->input->get('cid', array(), 'array');

// Access checks.
foreach ($ids as $i => $id)
{
if (!$user->authorise('core.delete', 'com_content.article.' . (int) $id))
{
// Prune items that you can't delete.
unset($ids[$i]);
$this->app->enqueueMessage(Text::_('JERROR_CORE_DELETE_NOT_PERMITTED'), 'notice');
}
}

if (empty($ids))
{
$this->app->enqueueMessage(Text::_('JERROR_NO_ITEMS_SELECTED'), 'error');
}
else
{
/** @var \Joomla\Component\Content\Administrator\Model\FeatureModel $model */
$featureModel = $this->getModel('Feature');

// Remove the items.
if (!$featureModel->featured($ids, 0))
{
$this->app->enqueueMessage($featureModel->getError(), 'error');
}
}

$this->setMessage(Text::plural('COM_CONTENT_N_ITEMS_DELETED', \count($ids)));
$this->setRedirect('index.php?option=com_content&view=articles&featured=1');
}
else
{
parent::delete();
}
}
}
29 changes: 26 additions & 3 deletions administrator/components/com_content/src/Model/ArticlesModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class ArticlesModel extends ListModel
*/
public function __construct($config = array())
{
$featured = $this->isFeatured();

if (empty($config['filter_fields']))
{
$config['filter_fields'] = array(
Expand All @@ -55,7 +57,6 @@ public function __construct($config = array())
'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',
Expand All @@ -72,6 +73,11 @@ public function __construct($config = array())
'ws.title'
);

if ($featured === '1')
{
$config['filter_fields'][] = 'fp.ordering';
}

if (Associations::isEnabled())
{
$config['filter_fields'][] = 'association';
Expand Down Expand Up @@ -145,7 +151,7 @@ protected function populateState($ordering = 'a.id', $direction = 'desc')
$search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
$this->setState('filter.search', $search);

$featured = $this->getUserStateFromRequest($this->context . '.filter.featured', 'filter_featured', '');
$featured = $this->isFeatured();
$this->setState('filter.featured', $featured);

$published = $this->getUserStateFromRequest($this->context . '.filter.published', 'filter_published', '');
Expand Down Expand Up @@ -349,7 +355,7 @@ protected function getListQuery()
}

// Filter by featured.
$featured = (string) $this->getState('filter.featured');
$featured = $this->isFeatured();

if (in_array($featured, ['0','1']))
{
Expand All @@ -358,6 +364,11 @@ protected function getListQuery()
->bind(':featured', $featured, ParameterType::INTEGER);
}

if ($featured === '1')
{
$query->select($this->getDbo()->quoteName('fp.ordering'));
}

// Filter by access level on categories.
if (!$user->authorise('core.admin'))
{
Expand Down Expand Up @@ -704,4 +715,16 @@ public function getItems()

return $items;
}

/**
* Method to get the value of featured selector.
*
* @return string Returns the value of featured selector.
*
* @since __DEPLOY_VERSION__
*/
public function isFeatured()
{
return $this->getUserStateFromRequest($this->context . '.featured', 'featured', '');
}
}
51 changes: 37 additions & 14 deletions administrator/components/com_content/src/View/Articles/HtmlView.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public function display($tpl = null)
$this->activeFilters = $this->get('ActiveFilters');
$this->vote = PluginHelper::isEnabled('content', 'vote');
$this->hits = ComponentHelper::getParams('com_content')->get('record_hits', 1);
$featured = $this->state->get('filter.featured');

if (!\count($this->items) && $this->isEmptyState = $this->get('IsEmptyState'))
{
Expand All @@ -110,7 +111,7 @@ public function display($tpl = null)
}

// Check for errors.
if (\count($errors = $this->get('Errors')) || $this->transitions === false)
if (\count($errors = $this->get('Errors')) || ($this->transitions === false && $featured === '1'))
{
throw new GenericDataException(implode("\n", $errors), 500);
}
Expand Down Expand Up @@ -157,13 +158,21 @@ public function display($tpl = null)
*/
protected function addToolbar()
{
$canDo = ContentHelper::getActions('com_content', 'category', $this->state->get('filter.category_id'));
$user = Factory::getApplication()->getIdentity();
$canDo = ContentHelper::getActions('com_content', 'category', $this->state->get('filter.category_id'));
$user = Factory::getApplication()->getIdentity();
$featured = $this->state->get('filter.featured');

// Get the toolbar object instance
$toolbar = Toolbar::getInstance('toolbar');

ToolbarHelper::title(Text::_('COM_CONTENT_ARTICLES_TITLE'), 'copy article');
if ($featured === '1')
{
ToolbarHelper::title(Text::_('COM_CONTENT_FEATURED_TITLE'), 'star featured');
}
else
{
ToolbarHelper::title(Text::_('COM_CONTENT_ARTICLES_TITLE'), 'copy article');
}

if ($canDo->get('core.create') || \count($user->getAuthorisedCategories('com_content', 'core.create')) > 0)
{
Expand Down Expand Up @@ -210,15 +219,21 @@ protected function addToolbar()

$childBar->unpublish('articles.unpublish')->listCheck(true);

$childBar->standardButton('featured')
->text('JFEATURE')
->task('articles.featured')
->listCheck(true);
if ($featured !== '1')
{
$childBar->standardButton('featured')
->text('JFEATURE')
->task('articles.featured')
->listCheck(true);
}

$childBar->standardButton('circle')
->text('JUNFEATURE')
->task('articles.unfeatured')
->listCheck(true);
if ($featured !== '0')
{
$childBar->standardButton('circle')
->text('JUNFEATURE')
->task('articles.unfeatured')
->listCheck(true);
}

$childBar->archive('articles.archive')->listCheck(true);

Expand All @@ -233,7 +248,8 @@ protected function addToolbar()
// Add a batch button
if ($user->authorise('core.create', 'com_content')
&& $user->authorise('core.edit', 'com_content')
&& $user->authorise('core.execute.transition', 'com_content'))
&& $user->authorise('core.execute.transition', 'com_content')
&& $featured !== '1')
{
$childBar->popupButton('batch')
->text('JTOOLBAR_BATCH')
Expand All @@ -255,6 +271,13 @@ protected function addToolbar()
$toolbar->preferences('com_content');
}

$toolbar->help('JHELP_CONTENT_ARTICLE_MANAGER');
if ($featured === '1')
{
$toolbar->help('JHELP_CONTENT_ARTICLE_MANAGER');
}
else
{
ToolbarHelper::help('JHELP_CONTENT_FEATURED_ARTICLES');
}
}
}
48 changes: 32 additions & 16 deletions administrator/components/com_content/tmpl/articles/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
$userId = $user->get('id');
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
$saveOrder = $listOrder == 'a.ordering';
$featured = $this->state->get('filter.featured');
$orderName = $featured === "1" ? 'fp.ordering' : 'a.ordering';
$saveOrder = $listOrder == $orderName;

if (strpos($listOrder, 'publish_up') !== false)
{
Expand Down Expand Up @@ -98,7 +100,7 @@
<div id="j-main-container" class="j-main-container">
<?php
// Search tools bar
echo LayoutHelper::render('joomla.searchtools.default', array('view' => $this));
echo LayoutHelper::render('joomla.searchtools.default', array('view' => $this, 'options' => ['selectorFieldName' => 'featured']));
?>
<?php if (empty($this->items)) : ?>
<div class="alert alert-info">
Expand All @@ -108,7 +110,7 @@
<?php else : ?>
<table class="table itemList" id="articleList">
<caption class="visually-hidden">
<?php echo Text::_('COM_CONTENT_ARTICLES_TABLE_CAPTION'); ?>,
<?php echo $featured === "1" ? Text::_('COM_CONTENT_ARTICLES_TABLE_CAPTION') : Text::_('COM_CONTENT_FEATURED_TABLE_CAPTION'); ?>,
<span id="orderedBy"><?php echo Text::_('JGLOBAL_SORTED_BY'); ?> </span>,
<span id="filteredBy"><?php echo Text::_('JGLOBAL_FILTERED_BY'); ?></span>
</caption>
Expand All @@ -118,15 +120,15 @@
<?php echo HTMLHelper::_('grid.checkall'); ?>
</td>
<th scope="col" class="w-1 text-center d-none d-md-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', '', 'a.ordering', $listDirn, $listOrder, null, 'asc', 'JGRID_HEADING_ORDERING', 'icon-sort'); ?>
<?php echo HTMLHelper::_('searchtools.sort', '', $orderName, $listDirn, $listOrder, null, 'asc', 'JGRID_HEADING_ORDERING', 'icon-sort'); ?>
</th>
<?php if ($workflow_enabled) : ?>
<th scope="col" class="w-1 text-center">
<?php echo HTMLHelper::_('searchtools.sort', 'JSTAGE', 'ws.title', $listDirn, $listOrder); ?>
</th>
<th scope="col" class="w-1 text-center">
<?php echo HTMLHelper::_('searchtools.sort', 'JSTAGE', 'ws.title', $listDirn, $listOrder); ?>
</th>
<?php endif; ?>
<th scope="col" class="w-1 text-center d-none d-md-table-cell">
<?php echo HTMLHelper::_('searchtools.sort', 'JFEATURED', 'a.featured', $listDirn, $listOrder); ?>
<?php echo $featured === "1" ? Text::_('JFEATURED') : HTMLHelper::_('searchtools.sort', 'JFEATURED', 'a.featured', $listDirn, $listOrder); ?>
</th>
<th scope="col" class="w-1 text-center">
<?php echo HTMLHelper::_('searchtools.sort', 'JSTATUS', 'a.state', $listDirn, $listOrder); ?>
Expand Down Expand Up @@ -174,6 +176,9 @@
<tbody<?php if ($saveOrder) : ?> class="js-draggable" data-url="<?php echo $saveOrderingUrl; ?>" data-direction="<?php echo strtolower($listDirn); ?>" data-nested="true"<?php endif; ?>>
<?php foreach ($this->items as $i => $item) :
$item->max_ordering = 0;
$ordering = ($listOrder == 'fp.ordering');
$assetId = 'com_content.article.' . $item->id;
$canCreate = $user->authorise('core.create', 'com_content.category.' . $item->catid);
$canEdit = $user->authorise('core.edit', 'com_content.article.' . $item->id);
$canCheckin = $user->authorise('core.manage', 'com_checkin') || $item->checked_out == $userId || is_null($item->checked_out);
$canEditOwn = $user->authorise('core.edit.own', 'com_content.article.' . $item->id) && $item->created_by == $userId;
Expand Down Expand Up @@ -388,19 +393,30 @@
<?php // load the pagination. ?>
<?php echo $this->pagination->getListFooter(); ?>

<?php // Load the batch processing form. ?>
<?php if ($user->authorise('core.create', 'com_content')
&& $user->authorise('core.edit', 'com_content')
&& $user->authorise('core.edit.state', 'com_content')) : ?>
<?php if ($featured === "1"): ?>
<?php echo HTMLHelper::_(
'bootstrap.renderModal',
'collapseModal',
'stageModal',
array(
'title' => Text::_('COM_CONTENT_BATCH_OPTIONS'),
'footer' => $this->loadTemplate('batch_footer'),
'title' => Text::_('JTOOLBAR_CHANGE_STATUS'),
'footer' => $this->loadTemplate('stage_footer'),
),
$this->loadTemplate('batch_body')
$this->loadTemplate('stage_body')
); ?>
<?php else: ?>
<?php if ($user->authorise('core.create', 'com_content')
&& $user->authorise('core.edit', 'com_content')
&& $user->authorise('core.edit.state', 'com_content')) : ?>
<?php echo HTMLHelper::_(
'bootstrap.renderModal',
'collapseModal',
array(
'title' => Text::_('COM_CONTENT_BATCH_OPTIONS'),
'footer' => $this->loadTemplate('batch_footer'),
),
$this->loadTemplate('batch_body')
); ?>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>

Expand Down
Loading