Skip to content

Commit

Permalink
Include filtering on multiple categories, authors, and access levels
Browse files Browse the repository at this point in the history
  • Loading branch information
jrseliga committed Mar 4, 2015
1 parent 581508d commit 9a78a59
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 12 deletions.
22 changes: 18 additions & 4 deletions administrator/components/com_content/models/articles.php
Expand Up @@ -138,10 +138,10 @@ protected function getStoreId($id = '')
{
// Compile the store id.
$id .= ':' . $this->getState('filter.search');
$id .= ':' . $this->getState('filter.access');
$id .= ':' . serialize($this->getState('filter.access'));
$id .= ':' . $this->getState('filter.published');
$id .= ':' . $this->getState('filter.category_id');
$id .= ':' . $this->getState('filter.author_id');
$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'));

Expand Down Expand Up @@ -204,10 +204,17 @@ protected function getListQuery()
}

// Filter by access level.
if ($access = $this->getState('filter.access'))
$access = $this->getState('filter.access');
if (is_numeric($access))
{
$query->where('a.access = ' . (int) $access);
}
else if(is_array($access))
{
JArrayHelper::toInteger($access);
$access = implode(',', $access);
$query->where('a.access IN (' . $access . ')');
}

// Implement View Level Access
if (!$user->authorise('core.admin'))
Expand Down Expand Up @@ -264,6 +271,13 @@ protected function getListQuery()
$query->where('a.created_by ' . $type . (int) $authorId);
}

elseif (is_array($authorId))
{
JArrayHelper::toInteger($categoryId);
$authorId = implode(',', $authorId);
$query->where('a.created_by IN (' . $authorId . ')');
}

// Filter by search in title.
$search = $this->getState('filter.search');

Expand Down
16 changes: 15 additions & 1 deletion administrator/components/com_content/models/featured.php
Expand Up @@ -110,10 +110,17 @@ protected function getListQuery($resolveFKs = true)
->join('LEFT', '#__users AS ua ON ua.id = a.created_by');

// Filter by access level.
if ($access = $this->getState('filter.access'))
$access = $this->getState('filter.access');
if (is_numeric($access))
{
$query->where('a.access = ' . (int) $access);
}
else if(is_array($access))
{
JArrayHelper::toInteger($access);
$access = implode(',', $access);
$query->where('a.access IN (' . $access . ')');
}

// Filter by published state
$published = $this->getState('filter.published');
Expand Down Expand Up @@ -162,6 +169,13 @@ protected function getListQuery($resolveFKs = true)
$query->where('a.created_by ' . $type . (int) $authorId);
}

elseif (is_array($authorId))
{
JArrayHelper::toInteger($categoryId);
$authorId = implode(',', $authorId);
$query->where('a.created_by IN (' . $authorId . ')');
}

// Filter by search in title.
$search = $this->getState('filter.search');

