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 1 commit
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
116 changes: 80 additions & 36 deletions administrator/components/com_content/models/articles.php
Expand Up @@ -21,7 +21,7 @@ class ContentModelArticles extends JModelList
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
* @param array $config An optional associative array of configuration settings.
Copy link
Contributor

@Quy Quy Aug 22, 2017

Choose a reason for hiding this comment

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

Per Joomla's Coding Manual:
The minimum whitespace between any text elements, such as tags, variable types, variable names and tag descriptions, is two real spaces.

*
* @since 1.6
* @see JControllerLegacy
Expand Down Expand Up @@ -71,8 +71,8 @@ public function __construct($config = array())
*
* 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).
* @param string $ordering An optional ordering field.
* @param string $direction An optional direction (asc|desc).
*
* @return void
*
Expand All @@ -99,26 +99,38 @@ 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);

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.

$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 All @@ -138,7 +150,7 @@ protected function populateState($ordering = 'a.id', $direction = 'desc')
* different modules that might need different sets of data or different
* ordering requirements.
*
* @param string $id A prefix for the store id.
* @param string $id A prefix for the store id.
*
* @return string A store id.
*
Expand All @@ -148,11 +160,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 +180,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 +236,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 +268,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 +303,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 +337,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 +386,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 @@ -22,34 +22,37 @@
<field
name="category_id"
type="category"
multiple="true"
class="multipleCategories"
Copy link
Contributor

Choose a reason for hiding this comment

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

The four attributes name, type, label and description should be written in this order and at the top of the element definition.

label="JOPTION_FILTER_CATEGORY"
description="JOPTION_FILTER_CATEGORY_DESC"
extension="com_content"
onchange="this.form.submit();"
published="0,1,2"
>
Copy link
Contributor

Choose a reason for hiding this comment

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

Please read the coding style for XML when element is empty: https://developer.joomla.org/coding-standards/xml.html

<option value="">JOPTION_SELECT_CATEGORY</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>
<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>
>
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix tab and coding style.

</field>

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

Choose a reason for hiding this comment

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

Fix coding style.


</field>

<field
Expand All @@ -86,6 +91,7 @@
>
<option value="">JOPTION_SELECT_MAX_LEVELS</option>
</field>
<input type="hidden" name="form_submited" value="1"/>
</fields>

<fields name="list">
Expand Down