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
Changes from 1 commit
cedb5ee
4a385fa
581c3b7
e0609c1
9cddc5f
52d7b39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
* | ||
* @since 1.6 | ||
* @see JControllerLegacy | ||
|
@@ -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 | ||
* | ||
|
@@ -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); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
@@ -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. | ||
* | ||
|
@@ -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); | ||
} | ||
|
@@ -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'); | ||
|
@@ -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')) | ||
|
@@ -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)) . ')'); | ||
} | ||
|
||
|
@@ -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'); | ||
|
@@ -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. | ||
|
@@ -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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,34 +22,37 @@ | |
<field | ||
name="category_id" | ||
type="category" | ||
multiple="true" | ||
class="multipleCategories" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
label="JOPTION_FILTER_CATEGORY" | ||
description="JOPTION_FILTER_CATEGORY_DESC" | ||
extension="com_content" | ||
onchange="this.form.submit();" | ||
published="0,1,2" | ||
> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix tab and coding style. |
||
</field> | ||
|
||
<field | ||
name="language" | ||
|
@@ -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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix coding style. |
||
|
||
</field> | ||
|
||
<field | ||
|
@@ -86,6 +91,7 @@ | |
> | ||
<option value="">JOPTION_SELECT_MAX_LEVELS</option> | ||
</field> | ||
<input type="hidden" name="form_submited" value="1"/> | ||
</fields> | ||
|
||
<fields name="list"> | ||
|
There was a problem hiding this comment.
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.