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

@ -1968,6 +1968,458 @@ abstract class ComponentbuilderHelper
return false;
}
/**
* get translation extention ids
**/
public static function getTranslationExtensionsIds($extention, $type)
{
// only allow these columns (extention types)
$columns = array(
'joomla_component' => 'components',
'joomla_module' => 'modules',
'joomla_plugin' => 'plugins'
);
// check if the column name is correct
if (isset($columns[$type]))
{
$column = $columns[$type];
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select($db->quoteName(array('id', $column)))
->from($db->quoteName('#__componentbuilder_language_translation'))
->where($db->quoteName($column) . ' != ' . $db->quote(''));
$db->setQuery($query);
$db->execute();
if ($db->getNumRows())
{
$results = $db->loadAssocList();
$matches = array();
foreach ($results as $k => $v)
{
$value = json_decode($v[$column], true);
if (in_array($extention, $value))
{
$matches[$v['id']] = $v['id'];
}
}
// Checks that we found matches
if (self::checkArray($matches))
{
return array_values($matches);
}
}
}
return false;
}
/**
* get translation ids
**/
public static function getTranslationIds($language, $translated = true)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select($db->quoteName('id'))
->from($db->quoteName('#__componentbuilder_language_translation'));
// Build the where condition
if ($translated === true) // Translated
{
if ($language === 'all')
{
if (($languages = self::getAvailableLanguages()) !== false)
{
$wheres = array();
foreach ($languages as $k => $v)
{
$wheres[] = $db->quoteName('translation') . ' LIKE ' . $db->quote('%' . $k . '%');
}
$query->where($wheres);
}
}
else
{
$query->where($db->quoteName('translation') . ' LIKE ' . $db->quote('%' . $language . '%'));
}
}
else // Not translated
{
if ($language === 'none')
{
$query->where(
array(
$db->quoteName('translation') . ' = ' . $db->quote(''),
$db->quoteName('translation') . ' = ' . $db->quote('[]'),
$db->quoteName('translation') . ' = ' . $db->quote('{}')
), 'OR'
);
}
else
{
$query->where($db->quoteName('translation') . ' NOT LIKE ' . $db->quote('%' . $language . '%'));
}
}
$db->setQuery($query);
$db->execute();
if ($db->getNumRows())
{
return array_unique($db->loadColumn());
}
return false;
}
/**
* get available languages
**/
public static function getAvailableLanguages()
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select($db->quoteName(array('langtag', 'name')))
->from($db->quoteName('#__componentbuilder_language'))
->where($db->quoteName('published') . ' = 1')
->order($db->quoteName('name') . ' desc');
$db->setQuery($query);
$db->execute();
if ($db->getNumRows())
{
return $db->loadAssocList('langtag', 'name');
}
return false;
}
/**
* get extensions grouped list xml
**/
public static function getExtensionGroupedListXml()
{
// the extension types
$extensions = array(
'joomla_component' => 'COM_COMPONENTBUILDER_COMPONENT',
'joomla_module' => 'COM_COMPONENTBUILDER_MODULE',
'joomla_plugin' => 'COM_COMPONENTBUILDER_PLUGIN'
);
// get the extension values
foreach ($extensions as $extension => $label)
{
${$extension} = self::getExtensionTypeIdSystemName($extension);
}
$xml = new DOMDocument();
$xml->formatOutput = true;
$root = $xml->createElement('field');
$root->setAttributeNode(new DOMAttr('name', 'extension'));
$root->setAttributeNode(new DOMAttr('type', 'groupedlist'));
$root->setAttributeNode(new DOMAttr('onchange', 'this.form.submit();'));
$root
->appendChild($xml->createElement('option', '- ' . JText::_('COM_COMPONENTBUILDER_SELECT_EXTENSION') . ' -'))
->setAttributeNode(new DOMAttr('value', ''));
foreach ($extensions as $extension => $label)
{
$extension_node = $xml->createElement('group');
$extension_node->setAttributeNode(new DOMAttr('label', $label));
if (!self::checkArray(${$extension}))
{
$extension_node
->appendChild($xml->createElement('option', '- ' . JText::_('COM_COMPONENTBUILDER_NONE') . ' -'))
->setAttributeNode(new DOMAttr('disabled', 'true'));
}
else
{
foreach (${$extension} as $id => $element)
{
$extension_node
->appendChild($xml->createElement('option', $element))
->setAttributeNode(new DOMAttr('value', $extension . '__' . $id));
}
}
$root->appendChild($extension_node);
}
$xml->appendChild($root);
return $xml->saveXML();
}
/**
* get extentions ids and system names
**/
public static function getExtensionTypeIdSystemName($type, $limiter = null)
{
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select($db->quoteName(array('id', 'system_name')))
->from($db->quoteName('#__componentbuilder_' . $type))
->where($db->quoteName('published') . ' >= 1')
->order($db->quoteName('modified') . ' desc')
->order($db->quoteName('created') . ' desc');
// check if we have a limter for admin views
if ($type === 'admin_view' && $limiter)
{
// first get all views
$adminviewIds = array();
// if this is a plugin or a module, then no views
if (strpos($limiter, 'joomla_component') !== false)
{
$component = (int) str_replace('joomla_component__', '', $limiter);
// get the views of this component
if ($addViews = self::getVar('component_admin_views', (int) $component, 'joomla_component', 'addadmin_views'))
{
if (self::checkJson($addViews))
{
$addViews = json_decode($addViews, true);
if (self::checkArray($addViews))
{
foreach($addViews as $addView)
{
if (isset($addView['adminview']))
{
$adminviewIds[(int) $addView['adminview']] = (int) $addView['adminview'];
}
}
}
}
}
}
// now check if we still have admin views
if (self::checkArray($adminviewIds))
{
$query->where($db->quoteName('id') . ' IN (' . implode(',', $adminviewIds) . ')');
}
else
{
return false;
}
}
$db->setQuery($query);
$db->execute();
if ($db->getNumRows())
{
return $db->loadAssocList('id', 'system_name');
}
return false;
}
/**
* get any extension field IDs
*/
public static function getExtensionFieldIDs($extension, $type)
{
// yes we use switches
switch ($type)
{
case 'joomla_component':
return self::getComponentFieldsIDs($extension);
break;
case 'joomla_module':
return self::getModuleFieldsIDs($extension);
break;
case 'joomla_plugin':
return self::getPluginFieldsIDs($extension);
break;
case 'admin_view':
return self::getAdminViewFieldsIDs($extension);
break;
default:
return false;
break;
}
}
/**
* get a component fields IDs
*/
public static function getComponentFieldsIDs($id)
{
// we start the field array
$fieldIds = array();
// first get all views
$adminviewIds = array();
// get the views of this component
if ($addViews = self::getVar('component_admin_views', (int) $id, 'joomla_component', 'addadmin_views'))
{
if (self::checkJson($addViews))
{
$addViews = json_decode($addViews, true);
if (self::checkArray($addViews))
{
foreach($addViews as $addView)
{
if (isset($addView['adminview']))
{
$adminviewIds[(int) $addView['adminview']] = (int) $addView['adminview'];
}
}
}
}
}
// check that we have views
if (self::checkArray($adminviewIds))
{
foreach ($adminviewIds as $adminView)
{
// get all the fields linked to the admin view
if ($addFields = self::getVar('admin_fields', (int) $adminView, 'admin_view', 'addfields'))
{
if (self::checkJson($addFields))
{
$addFields = json_decode($addFields, true);
if (self::checkArray($addFields))
{
foreach($addFields as $addField)
{
if (isset($addField['field']))
{
$fieldIds[(int) $addField['field']] = (int) $addField['field'];
}
}
}
}
}
}
}
// get config values
if ($addconfig = self::getVar('component_config', (int) $id, 'joomla_component', 'addconfig'))
{
if (self::checkJson($addconfig))
{
$addconfig = json_decode($addconfig, true);
if (self::checkArray($addconfig))
{
foreach($addconfig as $addconf)
{
if (isset($addconf['field']))
{
$fieldIds[(int) $addconf['field']] = (int) $addconf['field'];
}
}
}
}
}
// check that we have fields
if (self::checkArray($fieldIds))
{
return array_values($fieldIds);
}
return false;
}
/**
* get a module fields IDs
*/
public static function getModuleFieldsIDs($id)
{
// we start the field array
$fieldIds = array();
if ($fields = self::getVar('joomla_module', (int) $id, 'id', 'fields'))
{
if (self::checkJson($fields))
{
$fields = json_decode($fields, true);
if (self::checkArray($fields))
{
foreach($fields as $form)
{
if (isset($form['fields']) && self::checkArray($form['fields']))
{
foreach ($form['fields'] as $field)
{
if (isset($field['field']))
{
$fieldIds[(int) $field['field']] = (int) $field['field'];
}
}
}
}
}
}
}
// check that we have fields
if (self::checkArray($fieldIds))
{
return array_values($fieldIds);
}
return false;
}
/**
* get a plugin fields IDs
*/
public static function getPluginFieldsIDs($id)
{
// we start the field array
$fieldIds = array();
if ($fields = self::getVar('joomla_plugin', (int) $id, 'id', 'fields'))
{
if (self::checkJson($fields))
{
$fields = json_decode($fields, true);
if (self::checkArray($fields))
{
foreach($fields as $form)
{
if (isset($form['fields']) && self::checkArray($form['fields']))
{
foreach ($form['fields'] as $field)
{
if (isset($field['field']))
{
$fieldIds[(int) $field['field']] = (int) $field['field'];
}
}
}
}
}
}
}
// check that we have fields
if (self::checkArray($fieldIds))
{
return array_values($fieldIds);
}
return false;
}
/**
* get an admin view fields IDs
*/
public static function getAdminViewFieldsIDs($id)
{
// we start the field array
$fieldIds = array();
// get all the fields linked to the admin view
if ($addFields = self::getVar('admin_fields', (int) $id, 'admin_view', 'addfields'))
{
if (self::checkJson($addFields))
{
$addFields = json_decode($addFields, true);
if (self::checkArray($addFields))
{
foreach($addFields as $addField)
{
if (isset($addField['field']))
{
$fieldIds[(int) $addField['field']] = (int) $addField['field'];
}
}
}
}
}
// check that we have fields
if (self::checkArray($fieldIds))
{
return array_values($fieldIds);
}
return false;
}
/**
* The array of dynamic content
*