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

redo of flo's tag branch and merge #17668

Merged
merged 6 commits into from Aug 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
110 changes: 76 additions & 34 deletions administrator/components/com_content/models/articles.php
Expand Up @@ -99,26 +99,36 @@ protected function populateState($ordering = 'a.id', $direction = 'desc')
$search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
$this->setState('filter.search', $search);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove blank line.

$access = $this->getUserStateFromRequest($this->context . '.filter.access', 'filter_access');
$this->setState('filter.access', $access);

$authorId = $app->getUserStateFromRequest($this->context . '.filter.author_id', 'filter_author_id');
$this->setState('filter.author_id', $authorId);

$published = $this->getUserStateFromRequest($this->context . '.filter.published', 'filter_published', '');
$this->setState('filter.published', $published);

$categoryId = $this->getUserStateFromRequest($this->context . '.filter.category_id', 'filter_category_id');
$this->setState('filter.category_id', $categoryId);

$level = $this->getUserStateFromRequest($this->context . '.filter.level', 'filter_level');
$this->setState('filter.level', $level);

$language = $this->getUserStateFromRequest($this->context . '.filter.language', 'filter_language', '');
$this->setState('filter.language', $language);

$tag = $this->getUserStateFromRequest($this->context . '.filter.tag', 'filter_tag', '');
$this->setState('filter.tag', $tag);
$formSubmited = $app->input->post->get('form_submited');

$access = $this->getUserStateFromRequest($this->context . '.filter.access', 'filter_access');
$authorId = $this->getUserStateFromRequest($this->context . '.filter.author_id', 'filter_author_id');
$categoryId = $this->getUserStateFromRequest($this->context . '.filter.category_id', 'filter_category_id');
$tag = $this->getUserStateFromRequest($this->context . '.filter.tag', 'filter_tag', '');

if ($formSubmited)
{
$access = $app->input->post->get('access');
$this->setState('filter.access', $access);

$authorId = $app->input->post->get('author_id');
$this->setState('filter.author_id', $authorId);

$categoryId = $app->input->post->get('category_id');
$this->setState('filter.category_id', $categoryId);

$tag = $app->input->post->get('tag');
$this->setState('filter.tag', $tag);
}

// List state information.
parent::populateState($ordering, $direction);
Expand Down Expand Up @@ -148,11 +158,12 @@ 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'));

return parent::getStoreId($id);
}
Expand All @@ -167,17 +178,17 @@ protected function getStoreId($id = '')
protected function getListQuery()
{
// Create a new query object.
$db = $this->getDbo();
$db = $this->getDbo();
$query = $db->getQuery(true);
$user = JFactory::getUser();
$user = JFactory::getUser();

// Select the required fields from the table.
$query->select(
$this->getState(
'list.select',
'a.id, a.title, a.alias, a.checked_out, a.checked_out_time, a.catid' .
', a.state, a.access, a.created, a.created_by, a.created_by_alias, a.modified, a.ordering, a.featured, a.language, a.hits' .
', a.publish_up, a.publish_down'
'DISTINCT a.id, a.title, a.alias, a.checked_out, a.checked_out_time, a.catid' .
', a.state, a.access, a.created, a.created_by, a.created_by_alias, a.modified, a.ordering, a.featured, a.language, a.hits' .
', a.publish_up, a.publish_down'
)
);
$query->from('#__content AS a');
Expand Down Expand Up @@ -223,10 +234,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);
}
elseif (is_array($access))
{
$access = ArrayHelper::toInteger($access);
$access = implode(',', $access);
$query->where('a.access IN (' . $access . ')');
}

// Filter by access level on categories.
if (!$user->authorise('core.admin'))
Expand All @@ -248,22 +266,24 @@ protected function getListQuery()
$query->where('(a.state = 0 OR a.state = 1)');
}


// Filter by a single or group of categories.
$baselevel = 1;
$baselevel = 1;
$categoryId = $this->getState('filter.category_id');

if (is_numeric($categoryId))
{
$categoryTable= JTable::getInstance('Category', 'JTable');
$categoryTable = JTable::getInstance('Category', 'JTable');
$categoryTable->load($categoryId);
$rgt = $categoryTable->rgt;
$lft = $categoryTable->lft;
$rgt = $categoryTable->rgt;
$lft = $categoryTable->lft;
$baselevel = (int) $categoryTable->level;
$query->where('c.lft >= ' . (int) $lft)
->where('c.rgt <= ' . (int) $rgt);
}
elseif (is_array($categoryId))
{
$categoryId = ArrayHelper::toInteger($categoryId);
$query->where('a.catid IN (' . implode(',', ArrayHelper::toInteger($categoryId)) . ')');
}

