Improved the compiler power building class. Add the search form and the needed ajax functions.

This commit is contained in:
2022-10-20 16:40:18 +02:00
parent 9db33ad449
commit d4843d6696
25 changed files with 1222 additions and 232 deletions

View File

@ -3649,11 +3649,11 @@ class ComponentbuilderModelAjax extends ListModel
*
* @param string $tableName The main table to search
* @param string $searchValue The value to search for
* @param string|null $replaceValue The value to replace search value
* @param int $matchCase The switch to control match case
* @param int $wholeWord The switch to control whole word
* @param int $regexSearch The switch to control regex search
* @param int $componentId The option to filter by component
* @param string|null $replaceValue The value to replace search value
* @param int $matchCase The switch to control match case
* @param int $wholeWord The switch to control whole word
* @param int $regexSearch The switch to control regex search
* @param int $componentId The option to filter by component
*
* @return array|null
* @since 3.2.0
@ -3662,23 +3662,108 @@ class ComponentbuilderModelAjax extends ListModel
int $matchCase, int $wholeWord, int $regexSearch, int $componentId): ?array
{
// check if this is a valid table
if (SearchFactory('Table')->exist($tableName))
if (SearchFactory::_('Table')->exist($tableName))
{
// load the configurations
SearchFactory('Config')->table_name = $tableName;
SearchFactory('Config')->search_value = $searchValue;
SearchFactory('Config')->replace_value = $replaceValue;
SearchFactory('Config')->match_case = $matchCase;
SearchFactory('Config')->whole_word = $wholeWord;
SearchFactory('Config')->regex_search = $regexSearch;
SearchFactory('Config')->component_id = $componentId;
SearchFactory::_('Config')->table_name = $tableName;
SearchFactory::_('Config')->search_value = $searchValue;
SearchFactory::_('Config')->replace_value = $replaceValue;
SearchFactory::_('Config')->match_case = $matchCase;
SearchFactory::_('Config')->whole_word = $wholeWord;
SearchFactory::_('Config')->regex_search = $regexSearch;
SearchFactory::_('Config')->component_id = $componentId;
SearchFactory('Agent')->replace();
SearchFactory::_('Agent')->replace();
return ['success' => JText::sprintf('COM_COMPONENTBUILDER_ALL_FOUND_INSTANCES_IN_S_WHERE_REPLACED', $tableName)];
}
return ['error' => JText::_('COM_COMPONENTBUILDER_THERE_HAS_BEEN_AN_ERROR_PLEASE_TRY_AGAIN')];
}
/**
* Get a selected search value from a given table and row
*
* @param string $fieldName The field key
* @param int $rowId The item ID
* @param string $tableName The table
*
* @return array
* @since 3.2.0
**/
public function getSearchValue(string $fieldName, int $rowId, string $tableName): array
{
// check if this is a valid table and field
if ($rowId > 0 && SearchFactory('Table')->exist($tableName, $fieldName) &&
($value = SearchFactory('Agent')->getValue($fieldName, $rowId, 0, $tableName)) !== null)
{
// load the value
return ['value' => $value];
}
return ['error' => JText::_('COM_COMPONENTBUILDER_THERE_HAS_BEEN_AN_ERROR_PLEASE_TRY_AGAIN')];
}
/**
* Get a replaced search value from a given table and row
*
* @param string $fieldName The field key
* @param int $rowId The item ID
* @param mixed $line The line line
* @param string $tableName The table
* @param string $searchValue The value to search for
* @param string|null $replaceValue The value to replace search value
* @param int $matchCase The switch to control match case
* @param int $wholeWord The switch to control whole word
* @param int $regexSearch The switch to control regex search
*
* @return array
* @since 3.2.0
**/
public function getReplaceValue(string $fieldName, int $rowId, $line, string $tableName,
string $searchValue, ?string $replaceValue = null, int $matchCase, int $wholeWord, int $regexSearch): array
{
// check if this is a valid table and field
if ($rowId > 0 && SearchFactory('Table')->exist($tableName, $fieldName))
{
// load the configurations
SearchFactory::_('Config')->table_name = $tableName;
SearchFactory::_('Config')->search_value = $searchValue;
SearchFactory::_('Config')->replace_value = $replaceValue;
SearchFactory::_('Config')->match_case = $matchCase;
SearchFactory::_('Config')->whole_word = $wholeWord;
SearchFactory::_('Config')->regex_search = $regexSearch;
// load the value
if (($value = SearchFactory('Agent')->getValue($fieldName, $rowId, $line, $tableName, true)) !== null)
{
return ['value' => $value];
}
}
return ['error' => JText::_('COM_COMPONENTBUILDER_THERE_HAS_BEEN_AN_ERROR_PLEASE_TRY_AGAIN')];
}
/**
* Set selected search value in a given table and row
*
* @param mixed $value The field value
* @param int $rowId The item ID
* @param string $fieldName The field key
* @param string $tableName The table
*
* @return array
* @since 3.2.0
**/
public function setValue($value, int $rowId, string $fieldName, string $tableName): array
{
// check if this is a valid table and field
if ($rowId > 0 && SearchFactory('Table')->exist($tableName, $fieldName) &&
SearchFactory('Agent')->setValue($value, $rowId, $fieldName, $tableName))
{
return ['success' => JText::sprintf(
'<b>%s</b> (%s:%s) was successfully updated!',
$tableName, $rowId, $fieldName)];
}
return ['error' => JText::_('COM_COMPONENTBUILDER_THERE_HAS_BEEN_AN_ERROR_PLEASE_TRY_AGAIN')];
}
// Used in get_snippets

