Skip to content

Commit

Permalink
Merge pull request #10029 from andrepereiradasilva/com_finder-filters…
Browse files Browse the repository at this point in the history
…-searchtools

[com_finder] filters view: searchtools ordering, bug corrections and some improvements
  • Loading branch information
rdeutz committed Apr 29, 2016
2 parents 8f51c05 + 9855e85 commit 3176587
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 96 deletions.
35 changes: 17 additions & 18 deletions administrator/components/com_finder/models/filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,33 @@ protected function getListQuery()

// Select all fields from the table.
$query->select('a.*')
->from($db->quoteName('#__finder_filters') . ' AS a');
->from($db->quoteName('#__finder_filters', 'a'));

// Join over the users for the checked out user.
$query->select('uc.name AS editor')
->join('LEFT', $db->quoteName('#__users') . ' AS uc ON uc.id=a.checked_out');
$query->select($db->quoteName('uc.name', 'editor'))
->join('LEFT', $db->quoteName('#__users', 'uc') . ' ON ' . $db->quoteName('uc.id') . ' = ' . $db->quoteName('a.checked_out'));

// Join over the users for the author.
$query->select('ua.name AS user_name')
->join('LEFT', $db->quoteName('#__users') . ' AS ua ON ua.id = a.created_by');
$query->select($db->quoteName('ua.name', 'user_name'))
->join('LEFT', $db->quoteName('#__users', 'ua') . ' ON ' . $db->quoteName('ua.id') . ' = ' . $db->quoteName('a.created_by'));

// Check for a search filter.
if ($this->getState('filter.search'))
if ($search = $this->getState('filter.search'))
{
$search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($this->getState('filter.search')), true) . '%'));
$query->where('( a.title LIKE ' . $search . ' )');
$search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%'));
$query->where($db->quoteName('a.title') . ' LIKE ' . $search);
}

// If the model is set to check item state, add to the query.
if (is_numeric($this->getState('filter.state')))
$state = $this->getState('filter.state');

if (is_numeric($state))
{
$query->where('a.state = ' . (int) $this->getState('filter.state'));
$query->where($db->quoteName('a.state') . ' = ' . (int) $state);
}

// Add the list ordering clause.
$query->order($db->escape($this->getState('list.ordering', 'a.title') . ' ' . $db->escape($this->getState('list.direction'))));
$query->order($db->escape($this->getState('list.ordering', 'a.title') . ' ' . $db->escape($this->getState('list.direction', 'ASC'))));

return $query;
}
Expand Down Expand Up @@ -116,20 +118,17 @@ protected function getStoreId($id = '')
*
* @since 2.5
*/
protected function populateState($ordering = null, $direction = null)
protected function populateState($ordering = 'a.title', $direction = 'asc')
{
// Load the filter state.
$search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
$this->setState('filter.search', $search);

$state = $this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state', '', 'string');
$this->setState('filter.state', $state);
$this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string'));
$this->setState('filter.state', $this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state', '', 'cmd'));

// Load the parameters.
$params = JComponentHelper::getParams('com_finder');
$this->setState('params', $params);

// List state information.
parent::populateState('a.title', 'asc');
parent::populateState($ordering, $direction);
}
}
77 changes: 48 additions & 29 deletions administrator/components/com_finder/models/forms/filter_filters.xml
Original file line number Diff line number Diff line change
@@ -1,32 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<form>
<fields name="filter">
<field
name="search"
type="text"
label="COM_FINDER_FILTER_SEARCH_DESC"
hint="JSEARCH_FILTER"
/>
<field
name="state"
type="status"
filter="*,0,1"
label="COM_FINDER_FILTER_PUBLISHED"
description="COM_FINDER_FILTER_PUBLISHED_DESC"
onchange="this.form.submit();"
>
<option value="">JOPTION_SELECT_PUBLISHED</option>
</field>
</fields>
<fields name="list">
<field
name="limit"
type="limitbox"
class="input-mini"
default="25"
label="COM_FINDER_LIST_LIMIT"
description="COM_FINDER_LIST_LIMIT_DESC"
onchange="this.form.submit();"
/>
</fields>
<fields name="filter">
<field
name="search"
type="text"
label="COM_FINDER_SEARCH_FILTER_SEARCH_LABEL"
description="COM_FINDER_SEARCH_FILTER_SEARCH_DESC"
hint="JSEARCH_FILTER"
/>
<field
name="state"
type="status"
filter="0,1"
label="COM_FINDER_FILTER_PUBLISHED"
description="COM_FINDER_FILTER_PUBLISHED_DESC"
onchange="this.form.submit();"
>
<option value="">JOPTION_SELECT_PUBLISHED</option>
</field>
</fields>
<fields name="list">
<field
name="fullordering"
type="list"
onchange="this.form.submit();"
default="a.title ASC"
>
<option value="">JGLOBAL_SORT_BY</option>
<option value="a.state ASC">JSTATUS_ASC</option>
<option value="a.state DESC">JSTATUS_DESC</option>
<option value="a.title ASC">JGLOBAL_TITLE_ASC</option>
<option value="a.title DESC">JGLOBAL_TITLE_DESC</option>
<option value="a.created_by_alias ASC">COM_FINDER_HEADING_CREATED_BY_ASC</option>
<option value="a.created_by_alias DESC">COM_FINDER_HEADING_CREATED_BY_DESC</option>
<option value="a.created ASC">COM_FINDER_HEADING_CREATED_ON_ASC</option>
<option value="a.created DESC">COM_FINDER_HEADING_CREATED_ON_DESC</option>
<option value="a.map_count ASC">COM_FINDER_HEADING_MAP_COUNT_ASC</option>
<option value="a.map_count DESC">COM_FINDER_HEADING_MAP_COUNT_DESC</option>
<option value="a.filter_id ASC">JGRID_HEADING_ID_ASC</option>
<option value="a.filter_id DESC">JGRID_HEADING_ID_DESC</option>
</field>
<field
name="limit"
type="limitbox"
class="input-mini"
default="25"
onchange="this.form.submit();"
/>
</fields>
</form>
73 changes: 29 additions & 44 deletions administrator/components/com_finder/views/filters/tmpl/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,73 +37,70 @@
};
');
?>

