Added new filters to admin, and custom admin, and site list view. gh-651

This commit is contained in:
2021-01-19 00:10:59 +02:00
parent 30cb1a531a
commit 60f4e8af32
12 changed files with 524 additions and 21 deletions

View File

@ -42,6 +42,51 @@ class ComponentbuilderModelAdmin_views extends JModelList
}
parent::__construct($config);
}
/**
* Get the filter form - Override the parent method
*
* @param array $data data
* @param boolean $loadData load current data
*
* @return \JForm|boolean The \JForm object or false on error
*
* @since JCB 2.12.5
*/
public function getFilterForm($data = array(), $loadData = true)
{
// load form from the parent class
$form = parent::getFilterForm($data, $loadData);
// Create the "joomla_component" filter
$attributes = array(
'name' => 'joomla_component',
'type' => 'list',
'onchange' => 'this.form.submit();',
);
$options = array(
'' => '- ' . JText::_('COM_COMPONENTBUILDER_NO_COMPONENTS_FOUND') . ' -'
);
// check if we have joomla components
if (($joomla_components = ComponentbuilderHelper::getByTypeTheIdsSystemNames('joomla_component')) !== false)
{
$options = array(
'' => '- ' . JText::_('COM_COMPONENTBUILDER_SELECT_COMPONENT') . ' -'
);
// make sure we do not lose the key values in normal merge
$options = $options + $joomla_components;
}
$form->setField(ComponentbuilderHelper::getFieldXML($attributes, $options),'filter');
$form->setValue(
'joomla_component',
'filter',
$this->state->get("filter.joomla_component")
);
array_push($this->filter_fields, 'joomla_component');
return $form;
}
/**
@ -301,6 +346,25 @@ class ComponentbuilderModelAdmin_views extends JModelList
// From the componentbuilder_item table
$query->from($db->quoteName('#__componentbuilder_admin_view', 'a'));
// do not use these filters in the export method
if (!isset($_export) || !$_export)
{
// Filtering "joomla components"
$filter_joomla_component = $this->state->get("filter.joomla_component");
if ($filter_joomla_component !== null && !empty($filter_joomla_component))
{
if (($ids = ComponentbuilderHelper::getAreaLinkedIDs($filter_joomla_component, 'joomla_component_admin_views')) !== false)
{
$query->where($db->quoteName('a.id') . ' IN (' . implode(',', $ids) . ')');
}
else
{
// there is none
$query->where($db->quoteName('a.id') . ' = ' . 0);
}
}
}
// Filter by published state
$published = $this->getState('filter.published');
if (is_numeric($published))
@ -516,6 +580,25 @@ class ComponentbuilderModelAdmin_views extends JModelList
{
$query->where('a.id IN (' . implode(',',$pks) . ')');
}
// do not use these filters in the export method
if (!isset($_export) || !$_export)
{
// Filtering "joomla components"
$filter_joomla_component = $this->state->get("filter.joomla_component");
if ($filter_joomla_component !== null && !empty($filter_joomla_component))
{
if (($ids = ComponentbuilderHelper::getAreaLinkedIDs($filter_joomla_component, 'joomla_component_admin_views')) !== false)
{
$query->where($db->quoteName('a.id') . ' IN (' . implode(',', $ids) . ')');
}
else
{
// there is none
$query->where($db->quoteName('a.id') . ' = ' . 0);
}
}
}
// Implement View Level Access
if (!$user->authorise('core.options', 'com_componentbuilder'))
{

View File

@ -40,6 +40,51 @@ class ComponentbuilderModelCustom_admin_views extends JModelList
}
parent::__construct($config);
}
/**
* Get the filter form - Override the parent method
*
* @param array $data data
* @param boolean $loadData load current data
*
* @return \JForm|boolean The \JForm object or false on error
*
* @since JCB 2.12.5
*/
public function getFilterForm($data = array(), $loadData = true)
{
// load form from the parent class
$form = parent::getFilterForm($data, $loadData);
// Create the "joomla_component" filter
$attributes = array(
'name' => 'joomla_component',
'type' => 'list',
'onchange' => 'this.form.submit();',
);
$options = array(
'' => '- ' . JText::_('COM_COMPONENTBUILDER_NO_COMPONENTS_FOUND') . ' -'
);
// check if we have joomla components
if (($joomla_components = ComponentbuilderHelper::getByTypeTheIdsSystemNames('joomla_component')) !== false)
{
$options = array(
'' => '- ' . JText::_('COM_COMPONENTBUILDER_SELECT_COMPONENT') . ' -'
);
// make sure we do not lose the key values in normal merge
$options = $options + $joomla_components;
}
$form->setField(ComponentbuilderHelper::getFieldXML($attributes, $options),'filter');
$form->setValue(
'joomla_component',
'filter',
$this->state->get("filter.joomla_component")
);
array_push($this->filter_fields, 'joomla_component');
return $form;
}
/**
@ -240,6 +285,25 @@ class ComponentbuilderModelCustom_admin_views extends JModelList
// From the componentbuilder_item table
$query->from($db->quoteName('#__componentbuilder_custom_admin_view', 'a'));
// do not use these filters in the export method
if (!isset($_export) || !$_export)
{
// Filtering "joomla components"
$filter_joomla_component = $this->state->get("filter.joomla_component");
if ($filter_joomla_component !== null && !empty($filter_joomla_component))
{
if (($ids = ComponentbuilderHelper::getAreaLinkedIDs($filter_joomla_component, 'joomla_component_custom_admin_views')) !== false)
{
$query->where($db->quoteName('a.id') . ' IN (' . implode(',', $ids) . ')');
}
else
{
// there is none
$query->where($db->quoteName('a.id') . ' = ' . 0);
}
}
}
// From the componentbuilder_dynamic_get table.
$query->select($db->quoteName('g.name','main_get_name'));
$query->join('LEFT', $db->quoteName('#__componentbuilder_dynamic_get', 'g') . ' ON (' . $db->quoteName('a.main_get') . ' = ' . $db->quoteName('g.id') . ')');
@ -309,6 +373,29 @@ class ComponentbuilderModelCustom_admin_views extends JModelList
{
$query->where('a.main_get = ' . $db->quote($db->escape($_main_get)));
}
elseif (ComponentbuilderHelper::checkArray($_main_get))
{
// Secure the array for the query
$_main_get = array_map( function ($val) use(&$db) {
if (is_numeric($val))
{
if (is_float($val))
{
return (float) $val;
}
else
{
return (int) $val;
}
}
elseif (ComponentbuilderHelper::checkString($val))
{
return $db->quote($db->escape($val));
}
}, $_main_get);
// Filter by the Main_get Array.
$query->where('a.main_get IN (' . implode(',', $_main_get) . ')');
}
// Filter by Add_php_ajax.
$_add_php_ajax = $this->getState('filter.add_php_ajax');
if (is_numeric($_add_php_ajax))
@ -402,6 +489,25 @@ class ComponentbuilderModelCustom_admin_views extends JModelList
{
$query->where('a.id IN (' . implode(',',$pks) . ')');
}
// do not use these filters in the export method
if (!isset($_export) || !$_export)
{
// Filtering "joomla components"
$filter_joomla_component = $this->state->get("filter.joomla_component");
if ($filter_joomla_component !== null && !empty($filter_joomla_component))
{
if (($ids = ComponentbuilderHelper::getAreaLinkedIDs($filter_joomla_component, 'joomla_component_custom_admin_views')) !== false)
{
$query->where($db->quoteName('a.id') . ' IN (' . implode(',', $ids) . ')');
}
else
{
// there is none
$query->where($db->quoteName('a.id') . ' = ' . 0);
}
}
}
// Implement View Level Access
if (!$user->authorise('core.options', 'com_componentbuilder'))
{
@ -528,7 +634,18 @@ class ComponentbuilderModelCustom_admin_views extends JModelList
$id .= ':' . $this->getState('filter.ordering');
$id .= ':' . $this->getState('filter.created_by');
$id .= ':' . $this->getState('filter.modified_by');
$id .= ':' . $this->getState('filter.main_get');
// Check if the value is an array
$_main_get = $this->getState('filter.main_get');
if (ComponentbuilderHelper::checkArray($_main_get))
{
$id .= ':' . implode(':', $_main_get);
}
// Check if this is only an number or string
elseif (is_numeric($_main_get)
|| ComponentbuilderHelper::checkString($_main_get))
{
$id .= ':' . $_main_get;
}
$id .= ':' . $this->getState('filter.add_php_ajax');
$id .= ':' . $this->getState('filter.add_custom_button');
$id .= ':' . $this->getState('filter.system_name');

View File

@ -81,7 +81,7 @@ class ComponentbuilderModelFields extends JModelList
'' => '- ' . JText::_('COM_COMPONENTBUILDER_NO_ADMIN_VIEWS_FOUND') . ' -'
);
// check if we have admin views (and limit to an extension if it is set)
if (($admin_views = ComponentbuilderHelper::getExtensionTypeIdSystemName('admin_view', $this->state->get("filter.extension"))) !== false)
if (($admin_views = ComponentbuilderHelper::getByTypeTheIdsSystemNames('admin_view', $this->state->get("filter.extension"))) !== false)
{
$options = array(
'' => '- ' . JText::_('COM_COMPONENTBUILDER_SELECT_ADMIN_VIEW') . ' -'
@ -378,7 +378,7 @@ class ComponentbuilderModelFields extends JModelList
{
// column name, and id
$type_extension = explode('__', $filter_extension);
if (($ids = ComponentbuilderHelper::getExtensionFieldIDs($type_extension[1], $type_extension[0])) !== false)
if (($ids = ComponentbuilderHelper::getAreaLinkedIDs($type_extension[1], $type_extension[0])) !== false)
{
$field_ids = $ids;
}
@ -394,7 +394,7 @@ class ComponentbuilderModelFields extends JModelList
$filter_admin_view = $this->state->get("filter.admin_view");
if ($get_ids && $filter_admin_view !== null && !empty($filter_admin_view))
{
if (($ids = ComponentbuilderHelper::getExtensionFieldIDs($filter_admin_view, 'admin_view')) !== false)
if (($ids = ComponentbuilderHelper::getAreaLinkedIDs($filter_admin_view, 'admin_view')) !== false)
{
// view will return less fields, so we ignore the component
$field_ids = $ids;
@ -643,7 +643,7 @@ class ComponentbuilderModelFields extends JModelList
{
// column name, and id
$type_extension = explode('__', $filter_extension);
if (($ids = ComponentbuilderHelper::getExtensionFieldIDs($type_extension[1], $type_extension[0])) !== false)
if (($ids = ComponentbuilderHelper::getAreaLinkedIDs($type_extension[1], $type_extension[0])) !== false)
{
$field_ids = $ids;
}
@ -659,7 +659,7 @@ class ComponentbuilderModelFields extends JModelList
$filter_admin_view = $this->state->get("filter.admin_view");
if ($get_ids && $filter_admin_view !== null && !empty($filter_admin_view))
{
if (($ids = ComponentbuilderHelper::getExtensionFieldIDs($filter_admin_view, 'admin_view')) !== false)
if (($ids = ComponentbuilderHelper::getAreaLinkedIDs($filter_admin_view, 'admin_view')) !== false)
{
// view will return less fields, so we ignore the component
$field_ids = $ids;

View File

@ -276,7 +276,7 @@ class ComponentbuilderModelFieldtype extends JModelAdmin
{
// column name, and id
$type_extension = explode('__', $filter_extension);
if (($ids = ComponentbuilderHelper::getExtensionFieldIDs($type_extension[1], $type_extension[0])) !== false)
if (($ids = ComponentbuilderHelper::getAreaLinkedIDs($type_extension[1], $type_extension[0])) !== false)
{
$field_ids = $ids;
}
@ -292,7 +292,7 @@ class ComponentbuilderModelFieldtype extends JModelAdmin
$filter_admin_view = $this->state->get("filter.admin_view");
if ($get_ids && $filter_admin_view !== null && !empty($filter_admin_view))
{
if (($ids = ComponentbuilderHelper::getExtensionFieldIDs($filter_admin_view, 'admin_view')) !== false)
if (($ids = ComponentbuilderHelper::getAreaLinkedIDs($filter_admin_view, 'admin_view')) !== false)
{
// view will return less fields, so we ignore the component
$field_ids = $ids;

View File

@ -34,7 +34,8 @@
type="maingets"
name="main_get"
label="COM_COMPONENTBUILDER_CUSTOM_ADMIN_VIEW_MAIN_GET_LABEL"
multiple="false"
class="multipleMaingets"
multiple="true"
onchange="this.form.submit();"
/>
<field

View File

@ -41,6 +41,51 @@ class ComponentbuilderModelSite_views extends JModelList
}
parent::__construct($config);
}
/**
* Get the filter form - Override the parent method
*
* @param array $data data
* @param boolean $loadData load current data
*
* @return \JForm|boolean The \JForm object or false on error
*
* @since JCB 2.12.5
*/
public function getFilterForm($data = array(), $loadData = true)
{
// load form from the parent class
$form = parent::getFilterForm($data, $loadData);
// Create the "joomla_component" filter
$attributes = array(
'name' => 'joomla_component',
'type' => 'list',
'onchange' => 'this.form.submit();',
);
$options = array(
'' => '- ' . JText::_('COM_COMPONENTBUILDER_NO_COMPONENTS_FOUND') . ' -'
);
// check if we have joomla components
if (($joomla_components = ComponentbuilderHelper::getByTypeTheIdsSystemNames('joomla_component')) !== false)
{
$options = array(
'' => '- ' . JText::_('COM_COMPONENTBUILDER_SELECT_COMPONENT') . ' -'
);
// make sure we do not lose the key values in normal merge
$options = $options + $joomla_components;
}
$form->setField(ComponentbuilderHelper::getFieldXML($attributes, $options),'filter');
$form->setValue(
'joomla_component',
'filter',
$this->state->get("filter.joomla_component")
);
array_push($this->filter_fields, 'joomla_component');
return $form;
}
/**
@ -248,6 +293,25 @@ class ComponentbuilderModelSite_views extends JModelList
// From the componentbuilder_item table
$query->from($db->quoteName('#__componentbuilder_site_view', 'a'));
// do not use these filters in the export method
if (!isset($_export) || !$_export)
{
// Filtering "joomla components"
$filter_joomla_component = $this->state->get("filter.joomla_component");
if ($filter_joomla_component !== null && !empty($filter_joomla_component))
{
if (($ids = ComponentbuilderHelper::getAreaLinkedIDs($filter_joomla_component, 'joomla_component_site_views')) !== false)
{
$query->where($db->quoteName('a.id') . ' IN (' . implode(',', $ids) . ')');
}
else
{
// there is none
$query->where($db->quoteName('a.id') . ' = ' . 0);
}
}
}
// From the componentbuilder_dynamic_get table.
$query->select($db->quoteName('g.name','main_get_name'));
$query->join('LEFT', $db->quoteName('#__componentbuilder_dynamic_get', 'g') . ' ON (' . $db->quoteName('a.main_get') . ' = ' . $db->quoteName('g.id') . ')');
@ -433,6 +497,25 @@ class ComponentbuilderModelSite_views extends JModelList
{
$query->where('a.id IN (' . implode(',',$pks) . ')');
}
// do not use these filters in the export method
if (!isset($_export) || !$_export)
{
// Filtering "joomla components"
$filter_joomla_component = $this->state->get("filter.joomla_component");
if ($filter_joomla_component !== null && !empty($filter_joomla_component))
{
if (($ids = ComponentbuilderHelper::getAreaLinkedIDs($filter_joomla_component, 'joomla_component_site_views')) !== false)
{
$query->where($db->quoteName('a.id') . ' IN (' . implode(',', $ids) . ')');
}
else
{
// there is none
$query->where($db->quoteName('a.id') . ' = ' . 0);
}
}
}
// Implement View Level Access
if (!$user->authorise('core.options', 'com_componentbuilder'))
{