Added new filters to language translation, and fields admin list view. resolved gh-651

This commit is contained in:
2021-01-18 19:20:26 +02:00
parent bb414c980c
commit 3357f2cb40
11 changed files with 1287 additions and 5 deletions

View File

@ -35,6 +35,75 @@ class ComponentbuilderModelLanguage_translations 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 "extension" filter
$form->setField(new SimpleXMLElement(
ComponentbuilderHelper::getExtensionGroupedListXml()
),'filter');
$form->setValue(
'extension',
'filter',
$this->state->get("filter.extension")
);
array_push($this->filter_fields, 'extension');
// Create the "translated in" filter
$attributes = array(
'name' => 'translated',
'type' => 'list',
'onchange' => 'this.form.submit();',
);
$options = array(
'' => '- ' . JText::_('COM_COMPONENTBUILDER_TRANSLATED_IN') . ' -',
'all' => JText::_('COM_COMPONENTBUILDER_EVERY_LANGUAGE')
);
$options = array_merge($options, ComponentbuilderHelper::getAvailableLanguages());
$form->setField(ComponentbuilderHelper::getFieldXML($attributes, $options),'filter');
$form->setValue(
'translated',
'filter',
$this->state->get("filter.translated")
);
array_push($this->filter_fields, 'translated');
// Create the "not translated in" filter
$attributes = array(
'name' => 'not_translated',
'type' => 'list',
'onchange' => 'this.form.submit();',
);
$options = array(
'' => '- ' . JText::_('COM_COMPONENTBUILDER_NOT_TRANSLATED_IN') . ' -',
'none' => JText::_('COM_COMPONENTBUILDER_ANY_LANGUAGE')
);
$options = array_merge($options, ComponentbuilderHelper::getAvailableLanguages());
$form->setField(ComponentbuilderHelper::getFieldXML($attributes, $options),'filter');
$form->setValue(
'not_translated',
'filter',
$this->state->get("filter.not_translated")
);
array_push($this->filter_fields, 'not_translated');
return $form;
}
/**
@ -205,6 +274,57 @@ class ComponentbuilderModelLanguage_translations extends JModelList
// From the componentbuilder_item table
$query->from($db->quoteName('#__componentbuilder_language_translation', 'a'));
// do not use these filters in the export method
if (!isset($_export) || !$_export)
{
// Filtering "translated in"
$filter_translated = $this->state->get("filter.translated");
if ($filter_translated !== null && !empty($filter_translated))
{
if (($ids = ComponentbuilderHelper::getTranslationIds($filter_translated)) !== false)
{
$query->where($db->quoteName('a.id') . ' IN (' . implode(',', $ids) . ')');
}
else
{
// there is none
$query->where($db->quoteName('a.id') . ' = ' . 0);
}
}
// Filtering "not translated in"
$filter_not_translated = $this->state->get("filter.not_translated");
if ($filter_not_translated !== null && !empty($filter_not_translated))
{
if (($ids = ComponentbuilderHelper::getTranslationIds($filter_not_translated, false)) !== false)
{
$query->where($db->quoteName('a.id') . ' IN (' . implode(',',$ids) . ')');
}
else
{
// there is none
$query->where($db->quoteName('a.id') . ' = ' . 0);
}
}
// Filtering "extension"
$filter_extension = $this->state->get("filter.extension");
if ($filter_extension !== null && !empty($filter_extension))
{
// column name, and id
$type_extension = explode('__', $filter_extension);
if (($ids = ComponentbuilderHelper::getTranslationExtensionsIds($type_extension[1], $type_extension[0])) !== 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))
@ -312,6 +432,57 @@ class ComponentbuilderModelLanguage_translations extends JModelList
{
$query->where('a.id IN (' . implode(',',$pks) . ')');
}
// do not use these filters in the export method
if (!isset($_export) || !$_export)
{
// Filtering "translated in"
$filter_translated = $this->state->get("filter.translated");
if ($filter_translated !== null && !empty($filter_translated))
{
if (($ids = ComponentbuilderHelper::getTranslationIds($filter_translated)) !== false)
{
$query->where($db->quoteName('a.id') . ' IN (' . implode(',', $ids) . ')');
}
else
{
// there is none
$query->where($db->quoteName('a.id') . ' = ' . 0);
}
}
// Filtering "not translated in"
$filter_not_translated = $this->state->get("filter.not_translated");
if ($filter_not_translated !== null && !empty($filter_not_translated))
{
if (($ids = ComponentbuilderHelper::getTranslationIds($filter_not_translated, false)) !== false)
{
$query->where($db->quoteName('a.id') . ' IN (' . implode(',',$ids) . ')');
}
else
{
// there is none
$query->where($db->quoteName('a.id') . ' = ' . 0);
}
}
// Filtering "extension"
$filter_extension = $this->state->get("filter.extension");
if ($filter_extension !== null && !empty($filter_extension))
{
// column name, and id
$type_extension = explode('__', $filter_extension);
if (($ids = ComponentbuilderHelper::getTranslationExtensionsIds($type_extension[1], $type_extension[0])) !== 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'))
{