<form action="<?php echo JRoute::_('index.php?option=com_finder&view=filters');?>" method="post" name="adminForm" id="adminForm">
<form action="<?php echo JRoute::_('index.php?option=com_finder&view=filters'); ?>" method="post" name="adminForm" id="adminForm">
<?php if (!empty( $this->sidebar)) : ?>
<div id="j-sidebar-container" class="span2">
<?php echo $this->sidebar; ?>
</div>
<div id="j-main-container" class="span10">
<?php else : ?>
<div id="j-main-container">
<?php endif; ?>
<?php echo JLayoutHelper::render('joomla.searchtools.default', array('view' => $this)); ?>
<div class="clearfix"> </div>
<?php if (empty($this->items)) : ?>
<div class="alert alert-no-items">
<?php echo JText::_('COM_FINDER_NO_RESULTS_OR_FILTERS'); ?>
</div>
<?php else : ?>
<div id="j-main-container">
<?php endif;?>
<?php
// Search tools bar
echo JLayoutHelper::render('joomla.searchtools.default', array('view' => $this)); ?>
<table class="table table-striped">
<thead>
<tr>
<th width="1%">
<th width="1%" class="nowrap center">
<?php echo JHtml::_('grid.checkall'); ?>
</th>
<th class="nowrap">
<?php echo JHtml::_('grid.sort', 'JGLOBAL_TITLE', 'a.title', $listDirn, $listOrder); ?>
<th width="1%" class="nowrap">
<?php echo JHtml::_('searchtools.sort', 'JSTATUS', 'a.state', $listDirn, $listOrder); ?>
</th>
<th width="5%" class="nowrap">
<?php echo JHtml::_('grid.sort', 'JSTATUS', 'a.state', $listDirn, $listOrder); ?>
<th class="nowrap">
<?php echo JHtml::_('searchtools.sort', 'JGLOBAL_TITLE', 'a.title', $listDirn, $listOrder); ?>
</th>
<th width="10%" class="nowrap hidden-phone">
<?php echo JHtml::_('grid.sort', 'JGRID_HEADING_CREATED_BY', 'a.created_by_alias', $listDirn, $listOrder); ?>
<?php echo JHtml::_('searchtools.sort', 'COM_FINDER_HEADING_CREATED_BY', 'a.created_by_alias', $listDirn, $listOrder); ?>
</th>
<th width="10%" class="nowrap hidden-phone">
<?php echo JHtml::_('grid.sort', 'COM_FINDER_FILTER_TIMESTAMP', 'a.created', $listDirn, $listOrder); ?>
<?php echo JHtml::_('searchtools.sort', 'COM_FINDER_HEADING_CREATED_ON', 'a.created', $listDirn, $listOrder); ?>
</th>
<th width="5%" class="nowrap hidden-phone">
<?php echo JHtml::_('grid.sort', 'COM_FINDER_FILTER_MAP_COUNT', 'a.map_count', $listDirn, $listOrder); ?>
<?php echo JHtml::_('searchtools.sort', 'COM_FINDER_HEADING_MAP_COUNT', 'a.map_count', $listDirn, $listOrder); ?>
</th>
<th width="1%" class="nowrap hidden-phone">
<?php echo JHtml::_('grid.sort', 'JGRID_HEADING_ID', 'a.filter_id', $listDirn, $listOrder); ?>
<?php echo JHtml::_('searchtools.sort', 'JGRID_HEADING_ID', 'a.filter_id', $listDirn, $listOrder); ?>
</th>
</tr>
</thead>
<tbody>
<?php if (count($this->items) == 0) : ?>
<tr class="row0">
<td class="center" colspan="7">
<?php if ($this->total == 0) : ?>
<?php echo JText::_('COM_FINDER_NO_FILTERS'); ?>
<a href="<?php echo JRoute::_('index.php?option=com_finder&task=filter.add'); ?>" title="<?php echo JText::_('COM_FINDER_CREATE_FILTER'); ?>">
<?php echo JText::_('COM_FINDER_CREATE_FILTER'); ?>
</a>
<?php else : ?>
<?php echo JText::_('COM_FINDER_NO_RESULTS'); ?>
<?php endif; ?>
<tfoot>
<tr>
<td colspan="7">
<?php echo $this->pagination->getListFooter(); ?>
</td>
</tr>
<?php endif; ?>