Expand Down
Expand Up @@ -19,12 +19,13 @@
<field
name="category_id"
type="category"
multiple="true"
class="multipleCategories"
label="JOPTION_FILTER_CATEGORY"
extension="com_content"
description="JOPTION_FILTER_CATEGORY_DESC"
onchange="this.form.submit();"
>
<option value="">JOPTION_SELECT_CATEGORY</option>
</field>
<field
name="level"
Expand All @@ -42,20 +43,22 @@
<field
name="access"
type="accesslevel"
multiple="true"
class="multipleAccessLevels"
label="JOPTION_FILTER_ACCESS"
description="JOPTION_FILTER_ACCESS_DESC"
onchange="this.form.submit();"
>
<option value="">JOPTION_SELECT_ACCESS</option>
</field>
<field
name="author_id"
type="author"
multiple="true"
class="multipleAuthors"
label="COM_CONTENT_FILTER_AUTHOR"
description="COM_CONTENT_FILTER_AUTHOR_DESC"
onchange="this.form.submit();"
>
<option value="">JOPTION_SELECT_AUTHOR</option>
</field>
<field
name="language"
Expand Down
Expand Up @@ -21,12 +21,13 @@
<field
name="category_id"
type="category"
multiple="true"
class="multipleCategories"
label="JOPTION_FILTER_CATEGORY"
extension="com_content"
description="JOPTION_FILTER_CATEGORY_DESC"
onchange="this.form.submit();"
>
<option value="">JOPTION_SELECT_CATEGORY</option>
</field>
<field
name="level"
Expand All @@ -44,20 +45,22 @@
<field
name="author_id"
type="author"
multiple="true"
class="multipleAuthors"
label="COM_CONTENT_FILTER_AUTHOR"
description="COM_CONTENT_FILTER_AUTHOR_DESC"
onchange="this.form.submit();"
>
<option value="">JOPTION_SELECT_AUTHOR</option>
</field>
<field
name="access"
type="accesslevel"
multiple="true"
class="multipleAccessLevels"
label="JOPTION_FILTER_ACCESS"
description="JOPTION_FILTER_ACCESS_DESC"
onchange="this.form.submit();"
>
<option value="">JOPTION_SELECT_ACCESS</option>
</field>
<field
name="language"
Expand Down
Expand Up @@ -13,6 +13,9 @@

JHtml::_('bootstrap.tooltip');
JHtml::_('behavior.multiselect');
JHtml::_('formbehavior.chosen', '.multipleAccessLevels', null, array('placeholder_text_multiple' => JText::_('JOPTION_SELECT_ACCESS')));
JHtml::_('formbehavior.chosen', '.multipleAuthors', null, array('placeholder_text_multiple' => JText::_('JOPTION_SELECT_AUTHOR')));
JHtml::_('formbehavior.chosen', '.multipleCategories', null, array('placeholder_text_multiple' => JText::_('JOPTION_SELECT_CATEGORY')));
JHtml::_('formbehavior.chosen', '.multipleTags', null, array('placeholder_text_multiple' => JText::_('JOPTION_SELECT_TAG')));
JHtml::_('formbehavior.chosen', 'select');

Expand Down
Expand Up @@ -13,6 +13,9 @@

JHtml::_('bootstrap.tooltip');
JHtml::_('behavior.multiselect');
JHtml::_('formbehavior.chosen', '.multipleAccessLevels', null, array('placeholder_text_multiple' => JText::_('JOPTION_SELECT_ACCESS')));
JHtml::_('formbehavior.chosen', '.multipleAuthors', null, array('placeholder_text_multiple' => JText::_('JOPTION_SELECT_AUTHOR')));
JHtml::_('formbehavior.chosen', '.multipleCategories', null, array('placeholder_text_multiple' => JText::_('JOPTION_SELECT_CATEGORY')));
JHtml::_('formbehavior.chosen', '.multipleTags', null, array('placeholder_text_multiple' => JText::_('JOPTION_SELECT_TAG')));
JHtml::_('formbehavior.chosen', 'select');

Expand Down
Expand Up @@ -13,6 +13,7 @@

JHtml::_('behavior.formvalidator');
JHtml::_('behavior.combobox');
JHtml::_('formbehavior.chosen', '.multipleCategories', null, array('placeholder_text_multiple' => JText::_('JOPTION_SELECT_CATEGORY')));
JHtml::_('formbehavior.chosen', '.multipleTags', null, array('placeholder_text_multiple' => JText::_('JOPTION_SELECT_TAG')));
JHtml::_('formbehavior.chosen', 'select');

Expand Down
2 changes: 1 addition & 1 deletion modules/mod_articles_news/mod_articles_news.xml
Expand Up @@ -28,12 +28,12 @@
type="category"
extension="com_content"
multiple="true"
class="multipleCategories"
default=""
size="10"
label="JCATEGORY"
description="MOD_ARTICLES_NEWS_FIELD_CATEGORY_DESC"
>
<option value="">JOPTION_ALL_CATEGORIES</option>
</field>

<field
Expand Down

0 comments on commit 9a78a59

Please sign in to comment.