View File

@ -139,69 +139,6 @@ class ComponentbuilderModelCompiler extends ListModel
public $compiler;
public function getComponents()
{
// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
// Order it by the ordering field.
$query->select($db->quoteName(array('id', 'system_name'),array('id', 'name')));
$query->from($db->quoteName('#__componentbuilder_joomla_component'));
$query->where($db->quoteName('published') . ' = 1');
$query->order('modified DESC');
$query->order('created DESC');
// Reset the query using our newly populated query object.
$db->setQuery($query);
// return the result
return $db->loadObjectList();
}
public function getCompilerAnimations(&$errorMessage)
{
// convert error message to array
$errorMessage = array();
$searchArray = array(
// add banners (width - height)
'banner' => array(
'728-90',
'160-600'
),
// The build-gif by size (width - height)
'builder-gif' => array(
'480-540'
)
);
// start search, and get
foreach ($searchArray as $type => $sizes)
{
// per size
foreach ($sizes as $size)
{
// get size
if (($set_size = ComponentbuilderHelper::getDynamicContentSize($type, $size)) !== 0)
{
// we loop over all type size artwork
for ($target = 1; $target <= $set_size; $target++)
{
if (!ComponentbuilderHelper::getDynamicContent($type, $size, false, 0, $target))
{
$errorMessage[] = JText::sprintf('COM_COMPONENTBUILDER_S_S_NUMBER_BSB_COULD_NOT_BE_DOWNLOADED_SUCCESSFULLY_TO_THIS_JOOMLA_INSTALL', $type, $size, $target);
}
}
}
}
}
// check if we had any errors
if (ComponentbuilderHelper::checkArray($errorMessage))
{
// flatten the error message array
$errorMessage = implode('<br />', $errorMessage);
return false;
}
return true;
}
public function builder()
{
// run compiler
@ -359,5 +296,91 @@ class ComponentbuilderModelCompiler extends ListModel
$this->cleanCache('mod_menu', 1);
return $result;
}
}
/**
* Get all components in the system
*
* @return array
* @since 3.2.0
**/
public function getComponents(): array
{
// Get a db connection.
$db = $this->getDbo();
// Create a new query object.
$query = $db->getQuery(true);
// Select only id and system name
$query->select($db->quoteName(array('id', 'system_name'),array('id', 'name')));
$query->from($db->quoteName('#__componentbuilder_joomla_component'));
// only the active components
$query->where($db->quoteName('published') . ' = 1');
// Order it by the ordering field.
$query->order('modified DESC');
$query->order('created DESC');
// Reset the query using our newly populated query object.
$db->setQuery($query);
// return the result
return $db->loadObjectList();
}
/**
* Get all dynamic content
*
* @return bool
* @since 3.2.0
**/
public function getDynamicContent(&$errorMessage): bool
{
// convert error message to array
$errorMessage = [];
$searchArray = [
// add banners (width - height)
'banner' => [
'728-90',
'160-600'
],
// The build-gif by size (width - height)
'builder-gif' => [
'480-540'
]
];
// start search, and get
foreach ($searchArray as $type => $sizes)
{
// per size
foreach ($sizes as $size)
{
// get size
if (($set_size = ComponentbuilderHelper::getDynamicContentSize($type, $size)) !== 0)
{
// we loop over all type size artwork
for ($target = 1; $target <= $set_size; $target++)
{
if (!ComponentbuilderHelper::getDynamicContent($type, $size, false, 0, $target))
{
$errorMessage[] = JText::sprintf('COM_COMPONENTBUILDER_S_S_NUMBER_BSB_COULD_NOT_BE_DOWNLOADED_SUCCESSFULLY_TO_THIS_JOOMLA_INSTALL', $type, $size, $target);
}
}
}
}
}
// check if we had any errors
if (ComponentbuilderHelper::checkArray($errorMessage))
{
// flatten the error message array
$errorMessage = implode('<br />', $errorMessage);
return false;
}
return true;
}
}

View File

@ -114,8 +114,8 @@ class ComponentbuilderModelSearch extends ItemModel
$query = $db->getQuery(true);
// Get data
// load the tables and components (soon)
$data = ['tables' => SearchFactory::_('Table')->tables(), 'components' => null];
// load the tables and components
$data = ['tables' => SearchFactory::_('Table')->tables(), 'components' => $this->getComponents()];
if (empty($data))
@ -162,4 +162,38 @@ class ComponentbuilderModelSearch extends ItemModel
}
return false;
}
/**
* Get all components in the system
*
* @return array
* @since 3.2.0
**/
public function getComponents(): array
{
// Get a db connection.
$db = $this->getDbo();
// Create a new query object.
$query = $db->getQuery(true);
// Select only id and system name
$query->select($db->quoteName(array('id', 'system_name'),array('id', 'name')));
$query->from($db->quoteName('#__componentbuilder_joomla_component'));
// only the active components
$query->where($db->quoteName('published') . ' = 1');
// Order it by the ordering field.
$query->order('modified DESC');
$query->order('created DESC');
// Reset the query using our newly populated query object.
$db->setQuery($query);
// return the result
return $db->loadObjectList();
}
}