</tfoot>
<tbody>
<?php
foreach ($this->items as $i => $item) :
$canCreate = $user->authorise('core.create', 'com_finder');
$canEdit = $user->authorise('core.edit', 'com_finder');
$canCheckin = $user->authorise('core.manage', 'com_checkin') || $item->checked_out == $user->get('id') || $item->checked_out == 0;
$canChange = $user->authorise('core.edit.state', 'com_finder') && $canCheckin;
?>

<tr class="row<?php echo $i % 2; ?>">
<td class="center">
<?php echo JHtml::_('grid.id', $i, $item->filter_id); ?>
</td>
<td class="center nowrap">
<?php echo JHtml::_('jgrid.published', $item->state, $i, 'filters.', $canChange); ?>
</td>
<td>
<?php if ($item->checked_out) : ?>
<?php echo JHtml::_('jgrid.checkedout', $i, $item->editor, $item->checked_out_time, 'filters.', $canCheckin); ?>
Expand All @@ -115,9 +112,6 @@
<?php echo $this->escape($item->title); ?>
<?php endif; ?>
</td>
<td class="center nowrap">
<?php echo JHtml::_('jgrid.published', $item->state, $i, 'filters.', $canChange); ?>
</td>
<td class="nowrap hidden-phone">
<?php echo $item->created_by_alias ? $item->created_by_alias : $item->user_name; ?>
</td>
Expand All @@ -133,19 +127,10 @@
</tr>
<?php endforeach; ?>
</tbody>
<tfoot>
<tr>
<td colspan="7" class="nowrap">
<?php echo $this->pagination->getListFooter(); ?>
</td>
</tr>
</tfoot>
</table>

<?php endif; ?>
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="filter_order" value="<?php echo $this->state->get('list.ordering'); ?>" />
<input type="hidden" name="filter_order_Dir" value="<?php echo $this->state->get('list.direction'); ?>" />
<?php echo JHtml::_('form.token'); ?>
</div>
</form>
10 changes: 5 additions & 5 deletions administrator/components/com_finder/views/filters/view.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ class FinderViewFilters extends JViewLegacy
public function display($tpl = null)
{
// Load the view data.
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->total = $this->get('Total');
$this->state = $this->get('State');
$this->filterForm = $this->get('FilterForm');
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->total = $this->get('Total');
$this->state = $this->get('State');
$this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters');

FinderHelper::addSubmenu('filters');
Expand Down
10 changes: 10 additions & 0 deletions administrator/language/en-GB/en-GB.com_finder.ini
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,16 @@ COM_FINDER_FILTERS="Filters"
COM_FINDER_FILTERS_DELETE_CONFIRMATION="Are you sure you want to delete the selected filters(s)?"
COM_FINDER_FILTERS_TOOLBAR_TITLE="Smart Search: Search Filters"
COM_FINDER_GO="Go"
COM_FINDER_HEADING_CREATED_BY="Created By"
COM_FINDER_HEADING_CREATED_BY_ASC="Created By ascending"
COM_FINDER_HEADING_CREATED_BY_DESC="Created By descending"
COM_FINDER_HEADING_CREATED_ON="Created On"
COM_FINDER_HEADING_CREATED_ON_ASC="Created On ascending"
COM_FINDER_HEADING_CREATED_ON_DESC="Created On descending"
COM_FINDER_HEADING_INDEXER="Smart Search Indexer"
COM_FINDER_HEADING_MAP_COUNT="Map Count"
COM_FINDER_HEADING_MAP_COUNT_ASC="Map Count ascending"
COM_FINDER_HEADING_MAP_COUNT_DESC="Map Count descending"
COM_FINDER_IMPORT="Import"
COM_FINDER_INDEX="Index"
COM_FINDER_INDEX_CONFIRM_DELETE_PROMPT="Are you sure you want to delete the selected item(s)?"
Expand Down Expand Up @@ -199,6 +208,7 @@ COM_FINDER_N_ITEMS_UNPUBLISHED_1="%d item successfully unpublished."
COM_FINDER_NO_ERROR_RETURNED="No error was returned. Make sure error reporting is enabled."
COM_FINDER_NO_FILTERS="No filters have been created yet."
COM_FINDER_NO_RESULTS="No results match your search criteria."
COM_FINDER_NO_RESULTS_OR_FILTERS="No results match your search criteria or no filters have been created yet."
COM_FINDER_QUERY_FILTER_TODAY="Today"
COM_FINDER_QUERY_OPERATOR_AND="And"
COM_FINDER_QUERY_OPERATOR_NOT="Not"
Expand Down

0 comments on commit 3176587

Please sign in to comment.