Expand All @@ -281,6 +301,12 @@ protected function getListQuery()
$type = $this->getState('filter.author_id.include', true) ? '= ' : '<>';
$query->where('a.created_by ' . $type . (int) $authorId);
}
elseif (is_array($authorId))
{
$authorId = ArrayHelper::toInteger($authorId);
$authorId = implode(',', $authorId);
$query->where('a.created_by IN (' . $authorId . ')');
}

// Filter by search in title.
$search = $this->getState('filter.search');
Expand Down Expand Up @@ -309,18 +335,34 @@ protected function getListQuery()
$query->where('a.language = ' . $db->quote($language));
}

// Filter by a single tag.
$tagId = $this->getState('filter.tag');
// Filter by a single or group of tags.
$hasTag = false;
$tagId = $this->getState('filter.tag');

if (is_numeric($tagId))
{
$query->where($db->quoteName('tagmap.tag_id') . ' = ' . (int) $tagId)
->join(
'LEFT',
$db->quoteName('#__contentitem_tag_map', 'tagmap')
. ' ON ' . $db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id')
. ' AND ' . $db->quoteName('tagmap.type_alias') . ' = ' . $db->quote('com_content.article')
);
$hasTag = true;

$query->where($db->quoteName('tagmap.tag_id') . ' = ' . (int) $tagId);
}
elseif (is_array($tagId))
{
$tagId = ArrayHelper::toInteger($tagId);
$tagId = implode(',', $tagId);
if (!empty($tagId))
{
$hasTag = true;

$query->where($db->quoteName('tagmap.tag_id') . ' IN (' . $tagId . ')');
}
}

if ($hasTag)
{
$query->join('LEFT', $db->quoteName('#__contentitem_tag_map', 'tagmap')
. ' ON ' . $db->quoteName('tagmap.content_item_id') . ' = ' . $db->quoteName('a.id')
. ' AND ' . $db->quoteName('tagmap.type_alias') . ' = ' . $db->quote('com_content.article')
);
}

// Add the list ordering clause.
Expand All @@ -342,7 +384,7 @@ protected function getListQuery()
public function getAuthors()
{
// Create a new query object.
$db = $this->getDbo();
$db = $this->getDbo();
$query = $db->getQuery(true);

// Construct the query
Expand Down
Expand Up @@ -24,32 +24,32 @@
type="category"
label="JOPTION_FILTER_CATEGORY"
description="JOPTION_FILTER_CATEGORY_DESC"
multiple="true"
class="multipleCategories"
extension="com_content"
onchange="this.form.submit();"
published="0,1,2"
>
<option value="">JOPTION_SELECT_CATEGORY</option>
</field>
/>

<field
name="access"
type="accesslevel"
label="JOPTION_FILTER_ACCESS"
description="JOPTION_FILTER_ACCESS_DESC"
multiple="true"
class="multipleAccessLevels"
onchange="this.form.submit();"
>
<option value="">JOPTION_SELECT_ACCESS</option>
</field>
/>

<field
name="author_id"
type="author"
label="COM_CONTENT_FILTER_AUTHOR"
description="COM_CONTENT_FILTER_AUTHOR_DESC"
multiple="true"
class="multipleAuthors"
onchange="this.form.submit();"
>
<option value="">JOPTION_SELECT_AUTHOR</option>
</field>
/>

<field
name="language"
Expand All @@ -67,11 +67,11 @@
type="tag"
label="JOPTION_FILTER_TAG"
description="JOPTION_FILTER_TAG_DESC"
multiple="true"
class="multipleTags"
mode="nested"
onchange="this.form.submit();"
>
<option value="">JOPTION_SELECT_TAG</option>
</field>
/>

<field
name="level"
Expand All @@ -85,7 +85,8 @@
onchange="this.form.submit();"
>
<option value="">JOPTION_SELECT_MAX_LEVELS</option>
</field>
</field>
<input type="hidden" name="form_submited" value="1"/>
</fields>

<fields name="list">
Expand Down