Added filters above the admin list views to resolve gh-378

This commit is contained in:
2020-12-03 07:24:20 +02:00
parent 83e4562d62
commit 06c97afa05
277 changed files with 8176 additions and 4301 deletions

View File

@ -34,6 +34,10 @@ class ComponentbuilderViewCustom_admin_views extends JViewLegacy
$this->pagination = $this->get('Pagination');
$this->state = $this->get('State');
$this->user = JFactory::getUser();
// Load the filter form from xml.
$this->filterForm = $this->get('FilterForm');
// Load the active filters.
$this->activeFilters = $this->get('ActiveFilters');
// Add the list ordering clause.
$this->listOrder = $this->escape($this->state->get('list.ordering', 'a.id'));
$this->listDirn = $this->escape($this->state->get('list.direction', 'desc'));
@ -159,82 +163,6 @@ class ComponentbuilderViewCustom_admin_views extends JViewLegacy
JToolBarHelper::preferences('com_componentbuilder');
}
// Only load publish filter if state change is allowed
if ($this->canState)
{
JHtmlSidebar::addFilter(
JText::_('JOPTION_SELECT_PUBLISHED'),
'filter_published',
JHtml::_('select.options', JHtml::_('jgrid.publishedOptions'), 'value', 'text', $this->state->get('filter.published'), true)
);
}
JHtmlSidebar::addFilter(
JText::_('JOPTION_SELECT_ACCESS'),
'filter_access',
JHtml::_('select.options', JHtml::_('access.assetgroups'), 'value', 'text', $this->state->get('filter.access'))
);
// Set Main Get Name Selection
$this->main_getNameOptions = JFormHelper::loadFieldType('Maingets')->options;
// We do some sanitation for Main Get Name filter
if (ComponentbuilderHelper::checkArray($this->main_getNameOptions) &&
isset($this->main_getNameOptions[0]->value) &&
!ComponentbuilderHelper::checkString($this->main_getNameOptions[0]->value))
{
unset($this->main_getNameOptions[0]);
}
// Only load Main Get Name filter if it has values
if (ComponentbuilderHelper::checkArray($this->main_getNameOptions))
{
// Main Get Name Filter
JHtmlSidebar::addFilter(
'- Select ' . JText::_('COM_COMPONENTBUILDER_CUSTOM_ADMIN_VIEW_MAIN_GET_LABEL') . ' -',
'filter_main_get',
JHtml::_('select.options', $this->main_getNameOptions, 'value', 'text', $this->state->get('filter.main_get'))
);
}
// Set Add Php Ajax Selection
$this->add_php_ajaxOptions = $this->getTheAdd_php_ajaxSelections();
// We do some sanitation for Add Php Ajax filter
if (ComponentbuilderHelper::checkArray($this->add_php_ajaxOptions) &&
isset($this->add_php_ajaxOptions[0]->value) &&
!ComponentbuilderHelper::checkString($this->add_php_ajaxOptions[0]->value))
{
unset($this->add_php_ajaxOptions[0]);
}
// Only load Add Php Ajax filter if it has values
if (ComponentbuilderHelper::checkArray($this->add_php_ajaxOptions))
{
// Add Php Ajax Filter
JHtmlSidebar::addFilter(
'- Select '.JText::_('COM_COMPONENTBUILDER_CUSTOM_ADMIN_VIEW_ADD_PHP_AJAX_LABEL').' -',
'filter_add_php_ajax',
JHtml::_('select.options', $this->add_php_ajaxOptions, 'value', 'text', $this->state->get('filter.add_php_ajax'))
);
}
// Set Add Custom Button Selection
$this->add_custom_buttonOptions = $this->getTheAdd_custom_buttonSelections();
// We do some sanitation for Add Custom Button filter
if (ComponentbuilderHelper::checkArray($this->add_custom_buttonOptions) &&
isset($this->add_custom_buttonOptions[0]->value) &&
!ComponentbuilderHelper::checkString($this->add_custom_buttonOptions[0]->value))
{
unset($this->add_custom_buttonOptions[0]);
}
// Only load Add Custom Button filter if it has values
if (ComponentbuilderHelper::checkArray($this->add_custom_buttonOptions))
{
// Add Custom Button Filter
JHtmlSidebar::addFilter(
'- Select '.JText::_('COM_COMPONENTBUILDER_CUSTOM_ADMIN_VIEW_ADD_CUSTOM_BUTTON_LABEL').' -',
'filter_add_custom_button',
JHtml::_('select.options', $this->add_custom_buttonOptions, 'value', 'text', $this->state->get('filter.add_custom_button'))
);
}
// Only load published batch if state and batch is allowed
if ($this->canState && $this->canBatch)
{
@ -258,6 +186,15 @@ class ComponentbuilderViewCustom_admin_views extends JViewLegacy
// Only load Main Get Name batch if create, edit, and batch is allowed
if ($this->canBatch && $this->canCreate && $this->canEdit)
{
// Set Main Get Name Selection
$this->main_getNameOptions = JFormHelper::loadFieldType('Maingets')->options;
// We do some sanitation for Main Get Name filter
if (ComponentbuilderHelper::checkArray($this->main_getNameOptions) &&
isset($this->main_getNameOptions[0]->value) &&
!ComponentbuilderHelper::checkString($this->main_getNameOptions[0]->value))
{
unset($this->main_getNameOptions[0]);
}
// Main Get Name Batch Selection
JHtmlBatch_::addListSelection(
'- Keep Original '.JText::_('COM_COMPONENTBUILDER_CUSTOM_ADMIN_VIEW_MAIN_GET_LABEL').' -',
@ -269,6 +206,15 @@ class ComponentbuilderViewCustom_admin_views extends JViewLegacy
// Only load Add Php Ajax batch if create, edit, and batch is allowed
if ($this->canBatch && $this->canCreate && $this->canEdit)
{
// Set Add Php Ajax Selection
$this->add_php_ajaxOptions = JFormHelper::loadFieldType('customadminviewsfilteraddphpajax')->options;
// We do some sanitation for Add Php Ajax filter
if (ComponentbuilderHelper::checkArray($this->add_php_ajaxOptions) &&
isset($this->add_php_ajaxOptions[0]->value) &&
!ComponentbuilderHelper::checkString($this->add_php_ajaxOptions[0]->value))
{
unset($this->add_php_ajaxOptions[0]);
}
// Add Php Ajax Batch Selection
JHtmlBatch_::addListSelection(
'- Keep Original '.JText::_('COM_COMPONENTBUILDER_CUSTOM_ADMIN_VIEW_ADD_PHP_AJAX_LABEL').' -',
@ -280,6 +226,15 @@ class ComponentbuilderViewCustom_admin_views extends JViewLegacy
// Only load Add Custom Button batch if create, edit, and batch is allowed
if ($this->canBatch && $this->canCreate && $this->canEdit)
{
// Set Add Custom Button Selection
$this->add_custom_buttonOptions = JFormHelper::loadFieldType('customadminviewsfilteraddcustombutton')->options;
// We do some sanitation for Add Custom Button filter
if (ComponentbuilderHelper::checkArray($this->add_custom_buttonOptions) &&
isset($this->add_custom_buttonOptions[0]->value) &&
!ComponentbuilderHelper::checkString($this->add_custom_buttonOptions[0]->value))
{
unset($this->add_custom_buttonOptions[0]);
}
// Add Custom Button Batch Selection
JHtmlBatch_::addListSelection(
'- Keep Original '.JText::_('COM_COMPONENTBUILDER_CUSTOM_ADMIN_VIEW_ADD_CUSTOM_BUTTON_LABEL').' -',
@ -338,77 +293,5 @@ class ComponentbuilderViewCustom_admin_views extends JViewLegacy
'g.name' => JText::_('COM_COMPONENTBUILDER_CUSTOM_ADMIN_VIEW_MAIN_GET_LABEL'),
'a.id' => JText::_('JGRID_HEADING_ID')
);
}
protected function getTheAdd_php_ajaxSelections()
{
// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
// Select the text.
$query->select($db->quoteName('add_php_ajax'));
$query->from($db->quoteName('#__componentbuilder_custom_admin_view'));
$query->order($db->quoteName('add_php_ajax') . ' ASC');
// Reset the query using our newly populated query object.
$db->setQuery($query);
$results = $db->loadColumn();
if ($results)
{
// get model
$model = $this->getModel();
$results = array_unique($results);
$_filter = array();
foreach ($results as $add_php_ajax)
{
// Translate the add_php_ajax selection
$text = $model->selectionTranslation($add_php_ajax,'add_php_ajax');
// Now add the add_php_ajax and its text to the options array
$_filter[] = JHtml::_('select.option', $add_php_ajax, JText::_($text));
}
return $_filter;
}
return false;
}
protected function getTheAdd_custom_buttonSelections()
{
// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
// Select the text.
$query->select($db->quoteName('add_custom_button'));
$query->from($db->quoteName('#__componentbuilder_custom_admin_view'));
$query->order($db->quoteName('add_custom_button') . ' ASC');
// Reset the query using our newly populated query object.
$db->setQuery($query);
$results = $db->loadColumn();
if ($results)
{
// get model
$model = $this->getModel();
$results = array_unique($results);
$_filter = array();
foreach ($results as $add_custom_button)
{
// Translate the add_custom_button selection
$text = $model->selectionTranslation($add_custom_button,'add_custom_button');
// Now add the add_custom_button and its text to the options array
$_filter[] = JHtml::_('select.option', $add_custom_button, JText::_($text));
}
return $_filter;
}
return false;
}
}