Release of v4.1.1-rc1
Move all banners to GitHub. Adds library phpspreadsheet to JCB. Add import item example to demo component. Updates the Superpower class with the GetRemote class in the plugin. Ensures the super power autoloader triggers the correct repositories. Adds the Import Function to the Demo Component. Resolves the Database Updating issue in the compiler. #1212,#1209. Adds the Component Commands Plugin to the CLI for Import of spreadsheet data-sets. Add all needed Powers to the release package, to speed-up the build of the demo component. Refactored initialization flow to accommodate future scalability and integration with all designated areas. Refactor the Creator Builders class. Adds new JCB package engine. Fix issue with loading the Component Builder Wiki. Adds advanced version update notice to the Component Builder Dashboard. Completely refactors the class that builds the Component Dashboard. #1134. Adds Initialize, Reset, and Push functionality to the Repository entities. Completely refactors the SQL teaks and SQL dump classes. Changes J4 fields to allow NULL. Fix a bug in Dynamic Get JavaScript that causes table columns to not load. Refactor the FieldString and FieldXML classes.
This commit is contained in:
@ -970,7 +970,7 @@ class Admin_viewModel extends AdminModel
|
||||
/**
|
||||
* Method to validate the form data.
|
||||
*
|
||||
* @param JForm $form The form to validate against.
|
||||
* @param Form $form The form to validate against.
|
||||
* @param array $data The data to validate.
|
||||
* @param string $group The name of the field group to validate.
|
||||
*
|
||||
|
@ -28,6 +28,7 @@ use VDM\Joomla\Utilities\FormHelper as JCBFormHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper as UtilitiesArrayHelper;
|
||||
use VDM\Joomla\Utilities\ObjectHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use Joomla\CMS\Form\Form;
|
||||
|
||||
// No direct access to this file
|
||||
\defined('_JEXEC') or die;
|
||||
@ -109,7 +110,7 @@ class Admin_viewsModel extends ListModel
|
||||
* @param array $data data
|
||||
* @param boolean $loadData load current data
|
||||
*
|
||||
* @return \JForm|boolean The \JForm object or false on error
|
||||
* @return Form|boolean The Form object or false on error
|
||||
*
|
||||
* @since JCB 2.12.5
|
||||
*/
|
||||
|
@ -42,6 +42,8 @@ use VDM\Joomla\Utilities\Base64Helper;
|
||||
use VDM\Joomla\Componentbuilder\Table\Search;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\FieldHelper;
|
||||
use VDM\Joomla\Utilities\FormHelper;
|
||||
use VDM\Joomla\Componentbuilder\Utilities\FilterHelper;
|
||||
use VDM\Joomla\Data\Factory as DataFactory;
|
||||
use VDM\Joomla\Componentbuilder\Package\Factory as PackageFactory;
|
||||
use VDM\Joomla\Componentbuilder\Fieldtype\Factory as FieldtypeFactory;
|
||||
use VDM\Joomla\Componentbuilder\JoomlaPower\Factory as JoomlaPowerFactory;
|
||||
@ -4111,332 +4113,6 @@ class AjaxModel extends ListModel
|
||||
return '&ref=placeholder&refid=' . $id;
|
||||
}
|
||||
|
||||
// Used in snippet
|
||||
public function setSnippetGithub($path, $status)
|
||||
{
|
||||
// get user
|
||||
$user = Factory::getUser();
|
||||
$access = $user->authorise('snippet.access', 'com_componentbuilder');
|
||||
if ($access)
|
||||
{
|
||||
// secure path
|
||||
$path = StringHelper::safe(str_replace('.json','',$path), 'filename', '', false).'.json';
|
||||
// base path
|
||||
$base_path = basename($path);
|
||||
// set url
|
||||
$url = ComponentbuilderHelper::$snippetPath.rawurlencode($base_path);
|
||||
// get the snippets
|
||||
if (($snippet = ComponentbuilderHelper::getGithubRepoData('lib_snippet_' . $base_path, $url, null, 'array')) !== false)
|
||||
{
|
||||
return $this->saveSnippet($snippet, $status, $user);
|
||||
}
|
||||
// see if we have any errors from github
|
||||
if (UtilitiesArrayHelper::check(ComponentbuilderHelper::$githubRepoDataErrors))
|
||||
{
|
||||
return array('message' => Text::sprintf('COM_COMPONENTBUILDER_ERROR_BR_S', implode('<br />', ComponentbuilderHelper::$githubRepoDataErrors)), 'status' => 'danger');
|
||||
}
|
||||
return array('message' => Text::_('COM_COMPONENTBUILDER_ERROR_THE_PATH_HAS_A_MISMATCH_AND_COULD_THEREFORE_NOT_RETRIEVE_THE_SNIPPET_FROM_GITHUB'), 'status' => 'danger');
|
||||
}
|
||||
return array('message' => Text::_('COM_COMPONENTBUILDER_ERROR_YOU_DO_NOT_HAVE_ACCESS_TO_THE_SNIPPETS'), 'status' => 'danger');
|
||||
}
|
||||
|
||||
protected function saveSnippet($item, $status, $user)
|
||||
{
|
||||
// set some defaults
|
||||
$todayDate = Factory::getDate()->toSql();
|
||||
// get the type id
|
||||
$item['type'] = ($id = GetHelper::var('snippet_type', $item['type'], 'name', 'id')) ? $id : $this->createNew($item['type'], 'snippet_type', $user, $todayDate);
|
||||
// get the library id
|
||||
$item['library'] = ($id = GetHelper::var('library', $item['library'], 'name', 'id')) ? $id : $this->createNew($item['library'], 'library', $user, $todayDate);
|
||||
// remove type if zero
|
||||
if ($item['type'] == 0)
|
||||
{
|
||||
unset($item['type']);
|
||||
}
|
||||
// remove library if zero
|
||||
if ($item['library'] == 0)
|
||||
{
|
||||
unset($item['library']);
|
||||
}
|
||||
// get the snippet ID
|
||||
$item['id'] = $this->getSnippetId($item);
|
||||
if ($item['id'] == 0)
|
||||
{
|
||||
$canCreate = $user->authorise('snippet.create', 'com_componentbuilder');
|
||||
if ('new' === $status && !$canCreate)
|
||||
{
|
||||
return array('message' => Text::_('COM_COMPONENTBUILDER_ERROR_YOU_DO_NOT_HAVE_PERMISSION_TO_CREATE_THE_SNIPPET'), 'status' => 'danger');
|
||||
}
|
||||
}
|
||||
// get the snippet model
|
||||
$model = ComponentbuilderHelper::getModel('snippet', JPATH_ADMINISTRATOR . '/components/com_componentbuilder');
|
||||
// save the snippet
|
||||
if ($model->save($item))
|
||||
{
|
||||
if ($item['id'] == 0)
|
||||
{
|
||||
// get the saved item
|
||||
$updatedItem = $model->getItem();
|
||||
$item['id']= $updatedItem->get('id');
|
||||
}
|
||||
// we have to force modified date since the model does not allow you
|
||||
if ($this->forchDateFix($item))
|
||||
{
|
||||
return array('message' => Text::_('COM_COMPONENTBUILDER_SUCCESS_THE_SNIPPET_WAS_SAVED'), 'status' => 'success');
|
||||
}
|
||||
// return error
|
||||
return array('message' => Text::_('COM_COMPONENTBUILDER_SUCCESS_THE_SNIPPET_WAS_SAVED_BUT_THE_MODIFIED_DATE_COULD_NOT_BE_ADJUSTED_BR_BR_BTHIS_MEANS_THE_SNIPPETS_WILL_CONTINUE_TO_APPEAR_OUT_OF_DATEB'), 'status' => 'warning');
|
||||
}
|
||||
// return error
|
||||
return array('message' => Text::_('COM_COMPONENTBUILDER_ERROR_THE_SNIPPET_IS_FAULTY_AND_COULD_NOT_BE_SAVED'), 'status' => 'danger');
|
||||
}
|
||||
|
||||
protected function forchDateFix($item)
|
||||
{
|
||||
$object = new \stdClass();
|
||||
$object->id = (int) $item['id'];
|
||||
$object->created = $item['created'];
|
||||
$object->modified = $item['modified'];
|
||||
// force update
|
||||
return Factory::getDbo()->updateObject('#__componentbuilder_snippet', $object, 'id');
|
||||
}
|
||||
|
||||
protected function getSnippetId($item)
|
||||
{
|
||||
// Get a db connection.
|
||||
$db = Factory::getDbo();
|
||||
|
||||
// Create a new query object.
|
||||
$query = $db->getQuery(true);
|
||||
$query->select($db->quoteName(array('a.id')));
|
||||
$query->from($db->quoteName('#__componentbuilder_snippet', 'a'));
|
||||
$query->where($db->quoteName('a.name') . ' = ' . (string) $db->quote($item['name']));
|
||||
if (is_numeric($item['type']))
|
||||
{
|
||||
$query->where($db->quoteName('a.type') . ' = ' . (int) $item['type']);
|
||||
}
|
||||
if (is_numeric($item['library']))
|
||||
{
|
||||
$query->where($db->quoteName('a.library') . ' = ' . (int) $item['library']);
|
||||
}
|
||||
// Reset the query using our newly populated query object.
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
if ($db->getNumRows())
|
||||
{
|
||||
return $db->loadResult();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function createNew($name, $type, $user, $todayDate)
|
||||
{
|
||||
// verify that we can continue
|
||||
if (ComponentbuilderHelper::getActions($type)->get('core.create'))
|
||||
{
|
||||
// get the snippet model
|
||||
$model = ComponentbuilderHelper::getModel($type, JPATH_ADMINISTRATOR . '/components/com_componentbuilder');
|
||||
// build array to save
|
||||
$item['id'] = 0;
|
||||
$item['name'] = $name;
|
||||
$item['published'] = 1;
|
||||
$item['version'] = 1;
|
||||
$item['created'] = $todayDate;
|
||||
$item['created_by'] = $user->id;
|
||||
// save the new
|
||||
$model->save($item);
|
||||
// get the saved item
|
||||
$item = $model->getItem();
|
||||
return $item->get('id');
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves published snippet GUIDs for valid libraries.
|
||||
*
|
||||
* @param mixed $libraries JSON string or array of library GUIDs.
|
||||
*
|
||||
* @return array|false List of snippet IDs or false on failure.
|
||||
* @since 5.1.1
|
||||
*/
|
||||
public function getSnippets($libraries)
|
||||
{
|
||||
// Decode JSON if required
|
||||
if (JsonHelper::check($libraries))
|
||||
{
|
||||
$libraries = json_decode($libraries, true);
|
||||
}
|
||||
|
||||
// Ensure we have a valid array of libraries
|
||||
if (!UtilitiesArrayHelper::check($libraries))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validate and expand libraries
|
||||
$validatedLibraries = $this->expandAndValidateLibraries($libraries);
|
||||
|
||||
if (!$validatedLibraries)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$db = Factory::getDbo();
|
||||
$query = $db->getQuery(true)
|
||||
->select($db->quoteName('a.id'))
|
||||
->from($db->quoteName('#__componentbuilder_snippet', 'a'))
|
||||
->where($db->quoteName('a.published') . ' = 1')
|
||||
->where($db->quoteName('a.library') . ' IN ("' . implode('","', $validatedLibraries) . '")');
|
||||
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
|
||||
return $db->getNumRows() ? $db->loadColumn() : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates and expands library GUIDs to ensure only integers and valid references remain.
|
||||
*
|
||||
* @param array $libraries The original list of library GUIDs.
|
||||
*
|
||||
* @return array|false Sanitized and validated list of libraries, or false.
|
||||
* @since 5.1.1
|
||||
*/
|
||||
protected function expandAndValidateLibraries(array $libraries)
|
||||
{
|
||||
$expanded = [];
|
||||
|
||||
foreach ($libraries as $guid)
|
||||
{
|
||||
$guid = (string) $guid;
|
||||
$type = GetHelper::var('library', $guid, 'guid', 'type');
|
||||
|
||||
if ((int) $type === 2)
|
||||
{
|
||||
$bundled = GetHelper::var('library', $guid, 'guid', 'libraries');
|
||||
|
||||
if (JsonHelper::check($bundled))
|
||||
{
|
||||
$bundled = json_decode($bundled, true);
|
||||
}
|
||||
|
||||
if (UtilitiesArrayHelper::check($bundled))
|
||||
{
|
||||
foreach ($bundled as $lib)
|
||||
{
|
||||
$expanded[$lib] = $lib;
|
||||
}
|
||||
}
|
||||
elseif (is_numeric($bundled))
|
||||
{
|
||||
$expanded[$bundled] = $bundled;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$expanded[$guid] = $guid;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove invalid entries and duplicates
|
||||
$valid = array_filter(array_unique($expanded), function ($guid) {
|
||||
return GuidHelper::valid($guid);
|
||||
});
|
||||
|
||||
return UtilitiesArrayHelper::check($valid) ? array_values($valid) : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves snippet details by GUID or ID.
|
||||
*
|
||||
* @param string|int $key The snippet GUID (string) or ID (int).
|
||||
*
|
||||
* @return object|false The snippet data object or false on failure.
|
||||
* @since 5.1.1
|
||||
*/
|
||||
public function getSnippetDetails($key)
|
||||
{
|
||||
$target = $this->resolveSnippetKeyField($key);
|
||||
|
||||
if ($target === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$db = Factory::getDbo();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
$query
|
||||
->select($db->quoteName(
|
||||
[
|
||||
'a.name',
|
||||
'a.heading',
|
||||
'a.usage',
|
||||
'a.description',
|
||||
'b.name',
|
||||
'a.snippet',
|
||||
'a.url',
|
||||
'c.name'
|
||||
],
|
||||
[
|
||||
'name',
|
||||
'heading',
|
||||
'usage',
|
||||
'description',
|
||||
'type',
|
||||
'snippet',
|
||||
'url',
|
||||
'library'
|
||||
]
|
||||
))
|
||||
->from($db->quoteName('#__componentbuilder_snippet', 'a'))
|
||||
->join('LEFT', $db->quoteName('#__componentbuilder_snippet_type', 'b') . ' ON ' . $db->quoteName('a.type') . ' = ' . $db->quoteName('b.guid'))
|
||||
->join('LEFT', $db->quoteName('#__componentbuilder_library', 'c') . ' ON ' . $db->quoteName('a.library') . ' = ' . $db->quoteName('c.guid'))
|
||||
->where($db->quoteName('a.published') . ' >= 1')
|
||||
->where($db->quoteName("a.$target") . ' = ' . $db->quote($key));
|
||||
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
|
||||
if ($db->getNumRows() > 0)
|
||||
{
|
||||
$snippet = $db->loadObject();
|
||||
|
||||
if (isset($snippet->snippet))
|
||||
{
|
||||
$snippet->snippet = base64_decode($snippet->snippet);
|
||||
}
|
||||
|
||||
return $snippet;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves whether the given key is a GUID or numeric ID and returns the appropriate field.
|
||||
*
|
||||
* @param mixed $key The value used to identify the snippet.
|
||||
*
|
||||
* @return string|false 'guid', 'id', or false if invalid.
|
||||
* @since 5.1.1
|
||||
*/
|
||||
protected function resolveSnippetKeyField($key)
|
||||
{
|
||||
if (GuidHelper::valid($key))
|
||||
{
|
||||
return 'guid';
|
||||
}
|
||||
|
||||
if (is_numeric($key))
|
||||
{
|
||||
return 'id';
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Used in validation_rule
|
||||
public function getExistingValidationRuleCode($name)
|
||||
{
|
||||
@ -5011,6 +4687,237 @@ class AjaxModel extends ListModel
|
||||
return $xml;
|
||||
}
|
||||
|
||||
// Used in language_translation
|
||||
/**
|
||||
* Export language translation data by filtering records based on extension, translated, and untranslated tags.
|
||||
*
|
||||
* This method loads translation records from the database and structures them into an array
|
||||
* with language-tagged headers (e.g., `en-GB`, `de-DE`). It supports filtering for a specific
|
||||
* extension, already translated languages, and missing translations. All matching records are
|
||||
* padded with empty values for missing languages, and returned with a size count or errors.
|
||||
*
|
||||
* @param string $extension The extension identifier in format "type__name" (e.g., "com_example__field").
|
||||
* @param string $translated Comma-separated list of language tags that must have translations.
|
||||
* @param string $notTranslated Comma-separated list of language tags that must not yet have translations.
|
||||
*
|
||||
* @return array<string, mixed> Returns an array with:
|
||||
* - 'data' (array<int, array<string, string>>): The exportable translation rows.
|
||||
* - 'size' (int): Number of rows (if successful).
|
||||
* - 'errors' (string): Error message (if an error occurred).
|
||||
*
|
||||
* @throws \Throwable If any unexpected exception occurs during data fetching or parsing.
|
||||
* @since 5.1.1
|
||||
*/
|
||||
public function exportLanguageTranslations(string $extension, string $translated, string $notTranslated): array
|
||||
{
|
||||
try {
|
||||
$ids = $this->resolveLanguageTranslationFilterIds($extension, $translated, $notTranslated);
|
||||
$where = $this->buildLanguageTranslationWhereClause($ids);
|
||||
$records = $this->loadLanguageTranslationRows($where);
|
||||
$headers = $this->getLanguageTranslationHeaders();
|
||||
|
||||
if (empty($records))
|
||||
{
|
||||
return $this->errorLanguageTranslationResponse(Text::_('COM_COMPONENTBUILDER_NO_LANGUAGE_STRINGS_FOUND'));
|
||||
}
|
||||
|
||||
$data = $this->normalizeLanguageTranslationData($records, $headers);
|
||||
|
||||
return [
|
||||
'data' => $data,
|
||||
'size' => count($data),
|
||||
];
|
||||
} catch (\Throwable $e) {
|
||||
return $this->errorLanguageTranslationResponse($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve all relevant record IDs from the given filters.
|
||||
*
|
||||
* @param string $extension Extension string in format "type__name".
|
||||
* @param string $translated Comma-separated list of translated language tags.
|
||||
* @param string $notTranslated Comma-separated list of untranslated language tags.
|
||||
*
|
||||
* @return array<int>|null Array of record IDs, or empty array to load all or null to force a skip all.
|
||||
* @since 5.1.1
|
||||
*/
|
||||
protected function resolveLanguageTranslationFilterIds(string $extension, string $translated, string $notTranslated): ?array
|
||||
{
|
||||
$ids = [];
|
||||
$forceEmpty = false;
|
||||
|
||||
// Extension IDs
|
||||
if (!empty($extension) && strpos($extension, '__') !== false)
|
||||
{
|
||||
[$type, $name] = explode('__', $extension, 2);
|
||||
$extIds = FilterHelper::translation($name, $type);
|
||||
if (!empty($extIds))
|
||||
{
|
||||
$ids = array_merge($ids, $extIds);
|
||||
}
|
||||
else
|
||||
{
|
||||
$forceEmpty = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Translated IDs
|
||||
if (!empty($translated))
|
||||
{
|
||||
$trIds = FilterHelper::translations($translated);
|
||||
if (!empty($trIds))
|
||||
{
|
||||
$ids = array_merge($ids, $trIds);
|
||||
}
|
||||
else
|
||||
{
|
||||
$forceEmpty = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Not translated IDs
|
||||
if (!empty($notTranslated))
|
||||
{
|
||||
$untrIds = FilterHelper::translations($notTranslated, false);
|
||||
if (!empty($untrIds))
|
||||
{
|
||||
$ids = array_merge($ids, $untrIds);
|
||||
}
|
||||
else
|
||||
{
|
||||
$forceEmpty = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($ids === [] && !$forceEmpty)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
return $forceEmpty ? null : array_unique($ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a SQL WHERE clause using resolved IDs.
|
||||
*
|
||||
* @param array<int>|null $ids The record IDs to include in the query.
|
||||
*
|
||||
* @return array<string, array<string, mixed>> A structured WHERE clause.
|
||||
* @since 5.1.1
|
||||
*/
|
||||
protected function buildLanguageTranslationWhereClause(?array $ids): array
|
||||
{
|
||||
if ($ids === [])
|
||||
{
|
||||
// return all published
|
||||
return ['published' => ['value' => 1, 'operator' => '=', 'quote' => false]];
|
||||
}
|
||||
elseif ($ids === null)
|
||||
{
|
||||
// return none
|
||||
return ['id' => ['value' => 0, 'operator' => '=', 'quote' => false]];
|
||||
}
|
||||
|
||||
// return selected and published
|
||||
return [
|
||||
'id' => ['value' => $ids, 'operator' => 'IN', 'quote' => false],
|
||||
'published' => ['value' => 1, 'operator' => '=', 'quote' => false]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Load translation rows from the database based on the given WHERE clause.
|
||||
*
|
||||
* @param array<string, array<string, mixed>>|null $where Optional WHERE clause.
|
||||
*
|
||||
* @return array<int, array<string, mixed>> Loaded records with 'source' and 'translation' keys.
|
||||
* @since 5.1.1
|
||||
*/
|
||||
protected function loadLanguageTranslationRows(?array $where): array
|
||||
{
|
||||
return DataFactory::_('Load')->rows(
|
||||
['source', 'translation'],
|
||||
['language_translation'],
|
||||
$where,
|
||||
['source' => 'ASC']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of available language headers (e.g., ['en-GB' => 'en-GB']).
|
||||
*
|
||||
* This includes a default 'source' => 'source' entry.
|
||||
*
|
||||
* @return array<string, string> Associative list of language tags.
|
||||
* @since 5.1.1
|
||||
*/
|
||||
protected function getLanguageTranslationHeaders(): array
|
||||
{
|
||||
return ComponentbuilderHelper::getLanguageTranslationsHeaders() ?? ['source' => 'source'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize translation records by mapping language keys and padding missing headers.
|
||||
*
|
||||
* @param array<int, array<string, mixed>> $rows Raw translation rows from the database.
|
||||
* @param array<string, string> $headers Valid language header list.
|
||||
*
|
||||
* @return array<int, array<string, string>> Structured translation data ready for export.
|
||||
* @since 5.1.1
|
||||
*/
|
||||
protected function normalizeLanguageTranslationData(array $rows, array $headers): array
|
||||
{
|
||||
$normalized = [];
|
||||
|
||||
foreach ($rows as $row)
|
||||
{
|
||||
$translations = json_decode($row['translation'] ?? '[]', true) ?: [];
|
||||
unset($row['translation']);
|
||||
|
||||
// Pad all expected language headers
|
||||
foreach ($headers as $lang => $_)
|
||||
{
|
||||
if ($lang === 'source')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$row[$lang] = '';
|
||||
}
|
||||
|
||||
foreach ($translations as $entry)
|
||||
{
|
||||
$lang = $entry['language'] ?? '';
|
||||
$text = trim(($entry['translation'] ?? ''));
|
||||
|
||||
if (isset($headers[$lang]) && trim($text) !== '')
|
||||
{
|
||||
$row[$lang] = $text;
|
||||
}
|
||||
}
|
||||
|
||||
$normalized[] = $row;
|
||||
}
|
||||
|
||||
return $normalized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a standardized error response with message.
|
||||
*
|
||||
* @param string $message Error message to return.
|
||||
*
|
||||
* @return array<string, mixed> Error response with 'data' as empty array and 'errors' as message.
|
||||
* @since 5.1.1
|
||||
*/
|
||||
protected function errorLanguageTranslationResponse(string $message): array
|
||||
{
|
||||
return [
|
||||
'data' => [],
|
||||
'errors' => $message,
|
||||
];
|
||||
}
|
||||
|
||||
// Used in admin_fields_relations
|
||||
public function getCodeGlueOptions($listfield, $joinfields, $type, $area)
|
||||
{
|
||||
|
@ -599,7 +599,7 @@ class Class_methodModel extends AdminModel
|
||||
/**
|
||||
* Method to validate the form data.
|
||||
*
|
||||
* @param JForm $form The form to validate against.
|
||||
* @param Form $form The form to validate against.
|
||||
* @param array $data The data to validate.
|
||||
* @param string $group The name of the field group to validate.
|
||||
*
|
||||
|
@ -590,7 +590,7 @@ class Class_propertyModel extends AdminModel
|
||||
/**
|
||||
* Method to validate the form data.
|
||||
*
|
||||
* @param JForm $form The form to validate against.
|
||||
* @param Form $form The form to validate against.
|
||||
* @param array $data The data to validate.
|
||||
* @param string $group The name of the field group to validate.
|
||||
*
|
||||
|
@ -28,6 +28,7 @@ use VDM\Joomla\Componentbuilder\Utilities\FilterHelper as JCBFilterHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper as UtilitiesArrayHelper;
|
||||
use VDM\Joomla\Utilities\ObjectHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use Joomla\CMS\Form\Form;
|
||||
|
||||
// No direct access to this file
|
||||
\defined('_JEXEC') or die;
|
||||
@ -108,7 +109,7 @@ class Custom_admin_viewsModel extends ListModel
|
||||
* @param array $data data
|
||||
* @param boolean $loadData load current data
|
||||
*
|
||||
* @return \JForm|boolean The \JForm object or false on error
|
||||
* @return Form|boolean The Form object or false on error
|
||||
*
|
||||
* @since JCB 2.12.5
|
||||
*/
|
||||
|
@ -592,7 +592,7 @@ class Custom_codeModel extends AdminModel
|
||||
/**
|
||||
* Method to validate the form data.
|
||||
*
|
||||
* @param JForm $form The form to validate against.
|
||||
* @param Form $form The form to validate against.
|
||||
* @param array $data The data to validate.
|
||||
* @param string $group The name of the field group to validate.
|
||||
*
|
||||
|
@ -747,7 +747,7 @@ class Dynamic_getModel extends AdminModel
|
||||
/**
|
||||
* Method to validate the form data.
|
||||
*
|
||||
* @param JForm $form The form to validate against.
|
||||
* @param Form $form The form to validate against.
|
||||
* @param array $data The data to validate.
|
||||
* @param string $group The name of the field group to validate.
|
||||
*
|
||||
|
@ -678,7 +678,7 @@ class FieldModel extends AdminModel
|
||||
/**
|
||||
* Method to validate the form data.
|
||||
*
|
||||
* @param JForm $form The form to validate against.
|
||||
* @param Form $form The form to validate against.
|
||||
* @param array $data The data to validate.
|
||||
* @param string $group The name of the field group to validate.
|
||||
*
|
||||
|
@ -28,6 +28,7 @@ use VDM\Joomla\Componentbuilder\Utilities\FilterHelper as JCBFilterHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper as UtilitiesArrayHelper;
|
||||
use VDM\Joomla\Utilities\ObjectHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use Joomla\CMS\Form\Form;
|
||||
|
||||
// No direct access to this file
|
||||
\defined('_JEXEC') or die;
|
||||
@ -111,7 +112,7 @@ class FieldsModel extends ListModel
|
||||
* @param array $data data
|
||||
* @param boolean $loadData load current data
|
||||
*
|
||||
* @return \JForm|boolean The \JForm object or false on error
|
||||
* @return Form|boolean The Form object or false on error
|
||||
*
|
||||
* @since JCB 2.12.5
|
||||
*/
|
||||
|
@ -611,7 +611,7 @@ class FieldtypeModel extends AdminModel
|
||||
/**
|
||||
* Method to validate the form data.
|
||||
*
|
||||
* @param JForm $form The form to validate against.
|
||||
* @param Form $form The form to validate against.
|
||||
* @param array $data The data to validate.
|
||||
* @param string $group The name of the field group to validate.
|
||||
*
|
||||
|
@ -477,7 +477,7 @@ class Help_documentModel extends AdminModel
|
||||
/**
|
||||
* Method to validate the form data.
|
||||
*
|
||||
* @param JForm $form The form to validate against.
|
||||
* @param Form $form The form to validate against.
|
||||
* @param array $data The data to validate.
|
||||
* @param string $group The name of the field group to validate.
|
||||
*
|
||||
|
@ -904,7 +904,7 @@ class Joomla_componentModel extends AdminModel
|
||||
/**
|
||||
* Method to validate the form data.
|
||||
*
|
||||
* @param JForm $form The form to validate against.
|
||||
* @param Form $form The form to validate against.
|
||||
* @param array $data The data to validate.
|
||||
* @param string $group The name of the field group to validate.
|
||||
*
|
||||
|
@ -29,10 +29,7 @@ use Joomla\Utilities\ArrayHelper;
|
||||
use Joomla\Input\Input;
|
||||
use VDM\Component\Componentbuilder\Administrator\Helper\ComponentbuilderHelper;
|
||||
use Joomla\CMS\Helper\TagsHelper;
|
||||
use VDM\Joomla\Utilities\SessionHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper as UtilitiesStringHelper;
|
||||
use VDM\Joomla\Utilities\ObjectHelper;
|
||||
use VDM\Joomla\Utilities\GuidHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper as UtilitiesArrayHelper;
|
||||
|
||||
// No direct access to this file
|
||||
@ -118,62 +115,6 @@ class Language_translationModel extends AdminModel
|
||||
return parent::getTable($type, $prefix, $config);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves or generates a Vast Development Method (VDM) key for the current item.
|
||||
*
|
||||
* This function performs the following operations:
|
||||
* 1. Checks if the VDM key is already set. If not, it proceeds to generate or retrieve one.
|
||||
* 2. Determines the item ID based on the presence of a specific argument.
|
||||
* 3. Attempts to retrieve an existing VDM key from a helper method using the item ID.
|
||||
* 4. If a VDM key is not found, it generates a new random VDM key.
|
||||
* 5. Stores the VDM key and associates it with the item ID in a helper method.
|
||||
* 6. Optionally, stores return and GUID values if available.
|
||||
* 7. Returns the VDM key.
|
||||
*
|
||||
* @return string The VDM key for the current item.
|
||||
*/
|
||||
public function getVDM()
|
||||
{
|
||||
if (!isset($this->vastDevMod))
|
||||
{
|
||||
$_id = 0; // new item probably (since it was not set in the getItem method)
|
||||
|
||||
if (empty($_id))
|
||||
{
|
||||
$id = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$id = $_id;
|
||||
}
|
||||
// set the id and view name to session
|
||||
if (($vdm = SessionHelper::get('language_translation__'.$id)) !== null)
|
||||
{
|
||||
$this->vastDevMod = $vdm;
|
||||
}
|
||||
else
|
||||
{
|
||||
// set the vast development method key
|
||||
$this->vastDevMod = UtilitiesStringHelper::random(50);
|
||||
SessionHelper::set($this->vastDevMod, 'language_translation__'.$id);
|
||||
SessionHelper::set('language_translation__'.$id, $this->vastDevMod);
|
||||
// set a return value if found
|
||||
$jinput = Factory::getApplication()->input;
|
||||
$return = $jinput->get('return', null, 'base64');
|
||||
SessionHelper::set($this->vastDevMod . '__return', $return);
|
||||
// set a GUID value if found
|
||||
if (isset($item) && ObjectHelper::check($item) && isset($item->guid)
|
||||
&& GuidHelper::valid($item->guid))
|
||||
{
|
||||
SessionHelper::set($this->vastDevMod . '__guid', $item->guid);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->vastDevMod;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method to get a single record.
|
||||
*
|
||||
@ -202,6 +143,30 @@ class Language_translationModel extends AdminModel
|
||||
$item->metadata = $registry->toArray();
|
||||
}
|
||||
|
||||
if (!empty($item->plugins))
|
||||
{
|
||||
// Convert the plugins field to an array.
|
||||
$plugins = new Registry;
|
||||
$plugins->loadString($item->plugins);
|
||||
$item->plugins = $plugins->toArray();
|
||||
}
|
||||
|
||||
if (!empty($item->modules))
|
||||
{
|
||||
// Convert the modules field to an array.
|
||||
$modules = new Registry;
|
||||
$modules->loadString($item->modules);
|
||||
$item->modules = $modules->toArray();
|
||||
}
|
||||
|
||||
if (!empty($item->components))
|
||||
{
|
||||
// Convert the components field to an array.
|
||||
$components = new Registry;
|
||||
$components->loadString($item->components);
|
||||
$item->components = $components->toArray();
|
||||
}
|
||||
|
||||
if (!empty($item->translation))
|
||||
{
|
||||
// Convert the translation field to an array.
|
||||
@ -209,56 +174,6 @@ class Language_translationModel extends AdminModel
|
||||
$translation->loadString($item->translation);
|
||||
$item->translation = $translation->toArray();
|
||||
}
|
||||
|
||||
if (!empty($item->plugins))
|
||||
{
|
||||
// JSON Decode plugins.
|
||||
$item->plugins = json_decode($item->plugins);
|
||||
}
|
||||
|
||||
if (!empty($item->modules))
|
||||
{
|
||||
// JSON Decode modules.
|
||||
$item->modules = json_decode($item->modules);
|
||||
}
|
||||
|
||||
if (!empty($item->components))
|
||||
{
|
||||
// JSON Decode components.
|
||||
$item->components = json_decode($item->components);
|
||||
}
|
||||
|
||||
|
||||
if (empty($item->id))
|
||||
{
|
||||
$id = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$id = $item->id;
|
||||
}
|
||||
// set the id and view name to session
|
||||
if (($vdm = SessionHelper::get('language_translation__'.$id)) !== null)
|
||||
{
|
||||
$this->vastDevMod = $vdm;
|
||||
}
|
||||
else
|
||||
{
|
||||
// set the vast development method key
|
||||
$this->vastDevMod = UtilitiesStringHelper::random(50);
|
||||
SessionHelper::set($this->vastDevMod, 'language_translation__'.$id);
|
||||
SessionHelper::set('language_translation__'.$id, $this->vastDevMod);
|
||||
// set a return value if found
|
||||
$jinput = Factory::getApplication()->input;
|
||||
$return = $jinput->get('return', null, 'base64');
|
||||
SessionHelper::set($this->vastDevMod . '__return', $return);
|
||||
// set a GUID value if found
|
||||
if (isset($item) && ObjectHelper::check($item) && isset($item->guid)
|
||||
&& GuidHelper::valid($item->guid))
|
||||
{
|
||||
SessionHelper::set($this->vastDevMod . '__guid', $item->guid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $item;
|
||||
@ -987,6 +902,45 @@ class Language_translationModel extends AdminModel
|
||||
$data['metadata'] = (string) $metadata;
|
||||
}
|
||||
|
||||
// Set the plugins items to data.
|
||||
if (isset($data['plugins']) && is_array($data['plugins']))
|
||||
{
|
||||
$plugins = new Registry;
|
||||
$plugins->loadArray($data['plugins']);
|
||||
$data['plugins'] = (string) $plugins;
|
||||
}
|
||||
elseif (!isset($data['plugins']))
|
||||
{
|
||||
// Set the empty plugins to data
|
||||
$data['plugins'] = '';
|
||||
}
|
||||
|
||||
// Set the modules items to data.
|
||||
if (isset($data['modules']) && is_array($data['modules']))
|
||||
{
|
||||
$modules = new Registry;
|
||||
$modules->loadArray($data['modules']);
|
||||
$data['modules'] = (string) $modules;
|
||||
}
|
||||
elseif (!isset($data['modules']))
|
||||
{
|
||||
// Set the empty modules to data
|
||||
$data['modules'] = '';
|
||||
}
|
||||
|
||||
// Set the components items to data.
|
||||
if (isset($data['components']) && is_array($data['components']))
|
||||
{
|
||||
$components = new Registry;
|
||||
$components->loadArray($data['components']);
|
||||
$data['components'] = (string) $components;
|
||||
}
|
||||
elseif (!isset($data['components']))
|
||||
{
|
||||
// Set the empty components to data
|
||||
$data['components'] = '';
|
||||
}
|
||||
|
||||
// Set the translation items to data.
|
||||
if (isset($data['translation']) && is_array($data['translation']))
|
||||
{
|
||||
@ -1000,24 +954,6 @@ class Language_translationModel extends AdminModel
|
||||
$data['translation'] = '';
|
||||
}
|
||||
|
||||
// Set the plugins string to JSON string.
|
||||
if (isset($data['plugins']))
|
||||
{
|
||||
$data['plugins'] = (string) json_encode($data['plugins']);
|
||||
}
|
||||
|
||||
// Set the modules string to JSON string.
|
||||
if (isset($data['modules']))
|
||||
{
|
||||
$data['modules'] = (string) json_encode($data['modules']);
|
||||
}
|
||||
|
||||
// Set the components string to JSON string.
|
||||
if (isset($data['components']))
|
||||
{
|
||||
$data['components'] = (string) json_encode($data['components']);
|
||||
}
|
||||
|
||||
// Set the Params Items to data
|
||||
if (isset($data['params']) && is_array($data['params']))
|
||||
{
|
||||
|
@ -28,7 +28,7 @@ use VDM\Joomla\Componentbuilder\Utilities\FilterHelper as JCBFilterHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper as UtilitiesArrayHelper;
|
||||
use VDM\Joomla\Utilities\ObjectHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Utilities\JsonHelper;
|
||||
use Joomla\CMS\Form\Form;
|
||||
|
||||
// No direct access to this file
|
||||
\defined('_JEXEC') or die;
|
||||
@ -104,7 +104,7 @@ class Language_translationsModel extends ListModel
|
||||
* @param array $data data
|
||||
* @param boolean $loadData load current data
|
||||
*
|
||||
* @return \JForm|boolean The \JForm object or false on error
|
||||
* @return Form|boolean The Form object or false on error
|
||||
*
|
||||
* @since JCB 2.12.5
|
||||
*/
|
||||
@ -281,55 +281,6 @@ class Language_translationsModel extends ListModel
|
||||
}
|
||||
}
|
||||
}
|
||||
// prep the lang strings for export
|
||||
if (isset($_export) && $_export && UtilitiesArrayHelper::check($items))
|
||||
{
|
||||
// insure we have the same order in the languages
|
||||
$languages = ComponentbuilderHelper::getVars('language', 1, 'published', 'langtag');
|
||||
foreach ($items as $nr => &$item)
|
||||
{
|
||||
// remove some values completely
|
||||
unset($item->components);
|
||||
unset($item->modules);
|
||||
unset($item->plugins);
|
||||
unset($item->params);
|
||||
unset($item->published);
|
||||
unset($item->created_by);
|
||||
unset($item->modified_by);
|
||||
unset($item->created);
|
||||
unset($item->modified);
|
||||
unset($item->version);
|
||||
unset($item->hits);
|
||||
unset($item->access);
|
||||
unset($item->ordering);
|
||||
// set the lang order
|
||||
if ($nr != 0)
|
||||
{
|
||||
foreach ($languages as $lanTag)
|
||||
{
|
||||
$item->{$lanTag} = '';
|
||||
}
|
||||
// now adapt the source
|
||||
if (isset($item->translation) && JsonHelper::check($item->translation))
|
||||
{
|
||||
$translations = json_decode($item->translation, true);
|
||||
if (UtilitiesArrayHelper::check($translations))
|
||||
{
|
||||
foreach ($translations as $language)
|
||||
{
|
||||
if (isset($language['translation']) && StringHelper::check($language['translation'])
|
||||
&& isset($language['language']) && StringHelper::check($language['language']))
|
||||
{
|
||||
$item->{$language['language']} = $language['translation'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// remove translation
|
||||
unset($item->translation);
|
||||
}
|
||||
}
|
||||
|
||||
// return items
|
||||
return $items;
|
||||
@ -355,54 +306,50 @@ class Language_translationsModel extends ListModel
|
||||
// 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))
|
||||
{
|
||||
// Filtering "translated in"
|
||||
$filter_translated = $this->state->get("filter.translated");
|
||||
if ($filter_translated !== null && !empty($filter_translated))
|
||||
if (($ids = JCBFilterHelper::translations($filter_translated)) !== null)
|
||||
{
|
||||
if (($ids = JCBFilterHelper::translations($filter_translated)) !== null)
|
||||
{
|
||||
$query->where($db->quoteName('a.id') . ' IN (' . implode(',', $ids) . ')');
|
||||
}
|
||||
else
|
||||
{
|
||||
// there is none
|
||||
$query->where($db->quoteName('a.id') . ' = ' . 0);
|
||||
}
|
||||
$query->where($db->quoteName('a.id') . ' IN (' . implode(',', $ids) . ')');
|
||||
}
|
||||
|
||||
// Filtering "not translated in"
|
||||
$filter_not_translated = $this->state->get("filter.not_translated");
|
||||
if ($filter_not_translated !== null && !empty($filter_not_translated))
|
||||
else
|
||||
{
|
||||
if (($ids = JCBFilterHelper::translations($filter_not_translated, false)) !== null)
|
||||
{
|
||||
$query->where($db->quoteName('a.id') . ' IN (' . implode(',',$ids) . ')');
|
||||
}
|
||||
else
|
||||
{
|
||||
// there is none
|
||||
$query->where($db->quoteName('a.id') . ' = ' . 0);
|
||||
}
|
||||
// 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))
|
||||
// Filtering "not translated in"
|
||||
$filter_not_translated = $this->state->get("filter.not_translated");
|
||||
if ($filter_not_translated !== null && !empty($filter_not_translated))
|
||||
{
|
||||
if (($ids = JCBFilterHelper::translations($filter_not_translated, false)) !== null)
|
||||
{
|
||||
// column name, and id
|
||||
$type_extension = explode('__', $filter_extension);
|
||||
if (($ids = JCBFilterHelper::translation((int) $type_extension[1], $type_extension[0])) !== null)
|
||||
{
|
||||
$query->where($db->quoteName('a.id') . ' IN (' . implode(',', $ids) . ')');
|
||||
}
|
||||
else
|
||||
{
|
||||
// there is none
|
||||
$query->where($db->quoteName('a.id') . ' = ' . 0);
|
||||
}
|
||||
$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 = JCBFilterHelper::translation((string) $type_extension[1], (string) $type_extension[0])) !== null)
|
||||
{
|
||||
$query->where($db->quoteName('a.id') . ' IN (' . implode(',', $ids) . ')');
|
||||
}
|
||||
else
|
||||
{
|
||||
// there is none
|
||||
$query->where($db->quoteName('a.id') . ' = ' . 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -516,54 +463,50 @@ class Language_translationsModel extends ListModel
|
||||
$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))
|
||||
$filter_translated = $this->state->get("filter.translated");
|
||||
if ($filter_translated !== null && !empty($filter_translated))
|
||||
{
|
||||
if (($ids = JCBFilterHelper::translations($filter_translated)) !== null)
|
||||
{
|
||||
if (($ids = JCBFilterHelper::translations($filter_translated)) !== null)
|
||||
{
|
||||
$query->where($db->quoteName('a.id') . ' IN (' . implode(',', $ids) . ')');
|
||||
}
|
||||
else
|
||||
{
|
||||
// there is none
|
||||
$query->where($db->quoteName('a.id') . ' = ' . 0);
|
||||
}
|
||||
$query->where($db->quoteName('a.id') . ' IN (' . implode(',', $ids) . ')');
|
||||
}
|
||||
|
||||
// Filtering "not translated in"
|
||||
$filter_not_translated = $this->state->get("filter.not_translated");
|
||||
if ($filter_not_translated !== null && !empty($filter_not_translated))
|
||||
else
|
||||
{
|
||||
if (($ids = JCBFilterHelper::translations($filter_not_translated, false)) !== null)
|
||||
{
|
||||
$query->where($db->quoteName('a.id') . ' IN (' . implode(',',$ids) . ')');
|
||||
}
|
||||
else
|
||||
{
|
||||
// there is none
|
||||
$query->where($db->quoteName('a.id') . ' = ' . 0);
|
||||
}
|
||||
// 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))
|
||||
// Filtering "not translated in"
|
||||
$filter_not_translated = $this->state->get("filter.not_translated");
|
||||
if ($filter_not_translated !== null && !empty($filter_not_translated))
|
||||
{
|
||||
if (($ids = JCBFilterHelper::translations($filter_not_translated, false)) !== null)
|
||||
{
|
||||
// column name, and id
|
||||
$type_extension = explode('__', $filter_extension);
|
||||
if (($ids = JCBFilterHelper::translation((int) $type_extension[1], $type_extension[0])) !== null)
|
||||
{
|
||||
$query->where($db->quoteName('a.id') . ' IN (' . implode(',', $ids) . ')');
|
||||
}
|
||||
else
|
||||
{
|
||||
// there is none
|
||||
$query->where($db->quoteName('a.id') . ' = ' . 0);
|
||||
}
|
||||
$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 = JCBFilterHelper::translation((string) $type_extension[1], (string) $type_extension[0])) !== null)
|
||||
{
|
||||
$query->where($db->quoteName('a.id') . ' IN (' . implode(',', $ids) . ')');
|
||||
}
|
||||
else
|
||||
{
|
||||
// there is none
|
||||
$query->where($db->quoteName('a.id') . ' = ' . 0);
|
||||
}
|
||||
}
|
||||
// Implement View Level Access
|
||||
@ -613,56 +556,6 @@ class Language_translationsModel extends ListModel
|
||||
{
|
||||
array_unshift($items,$headers);
|
||||
}
|
||||
|
||||
// prep the lang strings for export
|
||||
if (isset($_export) && $_export && UtilitiesArrayHelper::check($items))
|
||||
{
|
||||
// insure we have the same order in the languages
|
||||
$languages = ComponentbuilderHelper::getVars('language', 1, 'published', 'langtag');
|
||||
foreach ($items as $nr => &$item)
|
||||
{
|
||||
// remove some values completely
|
||||
unset($item->components);
|
||||
unset($item->modules);
|
||||
unset($item->plugins);
|
||||
unset($item->params);
|
||||
unset($item->published);
|
||||
unset($item->created_by);
|
||||
unset($item->modified_by);
|
||||
unset($item->created);
|
||||
unset($item->modified);
|
||||
unset($item->version);
|
||||
unset($item->hits);
|
||||
unset($item->access);
|
||||
unset($item->ordering);
|
||||
// set the lang order
|
||||
if ($nr != 0)
|
||||
{
|
||||
foreach ($languages as $lanTag)
|
||||
{
|
||||
$item->{$lanTag} = '';
|
||||
}
|
||||
// now adapt the source
|
||||
if (isset($item->translation) && JsonHelper::check($item->translation))
|
||||
{
|
||||
$translations = json_decode($item->translation, true);
|
||||
if (UtilitiesArrayHelper::check($translations))
|
||||
{
|
||||
foreach ($translations as $language)
|
||||
{
|
||||
if (isset($language['translation']) && StringHelper::check($language['translation'])
|
||||
&& isset($language['language']) && StringHelper::check($language['language']))
|
||||
{
|
||||
$item->{$language['language']} = $language['translation'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// remove translation
|
||||
unset($item->translation);
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
}
|
||||
|
@ -615,7 +615,7 @@ class LibraryModel extends AdminModel
|
||||
/**
|
||||
* Method to validate the form data.
|
||||
*
|
||||
* @param JForm $form The form to validate against.
|
||||
* @param Form $form The form to validate against.
|
||||
* @param array $data The data to validate.
|
||||
* @param string $group The name of the field group to validate.
|
||||
*
|
||||
|
@ -28,6 +28,7 @@ use VDM\Joomla\Utilities\FormHelper as JCBFormHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper as UtilitiesArrayHelper;
|
||||
use VDM\Joomla\Utilities\ObjectHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use Joomla\CMS\Form\Form;
|
||||
|
||||
// No direct access to this file
|
||||
\defined('_JEXEC') or die;
|
||||
@ -107,7 +108,7 @@ class PowersModel extends ListModel
|
||||
* @param array $data data
|
||||
* @param boolean $loadData load current data
|
||||
*
|
||||
* @return \JForm|boolean The \JForm object or false on error
|
||||
* @return Form|boolean The Form object or false on error
|
||||
*
|
||||
* @since JCB 2.12.5
|
||||
*/
|
||||
|
@ -23,9 +23,11 @@ use Joomla\Utilities\ArrayHelper;
|
||||
use Joomla\Input\Input;
|
||||
use VDM\Component\Componentbuilder\Administrator\Helper\ComponentbuilderHelper;
|
||||
use Joomla\CMS\Helper\TagsHelper;
|
||||
use VDM\Joomla\Utilities\FormHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper as UtilitiesArrayHelper;
|
||||
use VDM\Joomla\Utilities\ObjectHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use Joomla\CMS\Form\Form;
|
||||
|
||||
// No direct access to this file
|
||||
\defined('_JEXEC') or die;
|
||||
@ -89,8 +91,8 @@ class RepositoriesModel extends ListModel
|
||||
'a.organisation','organisation',
|
||||
'a.repository','repository',
|
||||
'a.target','target',
|
||||
'a.base','base',
|
||||
'a.type','type'
|
||||
'a.type','type',
|
||||
'a.base','base'
|
||||
);
|
||||
}
|
||||
|
||||
@ -99,6 +101,48 @@ class RepositoriesModel extends ListModel
|
||||
$this->app ??= Factory::getApplication();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the filter form - Override the parent method
|
||||
*
|
||||
* @param array $data data
|
||||
* @param boolean $loadData load current data
|
||||
*
|
||||
* @return Form|boolean The Form 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 "read write branch" filter
|
||||
$attributes = array(
|
||||
'name' => 'branch',
|
||||
'type' => 'list',
|
||||
'onchange' => 'this.form.submit();',
|
||||
);
|
||||
$options = [
|
||||
'' => '- ' . Text::_('COM_COMPONENTBUILDER_SELECT_BRANCH_STATE') . ' -',
|
||||
'write' => Text::_('COM_COMPONENTBUILDER_WRITE_BRANCH_SET'),
|
||||
'no_write' => Text::_('COM_COMPONENTBUILDER_NO_WRITE_BRANCH_SET'),
|
||||
'read' => Text::_('COM_COMPONENTBUILDER_READ_BRANCH_SET'),
|
||||
'no_read' => Text::_('COM_COMPONENTBUILDER_NO_READ_BRANCH_SET'),
|
||||
'both' => Text::_('COM_COMPONENTBUILDER_BOTH_BRANCHES_SET'),
|
||||
'none' => Text::_('COM_COMPONENTBUILDER_NO_BRANCHES_SET')
|
||||
];
|
||||
|
||||
$form->setField(FormHelper::xml($attributes, $options),'filter');
|
||||
$form->setValue(
|
||||
'branch',
|
||||
'filter',
|
||||
$this->state->get("filter.branch")
|
||||
);
|
||||
array_push($this->filter_fields, 'branch');
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to auto-populate the model state.
|
||||
*
|
||||
@ -166,13 +210,6 @@ class RepositoriesModel extends ListModel
|
||||
$this->setState('filter.target', $target);
|
||||
}
|
||||
|
||||
$base = $this->getUserStateFromRequest($this->context . '.filter.base', 'filter_base');
|
||||
if ($formSubmited)
|
||||
{
|
||||
$base = $app->input->post->get('base');
|
||||
$this->setState('filter.base', $base);
|
||||
}
|
||||
|
||||
$type = $this->getUserStateFromRequest($this->context . '.filter.type', 'filter_type');
|
||||
if ($formSubmited)
|
||||
{
|
||||
@ -180,6 +217,13 @@ class RepositoriesModel extends ListModel
|
||||
$this->setState('filter.type', $type);
|
||||
}
|
||||
|
||||
$base = $this->getUserStateFromRequest($this->context . '.filter.base', 'filter_base');
|
||||
if ($formSubmited)
|
||||
{
|
||||
$base = $app->input->post->get('base');
|
||||
$this->setState('filter.base', $base);
|
||||
}
|
||||
|
||||
// List state information.
|
||||
parent::populateState($ordering, $direction);
|
||||
}
|
||||
@ -298,6 +342,51 @@ class RepositoriesModel extends ListModel
|
||||
// From the componentbuilder_item table
|
||||
$query->from($db->quoteName('#__componentbuilder_repository', 'a'));
|
||||
|
||||
// Filtering by "branch"
|
||||
$filterBranch = $this->state->get('filter.branch');
|
||||
|
||||
// Ensure the filter value is a string and not empty
|
||||
if (is_string($filterBranch) && $filterBranch !== '')
|
||||
{
|
||||
$readBranch = 'CHAR_LENGTH(TRIM(' . $db->quoteName('a.read_branch') . '))';
|
||||
$writeBranch = 'CHAR_LENGTH(TRIM(' . $db->quoteName('a.write_branch') . '))';
|
||||
|
||||
switch ($filterBranch)
|
||||
{
|
||||
case 'both':
|
||||
// Both read_branch and write_branch must be set
|
||||
$query->where("{$readBranch} > 1");
|
||||
$query->where("{$writeBranch} > 1");
|
||||
break;
|
||||
|
||||
case 'none':
|
||||
// Neither read_branch nor write_branch must be set
|
||||
$query->where("{$readBranch} = 0");
|
||||
$query->where("{$writeBranch} = 0");
|
||||
break;
|
||||
|
||||
case 'read':
|
||||
// Only read_branch must be set
|
||||
$query->where("{$readBranch} > 1");
|
||||
break;
|
||||
|
||||
case 'write':
|
||||
// Only write_branch must be set
|
||||
$query->where("{$writeBranch} > 1");
|
||||
break;
|
||||
|
||||
case 'no_read':
|
||||
// Only read_branch must NOT be set
|
||||
$query->where("{$readBranch} = 0");
|
||||
break;
|
||||
|
||||
case 'no_write':
|
||||
// Only write_branch must NOT be set
|
||||
$query->where("{$writeBranch} = 0");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Filter by published state
|
||||
$published = $this->getState('filter.published');
|
||||
if (is_numeric($published))
|
||||
@ -397,6 +486,23 @@ class RepositoriesModel extends ListModel
|
||||
{
|
||||
$query->where('a.target = ' . $db->quote($db->escape($_target)));
|
||||
}
|
||||
// Filter by Type.
|
||||
$_type = $this->getState('filter.type');
|
||||
if (is_numeric($_type))
|
||||
{
|
||||
if (is_float($_type))
|
||||
{
|
||||
$query->where('a.type = ' . (float) $_type);
|
||||
}
|
||||
else
|
||||
{
|
||||
$query->where('a.type = ' . (int) $_type);
|
||||
}
|
||||
}
|
||||
elseif (StringHelper::check($_type))
|
||||
{
|
||||
$query->where('a.type = ' . $db->quote($db->escape($_type)));
|
||||
}
|
||||
// Filter by Base.
|
||||
$_base = $this->getState('filter.base');
|
||||
if (is_numeric($_base))
|
||||
@ -458,8 +564,8 @@ class RepositoriesModel extends ListModel
|
||||
$id .= ':' . $this->getState('filter.organisation');
|
||||
$id .= ':' . $this->getState('filter.repository');
|
||||
$id .= ':' . $this->getState('filter.target');
|
||||
$id .= ':' . $this->getState('filter.base');
|
||||
$id .= ':' . $this->getState('filter.type');
|
||||
$id .= ':' . $this->getState('filter.base');
|
||||
|
||||
return parent::getStoreId($id);
|
||||
}
|
||||
|
@ -534,7 +534,7 @@ class ServerModel extends AdminModel
|
||||
/**
|
||||
* Method to validate the form data.
|
||||
*
|
||||
* @param JForm $form The form to validate against.
|
||||
* @param Form $form The form to validate against.
|
||||
* @param array $data The data to validate.
|
||||
* @param string $group The name of the field group to validate.
|
||||
*
|
||||
|
@ -28,6 +28,7 @@ use VDM\Joomla\Componentbuilder\Utilities\FilterHelper as JCBFilterHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper as UtilitiesArrayHelper;
|
||||
use VDM\Joomla\Utilities\ObjectHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use Joomla\CMS\Form\Form;
|
||||
|
||||
// No direct access to this file
|
||||
\defined('_JEXEC') or die;
|
||||
@ -109,7 +110,7 @@ class Site_viewsModel extends ListModel
|
||||
* @param array $data data
|
||||
* @param boolean $loadData load current data
|
||||
*
|
||||
* @return \JForm|boolean The \JForm object or false on error
|
||||
* @return Form|boolean The Form object or false on error
|
||||
*
|
||||
* @since JCB 2.12.5
|
||||
*/
|
||||
|
Reference in New Issue
Block a user