Release of v5.1.2-alpha2

Add native module builder for Joomla 4/5. Refactor dynamic get methods into dedicated classes. Move Joomla DB handling into compiler injector flow. Fix auto-check(in) method for Joomla 4/5 compatibility.
This commit is contained in:
2025-09-02 13:01:13 +00:00
parent 45453f7330
commit 129cdfe8da
274 changed files with 20547 additions and 5629 deletions

View File

@@ -270,12 +270,13 @@ abstract class Grep implements GrepInterface
/**
* Get the a path + indexes
*
* @param string $guid The unique identifier for the repo.
* @param string $guid The unique identifier for the repo.
* @param bool $reload The switch to reload the index, and not return from cache.
*
* @return object|null
* @since 5.1.1
*/
public function getPathIndexes(string $guid): ?object
public function getPathIndexes(string $guid, bool $reload = false): ?object
{
if (!is_array($this->paths) || $this->paths === [] || empty($guid))
{
@@ -289,6 +290,11 @@ abstract class Grep implements GrepInterface
continue;
}
if ($reload)
{
unset($path->index[$this->entity]);
}
// Get remote index
$this->indexRemote($path);
@@ -304,12 +310,13 @@ abstract class Grep implements GrepInterface
/**
* Get the index of a repo
*
* @param string $guid The unique identifier for the repo.
* @param string $guid The unique identifier for the repo.
* @param bool $reload The switch to reload the index, and not return from cache.
*
* @return object|null
* @since 3.2.2
*/
public function getRemoteIndex(string $guid): ?object
public function getRemoteIndex(string $guid, bool $reload = false): ?object
{
if (!is_array($this->paths) || $this->paths === [] || empty($guid))
{
@@ -323,6 +330,11 @@ abstract class Grep implements GrepInterface
continue;
}
if ($reload)
{
unset($path->index[$this->entity]);
}
// Get remote index
$this->indexRemote($path);
@@ -335,6 +347,20 @@ abstract class Grep implements GrepInterface
return null;
}
/**
* Reset the index of a entity
*
* @return void
* @since 5.1.2
*/
public function resetEntityIndex(): void
{
foreach ($this->paths as &$path)
{
unset($path->index[$this->entity]);
}
}
/**
* Get the network target name
*

View File

@@ -69,6 +69,17 @@ abstract class Base implements BaseInterface
return $this->config->getTable();
}
/**
* Get the current active table list view code name
*
* @return string|null
* @since 5.1.2
*/
public function getListViewCodeName(): ?string
{
return $this->config->getListViewCodeName();
}
/**
* Set the current active area
*

View File

@@ -251,6 +251,17 @@ abstract class Config implements ConfigInterface
return $this->table;
}
/**
* Get the current active table list view code name
*
* @return string|null
* @since 5.1.2
*/
public function getListViewCodeName(): ?string
{
return $this->core->listViewCodeName($this->getTable());
}
/**
* Set the current active area
*

View File

@@ -313,6 +313,11 @@ abstract class Set extends Base implements SetInterface
}
$settings = $this->mergeIndexSettings($repoGuid, $settings);
$json_settings = trim(json_encode($settings, JSON_PRETTY_PRINT));
if (empty($json_settings))
{
return;
}
// set the target system
$target = $repo->target ?? 'gitea';
@@ -326,14 +331,15 @@ abstract class Set extends Base implements SetInterface
);
try {
$area = $this->getArea();
$indexPath = $this->getIndexPath();
if (!empty($indexPath))
{
$this->setMainRepoFile(
$repo,
$indexPath,
json_encode($settings, JSON_PRETTY_PRINT),
'Update main index file', 'Create main index file'
$json_settings,
"Update {$area} main index file", "Create {$area} main index file"
);
}
if ($this->hasMainReadme())
@@ -342,7 +348,7 @@ abstract class Set extends Base implements SetInterface
$repo,
$this->getMainReadmePath(),
$this->mainReadme->get($settings),
'Update main readme file', 'Create main readme file'
"Update {$area} main readme file", "Create {$area} main readme file"
);
}
} catch (\Throwable $e) {
@@ -353,17 +359,32 @@ abstract class Set extends Base implements SetInterface
}
/**
* Validate repository and settings
* Validate repository and settings.
*
* @param mixed $repo
* @param mixed $settings
*
* @return bool
* @since 3.2.2
* Repo must be an object and not empty.
* Settings must be an object or an array and not empty.
*
* @param mixed $repo The repository value to validate.
* @param mixed $settings The settings value to validate.
*
* @return bool True if invalid, false if valid.
* @since 3.2.2
*/
protected function isInvalidIndexRepo($repo, $settings): bool
{
return empty($repo) || empty($settings);
// Validate repo: must be an object and not empty
if (!is_object($repo) || empty((array) $repo))
{
return true;
}
// Validate settings: must be an object or array and not empty
if ((!is_object($settings) && !is_array($settings)) || empty((array) $settings))
{
return true;
}
return false;
}
/**
@@ -377,17 +398,16 @@ abstract class Set extends Base implements SetInterface
*/
protected function mergeIndexSettings(string $repoGuid, array $settings): array
{
$current_settings = $this->grep->getRemoteIndex($repoGuid);
if ($current_settings === null || (array) $current_settings === [])
{
return $settings;
}
$mergedSettings = [];
foreach ($current_settings as $guid => $setting)
$current_settings = $this->grep->getRemoteIndex($repoGuid, true);
$this->grep->resetEntityIndex();
if ($current_settings !== null && (array) $current_settings !== [])
{
$mergedSettings[$guid] = (array) $setting;
foreach ($current_settings as $guid_current => $current_setting)
{
$mergedSettings[$guid_current] = (array) $current_setting;
}
}
foreach ($settings as $guid => $setting)

View File

@@ -12,7 +12,7 @@
namespace VDM\Joomla\Componentbuilder\Compiler\Adminview;
use Joomla\CMS\Factory;
use Joomla\Database\DatabaseInterface;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\EventInterface as Event;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
@@ -241,11 +241,12 @@ class Data
protected SiteEditView $siteeditview;
/**
* Database object to query local DB
* Joomla Database Class.
*
* @since 3.2.0
* @var DatabaseInterface
* @since 5.1.2
**/
protected $db;
protected DatabaseInterface $db;
/**
* Constructor.
@@ -272,13 +273,14 @@ class Data
* @param Sql $sql The Sql Class.
* @param Mysqlsettings $mysqlsettings The Mysqlsettings Class.
* @param SiteEditView $siteeditview The SiteEditView Class.
* @param DatabaseInterface $db The Joomla Database Class.
*
* @since 3.2.0
*/
public function __construct(Config $config, Event $event, Placeholder $placeholder, Dispenser $dispenser, Customtabs $customtabs, Tabs $tabs, Fields $fields,
History $history, Permissions $permissions, Conditions $conditions, Relations $relations, Linkedviews $linkedviews, Javascript $javascript,
Css $css, Php $php, Custombuttons $custombuttons, Customimportscripts $customimportscripts, Ajax $ajax, Customalias $customalias, Sql $sql,
Mysqlsettings $mysqlsettings, SiteEditView $siteeditview)
Mysqlsettings $mysqlsettings, SiteEditView $siteeditview, DatabaseInterface $db)
{
$this->config = $config;
$this->event = $event;
@@ -302,7 +304,7 @@ class Data
$this->sql = $sql;
$this->mysqlsettings = $mysqlsettings;
$this->siteeditview = $siteeditview;
$this->db = Factory::getDbo();
$this->db = $db;
}
/**

View File

@@ -12,7 +12,7 @@
namespace VDM\Joomla\Componentbuilder\Compiler\Alias;
use Joomla\CMS\Factory;
use Joomla\Database\DatabaseInterface;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Registry;
use VDM\Joomla\Componentbuilder\Compiler\Customcode;
@@ -95,26 +95,28 @@ class Data
protected Libraries $libraries;
/**
* Database object to query local DB
* Joomla Database Class.
*
* @since 3.2.0
* @var DatabaseInterface
* @since 5.1.2
**/
protected $db;
protected DatabaseInterface $db;
/**
* Constructor.
*
* @param Config $config The Config Class.
* @param Registry $registry The Registry Class.
* @param Customcode $customcode The Customcode Class.
* @param Gui $gui The Gui Class.
* @param Loader $loader The Loader Class.
* @param Libraries $libraries The Libraries Class.
* @param Config $config The Config Class.
* @param Registry $registry The Registry Class.
* @param Customcode $customcode The Customcode Class.
* @param Gui $gui The Gui Class.
* @param Loader $loader The Loader Class.
* @param Libraries $libraries The Libraries Class.
* @param DatabaseInterface $db The Joomla Database Class.
*
* @since 3.2.0
*/
public function __construct(Config $config, Registry $registry, Customcode $customcode,
Gui $gui, Loader $loader, Libraries $libraries)
Gui $gui, Loader $loader, Libraries $libraries, DatabaseInterface $db)
{
$this->config = $config;
$this->registry = $registry;
@@ -122,7 +124,7 @@ class Data
$this->gui = $gui;
$this->loader = $loader;
$this->libraries = $libraries;
$this->db = Factory::getDbo();
$this->db = $db;
}
/**

View File

@@ -0,0 +1,109 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Architecture\JoomlaFive\Model;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Model\CheckInNowInterface;
/**
* Check In Now Method for Joomla 5
*
* @since 5.1.2
*/
final class CheckInNow implements CheckInNowInterface
{
/**
* Get the generated call snippet that invokes the check-in method.
*
* @return string The code that calls the generated method.
* @since 5.1.2
*/
public function getCall(): string
{
$call = PHP_EOL . Indent::_(2) . "//" . Line::_(__Line__, __Class__) . " Check in items";
$call .= PHP_EOL . Indent::_(2) . "\$this->checkInNow();" . PHP_EOL;
return $call;
}
/**
* Build the full `checkInNow()` method code for the given view/table.
*
* @param string $view The view/table suffix (e.g. 'items').
* @param string $component The component name (without 'com_').
*
* @return string The full method code as a string.
* @since 5.1.2
*/
public function getMethod($view, $component): string
{
$checkin = PHP_EOL . PHP_EOL . Indent::_(1) . "/**";
$checkin .= PHP_EOL . Indent::_(1) . " * Build an SQL query to check in all items left checked out longer then a set time.";
$checkin .= PHP_EOL . Indent::_(1) . " *";
$checkin .= PHP_EOL . Indent::_(1) . " * @return void";
$checkin .= PHP_EOL . Indent::_(1) . " * @throws \DateMalformedStringException";
$checkin .= PHP_EOL . Indent::_(1) . " * @since 3.2.0";
$checkin .= PHP_EOL . Indent::_(1) . " */";
$checkin .= PHP_EOL . Indent::_(1) . "protected function checkInNow(): void";
$checkin .= PHP_EOL . Indent::_(1) . "{";
$checkin .= PHP_EOL . Indent::_(2) . "//" . Line::_(__Line__, __Class__) . " Get set check in time";
$checkin .= PHP_EOL . Indent::_(2) . "\$time = Joomla__"."_aeb8e463_291f_4445_9ac4_34b637c12dbd___Power::getParams('com_" . $component . "')->get('check_in');";
$checkin .= PHP_EOL . PHP_EOL . Indent::_(2) . "if (\$time)";
$checkin .= PHP_EOL . Indent::_(2) . "{";
$checkin .= PHP_EOL . Indent::_(3) . "//" . Line::_(__LINE__,__CLASS__) . " Get a db connection.";
$checkin .= PHP_EOL . Indent::_(3) . "\$db = \$this->getDatabase();";
$checkin .= PHP_EOL . Indent::_(3) . "//" . Line::_(__Line__, __Class__) . " Reset query.";
$checkin .= PHP_EOL . Indent::_(3) . "\$query = \$db->getQuery(true);";
$checkin .= PHP_EOL . Indent::_(3) . "\$query->select('*');";
$checkin .= PHP_EOL . Indent::_(3) . "\$query->from(\$db->quoteName('#__" . $component . "_" . $view . "'));";
$checkin .= PHP_EOL . Indent::_(3) . "//" . Line::_(__Line__, __Class__) . " Only select items that are checked out.";
$checkin .= PHP_EOL . Indent::_(3) . "\$query->where($db->quoteName('checked_out') . ' >= 0');";
Indent::_(3) . "//" . Line::_(__Line__, __Class__) . " Query only to see if we have a rows";
$checkin .= PHP_EOL . Indent::_(3) . "\$db->setQuery(\$query, 0, 1);";
$checkin .= PHP_EOL . Indent::_(3) . "\$db->execute();";
$checkin .= PHP_EOL . Indent::_(3) . "if (\$db->getNumRows())";
$checkin .= PHP_EOL . Indent::_(3) . "{";
$checkin .= PHP_EOL . Indent::_(4) . "//" . Line::_(__Line__, __Class__) . " Get target date in the past.";
$checkin .= PHP_EOL . Indent::_(4) . "\$date = Joomla__"."_39403062_84fb_46e0_bac4_0023f766e827___Power::getDate()->modify(\$time)->toSql();";
$checkin .= PHP_EOL . Indent::_(4) . "//" . Line::_(__Line__, __Class__) . " Reset query.";
$checkin .= PHP_EOL . Indent::_(4) . "\$query = \$db->getQuery(true);";
$checkin .= PHP_EOL . PHP_EOL . Indent::_(4) . "//" . Line::_(__LINE__,__CLASS__) . " Fields to update.";
$checkin .= PHP_EOL . Indent::_(4) . "\$fields = [";
$checkin .= PHP_EOL . Indent::_(5) . "\$db->quoteName('checked_out_time') . ' = NULL',";
$checkin .= PHP_EOL . Indent::_(5) . "\$db->quoteName('checked_out') . ' = NULL'";
$checkin .= PHP_EOL . Indent::_(4) . "];";
$checkin .= PHP_EOL . PHP_EOL . Indent::_(4) . "//" . Line::_(__LINE__,__CLASS__) . " Conditions for which records should be updated.";
$checkin .= PHP_EOL . Indent::_(4) . "\$conditions = [";
$checkin .= PHP_EOL . Indent::_(5) . "\$db->quoteName('checked_out') . ' = 0 OR ' . \$db->quoteName('checked_out') . ' > 0',";
$checkin .= PHP_EOL . Indent::_(5) . "\$db->quoteName('checked_out_time') . ' < ' . \$db->quote(\$date)";
$checkin .= PHP_EOL . Indent::_(4) . "];";
$checkin .= PHP_EOL . PHP_EOL . Indent::_(4) . "//" . Line::_(__LINE__,__CLASS__) . " Check table.";
$checkin .= PHP_EOL . Indent::_(4) . "\$query->update(\$db->quoteName('#__" . $component . "_" . $view . "'))->set(\$fields)->where(\$conditions); ";
$checkin .= PHP_EOL . PHP_EOL . Indent::_(4) . "\$db->setQuery(\$query);";
$checkin .= PHP_EOL . PHP_EOL . Indent::_(4) . "\$db->execute();";
$checkin .= PHP_EOL . Indent::_(3) . "}";
$checkin .= PHP_EOL . Indent::_(2) . "}";
$checkin .= PHP_EOL . Indent::_(1) . "}";
return $checkin;
}
}

View File

@@ -0,0 +1,170 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Architecture\JoomlaFive\Module;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ContentOne as Builder;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module\LibraryInterface as Library;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module\DispatcherInterface;
/**
* Module Dispatcher Class for Joomla 5
*
* @since 5.1.2
*/
final class Dispatcher implements DispatcherInterface
{
/**
* The Placeholder Class.
*
* @var Placeholder
* @since 5.1.2
*/
protected Placeholder $placeholder;
/**
* The ContentOne Class.
*
* @var Builder
* @since 5.1.2
*/
protected Builder $builder;
/**
* The Library Class.
*
* @var Library
* @since 5.1.2
*/
protected Library $library;
/**
* The Namespace Prefix
*
* @var string
* @since 5.0.0
*/
protected string $NamespacePrefix;
/**
* Constructor.
*
* @param Placeholder $placeholder The Placeholder Class.
* @param Builder $builder The ContentOne Class.
* @param Library $library The Library Class.
*
* @since 5.1.2
*/
public function __construct(Placeholder $placeholder, Builder $builder, Library $library)
{
$this->placeholder = $placeholder;
$this->builder = $builder;
$this->library = $library;
// set some global values
$this->NamespacePrefix = $this->placeholder->get('NamespacePrefix');
}
/**
* Get the updated placeholder content for the given module.
*
* @param object $module The module object containing the necessary data.
*
* @return string The updated placeholder content.
* @since 5.1.2
*/
public function get(object $module): string
{
$dispatcher = [];
$dispatcher[] = "/**";
$dispatcher[] = " *" . Line::_(__LINE__, __CLASS__) . " Dispatcher class for {$module->official_name}";
$dispatcher[] = " *";
$dispatcher[] = " * @since 5.3.0";
$dispatcher[] = " */";
$library = $this->library->get($module);
if (empty($module->layout_data) && empty($module->add_class_helper) && empty($module->custom_get) && empty($library))
{
$dispatcher[] = "class Dispatcher extends AbstractModuleDispatcher {}";
return implode(PHP_EOL, $dispatcher). PHP_EOL;
}
if ($module->add_class_helper == 1 || $module->custom_get)
{
$dispatcher[] = "class Dispatcher extends AbstractModuleDispatcher implements HelperFactoryAwareInterface";
$dispatcher[] = "{";
$dispatcher[] = Indent::_(1) . "use HelperFactoryAwareTrait;";
}
else
{
$dispatcher[] = "class Dispatcher extends AbstractModuleDispatcher";
$dispatcher[] = "{";
}
$dispatcher[] = "";
$dispatcher[] = Indent::_(1) . "/**";
$dispatcher[] = Indent::_(1) . " *" . Line::_(__LINE__, __CLASS__) . " Returns the layout data.";
$dispatcher[] = Indent::_(1) . " *";
$dispatcher[] = Indent::_(1) . " * @return array";
$dispatcher[] = Indent::_(1) . " *";
$dispatcher[] = Indent::_(1) . " * @since 5.3.0";
$dispatcher[] = Indent::_(1) . " */";
$dispatcher[] = Indent::_(1) . "protected function getLayoutData(): array";
$dispatcher[] = Indent::_(1) . "{";
$dispatcher[] = Indent::_(2) . "\$data = parent::getLayoutData();";
$dispatcher[] = "";
if ($module->add_class_helper == 1)
{
$dispatcher[] = Indent::_(2) . "\$data['helper'] = \$this->getHelperFactory()->getHelper('{$module->class_helper_name}', \$data);";
}
elseif ($module->add_class_helper == 2)
{
$dispatcher[] = Indent::_(2) . "\$data['helper'] = \\{$this->NamespacePrefix}\\Module\\{$module->namespace}\\{$module->target_client_namespace}\\Helper\\{$module->class_helper_name}::class;";
}
if ($module->custom_get)
{
$dispatcher[] = Indent::_(2) . "\$data['data'] = \$this->getHelperFactory()->getHelper('{$module->class_data_name}', \$data);";
}
// load the libraries
if (!empty($library))
{
$dispatcher[] = "";
$dispatcher[] = Indent::_(2) . $library;
}
// load the custom code here
if (!empty($module->layout_data))
{
$dispatcher[] = "";
$dispatcher[] = $module->layout_data;
}
$dispatcher[] = "";
$dispatcher[] = Indent::_(2) . "return \$data;";
$dispatcher[] = Indent::_(1) . "}";
$dispatcher[] = "}";
return $this->placeholder->update(
implode(PHP_EOL, $dispatcher). PHP_EOL,
$this->builder->allActive()
);
}
}

View File

@@ -0,0 +1,151 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Architecture\JoomlaFive\Module;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ContentOne;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module\HelperInterface;
/**
* Module Helper Code Joomla 5
*
* @since 5.1.2
*/
final class Helper implements HelperInterface
{
/**
* The Placeholder Class.
*
* @var Placeholder
* @since 5.1.2
*/
protected Placeholder $placeholder;
/**
* The ContentOne Class.
*
* @var ContentOne
* @since 5.1.2
*/
protected ContentOne $contentone;
/**
* Constructor.
*
* @param Placeholder $placeholder The Placeholder Class.
* @param ContentOne $contentone The ContentOne Class.
*
* @since 5.1.2
*/
public function __construct(Placeholder $placeholder, ContentOne $contentone)
{
$this->placeholder = $placeholder;
$this->contentone = $contentone;
}
/**
* Get Module Helper Class code
*
* @param object $module The module object
*
* @return string The helper class code
* @since 5.1.2
*/
public function get(object $module): string
{
$type = trim((string) ($module->class_helper_type ?? 'class'));
$name = trim((string) ($module->class_helper_name ?? 'Helper'));
$body = (string) ($module->class_helper_code ?? '');
$implements = '';
if ($this->usesDatabaseFeatures($body))
{
$implements = ' implements DatabaseAwareInterface';
if (!str_contains($body, 'use DatabaseAwareTrait;'))
{
$body = Indent::_(1) . 'use DatabaseAwareTrait;' . PHP_EOL . PHP_EOL . $body;
}
}
$code = PHP_EOL . $type . ' ' . $name . $implements . PHP_EOL . '{' . PHP_EOL . $body . PHP_EOL . '}' . PHP_EOL;
return $this->placeholder->update($code, $this->contentone->allActive());
}
/**
* Get Module Helper Header code
*
* @param object $module The module object
*
* @return string The helper header code
* @since 5.1.2
*/
public function header(object $module): string
{
$code = (string) trim($module->class_helper_header ?? '');
$body = trim((string) ($module->class_helper_code ?? ''));
if ($this->usesDatabaseFeatures($body))
{
if ($code === '')
{
$code = 'use Joomla\\Database\\DatabaseAwareInterface;' .
PHP_EOL . 'use Joomla\\Database\\DatabaseAwareTrait;';
}
else
{
if (!str_contains($code, '\\DatabaseAwareInterface;'))
{
$code .= PHP_EOL . 'use Joomla\\Database\\DatabaseAwareInterface;';
}
if (!str_contains($code, '\\DatabaseAwareTrait;'))
{
$code .= PHP_EOL . 'use Joomla\\Database\\DatabaseAwareTrait;';
}
}
}
if ($code === '')
{
return '';
}
return $this->placeholder->update(
PHP_EOL . $code, $this->contentone->allActive()
);
}
/**
* Determine if the helper body uses database features.
*
* @param string $body The helper class body.
*
* @return bool
* @since 5.1.2
*/
protected function usesDatabaseFeatures(string $body): bool
{
if ($body === '')
{
return false;
}
return str_contains($body, '$this->getDatabase(')
|| str_contains($body, 'use DatabaseAwareTrait;');
}
}

View File

@@ -0,0 +1,154 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Architecture\JoomlaFive\Module;
use VDM\Joomla\Componentbuilder\Compiler\Builder\LibraryManager;
use VDM\Joomla\Componentbuilder\Compiler\Library\Document;
use VDM\Joomla\Componentbuilder\Compiler\Registry;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ContentOne;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module\LibraryInterface;
/**
* Module Library Joomla 5
*
* @since 5.1.2
*/
final class Library implements LibraryInterface
{
/**
* The LibraryManager Class.
*
* @var LibraryManager
* @since 5.1.2
*/
protected LibraryManager $librarymanager;
/**
* The Document Class.
*
* @var Document
* @since 5.1.2
*/
protected Document $document;
/**
* The Registry Class.
*
* @var Registry
* @since 5.1.2
*/
protected Registry $registry;
/**
* The Placeholder Class.
*
* @var Placeholder
* @since 5.1.2
*/
protected Placeholder $placeholder;
/**
* The ContentOne Class.
*
* @var ContentOne
* @since 5.1.2
*/
protected ContentOne $contentone;
/**
* Constructor.
*
* @param LibraryManager $librarymanager The LibraryManager Class.
* @param Document $document The Document Class.
* @param Registry $registry The Registry Class.
* @param Placeholder $placeholder The Placeholder Class.
* @param ContentOne $contentone The ContentOne Class.
*
* @since 5.1.2
*/
public function __construct(LibraryManager $librarymanager, Document $document,
Registry $registry, Placeholder $placeholder,
ContentOne $contentone)
{
$this->librarymanager = $librarymanager;
$this->document = $document;
$this->registry = $registry;
$this->placeholder = $placeholder;
$this->contentone = $contentone;
}
/**
* Get the module's library loading code.
*
* @param object $module The module object
*
* @return string The generated code to load libraries into the document.
* @since 5.1.2
*/
public function get(object $module): string
{
$data = $this->librarymanager->get($module->key . '.' . $module->code_name);
if ($data === null)
{
return '';
}
$code = '// ' . Line::_(__LINE__, __CLASS__) . ' get the document object' . PHP_EOL;
$code .= '$document = $this->app->getDocument();';
$found = false;
foreach ($data as $id => $item)
{
$library = $this->registry->get("builder.libraries.{$id}");
if (!is_object($library))
{
continue;
}
if (!empty($library->document) && StringHelper::check($library->document))
{
$code .= PHP_EOL . $library->document;
$found = true;
}
elseif (isset($library->how))
{
$code .= $this->document->get($id);
$found = true;
}
}
if (!$found)
{
return '';
}
// Normalize and inject placeholders
$lines = explode(PHP_EOL, $code);
$trimmed = array_map('trim', $lines);
$normalized = str_replace('$this->document->', '$document->', implode(PHP_EOL . Indent::_(2), $trimmed));
return $this->placeholder->update(
$this->placeholder->update_($normalized),
$this->contentone->allActive()
);
}
}

View File

@@ -0,0 +1,570 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Architecture\JoomlaFive\Module;
use Joomla\Filesystem\Folder;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Language;
use VDM\Joomla\Componentbuilder\Compiler\Language\Set;
use VDM\Joomla\Componentbuilder\Compiler\Language\Purge;
use VDM\Joomla\Componentbuilder\Compiler\Language\Translation;
use VDM\Joomla\Componentbuilder\Compiler\Language\Multilingual;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\EventInterface as Event;
use VDM\Joomla\Componentbuilder\Compiler\Creator\FieldsetExtension;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ContentOne;
use VDM\Joomla\Componentbuilder\Compiler\Builder\Languages;
use VDM\Joomla\Componentbuilder\Compiler\Builder\Multilingual as BuilderMultilingual;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Counter;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\File;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Componentbuilder\Interfaces\Architecture\Module\MainXMLInterface;
/**
* Joomla 5 Module Main XML Class
*
* @since 5.1.2
*/
final class MainXML implements MainXMLInterface
{
/**
* The Config Class.
*
* @var Config
* @since 5.1.2
*/
protected Config $config;
/**
* The Language Class.
*
* @var Language
* @since 5.1.2
*/
protected Language $language;
/**
* The Set Class.
*
* @var Set
* @since 5.1.2
*/
protected Set $set;
/**
* The Purge Class.
*
* @var Purge
* @since 5.1.2
*/
protected Purge $purge;
/**
* The Translation Class.
*
* @var Translation
* @since 5.1.2
*/
protected Translation $translation;
/**
* The Multilingual Class.
*
* @var Multilingual
* @since 5.1.2
*/
protected Multilingual $multilingual;
/**
* The EventInterface Class.
*
* @var Event
* @since 5.1.2
*/
protected Event $event;
/**
* The FieldsetExtension Class.
*
* @var FieldsetExtension
* @since 5.1.2
*/
protected FieldsetExtension $fieldsetextension;
/**
* The ContentOne Class.
*
* @var ContentOne
* @since 5.1.2
*/
protected ContentOne $contentone;
/**
* The Languages Class.
*
* @var Languages
* @since 5.1.2
*/
protected Languages $languages;
/**
* The Multilingual Class.
*
* @var BuilderMultilingual
* @since 5.1.2
*/
protected BuilderMultilingual $buildermultilingual;
/**
* The Counter Class.
*
* @var Counter
* @since 5.1.2
*/
protected Counter $counter;
/**
* The File Class.
*
* @var File
* @since 5.1.2
*/
protected File $file;
/**
* Constructor.
*
* @param Config $config The Config Class.
* @param Language $language The Language Class.
* @param Set $set The Set Class.
* @param Purge $purge The Purge Class.
* @param Translation $translation The Translation Class.
* @param Multilingual $multilingual The Multilingual Class.
* @param Event $event The EventInterface Class.
* @param FieldsetExtension $fieldsetextension The FieldsetExtension Class.
* @param ContentOne $contentone The ContentOne Class.
* @param Languages $languages The Languages Class.
* @param BuilderMultilingual $buildermultilingual The Multilingual Class.
* @param Counter $counter The Counter Class.
* @param File $file The File Class.
*
* @since 5.1.2
*/
public function __construct(Config $config, Language $language, Set $set, Purge $purge,
Translation $translation, Multilingual $multilingual,
Event $event, FieldsetExtension $fieldsetextension,
ContentOne $contentone, Languages $languages,
BuilderMultilingual $buildermultilingual,
Counter $counter, File $file)
{
$this->config = $config;
$this->language = $language;
$this->set = $set;
$this->purge = $purge;
$this->translation = $translation;
$this->multilingual = $multilingual;
$this->event = $event;
$this->fieldsetextension = $fieldsetextension;
$this->contentone = $contentone;
$this->languages = $languages;
$this->buildermultilingual = $buildermultilingual;
$this->counter = $counter;
$this->file = $file;
}
/**
* Generates the main XML for the module.
*
* @param object $module The module object.
*
* @return string The generated XML.
* @since 5.1.2
*/
public function get(object $module): string
{
$config_fields = $this->buildConfigFields($module);
$add_component_path = $this->shouldAddComponentPath($module);
$language_files = $this->generateLanguageFiles($module);
$xml = $this->generateScriptAndSqlXml($module);
$xml .= $this->generateLanguageXml($module, $language_files);
$xml .= $this->generateFileXml($module, $language_files);
$xml .= $this->generateConfigXml($module, $config_fields, $add_component_path);
$xml .= $this->generateUpdateServerXml($module);
return $xml;
}
/**
* Build configuration fields XML.
*
* @param object $module The module object.
*
* @return array The configuration fields.
* @since 5.1.2
*/
protected function buildConfigFields(object $module): array
{
$configFields = [];
if (!isset($module->config_fields) || !ArrayHelper::check($module->config_fields))
{
return $configFields;
}
$dbKey = 'yyy';
$addScriptsField = true;
foreach ($module->config_fields as $fieldName => $fieldsets)
{
foreach ($fieldsets as $fieldset => $fields)
{
$xmlFields = $this->fieldsetextension->get($module, $fields, $dbKey);
if ($addScriptsField && $module->add_scripts_field)
{
$xmlFields .= PHP_EOL . Indent::_(2) . '<field type="modadminvvvvvvvdm" />';
$addScriptsField = false;
}
if (isset($xmlFields) && StringHelper::check($xmlFields))
{
$configFields["{$fieldName}{$fieldset}"] = $xmlFields;
}
$dbKey++;
}
}
return $configFields;
}
/**
* Determine if the component path should be added.
*
* @param object $module The module object.
*
* @return bool True if the component path should be added, false otherwise.
* @since 5.1.2
*/
protected function shouldAddComponentPath(object $module): bool
{
if (!isset($module->config_fields) || !ArrayHelper::check($module->config_fields) ||
!isset($module->fieldsets_paths) || !ArrayHelper::check($module->fieldsets_paths))
{
return false;
}
foreach ($module->config_fields as $fieldName => $fieldsets)
{
foreach ($fieldsets as $fieldset => $fields)
{
if (isset($module->fieldsets_paths["{$fieldName}{$fieldset}"]) &&
$module->fieldsets_paths["{$fieldName}{$fieldset}"] == 1)
{
return true;
}
}
}
return false;
}
/**
* Generate XML for script and SQL files.
*
* @param object $module The module object.
*
* @return string The XML for script and SQL files.
* @since 5.1.2
*/
protected function generateScriptAndSqlXml(object $module): string
{
$xml = '';
if ($module->add_install_script)
{
$xml .= PHP_EOL . PHP_EOL . Indent::_(1) . '<!--' . Line::_(
__LINE__,__CLASS__
) . ' Scripts to run on installation -->';
$xml .= PHP_EOL . Indent::_(1) . '<scriptfile>script.php</scriptfile>';
}
if ($module->add_sql)
{
$xml .= PHP_EOL . PHP_EOL . Indent::_(1) . '<!--' . Line::_(
__LINE__,__CLASS__
) . ' Runs on install -->';
$xml .= PHP_EOL . Indent::_(1) . '<install>';
$xml .= PHP_EOL . Indent::_(2) . '<sql>';
$xml .= PHP_EOL . Indent::_(3) . '<file driver="mysql" charset="utf8">sql/mysql/install.sql</file>';
$xml .= PHP_EOL . Indent::_(2) . '</sql>';
$xml .= PHP_EOL . Indent::_(1) . '</install>';
}
if ($module->add_sql_uninstall)
{
$xml .= PHP_EOL . PHP_EOL . Indent::_(1) . '<!--' . Line::_(
__LINE__,__CLASS__
) . ' Runs on uninstall -->';
$xml .= PHP_EOL . Indent::_(1) . '<uninstall>';
$xml .= PHP_EOL . Indent::_(2) . '<sql>';
$xml .= PHP_EOL . Indent::_(3) . '<file driver="mysql" charset="utf8">sql/mysql/uninstall.sql</file>';
$xml .= PHP_EOL . Indent::_(2) . '</sql>';
$xml .= PHP_EOL . Indent::_(1) . '</uninstall>';
}
return $xml;
}
/**
* Generate XML for language files.
*
* @param object $module The module object.
* @param array $languageFiles The language files.
*
* @return string The XML for language files.
* @since 5.1.2
*/
protected function generateLanguageXml(object $module, array $languageFiles): string
{
$xml = '';
if (ArrayHelper::check($languageFiles))
{
$xml .= PHP_EOL . PHP_EOL . Indent::_(1) . '<!--' . Line::_(
__LINE__, __CLASS__
) . ' Language files -->';
$xml .= PHP_EOL . Indent::_(1) . '<languages folder="language">';
foreach ($languageFiles as $tag)
{
$xml .= PHP_EOL . Indent::_(2) . "<language tag=\"{$tag}\">{$tag}/{$module->file_name}.ini</language>";
$xml .= PHP_EOL . Indent::_(2) . "<language tag=\"{$tag}\">{$tag}/{$module->file_name}.sys.ini</language>";
}
$xml .= PHP_EOL . Indent::_(1) . '</languages>';
}
return $xml;
}
/**
* Generate the XML for the files.
*
* @param object $module The module object.
* @param array $languageFiles The language files.
*
* @return string The XML for the files.
* @since 5.1.2
*/
protected function generateFileXml(object $module, array $languageFiles): string
{
$files = Folder::files($module->folder_path);
$folders = Folder::folders($module->folder_path);
$ignore = ['services', 'sql', 'language', 'script.php', "{$module->file_name}.xml", "{$module->file_name}.php"];
$xml = PHP_EOL . PHP_EOL . Indent::_(1) . '<!--' . Line::_(
__LINE__, __CLASS__
) . ' Module files -->';
$xml .= PHP_EOL . Indent::_(1) . '<files>';
$xml .= PHP_EOL . Indent::_(2) . "<folder module=\"{$module->file_name}\">services</folder>";
foreach ($files as $file)
{
if (!in_array($file, $ignore))
{
$xml .= PHP_EOL . Indent::_(2) . "<filename>{$file}</filename>";
}
}
if (!empty($languageFiles))
{
$xml .= PHP_EOL . Indent::_(2) . '<folder>language</folder>';
}
if ($module->add_sql || $module->add_sql_uninstall)
{
$xml .= PHP_EOL . Indent::_(2) . '<folder>sql</folder>';
}
foreach ($folders as $folder)
{
if (!in_array($folder, $ignore))
{
$xml .= PHP_EOL . Indent::_(2) . "<folder>{$folder}</folder>";
}
}
$xml .= PHP_EOL . Indent::_(1) . '</files>';
return $xml;
}
/**
* Generate XML for configuration fields.
*
* @param object $module The module object.
* @param array $configFields The configuration fields.
* @param bool $addComponentPath Whether to add the component path.
*
* @return string The XML for configuration fields.
* @since 5.1.2
*/
protected function generateConfigXml(object $module, array $configFields, bool $addComponentPath): string
{
if (!isset($module->config_fields) || !ArrayHelper::check($configFields))
{
return '';
}
$xml = PHP_EOL . PHP_EOL . Indent::_(1) . '<!--' . Line::_(
__LINE__, __CLASS__
) . ' Config parameters -->';
$xml .= $addComponentPath ? PHP_EOL . Indent::_(1) . '<config' : PHP_EOL . Indent::_(1) . '<config>';
if ($addComponentPath)
{
$namespace = $this->config->namespace_prefix . '\\Component\\' . $this->contentone->get('ComponentNamespace') . '\\Administrator';
$xml .= PHP_EOL . Indent::_(3) . "addruleprefix=\"{$namespace}\\Rule\"";
$xml .= PHP_EOL . Indent::_(3) . "addfieldprefix=\"{$namespace}\\Field\">";
$xml .= PHP_EOL . Indent::_(1) . '>';
}
foreach ($module->config_fields as $fieldName => $fieldsets)
{
$xml .= PHP_EOL . Indent::_(1) . "<fields name=\"{$fieldName}\">";
foreach ($fieldsets as $fieldset => $fields)
{
$label = $module->fieldsets_label["{$fieldName}{$fieldset}"] ?? $fieldset;
$xml .= PHP_EOL . Indent::_(1) . "<fieldset name=\"{$fieldset}\" label=\"{$label}\">";
if (isset($configFields["{$fieldName}{$fieldset}"]))
{
$xml .= $configFields["{$fieldName}{$fieldset}"];
}
$xml .= PHP_EOL . Indent::_(1) . '</fieldset>';
}
$xml .= PHP_EOL . Indent::_(1) . '</fields>';
}
$xml .= PHP_EOL . Indent::_(1) . '</config>';
return $xml;
}
/**
* Generate XML for update servers.
*
* @param object $module The module object.
*
* @return string The XML for update servers.
* @since 5.1.2
*/
protected function generateUpdateServerXml(object $module): string
{
$xml = '';
if ($module->add_update_server)
{
$xml .= PHP_EOL . PHP_EOL . Indent::_(1) . '<!--' . Line::_(
__LINE__, __CLASS__
) . ' Update servers -->';
$xml .= PHP_EOL . Indent::_(1) . '<updateservers>';
$xml .= PHP_EOL . Indent::_(2) . "<server type=\"extension\" priority=\"1\" name=\"{$module->official_name}\">{$module->update_server_url}</server>";
$xml .= PHP_EOL . Indent::_(1) . '</updateservers>';
}
return $xml;
}
/**
* Generate language files.
*
* @param object $module The module object.
*
* @return array The language files.
* @since 5.1.2
*/
protected function generateLanguageFiles(object $module): array
{
$languageFiles = [];
if (!$this->language->exist($module->key))
{
return $languageFiles;
}
$langContent = $this->language->getTarget($module->key);
$this->event->trigger('jcb_ce_onBeforeBuildModuleLang', [&$module, &$langContent]);
$values = array_unique($langContent);
$this->buildermultilingual->set('modules', $this->multilingual->get($values));
$langTag = $this->config->get('lang_tag', 'en-GB');
$this->languages->set("modules.{$langTag}.all", $langContent);
$this->language->setTarget($module->key, null);
$this->set->execute($values, $module->guid, 'modules');
$this->purge->execute($values, $module->guid, 'modules');
$this->event->trigger('jcb_ce_onBeforeBuildModuleLangFiles', [&$module]);
if ($this->languages->IsArray('modules'))
{
foreach ($this->languages->get('modules') as $tag => $areas)
{
$tag = trim($tag);
foreach ($areas as $area => $languageStrings)
{
$fileName = "{$module->file_name}.ini";
$fileSysName = "{$module->file_name}.sys.ini";
$total = count($values);
if ($this->translation->check($tag, $languageStrings, $total, $fileName))
{
$lang = array_map(
fn($langString, $placeholder) => "{$placeholder}=\"{$langString}\"",
array_values($languageStrings),
array_keys($languageStrings)
);
$path = "{$module->folder_path}/language/{$tag}/";
if (!is_dir($path))
{
Folder::create($path);
$this->counter->folder++;
}
$this->file->write($path . $fileName, implode(PHP_EOL, $lang));
$this->file->write($path . $fileSysName, implode(PHP_EOL, $lang));
$this->counter->line += count($lang);
unset($lang);
$languageFiles[$tag] = $tag;
}
}
}
}
return $languageFiles;
}
}

View File

@@ -0,0 +1,114 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Architecture\JoomlaFive\Module;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ContentOne as Builder;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module\ProviderInterface;
/**
* Module Provider Class for Joomla 5
*
* @since 5.1.2
*/
final class Provider implements ProviderInterface
{
/**
* The Placeholder Class.
*
* @var Placeholder
* @since 5.1.2
*/
protected Placeholder $placeholder;
/**
* The ContentOne Class.
*
* @var Builder
* @since 5.1.2
*/
protected Builder $builder;
/**
* The Namespace Prefix
*
* @var string
* @since 5.1.2
*/
protected string $NamespacePrefix;
/**
* Constructor.
*
* @param Placeholder $placeholder The Placeholder Class.
* @param Builder $builder The Content One Class.
*
* @since 5.1.2
*/
public function __construct(Placeholder $placeholder, Builder $builder)
{
$this->placeholder = $placeholder;
$this->builder = $builder;
// set some global values
$this->NamespacePrefix = $this->placeholder->get('NamespacePrefix');
}
/**
* Get the updated provider for the given module.
*
* @param object $module The module object containing the necessary data.
*
* @return string The provider content.
*
* @since 5.1.2
*/
public function get(object $module): string
{
$provider = [];
$provider[] = "/**";
$provider[] = " *" . Line::_(__Line__, __Class__) . " The {$module->official_name} module service provider";
$provider[] = " *";
$provider[] = " * @since 5.4.0";
$provider[] = " */";
$provider[] = "return new class () implements ServiceProviderInterface {";
$provider[] = Indent::_(1) . "/**";
$provider[] = Indent::_(1) . " *" . Line::_(__Line__, __Class__) . " Registers the service provider with a DI container.";
$provider[] = Indent::_(1) . " *";
$provider[] = Indent::_(1) . " * @param Container \$container The DI container.";
$provider[] = Indent::_(1) . " *";
$provider[] = Indent::_(1) . " * @return void";
$provider[] = Indent::_(1) . " * @since 5.4.0";
$provider[] = Indent::_(1) . " */";
$provider[] = Indent::_(1) . "public function register(Container \$container)";
$provider[] = Indent::_(1) . "{";
$provider[] = Indent::_(2) . "\$container->registerServiceProvider(new ModuleDispatcherFactory('\\\\{$this->NamespacePrefix}\\\\Module\\\\{$module->namespace}'));";
if ($module->add_class_helper == 1 || $module->custom_get)
{
$provider[] = Indent::_(2) . "\$container->registerServiceProvider(new HelperFactory('\\\\{$this->NamespacePrefix}\\\\Module\\\\{$module->namespace}\\\\{$module->target_client_namespace}\\\\Helper'));";
}
$provider[] = '';
$provider[] = Indent::_(2) . "\$container->registerServiceProvider(new Module());";
$provider[] = Indent::_(1) . "}";
$provider[] = "};";
return $this->placeholder->update(
implode(PHP_EOL, $provider). PHP_EOL,
$this->builder->allActive()
);
}
}

View File

@@ -0,0 +1,242 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Architecture\JoomlaFive\Module;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\HeaderInterface as Header;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Customcode\DispenserInterface as Dispenser;
use VDM\Joomla\Componentbuilder\Compiler\Builder\TemplateData;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ContentOne;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ContentMulti;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module\TemplateInterface;
/**
* Module Template Joomla 5
*
* @since 5.1.2
*/
final class Template implements TemplateInterface
{
/**
* The Config Class.
*
* @var Config
* @since 5.1.2
*/
protected Config $config;
/**
* The Header Class.
*
* @var Header
* @since 5.1.2
*/
protected Header $header;
/**
* The Dispenser Class.
*
* @var Dispenser
* @since 5.1.2
*/
protected Dispenser $dispenser;
/**
* The TemplateData Class.
*
* @var TemplateData
* @since 5.1.2
*/
protected TemplateData $templatedata;
/**
* The Placeholder Class.
*
* @var Placeholder
* @since 5.1.2
*/
protected Placeholder $placeholder;
/**
* The ContentOne Class.
*
* @var ContentOne
* @since 5.1.2
*/
protected ContentOne $contentone;
/**
* The ContentMulti Class.
*
* @var ContentMulti
* @since 5.1.2
*/
protected ContentMulti $contentmulti;
/**
* Constructor.
*
* @param Config $config The Config Class.
* @param Header $header The Header Class.
* @param Dispenser $dispenser The Dispenser Class.
* @param TemplateData $templatedata The TemplateData Class.
* @param Placeholder $placeholder The Placeholder Class.
* @param ContentOne $contentone The ContentOne Class.
* @param ContentMulti $contentmulti The ContentMulti Class.
*
* @since 5.1.2
*/
public function __construct(Config $config, Header $header, Dispenser $dispenser,
TemplateData $templatedata, Placeholder $placeholder,
ContentOne $contentone, ContentMulti $contentmulti)
{
$this->config = $config;
$this->header = $header;
$this->dispenser = $dispenser;
$this->templatedata = $templatedata;
$this->placeholder = $placeholder;
$this->contentone = $contentone;
$this->contentmulti = $contentmulti;
}
/**
* Get the updated placeholder default template content for the given module.
*
* @param object $module The module object containing the necessary data.
* @param string $key The dispenser key for this given module.
*
* @return string The updated placeholder content.
* @since 5.1.2
*/
public function default(object $module, string $key): string
{
// add any css from the fields
$default = $this->dispenser->get(
'css_views',
$key,
PHP_EOL . '<style>',
'',
true,
null,
PHP_EOL . '</style>' . PHP_EOL
);
// now add the body
$body = trim((string) ($module->default ?? ''));
if (!empty($body))
{
$default .= PHP_EOL . $body . PHP_EOL;
}
// add any JavaScript from the fields
$default .= $this->dispenser->get(
'views_footer',
$key,
PHP_EOL . '<script type="text/javascript">',
'',
true,
null,
PHP_EOL . '</script>' . PHP_EOL
);
// return the default content for the model default area
return $this->placeholder->update(
$default,
$this->contentone->allActive()
);
}
/**
* Get the updated placeholder default header template content for the given module.
*
* @param object $module The module object containing the necessary data.
*
* @return string The updated placeholder content.
* @since 5.1.2
*/
public function header(object $module): string
{
// first add the header
$add_default_header = (int) ($module->add_default_header ?? 0);
$default = $add_default_header === 1 ? trim((string) ($module->default_header ?? '')) : '';
if (empty($default))
{
return '';
}
// return the header for the model default area
return PHP_EOL . PHP_EOL . $this->placeholder->update($default, $this->contentone->allActive());
}
/**
* Get the updated placeholder extra template content for the given module.
*
* @param object $module The module object containing the necessary data.
*
* @return void
* @since 5.1.2
*/
public function extra(object $module): void
{
// Build the data key and fetch template data once
$data = $this->templatedata->get($module->key . '.' . $module->code_name);
// Nothing to do if there's no data
if (!is_array($data) || $data === [])
{
return;
}
// Cache these to avoid repeated calls
$activePlaceholders = $this->contentone->allActive();
// --- HEADER (text) ---
$header = (string) ($this->header->get('module.extra.template.header', $module->class_name) ?? '');
if ($header !== '')
{
$header = PHP_EOL . PHP_EOL . $this->placeholder->update($header, $activePlaceholders);
}
foreach ($data as $template => $item)
{
$target = StringHelper::safe("MODDEFAULT_HEADER_{$template}", 'U');
$key = $module->key . '|' . $target;
$this->contentmulti->set($key, $header);
// --- HEADER CODE (php_view) ---
$phpView = trim((string) ($item['php_view'] ?? ''));
$headerCode = ($phpView === '')
? ''
: PHP_EOL . $this->placeholder->update($phpView, $activePlaceholders);
$target = StringHelper::safe("MODDEFAULT_HEADER_CODE_{$template}", 'U');
$key = $module->key . '|' . $target;
$this->contentmulti->set($key, $headerCode);
// --- BODY (html) ---
$html = (string) ($item['html'] ?? '');
$body = ($html === '')
? PHP_EOL
: PHP_EOL . $this->placeholder->update($html, $activePlaceholders);
$target = StringHelper::safe("MODDEFAULT_{$template}", 'U');
$key = $module->key . '|' . $target;
$this->contentmulti->set($key, $body);
}
}
}

View File

@@ -435,8 +435,9 @@ final class MainXML implements MainXMLInterface
if ($addComponentPath)
{
$xml .= PHP_EOL . Indent::_(3) . 'addruleprefix="' . $this->config->namespace_prefix . '\Component\\' . $this->contentone->get('ComponentNamespace') . '\Administrator\Rule"';
$xml .= PHP_EOL . Indent::_(3) . 'addfieldprefix="' . $this->config->namespace_prefix . '\Component\\' . $this->contentone->get('ComponentNamespace') . '\Administrator\Field">';
$namespace = $this->config->namespace_prefix . '\\Component\\' . $this->contentone->get('ComponentNamespace') . '\\Administrator';
$xml .= PHP_EOL . Indent::_(3) . "addruleprefix=\"{$namespace}\\Rule\"";
$xml .= PHP_EOL . Indent::_(3) . "addfieldprefix=\"{$namespace}\\Field\">";
$xml .= PHP_EOL . Indent::_(1) . '>';
}

View File

@@ -0,0 +1,109 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Architecture\JoomlaFour\Model;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Model\CheckInNowInterface;
/**
* Check In Now Method for Joomla 4
*
* @since 5.1.2
*/
final class CheckInNow implements CheckInNowInterface
{
/**
* Get the generated call snippet that invokes the check-in method.
*
* @return string The code that calls the generated method.
* @since 5.1.2
*/
public function getCall(): string
{
$call = PHP_EOL . Indent::_(2) . "//" . Line::_(__Line__, __Class__) . " Check in items";
$call .= PHP_EOL . Indent::_(2) . "\$this->checkInNow();" . PHP_EOL;
return $call;
}
/**
* Build the full `checkInNow()` method code for the given view/table.
*
* @param string $view The view/table suffix (e.g. 'items').
* @param string $component The component name (without 'com_').
*
* @return string The full method code as a string.
* @since 5.1.2
*/
public function getMethod($view, $component): string
{
$checkin = PHP_EOL . PHP_EOL . Indent::_(1) . "/**";
$checkin .= PHP_EOL . Indent::_(1) . " * Build an SQL query to check in all items left checked out longer then a set time.";
$checkin .= PHP_EOL . Indent::_(1) . " *";
$checkin .= PHP_EOL . Indent::_(1) . " * @return void";
$checkin .= PHP_EOL . Indent::_(1) . " * @throws \DateMalformedStringException";
$checkin .= PHP_EOL . Indent::_(1) . " * @since 3.2.0";
$checkin .= PHP_EOL . Indent::_(1) . " */";
$checkin .= PHP_EOL . Indent::_(1) . "protected function checkInNow(): void";
$checkin .= PHP_EOL . Indent::_(1) . "{";
$checkin .= PHP_EOL . Indent::_(2) . "//" . Line::_(__Line__, __Class__) . " Get set check in time";
$checkin .= PHP_EOL . Indent::_(2) . "\$time = Joomla__"."_aeb8e463_291f_4445_9ac4_34b637c12dbd___Power::getParams('com_" . $component . "')->get('check_in');";
$checkin .= PHP_EOL . PHP_EOL . Indent::_(2) . "if (\$time)";
$checkin .= PHP_EOL . Indent::_(2) . "{";
$checkin .= PHP_EOL . Indent::_(3) . "//" . Line::_(__LINE__,__CLASS__) . " Get a db connection.";
$checkin .= PHP_EOL . Indent::_(3) . "\$db = \$this->getDatabase();";
$checkin .= PHP_EOL . Indent::_(3) . "//" . Line::_(__Line__, __Class__) . " Reset query.";
$checkin .= PHP_EOL . Indent::_(3) . "\$query = \$db->getQuery(true);";
$checkin .= PHP_EOL . Indent::_(3) . "\$query->select('*');";
$checkin .= PHP_EOL . Indent::_(3) . "\$query->from(\$db->quoteName('#__" . $component . "_" . $view . "'));";
$checkin .= PHP_EOL . Indent::_(3) . "//" . Line::_(__Line__, __Class__) . " Only select items that are checked out.";
$checkin .= PHP_EOL . Indent::_(3) . "\$query->where($db->quoteName('checked_out') . ' >= 0');";
Indent::_(3) . "//" . Line::_(__Line__, __Class__) . " Query only to see if we have a rows";
$checkin .= PHP_EOL . Indent::_(3) . "\$db->setQuery(\$query, 0, 1);";
$checkin .= PHP_EOL . Indent::_(3) . "\$db->execute();";
$checkin .= PHP_EOL . Indent::_(3) . "if (\$db->getNumRows())";
$checkin .= PHP_EOL . Indent::_(3) . "{";
$checkin .= PHP_EOL . Indent::_(4) . "//" . Line::_(__Line__, __Class__) . " Get target date in the past.";
$checkin .= PHP_EOL . Indent::_(4) . "\$date = Joomla__"."_39403062_84fb_46e0_bac4_0023f766e827___Power::getDate()->modify(\$time)->toSql();";
$checkin .= PHP_EOL . Indent::_(4) . "//" . Line::_(__Line__, __Class__) . " Reset query.";
$checkin .= PHP_EOL . Indent::_(4) . "\$query = \$db->getQuery(true);";
$checkin .= PHP_EOL . PHP_EOL . Indent::_(4) . "//" . Line::_(__LINE__,__CLASS__) . " Fields to update.";
$checkin .= PHP_EOL . Indent::_(4) . "\$fields = [";
$checkin .= PHP_EOL . Indent::_(5) . "\$db->quoteName('checked_out_time') . ' = NULL',";
$checkin .= PHP_EOL . Indent::_(5) . "\$db->quoteName('checked_out') . ' = NULL'";
$checkin .= PHP_EOL . Indent::_(4) . "];";
$checkin .= PHP_EOL . PHP_EOL . Indent::_(4) . "//" . Line::_(__LINE__,__CLASS__) . " Conditions for which records should be updated.";
$checkin .= PHP_EOL . Indent::_(4) . "\$conditions = [";
$checkin .= PHP_EOL . Indent::_(5) . "\$db->quoteName('checked_out') . ' = 0 OR ' . \$db->quoteName('checked_out') . ' > 0',";
$checkin .= PHP_EOL . Indent::_(5) . "\$db->quoteName('checked_out_time') . ' < ' . \$db->quote(\$date)";
$checkin .= PHP_EOL . Indent::_(4) . "];";
$checkin .= PHP_EOL . PHP_EOL . Indent::_(4) . "//" . Line::_(__LINE__,__CLASS__) . " Check table.";
$checkin .= PHP_EOL . Indent::_(4) . "\$query->update(\$db->quoteName('#__" . $component . "_" . $view . "'))->set(\$fields)->where(\$conditions); ";
$checkin .= PHP_EOL . PHP_EOL . Indent::_(4) . "\$db->setQuery(\$query);";
$checkin .= PHP_EOL . PHP_EOL . Indent::_(4) . "\$db->execute();";
$checkin .= PHP_EOL . Indent::_(3) . "}";
$checkin .= PHP_EOL . Indent::_(2) . "}";
$checkin .= PHP_EOL . Indent::_(1) . "}";
return $checkin;
}
}

View File

@@ -0,0 +1,170 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Architecture\JoomlaFour\Module;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ContentOne as Builder;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module\LibraryInterface as Library;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module\DispatcherInterface;
/**
* Module Dispatcher Class for Joomla 4
*
* @since 5.1.2
*/
final class Dispatcher implements DispatcherInterface
{
/**
* The Placeholder Class.
*
* @var Placeholder
* @since 5.1.2
*/
protected Placeholder $placeholder;
/**
* The ContentOne Class.
*
* @var Builder
* @since 5.1.2
*/
protected Builder $builder;
/**
* The Library Class.
*
* @var Library
* @since 5.1.2
*/
protected Library $library;
/**
* The Namespace Prefix
*
* @var string
* @since 5.0.0
*/
protected string $NamespacePrefix;
/**
* Constructor.
*
* @param Placeholder $placeholder The Placeholder Class.
* @param Builder $builder The ContentOne Class.
* @param Library $library The Library Class.
*
* @since 5.1.2
*/
public function __construct(Placeholder $placeholder, Builder $builder, Library $library)
{
$this->placeholder = $placeholder;
$this->builder = $builder;
$this->library = $library;
// set some global values
$this->NamespacePrefix = $this->placeholder->get('NamespacePrefix');
}
/**
* Get the updated placeholder content for the given module.
*
* @param object $module The module object containing the necessary data.
*
* @return string The updated placeholder content.
* @since 5.1.2
*/
public function get(object $module): string
{
$dispatcher = [];
$dispatcher[] = "/**";
$dispatcher[] = " *" . Line::_(__LINE__, __CLASS__) . " Dispatcher class for {$module->official_name}";
$dispatcher[] = " *";
$dispatcher[] = " * @since 5.3.0";
$dispatcher[] = " */";
$library = $this->library->get($module);
if (empty($module->layout_data) && empty($module->add_class_helper) && empty($module->custom_get) && empty($library))
{
$dispatcher[] = "class Dispatcher extends AbstractModuleDispatcher {}";
return implode(PHP_EOL, $dispatcher). PHP_EOL;
}
if ($module->add_class_helper == 1 || $module->custom_get)
{
$dispatcher[] = "class Dispatcher extends AbstractModuleDispatcher implements HelperFactoryAwareInterface";
$dispatcher[] = "{";
$dispatcher[] = Indent::_(1) . "use HelperFactoryAwareTrait;";
}
else
{
$dispatcher[] = "class Dispatcher extends AbstractModuleDispatcher";
$dispatcher[] = "{";
}
$dispatcher[] = "";
$dispatcher[] = Indent::_(1) . "/**";
$dispatcher[] = Indent::_(1) . " *" . Line::_(__LINE__, __CLASS__) . " Returns the layout data.";
$dispatcher[] = Indent::_(1) . " *";
$dispatcher[] = Indent::_(1) . " * @return array";
$dispatcher[] = Indent::_(1) . " *";
$dispatcher[] = Indent::_(1) . " * @since 5.3.0";
$dispatcher[] = Indent::_(1) . " */";
$dispatcher[] = Indent::_(1) . "protected function getLayoutData(): array";
$dispatcher[] = Indent::_(1) . "{";
$dispatcher[] = Indent::_(2) . "\$data = parent::getLayoutData();";
$dispatcher[] = "";
if ($module->add_class_helper == 1)
{
$dispatcher[] = Indent::_(2) . "\$data['helper'] = \$this->getHelperFactory()->getHelper('{$module->class_helper_name}', \$data);";
}
elseif ($module->add_class_helper == 2)
{
$dispatcher[] = Indent::_(2) . "\$data['helper'] = \\{$this->NamespacePrefix}\\Module\\{$module->namespace}\\{$module->target_client_namespace}\\Helper\\{$module->class_helper_name}::class;";
}
if ($module->custom_get)
{
$dispatcher[] = Indent::_(2) . "\$data['data'] = \$this->getHelperFactory()->getHelper('{$module->class_data_name}', \$data);";
}
// load the libraries
if (!empty($library))
{
$dispatcher[] = "";
$dispatcher[] = Indent::_(2) . $library;
}
// load the custom code here
if (!empty($module->layout_data))
{
$dispatcher[] = "";
$dispatcher[] = $module->layout_data;
}
$dispatcher[] = "";
$dispatcher[] = Indent::_(2) . "return \$data;";
$dispatcher[] = Indent::_(1) . "}";
$dispatcher[] = "}";
return $this->placeholder->update(
implode(PHP_EOL, $dispatcher). PHP_EOL,
$this->builder->allActive()
);
}
}

View File

@@ -0,0 +1,150 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Architecture\JoomlaFour\Module;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ContentOne;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module\HelperInterface;
/**
* Module Helper Code Joomla 4
*
* @since 5.1.2
*/
final class Helper implements HelperInterface
{
/**
* The Placeholder Class.
*
* @var Placeholder
* @since 5.1.2
*/
protected Placeholder $placeholder;
/**
* The ContentOne Class.
*
* @var ContentOne
* @since 5.1.2
*/
protected ContentOne $contentone;
/**
* Constructor.
*
* @param Placeholder $placeholder The Placeholder Class.
* @param ContentOne $contentone The ContentOne Class.
*
* @since 5.1.2
*/
public function __construct(Placeholder $placeholder, ContentOne $contentone)
{
$this->placeholder = $placeholder;
$this->contentone = $contentone;
}
/**
* Get Module Helper Class code
*
* @param object $module The module object
*
* @return string The helper class code
* @since 5.1.2
*/
public function get(object $module): string
{
$type = trim((string) ($module->class_helper_type ?? 'class'));
$name = trim((string) ($module->class_helper_name ?? 'Helper'));
$body = (string) ($module->class_helper_code ?? '');
$implements = '';
if ($this->usesDatabaseFeatures($body))
{
$implements = ' implements DatabaseAwareInterface';
if (!str_contains($body, 'use DatabaseAwareTrait;'))
{
$body = Indent::_(1) . 'use DatabaseAwareTrait;' . PHP_EOL . PHP_EOL . $body;
}
}
$code = PHP_EOL . $type . ' ' . $name . $implements . PHP_EOL . '{' . PHP_EOL . $body . PHP_EOL . '}' . PHP_EOL;
return $this->placeholder->update($code, $this->contentone->allActive());
}
/**
* Get Module Helper Header code
*
* @param object $module The module object
*
* @return string The helper header code
* @since 5.1.2
*/
public function header(object $module): string
{
$code = (string) trim($module->class_helper_header ?? '');
$body = trim((string) ($module->class_helper_code ?? ''));
if ($this->usesDatabaseFeatures($body))
{
if ($code === '')
{
$code = 'use Joomla\\Database\\DatabaseAwareInterface;' .
PHP_EOL . 'use Joomla\\Database\\DatabaseAwareTrait;';
}
else
{
if (!str_contains($code, '\\DatabaseAwareInterface;'))
{
$code .= PHP_EOL . 'use Joomla\\Database\\DatabaseAwareInterface;';
}
if (!str_contains($code, '\\DatabaseAwareTrait;'))
{
$code .= PHP_EOL . 'use Joomla\\Database\\DatabaseAwareTrait;';
}
}
}
if ($code === '')
{
return '';
}
return $this->placeholder->update(
PHP_EOL . $code, $this->contentone->allActive()
);
}
/**
* Determine if the helper body uses database features.
*
* @param string $body The helper class body.
*
* @return bool
* @since 5.1.2
*/
protected function usesDatabaseFeatures(string $body): bool
{
if ($body === '')
{
return false;
}
return str_contains($body, '$this->getDatabase(')
|| str_contains($body, 'use DatabaseAwareTrait;');
}
}

View File

@@ -0,0 +1,154 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Architecture\JoomlaFour\Module;
use VDM\Joomla\Componentbuilder\Compiler\Builder\LibraryManager;
use VDM\Joomla\Componentbuilder\Compiler\Library\Document;
use VDM\Joomla\Componentbuilder\Compiler\Registry;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ContentOne;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module\LibraryInterface;
/**
* Module Library Joomla 4
*
* @since 5.1.2
*/
final class Library implements LibraryInterface
{
/**
* The LibraryManager Class.
*
* @var LibraryManager
* @since 5.1.2
*/
protected LibraryManager $librarymanager;
/**
* The Document Class.
*
* @var Document
* @since 5.1.2
*/
protected Document $document;
/**
* The Registry Class.
*
* @var Registry
* @since 5.1.2
*/
protected Registry $registry;
/**
* The Placeholder Class.
*
* @var Placeholder
* @since 5.1.2
*/
protected Placeholder $placeholder;
/**
* The ContentOne Class.
*
* @var ContentOne
* @since 5.1.2
*/
protected ContentOne $contentone;
/**
* Constructor.
*
* @param LibraryManager $librarymanager The LibraryManager Class.
* @param Document $document The Document Class.
* @param Registry $registry The Registry Class.
* @param Placeholder $placeholder The Placeholder Class.
* @param ContentOne $contentone The ContentOne Class.
*
* @since 5.1.2
*/
public function __construct(LibraryManager $librarymanager, Document $document,
Registry $registry, Placeholder $placeholder,
ContentOne $contentone)
{
$this->librarymanager = $librarymanager;
$this->document = $document;
$this->registry = $registry;
$this->placeholder = $placeholder;
$this->contentone = $contentone;
}
/**
* Get the module's library loading code.
*
* @param object $module The module object
*
* @return string The generated code to load libraries into the document.
* @since 5.1.2
*/
public function get(object $module): string
{
$data = $this->librarymanager->get($module->key . '.' . $module->code_name);
if ($data === null)
{
return '';
}
$code = '// ' . Line::_(__LINE__, __CLASS__) . ' get the document object' . PHP_EOL;
$code .= '$document = $this->app->getDocument();';
$found = false;
foreach ($data as $id => $item)
{
$library = $this->registry->get("builder.libraries.{$id}");
if (!is_object($library))
{
continue;
}
if (!empty($library->document) && StringHelper::check($library->document))
{
$code .= PHP_EOL . $library->document;
$found = true;
}
elseif (isset($library->how))
{
$code .= $this->document->get($id);
$found = true;
}
}
if (!$found)
{
return '';
}
// Normalize and inject placeholders
$lines = explode(PHP_EOL, $code);
$trimmed = array_map('trim', $lines);
$normalized = str_replace('$this->document->', '$document->', implode(PHP_EOL . Indent::_(2), $trimmed));
return $this->placeholder->update(
$this->placeholder->update_($normalized),
$this->contentone->allActive()
);
}
}

View File

@@ -0,0 +1,570 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Architecture\JoomlaFour\Module;
use Joomla\Filesystem\Folder;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Language;
use VDM\Joomla\Componentbuilder\Compiler\Language\Set;
use VDM\Joomla\Componentbuilder\Compiler\Language\Purge;
use VDM\Joomla\Componentbuilder\Compiler\Language\Translation;
use VDM\Joomla\Componentbuilder\Compiler\Language\Multilingual;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\EventInterface as Event;
use VDM\Joomla\Componentbuilder\Compiler\Creator\FieldsetExtension;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ContentOne;
use VDM\Joomla\Componentbuilder\Compiler\Builder\Languages;
use VDM\Joomla\Componentbuilder\Compiler\Builder\Multilingual as BuilderMultilingual;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Counter;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\File;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Componentbuilder\Interfaces\Architecture\Module\MainXMLInterface;
/**
* Joomla 4 Module Main XML Class
*
* @since 5.1.2
*/
final class MainXML implements MainXMLInterface
{
/**
* The Config Class.
*
* @var Config
* @since 5.1.2
*/
protected Config $config;
/**
* The Language Class.
*
* @var Language
* @since 5.1.2
*/
protected Language $language;
/**
* The Set Class.
*
* @var Set
* @since 5.1.2
*/
protected Set $set;
/**
* The Purge Class.
*
* @var Purge
* @since 5.1.2
*/
protected Purge $purge;
/**
* The Translation Class.
*
* @var Translation
* @since 5.1.2
*/
protected Translation $translation;
/**
* The Multilingual Class.
*
* @var Multilingual
* @since 5.1.2
*/
protected Multilingual $multilingual;
/**
* The EventInterface Class.
*
* @var Event
* @since 5.1.2
*/
protected Event $event;
/**
* The FieldsetExtension Class.
*
* @var FieldsetExtension
* @since 5.1.2
*/
protected FieldsetExtension $fieldsetextension;
/**
* The ContentOne Class.
*
* @var ContentOne
* @since 5.1.2
*/
protected ContentOne $contentone;
/**
* The Languages Class.
*
* @var Languages
* @since 5.1.2
*/
protected Languages $languages;
/**
* The Multilingual Class.
*
* @var BuilderMultilingual
* @since 5.1.2
*/
protected BuilderMultilingual $buildermultilingual;
/**
* The Counter Class.
*
* @var Counter
* @since 5.1.2
*/
protected Counter $counter;
/**
* The File Class.
*
* @var File
* @since 5.1.2
*/
protected File $file;
/**
* Constructor.
*
* @param Config $config The Config Class.
* @param Language $language The Language Class.
* @param Set $set The Set Class.
* @param Purge $purge The Purge Class.
* @param Translation $translation The Translation Class.
* @param Multilingual $multilingual The Multilingual Class.
* @param Event $event The EventInterface Class.
* @param FieldsetExtension $fieldsetextension The FieldsetExtension Class.
* @param ContentOne $contentone The ContentOne Class.
* @param Languages $languages The Languages Class.
* @param BuilderMultilingual $buildermultilingual The Multilingual Class.
* @param Counter $counter The Counter Class.
* @param File $file The File Class.
*
* @since 5.1.2
*/
public function __construct(Config $config, Language $language, Set $set, Purge $purge,
Translation $translation, Multilingual $multilingual,
Event $event, FieldsetExtension $fieldsetextension,
ContentOne $contentone, Languages $languages,
BuilderMultilingual $buildermultilingual,
Counter $counter, File $file)
{
$this->config = $config;
$this->language = $language;
$this->set = $set;
$this->purge = $purge;
$this->translation = $translation;
$this->multilingual = $multilingual;
$this->event = $event;
$this->fieldsetextension = $fieldsetextension;
$this->contentone = $contentone;
$this->languages = $languages;
$this->buildermultilingual = $buildermultilingual;
$this->counter = $counter;
$this->file = $file;
}
/**
* Generates the main XML for the module.
*
* @param object $module The module object.
*
* @return string The generated XML.
* @since 5.1.2
*/
public function get(object $module): string
{
$config_fields = $this->buildConfigFields($module);
$add_component_path = $this->shouldAddComponentPath($module);
$language_files = $this->generateLanguageFiles($module);
$xml = $this->generateScriptAndSqlXml($module);
$xml .= $this->generateLanguageXml($module, $language_files);
$xml .= $this->generateFileXml($module, $language_files);
$xml .= $this->generateConfigXml($module, $config_fields, $add_component_path);
$xml .= $this->generateUpdateServerXml($module);
return $xml;
}
/**
* Build configuration fields XML.
*
* @param object $module The module object.
*
* @return array The configuration fields.
* @since 5.1.2
*/
protected function buildConfigFields(object $module): array
{
$configFields = [];
if (!isset($module->config_fields) || !ArrayHelper::check($module->config_fields))
{
return $configFields;
}
$dbKey = 'yyy';
$addScriptsField = true;
foreach ($module->config_fields as $fieldName => $fieldsets)
{
foreach ($fieldsets as $fieldset => $fields)
{
$xmlFields = $this->fieldsetextension->get($module, $fields, $dbKey);
if ($addScriptsField && $module->add_scripts_field)
{
$xmlFields .= PHP_EOL . Indent::_(2) . '<field type="modadminvvvvvvvdm" />';
$addScriptsField = false;
}
if (isset($xmlFields) && StringHelper::check($xmlFields))
{
$configFields["{$fieldName}{$fieldset}"] = $xmlFields;
}
$dbKey++;
}
}
return $configFields;
}
/**
* Determine if the component path should be added.
*
* @param object $module The module object.
*
* @return bool True if the component path should be added, false otherwise.
* @since 5.1.2
*/
protected function shouldAddComponentPath(object $module): bool
{
if (!isset($module->config_fields) || !ArrayHelper::check($module->config_fields) ||
!isset($module->fieldsets_paths) || !ArrayHelper::check($module->fieldsets_paths))
{
return false;
}
foreach ($module->config_fields as $fieldName => $fieldsets)
{
foreach ($fieldsets as $fieldset => $fields)
{
if (isset($module->fieldsets_paths["{$fieldName}{$fieldset}"]) &&
$module->fieldsets_paths["{$fieldName}{$fieldset}"] == 1)
{
return true;
}
}
}
return false;
}
/**
* Generate XML for script and SQL files.
*
* @param object $module The module object.
*
* @return string The XML for script and SQL files.
* @since 5.1.2
*/
protected function generateScriptAndSqlXml(object $module): string
{
$xml = '';
if ($module->add_install_script)
{
$xml .= PHP_EOL . PHP_EOL . Indent::_(1) . '<!--' . Line::_(
__LINE__,__CLASS__
) . ' Scripts to run on installation -->';
$xml .= PHP_EOL . Indent::_(1) . '<scriptfile>script.php</scriptfile>';
}
if ($module->add_sql)
{
$xml .= PHP_EOL . PHP_EOL . Indent::_(1) . '<!--' . Line::_(
__LINE__,__CLASS__
) . ' Runs on install -->';
$xml .= PHP_EOL . Indent::_(1) . '<install>';
$xml .= PHP_EOL . Indent::_(2) . '<sql>';
$xml .= PHP_EOL . Indent::_(3) . '<file driver="mysql" charset="utf8">sql/mysql/install.sql</file>';
$xml .= PHP_EOL . Indent::_(2) . '</sql>';
$xml .= PHP_EOL . Indent::_(1) . '</install>';
}
if ($module->add_sql_uninstall)
{
$xml .= PHP_EOL . PHP_EOL . Indent::_(1) . '<!--' . Line::_(
__LINE__,__CLASS__
) . ' Runs on uninstall -->';
$xml .= PHP_EOL . Indent::_(1) . '<uninstall>';
$xml .= PHP_EOL . Indent::_(2) . '<sql>';
$xml .= PHP_EOL . Indent::_(3) . '<file driver="mysql" charset="utf8">sql/mysql/uninstall.sql</file>';
$xml .= PHP_EOL . Indent::_(2) . '</sql>';
$xml .= PHP_EOL . Indent::_(1) . '</uninstall>';
}
return $xml;
}
/**
* Generate XML for language files.
*
* @param object $module The module object.
* @param array $languageFiles The language files.
*
* @return string The XML for language files.
* @since 5.1.2
*/
protected function generateLanguageXml(object $module, array $languageFiles): string
{
$xml = '';
if (ArrayHelper::check($languageFiles))
{
$xml .= PHP_EOL . PHP_EOL . Indent::_(1) . '<!--' . Line::_(
__LINE__, __CLASS__
) . ' Language files -->';
$xml .= PHP_EOL . Indent::_(1) . '<languages folder="language">';
foreach ($languageFiles as $tag)
{
$xml .= PHP_EOL . Indent::_(2) . "<language tag=\"{$tag}\">{$tag}/{$module->file_name}.ini</language>";
$xml .= PHP_EOL . Indent::_(2) . "<language tag=\"{$tag}\">{$tag}/{$module->file_name}.sys.ini</language>";
}
$xml .= PHP_EOL . Indent::_(1) . '</languages>';
}
return $xml;
}
/**
* Generate the XML for the files.
*
* @param object $module The module object.
* @param array $languageFiles The language files.
*
* @return string The XML for the files.
* @since 5.1.2
*/
protected function generateFileXml(object $module, array $languageFiles): string
{
$files = Folder::files($module->folder_path);
$folders = Folder::folders($module->folder_path);
$ignore = ['services', 'sql', 'language', 'script.php', "{$module->file_name}.xml", "{$module->file_name}.php"];
$xml = PHP_EOL . PHP_EOL . Indent::_(1) . '<!--' . Line::_(
__LINE__, __CLASS__
) . ' Module files -->';
$xml .= PHP_EOL . Indent::_(1) . '<files>';
$xml .= PHP_EOL . Indent::_(2) . "<folder module=\"{$module->file_name}\">services</folder>";
foreach ($files as $file)
{
if (!in_array($file, $ignore))
{
$xml .= PHP_EOL . Indent::_(2) . "<filename>{$file}</filename>";
}
}
if (!empty($languageFiles))
{
$xml .= PHP_EOL . Indent::_(2) . '<folder>language</folder>';
}
if ($module->add_sql || $module->add_sql_uninstall)
{
$xml .= PHP_EOL . Indent::_(2) . '<folder>sql</folder>';
}
foreach ($folders as $folder)
{
if (!in_array($folder, $ignore))
{
$xml .= PHP_EOL . Indent::_(2) . "<folder>{$folder}</folder>";
}
}
$xml .= PHP_EOL . Indent::_(1) . '</files>';
return $xml;
}
/**
* Generate XML for configuration fields.
*
* @param object $module The module object.
* @param array $configFields The configuration fields.
* @param bool $addComponentPath Whether to add the component path.
*
* @return string The XML for configuration fields.
* @since 5.1.2
*/
protected function generateConfigXml(object $module, array $configFields, bool $addComponentPath): string
{
if (!isset($module->config_fields) || !ArrayHelper::check($configFields))
{
return '';
}
$xml = PHP_EOL . PHP_EOL . Indent::_(1) . '<!--' . Line::_(
__LINE__, __CLASS__
) . ' Config parameters -->';
$xml .= $addComponentPath ? PHP_EOL . Indent::_(1) . '<config' : PHP_EOL . Indent::_(1) . '<config>';
if ($addComponentPath)
{
$namespace = $this->config->namespace_prefix . '\\Component\\' . $this->contentone->get('ComponentNamespace') . '\\Administrator';
$xml .= PHP_EOL . Indent::_(3) . "addruleprefix=\"{$namespace}\\Rule\"";
$xml .= PHP_EOL . Indent::_(3) . "addfieldprefix=\"{$namespace}\\Field\">";
$xml .= PHP_EOL . Indent::_(1) . '>';
}
foreach ($module->config_fields as $fieldName => $fieldsets)
{
$xml .= PHP_EOL . Indent::_(1) . "<fields name=\"{$fieldName}\">";
foreach ($fieldsets as $fieldset => $fields)
{
$label = $module->fieldsets_label["{$fieldName}{$fieldset}"] ?? $fieldset;
$xml .= PHP_EOL . Indent::_(1) . "<fieldset name=\"{$fieldset}\" label=\"{$label}\">";
if (isset($configFields["{$fieldName}{$fieldset}"]))
{
$xml .= $configFields["{$fieldName}{$fieldset}"];
}
$xml .= PHP_EOL . Indent::_(1) . '</fieldset>';
}
$xml .= PHP_EOL . Indent::_(1) . '</fields>';
}
$xml .= PHP_EOL . Indent::_(1) . '</config>';
return $xml;
}
/**
* Generate XML for update servers.
*
* @param object $module The module object.
*
* @return string The XML for update servers.
* @since 5.1.2
*/
protected function generateUpdateServerXml(object $module): string
{
$xml = '';
if ($module->add_update_server)
{
$xml .= PHP_EOL . PHP_EOL . Indent::_(1) . '<!--' . Line::_(
__LINE__, __CLASS__
) . ' Update servers -->';
$xml .= PHP_EOL . Indent::_(1) . '<updateservers>';
$xml .= PHP_EOL . Indent::_(2) . "<server type=\"extension\" priority=\"1\" name=\"{$module->official_name}\">{$module->update_server_url}</server>";
$xml .= PHP_EOL . Indent::_(1) . '</updateservers>';
}
return $xml;
}
/**
* Generate language files.
*
* @param object $module The module object.
*
* @return array The language files.
* @since 5.1.2
*/
protected function generateLanguageFiles(object $module): array
{
$languageFiles = [];
if (!$this->language->exist($module->key))
{
return $languageFiles;
}
$langContent = $this->language->getTarget($module->key);
$this->event->trigger('jcb_ce_onBeforeBuildModuleLang', [&$module, &$langContent]);
$values = array_unique($langContent);
$this->buildermultilingual->set('modules', $this->multilingual->get($values));
$langTag = $this->config->get('lang_tag', 'en-GB');
$this->languages->set("modules.{$langTag}.all", $langContent);
$this->language->setTarget($module->key, null);
$this->set->execute($values, $module->guid, 'modules');
$this->purge->execute($values, $module->guid, 'modules');
$this->event->trigger('jcb_ce_onBeforeBuildModuleLangFiles', [&$module]);
if ($this->languages->IsArray('modules'))
{
foreach ($this->languages->get('modules') as $tag => $areas)
{
$tag = trim($tag);
foreach ($areas as $area => $languageStrings)
{
$fileName = "{$module->file_name}.ini";
$fileSysName = "{$module->file_name}.sys.ini";
$total = count($values);
if ($this->translation->check($tag, $languageStrings, $total, $fileName))
{
$lang = array_map(
fn($langString, $placeholder) => "{$placeholder}=\"{$langString}\"",
array_values($languageStrings),
array_keys($languageStrings)
);
$path = "{$module->folder_path}/language/{$tag}/";
if (!is_dir($path))
{
Folder::create($path);
$this->counter->folder++;
}
$this->file->write($path . $fileName, implode(PHP_EOL, $lang));
$this->file->write($path . $fileSysName, implode(PHP_EOL, $lang));
$this->counter->line += count($lang);
unset($lang);
$languageFiles[$tag] = $tag;
}
}
}
}
return $languageFiles;
}
}

View File

@@ -0,0 +1,114 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Architecture\JoomlaFour\Module;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ContentOne as Builder;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module\ProviderInterface;
/**
* Module Provider Class for Joomla 4
*
* @since 5.1.2
*/
final class Provider implements ProviderInterface
{
/**
* The Placeholder Class.
*
* @var Placeholder
* @since 5.1.2
*/
protected Placeholder $placeholder;
/**
* The ContentOne Class.
*
* @var Builder
* @since 5.1.2
*/
protected Builder $builder;
/**
* The Namespace Prefix
*
* @var string
* @since 5.1.2
*/
protected string $NamespacePrefix;
/**
* Constructor.
*
* @param Placeholder $placeholder The Placeholder Class.
* @param Builder $builder The Content One Class.
*
* @since 5.1.2
*/
public function __construct(Placeholder $placeholder, Builder $builder)
{
$this->placeholder = $placeholder;
$this->builder = $builder;
// set some global values
$this->NamespacePrefix = $this->placeholder->get('NamespacePrefix');
}
/**
* Get the updated provider for the given module.
*
* @param object $module The module object containing the necessary data.
*
* @return string The provider content.
*
* @since 5.1.2
*/
public function get(object $module): string
{
$provider = [];
$provider[] = "/**";
$provider[] = " *" . Line::_(__Line__, __Class__) . " The {$module->official_name} module service provider";
$provider[] = " *";
$provider[] = " * @since 5.4.0";
$provider[] = " */";
$provider[] = "return new class () implements ServiceProviderInterface {";
$provider[] = Indent::_(1) . "/**";
$provider[] = Indent::_(1) . " *" . Line::_(__Line__, __Class__) . " Registers the service provider with a DI container.";
$provider[] = Indent::_(1) . " *";
$provider[] = Indent::_(1) . " * @param Container \$container The DI container.";
$provider[] = Indent::_(1) . " *";
$provider[] = Indent::_(1) . " * @return void";
$provider[] = Indent::_(1) . " * @since 5.4.0";
$provider[] = Indent::_(1) . " */";
$provider[] = Indent::_(1) . "public function register(Container \$container)";
$provider[] = Indent::_(1) . "{";
$provider[] = Indent::_(2) . "\$container->registerServiceProvider(new ModuleDispatcherFactory('\\{$this->NamespacePrefix}\\Module\\{$module->namespace}'));";
if ($module->add_class_helper == 1 || $module->custom_get)
{
$provider[] = Indent::_(2) . "\$container->registerServiceProvider(new HelperFactory('\\{$this->NamespacePrefix}\\Module\\{$module->namespace}\\{$module->target_client_namespace}\\Helper'));";
}
$provider[] = '';
$provider[] = Indent::_(2) . "\$container->registerServiceProvider(new Module());";
$provider[] = Indent::_(1) . "}";
$provider[] = "};";
return $this->placeholder->update(
implode(PHP_EOL, $provider). PHP_EOL,
$this->builder->allActive()
);
}
}

View File

@@ -0,0 +1,242 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Architecture\JoomlaFour\Module;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\HeaderInterface as Header;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Customcode\DispenserInterface as Dispenser;
use VDM\Joomla\Componentbuilder\Compiler\Builder\TemplateData;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ContentOne;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ContentMulti;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module\TemplateInterface;
/**
* Module Template Joomla 4
*
* @since 5.1.2
*/
final class Template implements TemplateInterface
{
/**
* The Config Class.
*
* @var Config
* @since 5.1.2
*/
protected Config $config;
/**
* The Header Class.
*
* @var Header
* @since 5.1.2
*/
protected Header $header;
/**
* The Dispenser Class.
*
* @var Dispenser
* @since 5.1.2
*/
protected Dispenser $dispenser;
/**
* The TemplateData Class.
*
* @var TemplateData
* @since 5.1.2
*/
protected TemplateData $templatedata;
/**
* The Placeholder Class.
*
* @var Placeholder
* @since 5.1.2
*/
protected Placeholder $placeholder;
/**
* The ContentOne Class.
*
* @var ContentOne
* @since 5.1.2
*/
protected ContentOne $contentone;
/**
* The ContentMulti Class.
*
* @var ContentMulti
* @since 5.1.2
*/
protected ContentMulti $contentmulti;
/**
* Constructor.
*
* @param Config $config The Config Class.
* @param Header $header The Header Class.
* @param Dispenser $dispenser The Dispenser Class.
* @param TemplateData $templatedata The TemplateData Class.
* @param Placeholder $placeholder The Placeholder Class.
* @param ContentOne $contentone The ContentOne Class.
* @param ContentMulti $contentmulti The ContentMulti Class.
*
* @since 5.1.2
*/
public function __construct(Config $config, Header $header, Dispenser $dispenser,
TemplateData $templatedata, Placeholder $placeholder,
ContentOne $contentone, ContentMulti $contentmulti)
{
$this->config = $config;
$this->header = $header;
$this->dispenser = $dispenser;
$this->templatedata = $templatedata;
$this->placeholder = $placeholder;
$this->contentone = $contentone;
$this->contentmulti = $contentmulti;
}
/**
* Get the updated placeholder default template content for the given module.
*
* @param object $module The module object containing the necessary data.
* @param string $key The dispenser key for this given module.
*
* @return string The updated placeholder content.
* @since 5.1.2
*/
public function default(object $module, string $key): string
{
// add any css from the fields
$default = $this->dispenser->get(
'css_views',
$key,
PHP_EOL . '<style>',
'',
true,
null,
PHP_EOL . '</style>' . PHP_EOL
);
// now add the body
$body = trim((string) ($module->default ?? ''));
if (!empty($body))
{
$default .= PHP_EOL . $body . PHP_EOL;
}
// add any JavaScript from the fields
$default .= $this->dispenser->get(
'views_footer',
$key,
PHP_EOL . '<script type="text/javascript">',
'',
true,
null,
PHP_EOL . '</script>' . PHP_EOL
);
// return the default content for the model default area
return $this->placeholder->update(
$default,
$this->contentone->allActive()
);
}
/**
* Get the updated placeholder default header template content for the given module.
*
* @param object $module The module object containing the necessary data.
*
* @return string The updated placeholder content.
* @since 5.1.2
*/
public function header(object $module): string
{
// first add the header
$add_default_header = (int) ($module->add_default_header ?? 0);
$default = $add_default_header === 1 ? trim((string) ($module->default_header ?? '')) : '';
if (empty($default))
{
return '';
}
// return the header for the model default area
return PHP_EOL . PHP_EOL . $this->placeholder->update($default, $this->contentone->allActive());
}
/**
* Get the updated placeholder extra template content for the given module.
*
* @param object $module The module object containing the necessary data.
*
* @return void
* @since 5.1.2
*/
public function extra(object $module): void
{
// Build the data key and fetch template data once
$data = $this->templatedata->get($module->key . '.' . $module->code_name);
// Nothing to do if there's no data
if (!is_array($data) || $data === [])
{
return;
}
// Cache these to avoid repeated calls
$activePlaceholders = $this->contentone->allActive();
// --- HEADER (text) ---
$header = (string) ($this->header->get('module.extra.template.header', $module->class_name) ?? '');
if ($header !== '')
{
$header = PHP_EOL . PHP_EOL . $this->placeholder->update($header, $activePlaceholders);
}
foreach ($data as $template => $item)
{
$target = StringHelper::safe("MODDEFAULT_HEADER_{$template}", 'U');
$key = $module->key . '|' . $target;
$this->contentmulti->set($key, $header);
// --- HEADER CODE (php_view) ---
$phpView = trim((string) ($item['php_view'] ?? ''));
$headerCode = ($phpView === '')
? ''
: PHP_EOL . $this->placeholder->update($phpView, $activePlaceholders);
$target = StringHelper::safe("MODDEFAULT_HEADER_CODE_{$template}", 'U');
$key = $module->key . '|' . $target;
$this->contentmulti->set($key, $headerCode);
// --- BODY (html) ---
$html = (string) ($item['html'] ?? '');
$body = ($html === '')
? PHP_EOL
: PHP_EOL . $this->placeholder->update($html, $activePlaceholders);
$target = StringHelper::safe("MODDEFAULT_{$template}", 'U');
$key = $module->key . '|' . $target;
$this->contentmulti->set($key, $body);
}
}
}

View File

@@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>

View File

@@ -435,8 +435,9 @@ final class MainXML implements MainXMLInterface
if ($addComponentPath)
{
$xml .= PHP_EOL . Indent::_(3) . 'addruleprefix="' . $this->config->namespace_prefix . '\Component\\' . $this->contentone->get('ComponentNamespace') . '\Administrator\Rule"';
$xml .= PHP_EOL . Indent::_(3) . 'addfieldprefix="' . $this->config->namespace_prefix . '\Component\\' . $this->contentone->get('ComponentNamespace') . '\Administrator\Field">';
$namespace = $this->config->namespace_prefix . '\\Component\\' . $this->contentone->get('ComponentNamespace') . '\\Administrator';
$xml .= PHP_EOL . Indent::_(3) . "addruleprefix=\"{$namespace}\\Rule\"";
$xml .= PHP_EOL . Indent::_(3) . "addfieldprefix=\"{$namespace}\\Field\">";
$xml .= PHP_EOL . Indent::_(1) . '>';
}

View File

@@ -0,0 +1,108 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Architecture\JoomlaThree\Model;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Model\CheckInNowInterface;
/**
* Check In Now Method for Joomla 3
*
* @since 5.1.2
*/
final class CheckInNow implements CheckInNowInterface
{
/**
* Get the generated call snippet that invokes the check-in method.
*
* @return string The code that calls the generated method.
* @since 5.1.2
*/
public function getCall(): string
{
$call = PHP_EOL . Indent::_(2) . "//" . Line::_(__Line__, __Class__) . " Check in items";
$call .= PHP_EOL . Indent::_(2) . "\$this->checkInNow();" . PHP_EOL;
return $call;
}
/**
* Build the full `checkInNow()` method code for the given view/table.
*
* @param string $view The view/table suffix (e.g. 'items').
* @param string $component The component name (without 'com_').
*
* @return string The full method code as a string.
* @since 5.1.2
*/
public function getMethod($view, $component): string
{
$checkin = PHP_EOL . PHP_EOL . Indent::_(1) . "/**";
$checkin .= PHP_EOL . Indent::_(1) . " * Build an SQL query to check in all items left checked out longer then a set time.";
$checkin .= PHP_EOL . Indent::_(1) . " *";
$checkin .= PHP_EOL . Indent::_(1) . " * @return void";
$checkin .= PHP_EOL . Indent::_(1) . " * @since 3.2.0";
$checkin .= PHP_EOL . Indent::_(1) . " */";
$checkin .= PHP_EOL . Indent::_(1) . "protected function checkInNow(): void";
$checkin .= PHP_EOL . Indent::_(1) . "{";
$checkin .= PHP_EOL . Indent::_(2) . "//" . Line::_(__Line__, __Class__) . " Get set check in time";
$checkin .= PHP_EOL . Indent::_(2) . "\$time = Joomla__"."_aeb8e463_291f_4445_9ac4_34b637c12dbd___Power::getParams('com_" . $component . "')->get('check_in');";
$checkin .= PHP_EOL . PHP_EOL . Indent::_(2) . "if (\$time)";
$checkin .= PHP_EOL . Indent::_(2) . "{";
$checkin .= PHP_EOL . Indent::_(3) . "//" . Line::_(__LINE__,__CLASS__) . " Get a db connection.";
$checkin .= PHP_EOL . Indent::_(3) . "\$db = Joomla__"."_39403062_84fb_46e0_bac4_0023f766e827___Power::getDbo();";
$checkin .= PHP_EOL . Indent::_(3) . "//" . Line::_(__Line__, __Class__) . " Reset query.";
$checkin .= PHP_EOL . Indent::_(3) . "\$query = \$db->getQuery(true);";
$checkin .= PHP_EOL . Indent::_(3) . "\$query->select('*');";
$checkin .= PHP_EOL . Indent::_(3) . "\$query->from(\$db->quoteName('#__" . $component . "_" . $view . "'));";
$checkin .= PHP_EOL . Indent::_(3) . "//" . Line::_(__Line__, __Class__) . " Only select items that are checked out.";
$checkin .= PHP_EOL . Indent::_(3) . "\$query->where(\$db->quoteName('checked_out') . ' != 0');";
Indent::_(3) . "//" . Line::_(__Line__, __Class__) . " Query only to see if we have a rows";
$checkin .= PHP_EOL . Indent::_(3) . "\$db->setQuery(\$query, 0, 1);";
$checkin .= PHP_EOL . Indent::_(3) . "\$db->execute();";
$checkin .= PHP_EOL . Indent::_(3) . "if (\$db->getNumRows())";
$checkin .= PHP_EOL . Indent::_(3) . "{";
$checkin .= PHP_EOL . Indent::_(4) . "//" . Line::_(__Line__, __Class__) . " Get target date in the past.";
$checkin .= PHP_EOL . Indent::_(4) . "\$date = Joomla__"."_39403062_84fb_46e0_bac4_0023f766e827___Power::getDate()->modify(\$time)->toSql();";
$checkin .= PHP_EOL . Indent::_(4) . "//" . Line::_(__Line__, __Class__) . " Reset query.";
$checkin .= PHP_EOL . Indent::_(4) . "\$query = \$db->getQuery(true);";
$checkin .= PHP_EOL . PHP_EOL . Indent::_(4) . "//" . Line::_(__LINE__,__CLASS__) . " Fields to update.";
$checkin .= PHP_EOL . Indent::_(4) . "\$fields = [";
$checkin .= PHP_EOL . Indent::_(5) . "\$db->quoteName('checked_out_time') . ' = ' . \$db->quote('0000-00-00 00:00:00'),";
$checkin .= PHP_EOL . Indent::_(5) . "\$db->quoteName('checked_out') . ' = 0'";
$checkin .= PHP_EOL . Indent::_(4) . "];";
$checkin .= PHP_EOL . PHP_EOL . Indent::_(4) . "//" . Line::_(__LINE__,__CLASS__) . " Conditions for which records should be updated.";
$checkin .= PHP_EOL . Indent::_(4) . "\$conditions = [";
$checkin .= PHP_EOL . Indent::_(5) . "\$db->quoteName('checked_out') . ' != 0', ";
$checkin .= PHP_EOL . Indent::_(5) . "\$db->quoteName('checked_out_time') . ' < ' . \$db->quote(\$date)";
$checkin .= PHP_EOL . Indent::_(4) . "];";
$checkin .= PHP_EOL . PHP_EOL . Indent::_(4) . "//" . Line::_(__LINE__,__CLASS__) . " Check table.";
$checkin .= PHP_EOL . Indent::_(4) . "\$query->update(\$db->quoteName('#__" . $component . "_" . $view . "'))->set(\$fields)->where(\$conditions); ";
$checkin .= PHP_EOL . PHP_EOL . Indent::_(4) . "\$db->setQuery(\$query);";
$checkin .= PHP_EOL . PHP_EOL . Indent::_(4) . "\$db->execute();";
$checkin .= PHP_EOL . Indent::_(3) . "}";
$checkin .= PHP_EOL . Indent::_(2) . "}";
$checkin .= PHP_EOL . Indent::_(1) . "}";
return $checkin;
}
}

View File

@@ -0,0 +1,108 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Architecture\JoomlaThree\Module;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ContentOne as Builder;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module\LibraryInterface as Library;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Placefix;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module\DispatcherInterface;
/**
* Module Dispatcher Class for Joomla 3
*
* @since 5.1.2
*/
final class Dispatcher implements DispatcherInterface
{
/**
* The Placeholder Class.
*
* @var Placeholder
* @since 5.1.2
*/
protected Placeholder $placeholder;
/**
* The ContentOne Class.
*
* @var Builder
* @since 5.1.2
*/
protected Builder $builder;
/**
* The Library Class.
*
* @var Library
* @since 5.1.2
*/
protected Library $library;
/**
* Constructor.
*
* @param Placeholder $placeholder The Placeholder Class.
* @param Builder $builder The ContentOne Class.
* @param Library $library The Library Class.
*
* @since 5.1.2
*/
public function __construct(Placeholder $placeholder, Builder $builder,
Library $library)
{
$this->placeholder = $placeholder;
$this->builder = $builder;
$this->library = $library;
}
/**
* Get the updated placeholder content for the given module.
*
* @param object $module The module object containing the necessary data.
*
* @return string The updated placeholder content.
* @since 5.1.2
*/
public function get(object $module): string
{
$Helper = $this->builder->get('Component') . 'Helper';
$component = $this->builder->get('component');
$_helper = '';
$libraries = [Placefix::_('MOD_LIBRARIES') => $this->library->get($module)];
$code = $this->placeholder->update($module->mod_code, $libraries);
if (strpos((string) $code, $Helper . '::') !== false
&& strpos(
(string) $code,
"/components/com_" . $component . "/helpers/" . $component
. ".php"
) === false)
{
$_helper = '//' . Line::_(__Line__, __Class__)
. ' Include the component helper functions only once';
$_helper .= PHP_EOL . "JLoader::register('" . $Helper
. "', JPATH_ADMINISTRATOR . '/components/com_" . $component
. "/helpers/" . $component . ".php');";
}
return $this->placeholder->update(
$_helper . PHP_EOL . $code . PHP_EOL,
$this->builder->allActive()
);
}
}

View File

@@ -0,0 +1,98 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Architecture\JoomlaThree\Module;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ContentOne;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module\HelperInterface;
/**
* Module Helper Code Joomla 3
*
* @since 5.1.2
*/
final class Helper implements HelperInterface
{
/**
* The Placeholder Class.
*
* @var Placeholder
* @since 5.1.2
*/
protected Placeholder $placeholder;
/**
* The ContentOne Class.
*
* @var ContentOne
* @since 5.1.2
*/
protected ContentOne $contentone;
/**
* Constructor.
*
* @param Placeholder $placeholder The Placeholder Class.
* @param ContentOne $contentone The ContentOne Class.
*
* @since 5.1.2
*/
public function __construct(Placeholder $placeholder, ContentOne $contentone)
{
$this->placeholder = $placeholder;
$this->contentone = $contentone;
}
/**
* Get Module Helper Class code
*
* @param object $module The module object
*
* @return string The helper class code
* @since 5.1.2
*/
public function get(object $module): string
{
$type = trim((string) ($module->class_helper_type ?? 'class'));
$name = trim((string) ($module->class_helper_name ?? 'Helper'));
$body = (string) ($module->class_helper_code ?? '');
$code = PHP_EOL . $type . ' ' . $name . PHP_EOL . '{' . PHP_EOL . $body . PHP_EOL . '}' . PHP_EOL;
return $this->placeholder->update($code, $this->contentone->allActive());
}
/**
* Get Module Helper Header code
*
* @param object $module The module object
*
* @return string The helper header code
* @since 5.1.2
*/
public function header(object $module): string
{
$code = (string) trim($module->class_helper_header ?? '');
if ($code === '')
{
return '';
}
return $this->placeholder->update(
PHP_EOL . $code, $this->contentone->allActive()
);
}
}

View File

@@ -0,0 +1,153 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Architecture\JoomlaThree\Module;
use VDM\Joomla\Componentbuilder\Compiler\Builder\LibraryManager;
use VDM\Joomla\Componentbuilder\Compiler\Library\Document;
use VDM\Joomla\Componentbuilder\Compiler\Registry;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ContentOne;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module\LibraryInterface;
/**
* Module Library Joomla 3
*
* @since 5.1.2
*/
final class Library implements LibraryInterface
{
/**
* The LibraryManager Class.
*
* @var LibraryManager
* @since 5.1.2
*/
protected LibraryManager $librarymanager;
/**
* The Document Class.
*
* @var Document
* @since 5.1.2
*/
protected Document $document;
/**
* The Registry Class.
*
* @var Registry
* @since 5.1.2
*/
protected Registry $registry;
/**
* The Placeholder Class.
*
* @var Placeholder
* @since 5.1.2
*/
protected Placeholder $placeholder;
/**
* The ContentOne Class.
*
* @var ContentOne
* @since 5.1.2
*/
protected ContentOne $contentone;
/**
* Constructor.
*
* @param LibraryManager $librarymanager The LibraryManager Class.
* @param Document $document The Document Class.
* @param Registry $registry The Registry Class.
* @param Placeholder $placeholder The Placeholder Class.
* @param ContentOne $contentone The ContentOne Class.
*
* @since 5.1.2
*/
public function __construct(LibraryManager $librarymanager, Document $document,
Registry $registry, Placeholder $placeholder,
ContentOne $contentone)
{
$this->librarymanager = $librarymanager;
$this->document = $document;
$this->registry = $registry;
$this->placeholder = $placeholder;
$this->contentone = $contentone;
}
/**
* Get the module's library loading code.
*
* @param object $module The module object
*
* @return string The generated code to load libraries into the document.
* @since 5.1.2
*/
public function get(object $module): string
{
$data = $this->librarymanager->get($module->key . '.' . $module->code_name);
if ($data === null)
{
return '';
}
$code = '// ' . Line::_(__LINE__, __CLASS__) . ' get the document object' . PHP_EOL;
$code .= '$document = Joomla__' . '_39403062_84fb_46e0_bac4_0023f766e827___Power::getDocument();';
$found = false;
foreach ($data as $id => $item)
{
$library = $this->registry->get("builder.libraries.{$id}");
if (!is_object($library))
{
continue;
}
if (!empty($library->document) && StringHelper::check($library->document))
{
$code .= PHP_EOL . $library->document;
$found = true;
}
elseif (isset($library->how))
{
$code .= $this->document->get($id);
$found = true;
}
}
if (!$found)
{
return '';
}
// Normalize and inject placeholders
$lines = explode(PHP_EOL, $code);
$trimmed = array_map('trim', $lines);
$normalized = str_replace('$this->document->', '$document->', implode(PHP_EOL, $trimmed));
return $this->placeholder->update(
$this->placeholder->update_($normalized),
$this->contentone->allActive()
);
}
}

View File

@@ -0,0 +1,612 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Architecture\JoomlaThree\Module;
use Joomla\Filesystem\Folder;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Language;
use VDM\Joomla\Componentbuilder\Compiler\Language\Set;
use VDM\Joomla\Componentbuilder\Compiler\Language\Purge;
use VDM\Joomla\Componentbuilder\Compiler\Language\Translation;
use VDM\Joomla\Componentbuilder\Compiler\Language\Multilingual;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\EventInterface as Event;
use VDM\Joomla\Componentbuilder\Compiler\Creator\FieldsetExtension;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ContentOne;
use VDM\Joomla\Componentbuilder\Compiler\Builder\Languages;
use VDM\Joomla\Componentbuilder\Compiler\Builder\Multilingual as BuilderMultilingual;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Counter;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\File;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Componentbuilder\Interfaces\Architecture\Module\MainXMLInterface;
/**
* Joomla 3 Module Main XML Class
*
* @since 5.1.2
*/
final class MainXML implements MainXMLInterface
{
/**
* The Config Class.
*
* @var Config
* @since 5.1.2
*/
protected Config $config;
/**
* The Language Class.
*
* @var Language
* @since 5.1.2
*/
protected Language $language;
/**
* The Set Class.
*
* @var Set
* @since 5.1.2
*/
protected Set $set;
/**
* The Purge Class.
*
* @var Purge
* @since 5.1.2
*/
protected Purge $purge;
/**
* The Translation Class.
*
* @var Translation
* @since 5.1.2
*/
protected Translation $translation;
/**
* The Multilingual Class.
*
* @var Multilingual
* @since 5.1.2
*/
protected Multilingual $multilingual;
/**
* The EventInterface Class.
*
* @var Event
* @since 5.1.2
*/
protected Event $event;
/**
* The FieldsetExtension Class.
*
* @var FieldsetExtension
* @since 5.1.2
*/
protected FieldsetExtension $fieldsetextension;
/**
* The ContentOne Class.
*
* @var ContentOne
* @since 5.1.2
*/
protected ContentOne $contentone;
/**
* The Languages Class.
*
* @var Languages
* @since 5.1.2
*/
protected Languages $languages;
/**
* The Multilingual Class.
*
* @var BuilderMultilingual
* @since 5.1.2
*/
protected BuilderMultilingual $buildermultilingual;
/**
* The Counter Class.
*
* @var Counter
* @since 5.1.2
*/
protected Counter $counter;
/**
* The File Class.
*
* @var File
* @since 5.1.2
*/
protected File $file;
/**
* Constructor.
*
* @param Config $config The Config Class.
* @param Language $language The Language Class.
* @param Set $set The Set Class.
* @param Purge $purge The Purge Class.
* @param Translation $translation The Translation Class.
* @param Multilingual $multilingual The Multilingual Class.
* @param Event $event The EventInterface Class.
* @param FieldsetExtension $fieldsetextension The FieldsetExtension Class.
* @param ContentOne $contentone The ContentOne Class.
* @param Languages $languages The Languages Class.
* @param BuilderMultilingual $buildermultilingual The Multilingual Class.
* @param Counter $counter The Counter Class.
* @param File $file The File Class.
*
* @since 5.1.2
*/
public function __construct(Config $config, Language $language, Set $set, Purge $purge,
Translation $translation, Multilingual $multilingual,
Event $event, FieldsetExtension $fieldsetextension,
ContentOne $contentone, Languages $languages,
BuilderMultilingual $buildermultilingual,
Counter $counter, File $file)
{
$this->config = $config;
$this->language = $language;
$this->set = $set;
$this->purge = $purge;
$this->translation = $translation;
$this->multilingual = $multilingual;
$this->event = $event;
$this->fieldsetextension = $fieldsetextension;
$this->contentone = $contentone;
$this->languages = $languages;
$this->buildermultilingual = $buildermultilingual;
$this->counter = $counter;
$this->file = $file;
}
/**
* Generates the main XML for the module.
*
* @param object $module The module object.
*
* @return string The generated XML.
* @since 5.1.2
*/
public function get(object $module): string
{
$config_fields = $this->buildConfigFields($module);
$add_component_path = $this->shouldAddComponentPath($module);
$language_files = $this->generateLanguageFiles($module);
$xml = $this->generateScriptAndSqlXml($module);
$xml .= $this->generateLanguageXml($module, $language_files);
$xml .= $this->generateFileXml($module, $language_files);
$xml .= $this->generateConfigXml($module, $config_fields, $add_component_path);
$xml .= $this->generateUpdateServerXml($module);
return $xml;
}
/**
* Build configuration fields XML.
*
* @param object $module The module object.
*
* @return array The configuration fields.
* @since 5.1.2
*/
protected function buildConfigFields(object $module): array
{
$configFields = [];
if (!isset($module->config_fields) || !ArrayHelper::check($module->config_fields))
{
return $configFields;
}
$dbKey = 'yyy';
$addScriptsField = true;
foreach ($module->config_fields as $fieldName => $fieldsets)
{
foreach ($fieldsets as $fieldset => $fields)
{
$xmlFields = $this->fieldsetextension->get($module, $fields, $dbKey);
if ($addScriptsField && $module->add_scripts_field)
{
$xmlFields .= PHP_EOL . Indent::_(2) . '<field type="modadminvvvvvvvdm" />';
$addScriptsField = false;
}
if (isset($xmlFields) && StringHelper::check($xmlFields))
{
$configFields["{$fieldName}{$fieldset}"] = $xmlFields;
}
$dbKey++;
}
}
return $configFields;
}
/**
* Determine if the component path should be added.
*
* @param object $module The module object.
*
* @return bool True if the component path should be added, false otherwise.
* @since 5.1.2
*/
protected function shouldAddComponentPath(object $module): bool
{
if (!isset($module->config_fields) || !ArrayHelper::check($module->config_fields) ||
!isset($module->fieldsets_paths) || !ArrayHelper::check($module->fieldsets_paths))
{
return false;
}
foreach ($module->config_fields as $fieldName => $fieldsets)
{
foreach ($fieldsets as $fieldset => $fields)
{
if (isset($module->fieldsets_paths["{$fieldName}{$fieldset}"]) &&
$module->fieldsets_paths["{$fieldName}{$fieldset}"] == 1)
{
return true;
}
}
}
return false;
}
/**
* Generate XML for script and SQL files.
*
* @param object $module The module object.
*
* @return string The XML for script and SQL files.
* @since 5.1.2
*/
protected function generateScriptAndSqlXml(object $module): string
{
$xml = '';
if ($module->add_install_script)
{
$xml .= PHP_EOL . PHP_EOL . Indent::_(1) . '<!--' . Line::_(
__LINE__,__CLASS__
) . ' Scripts to run on installation -->';
$xml .= PHP_EOL . Indent::_(1) . '<scriptfile>script.php</scriptfile>';
}
if ($module->add_sql)
{
$xml .= PHP_EOL . PHP_EOL . Indent::_(1) . '<!--' . Line::_(
__LINE__,__CLASS__
) . ' Runs on install -->';
$xml .= PHP_EOL . Indent::_(1) . '<install>';
$xml .= PHP_EOL . Indent::_(2) . '<sql>';
$xml .= PHP_EOL . Indent::_(3) . '<file driver="mysql" charset="utf8">sql/mysql/install.sql</file>';
$xml .= PHP_EOL . Indent::_(2) . '</sql>';
$xml .= PHP_EOL . Indent::_(1) . '</install>';
}
if ($module->add_sql_uninstall)
{
$xml .= PHP_EOL . PHP_EOL . Indent::_(1) . '<!--' . Line::_(
__LINE__,__CLASS__
) . ' Runs on uninstall -->';
$xml .= PHP_EOL . Indent::_(1) . '<uninstall>';
$xml .= PHP_EOL . Indent::_(2) . '<sql>';
$xml .= PHP_EOL . Indent::_(3) . '<file driver="mysql" charset="utf8">sql/mysql/uninstall.sql</file>';
$xml .= PHP_EOL . Indent::_(2) . '</sql>';
$xml .= PHP_EOL . Indent::_(1) . '</uninstall>';
}
return $xml;
}
/**
* Generate XML for language files.
*
* @param object $module The module object.
* @param array $languageFiles The language files.
*
* @return string The XML for language files.
* @since 5.1.2
*/
protected function generateLanguageXml(object $module, array $languageFiles): string
{
$xml = '';
if (ArrayHelper::check($languageFiles))
{
$xml .= PHP_EOL . PHP_EOL . Indent::_(1) . '<!--' . Line::_(
__LINE__, __CLASS__
) . ' Language files -->';
$xml .= PHP_EOL . Indent::_(1) . '<languages folder="language">';
foreach ($languageFiles as $tag)
{
$xml .= PHP_EOL . Indent::_(2) . "<language tag=\"{$tag}\">{$tag}/{$tag}.{$module->file_name}.ini</language>";
$xml .= PHP_EOL . Indent::_(2) . "<language tag=\"{$tag}\">{$tag}/{$tag}.{$module->file_name}.sys.ini</language>";
}
$xml .= PHP_EOL . Indent::_(1) . '</languages>';
}
return $xml;
}
/**
* Generate the XML for the files.
*
* @param object $module The module object.
* @param array $languageFiles The language files.
*
* @return string The XML for the files.
* @since 5.1.2
*/
protected function generateFileXml(object $module, array $languageFiles): string
{
$files = Folder::files($module->folder_path);
$folders = Folder::folders($module->folder_path);
$ignore = ['sql', 'language', 'script.php', "{$module->file_name}.xml", "{$module->file_name}.php"];
$xml = PHP_EOL . PHP_EOL . Indent::_(1) . '<!--' . Line::_(
__LINE__, __CLASS__
) . ' Module files -->';
$xml .= PHP_EOL . Indent::_(1) . '<files>';
$xml .= PHP_EOL . Indent::_(2) . "<filename module=\"{$module->file_name}\">{$module->file_name}.php</filename>";
foreach ($files as $file)
{
if (!in_array($file, $ignore))
{
$xml .= PHP_EOL . Indent::_(2) . "<filename>{$file}</filename>";
}
}
if (!empty($languageFiles))
{
$xml .= PHP_EOL . Indent::_(2) . '<folder>language</folder>';
}
if ($module->add_sql || $module->add_sql_uninstall)
{
$xml .= PHP_EOL . Indent::_(2) . '<folder>sql</folder>';
}
foreach ($folders as $folder)
{
if (!in_array($folder, $ignore))
{
$xml .= PHP_EOL . Indent::_(2) . "<folder>{$folder}</folder>";
}
}
$xml .= PHP_EOL . Indent::_(1) . '</files>';
return $xml;
}
/**
* Generate XML for configuration fields.
*
* @param object $module The module object.
* @param array $configFields The configuration fields.
* @param bool $addComponentPath Whether to add the component path.
*
* @return string The XML for configuration fields.
* @since 5.1.2
*/
protected function generateConfigXml(object $module, array $configFields, bool $addComponentPath): string
{
if (!isset($module->config_fields) || !ArrayHelper::check($configFields))
{
return '';
}
$xml = PHP_EOL . PHP_EOL . Indent::_(1) . '<!--' . Line::_(
__LINE__, __CLASS__
) . ' Config parameters -->';
$xml .= $addComponentPath ? PHP_EOL . Indent::_(1) . '<config' : PHP_EOL . Indent::_(1) . '<config>';
if ($addComponentPath)
{
$xml .= PHP_EOL . Indent::_(2)
. 'addrulepath="/administrator/components/com_'
. $this->config->component_code_name . '/models/rules"';
$xml .= PHP_EOL . Indent::_(2)
. 'addfieldpath="/administrator/components/com_'
. $this->config->component_code_name . '/models/fields"';
$xml .= PHP_EOL . Indent::_(1) . '>';
}
foreach ($module->config_fields as $fieldName => $fieldsets)
{
$xml .= PHP_EOL . Indent::_(1) . "<fields name=\"{$fieldName}\">";
foreach ($fieldsets as $fieldset => $fields)
{
$label = $module->fieldsets_label["{$fieldName}{$fieldset}"] ?? $fieldset;
// Add path to module rules and custom fields if required
if (isset($module->fieldsets_paths["{$fieldName}{$fieldset}"]) &&
in_array($module->fieldsets_paths["{$fieldName}{$fieldset}"], [2, 3]))
{
if ($module->target === 2)
{
$module->add_rule_path["{$fieldName}{$fieldset}"] ??= "/administrator/modules/{$module->file_name}/rules";
$module->add_field_path["{$fieldName}{$fieldset}"] ??= "/administrator/modules/{$module->file_name}/fields";
}
else
{
$module->add_rule_path["{$fieldName}{$fieldset}"] ??= "/modules/{$module->file_name}/rules";
$module->add_field_path["{$fieldName}{$fieldset}"] ??= "/modules/{$module->file_name}/fields";
}
}
if (isset($module->add_rule_path["{$fieldName}{$fieldset}"]) || isset($module->add_field_path["{$fieldName}{$fieldset}"]))
{
$xml .= PHP_EOL . Indent::_(1) . '<!--' . Line::_(__LINE__, __CLASS__) . " default paths of {$fieldset} fieldset points to the module -->";
$xml .= PHP_EOL . Indent::_(1) . "<fieldset name=\"{$fieldset}\" label=\"{$label}\"";
if (isset($module->add_rule_path["{$fieldName}{$fieldset}"]))
{
$xml .= PHP_EOL . Indent::_(2) . "addrulepath=\"{$module->add_rule_path["{$fieldName}{$fieldset}"]}\"";
}
if (isset($module->add_field_path["{$fieldName}{$fieldset}"]))
{
$xml .= PHP_EOL . Indent::_(2) . "addfieldpath=\"{$module->add_field_path["{$fieldName}{$fieldset}"]}\"";
}
$xml .= PHP_EOL . Indent::_(1) . '>';
}
else
{
$xml .= PHP_EOL . Indent::_(1) . "<fieldset name=\"{$fieldset}\" label=\"{$label}\">";
}
if (isset($configFields["{$fieldName}{$fieldset}"]))
{
$xml .= $configFields["{$fieldName}{$fieldset}"];
}
$xml .= PHP_EOL . Indent::_(1) . '</fieldset>';
}
$xml .= PHP_EOL . Indent::_(1) . '</fields>';
}
$xml .= PHP_EOL . Indent::_(1) . '</config>';
return $xml;
}
/**
* Generate XML for update servers.
*
* @param object $module The module object.
*
* @return string The XML for update servers.
* @since 5.1.2
*/
protected function generateUpdateServerXml(object $module): string
{
$xml = '';
if ($module->add_update_server)
{
$xml .= PHP_EOL . PHP_EOL . Indent::_(1) . '<!--' . Line::_(
__LINE__, __CLASS__
) . ' Update servers -->';
$xml .= PHP_EOL . Indent::_(1) . '<updateservers>';
$xml .= PHP_EOL . Indent::_(2) . "<server type=\"extension\" priority=\"1\" name=\"{$module->official_name}\">{$module->update_server_url}</server>";
$xml .= PHP_EOL . Indent::_(1) . '</updateservers>';
}
return $xml;
}
/**
* Generate language files.
*
* @param object $module The module object.
*
* @return array The language files.
* @since 5.1.2
*/
protected function generateLanguageFiles(object $module): array
{
$languageFiles = [];
if (!$this->language->exist($module->key))
{
return $languageFiles;
}
$langContent = $this->language->getTarget($module->key);
$this->event->trigger('jcb_ce_onBeforeBuildModuleLang', [&$module, &$langContent]);
$values = array_unique($langContent);
$this->buildermultilingual->set('modules', $this->multilingual->get($values));
$langTag = $this->config->get('lang_tag', 'en-GB');
$this->languages->set("modules.{$langTag}.all", $langContent);
$this->language->setTarget($module->key, null);
$this->set->execute($values, $module->guid, 'modules');
$this->purge->execute($values, $module->guid, 'modules');
$this->event->trigger('jcb_ce_onBeforeBuildModuleLangFiles', [&$module]);
if ($this->languages->IsArray('modules'))
{
foreach ($this->languages->get('modules') as $tag => $areas)
{
$tag = trim($tag);
foreach ($areas as $area => $languageStrings)
{
$fileName = "{$tag}.{$module->file_name}.ini";
$total = count($values);
if ($this->translation->check($tag, $languageStrings, $total, $fileName))
{
$lang = array_map(
fn($langString, $placeholder) => "{$placeholder}=\"{$langString}\"",
array_values($languageStrings),
array_keys($languageStrings)
);
$path = "{$module->folder_path}/language/{$tag}/";
if (!is_dir($path))
{
Folder::create($path);
$this->counter->folder++;
}
$this->file->write($path . $fileName, implode(PHP_EOL, $lang));
$this->file->write(
$path . "{$tag}.{$module->file_name}.sys.ini",
implode(PHP_EOL, $lang)
);
$this->counter->line += count($lang);
unset($lang);
$languageFiles[$tag] = $tag;
}
}
}
}
return $languageFiles;
}
}

View File

@@ -0,0 +1,71 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Architecture\JoomlaThree\Module;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ContentOne as Builder;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module\ProviderInterface;
/**
* Module Provider Class for Joomla 3
*
* @since 5.1.2
*/
final class Provider implements ProviderInterface
{
/**
* The Placeholder Class.
*
* @var Placeholder
* @since 5.1.2
*/
protected Placeholder $placeholder;
/**
* The ContentOne Class.
*
* @var Builder
* @since 5.1.2
*/
protected Builder $builder;
/**
* Constructor.
*
* @param Placeholder $placeholder The Placeholder Class.
* @param Builder $builder The Content One Class.
*
* @since 5.1.2
*/
public function __construct(Placeholder $placeholder, Builder $builder)
{
$this->placeholder = $placeholder;
$this->builder = $builder;
}
/**
* Get the updated provider for the given module.
*
* @param object $module The module object containing the necessary data.
*
* @return string The provider content.
*
* @since 5.1.2
*/
public function get(object $module): string
{
return ''; // no provider in Joomla 3
}
}

View File

@@ -0,0 +1,178 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Architecture\JoomlaThree\Module;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Customcode\DispenserInterface as Dispenser;
use VDM\Joomla\Componentbuilder\Compiler\Builder\TemplateData;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ContentOne;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ContentMulti;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module\TemplateInterface;
/**
* Module Template Joomla 3
*
* @since 5.1.2
*/
final class Template implements TemplateInterface
{
/**
* The Config Class.
*
* @var Config
* @since 5.1.2
*/
protected Config $config;
/**
* The Dispenser Class.
*
* @var Dispenser
* @since 5.1.2
*/
protected Dispenser $dispenser;
/**
* The TemplateData Class.
*
* @var TemplateData
* @since 5.1.2
*/
protected TemplateData $templatedata;
/**
* The Placeholder Class.
*
* @var Placeholder
* @since 5.1.2
*/
protected Placeholder $placeholder;
/**
* The ContentOne Class.
*
* @var ContentOne
* @since 5.1.2
*/
protected ContentOne $contentone;
/**
* The ContentMulti Class.
*
* @var ContentMulti
* @since 5.1.2
*/
protected ContentMulti $contentmulti;
/**
* Constructor.
*
* @param Config $config The Config Class.
* @param Dispenser $dispenser The Dispenser Class.
* @param TemplateData $templatedata The TemplateData Class.
* @param Placeholder $placeholder The Placeholder Class.
* @param ContentOne $contentone The ContentOne Class.
* @param ContentMulti $contentmulti The ContentMulti Class.
*
* @since 5.1.2
*/
public function __construct(Config $config, Dispenser $dispenser,
TemplateData $templatedata, Placeholder $placeholder,
ContentOne $contentone, ContentMulti $contentmulti)
{
$this->config = $config;
$this->dispenser = $dispenser;
$this->templatedata = $templatedata;
$this->placeholder = $placeholder;
$this->contentone = $contentone;
$this->contentmulti = $contentmulti;
}
/**
* Get the updated placeholder default template content for the given module.
*
* @param object $module The module object containing the necessary data.
* @param string $key The dispenser key for this given module.
*
* @return string The updated placeholder content.
* @since 5.1.2
*/
public function default(object $module, string $key): string
{
// first add the header
$default = PHP_EOL . ($module->default_header ?? '') . PHP_EOL . '?>';
// add any css from the fields
$default .= $this->dispenser->get(
'css_views',
$key,
PHP_EOL . '<style>',
'',
true,
null,
PHP_EOL . '</style>' . PHP_EOL
);
// now add the body
$default .= PHP_EOL . ($module->default ?? '') . PHP_EOL;
// add any JavaScript from the fields
$default .= $this->dispenser->get(
'views_footer',
$key,
PHP_EOL . '<script type="text/javascript">',
'',
true,
null,
PHP_EOL . '</script>' . PHP_EOL
);
// return the default content for the model default area
return $this->placeholder->update($default, $this->contentone->allActive());
}
/**
* Get the updated placeholder extra template content for the given module.
*
* @param object $module The module object containing the necessary data.
*
* @return void
* @since 5.1.2
*/
public function extra(object $module): void
{
$dataKey = $this->config->build_target . '.' . $module->code_name;
if (($data = $this->templatedata->get($dataKey)) !== null)
{
foreach ($data as $template => $item)
{
$header = $item['php_view'] ?? null;
$body = $item['html'] ?? '';
$default = ($header ? PHP_EOL . $header . PHP_EOL . '?>' : PHP_EOL . '?>') . PHP_EOL . $body;
$TARGET = StringHelper::safe("MODDEFAULT_{$template}", 'U');
$key = $module->key . '|' . $TARGET;
$this->contentmulti->set(
$key,
$this->placeholder->update($default, $this->contentone->allActive())
);
}
}
}
}

View File

@@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>

View File

@@ -0,0 +1,27 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Builder;
use VDM\Joomla\Interfaces\Registryinterface;
use VDM\Joomla\Abstraction\Registry;
/**
* Event Dispatcher Class
*
* @since 5.1.2
*/
final class EventDispatcher extends Registry implements Registryinterface
{
}

View File

@@ -12,7 +12,7 @@
namespace VDM\Joomla\Componentbuilder\Compiler\Component;
use Joomla\CMS\Factory;
use Joomla\Database\DatabaseInterface;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\EventInterface as Event;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
@@ -216,11 +216,12 @@ final class Data
protected Router $router;
/**
* Database object to query local DB
* Joomla Database Class.
*
* @since 3.2.0
* @var DatabaseInterface
* @since 5.1.2
**/
protected $db;
protected DatabaseInterface $db;
/**
* Constructor.
@@ -246,6 +247,7 @@ final class Data
* @param Joomlamodules $joomlamodules The Joomlamodules Class.
* @param Joomlaplugins $joomlaplugins The Joomlaplugins Class.
* @param Router $router The Router Class.
* @param DatabaseInterface $db The Joomla Database Class.
*
* @since 3.2.0
*/
@@ -258,7 +260,7 @@ final class Data
Sqltweaking $sqltweaking, Adminviews $adminviews,
Siteviews $siteviews, Customadminviews $customadminviews,
Updateserver $updateserver, Joomlamodules $joomlamodules,
Joomlaplugins $joomlaplugins, Router $router)
Joomlaplugins $joomlaplugins, Router $router, DatabaseInterface $db)
{
$this->config = $config;
$this->event = $event;
@@ -281,7 +283,7 @@ final class Data
$this->modules = $joomlamodules;
$this->plugins = $joomlaplugins;
$this->router = $router;
$this->db = Factory::getDbo();
$this->db = $db;
}
/**

View File

@@ -12,7 +12,7 @@
namespace VDM\Joomla\Componentbuilder\Compiler\Component;
use Joomla\CMS\Factory;
use Joomla\Database\DatabaseInterface;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Utilities\GetHelper;
use VDM\Joomla\Utilities\JsonHelper;
@@ -48,24 +48,25 @@ final class Placeholder implements PlaceholderInterface
protected $config;
/**
* Database object to query local DB
* Joomla Database Class.
*
* @since 3.2.0
* @var DatabaseInterface
* @since 5.1.2
**/
protected $db;
protected DatabaseInterface $db;
/**
* Constructor.
*
* @param Config $config The compiler config object.
* @param \JDatabaseDriver $db The Database Driver object.
* @param Config $config The compiler config object.
* @param DatabaseInterface $db The Joomla Database Class.
*
* @since 3.2.0
**/
public function __construct(?Config $config = null)
public function __construct(Config $config, DatabaseInterface $db)
{
$this->config = $config ?: Compiler::_('Config');
$this->db = Factory::getDbo();
$this->config = $config;
$this->db = $db;
}
/**

View File

@@ -12,7 +12,7 @@
namespace VDM\Joomla\Componentbuilder\Compiler;
use Joomla\CMS\Factory;
use Joomla\Database\DatabaseInterface;
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
@@ -129,11 +129,12 @@ class Customcode implements CustomcodeInterface
protected External $external;
/**
* Database object to query local DB
* Joomla Database Class.
*
* @since 3.2.0
* @var DatabaseInterface
* @since 5.1.2
**/
protected $db;
protected DatabaseInterface $db;
/**
* Constructor.
@@ -144,12 +145,12 @@ class Customcode implements CustomcodeInterface
* @param Power $power The compiler power extractor object.
* @param JoomlaPower $joomla The compiler joomla power extractor object.
* @param External $external The compiler external custom code object.
* @param \JDatabaseDriver $db The Database Driver object.
* @param DatabaseInterface $db The Joomla Database Class.
*
* @since 3.2.0
*/
public function __construct(Config $config, Placeholder $placeholder,
Extractor $extractor, Power $power, JoomlaPower $joomla, External $external)
Extractor $extractor, Power $power, JoomlaPower $joomla, External $external, DatabaseInterface $db)
{
$this->config = $config;
$this->placeholder = $placeholder;
@@ -157,7 +158,7 @@ class Customcode implements CustomcodeInterface
$this->power = $power;
$this->joomla = $joomla;
$this->external = $external;
$this->db = Factory::getDbo();
$this->db = $db;
}
/**
@@ -656,7 +657,6 @@ class Customcode implements CustomcodeInterface
}
return false;
}
}
}

View File

@@ -16,13 +16,13 @@ use Joomla\CMS\Factory;
use Joomla\CMS\User\User;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Filesystem\Path;
use Joomla\CMS\Filesystem\Path;
use Joomla\Database\DatabaseInterface;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Utilities\GetHelper;
use VDM\Joomla\Utilities\FileHelper;
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Customcode\ExternalInterface;
@@ -58,11 +58,12 @@ class External implements ExternalInterface
protected Placeholder $placeholder;
/**
* Database object to query local DB
* Joomla Database Class.
*
* @since 3.2.0
* @var DatabaseInterface
* @since 5.1.2
**/
protected $db;
protected DatabaseInterface $db;
/**
* User object
@@ -81,17 +82,19 @@ class External implements ExternalInterface
/**
* Constructor.
*
* @param Placeholder|null $placeholder The compiler placeholder object.
* @param Placeholder $placeholder The compiler placeholder object.
* @param DatabaseInterface $db The Joomla Database Class.
*
* @throws \Exception
* @since 3.2.0
*/
public function __construct(?Placeholder $placeholder = null)
public function __construct(Placeholder $placeholder, DatabaseInterface $db)
{
$this->placeholder = $placeholder ?: Compiler::_('Placeholder');
$this->db = Factory::getDbo();
$this->user = Factory::getUser();
$this->placeholder = $placeholder;
$this->db = $db;
$this->app = Factory::getApplication();
$this->user = $this->app->getIdentity();
}
/**
@@ -386,7 +389,6 @@ class External implements ExternalInterface
);
return '';
}
}
}

View File

@@ -14,13 +14,11 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Customcode;
use Joomla\CMS\Factory;
use Joomla\CMS\User\User;
use Joomla\Filesystem\Folder;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Version;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
use Joomla\CMS\Version;
use Joomla\Database\DatabaseInterface;
use Joomla\Filesystem\Folder;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Customcode\Gui;
use VDM\Joomla\Componentbuilder\Compiler\Customcode\Extractor\Paths;
@@ -28,6 +26,8 @@ use VDM\Joomla\Componentbuilder\Compiler\Placeholder\Reverse;
use VDM\Joomla\Componentbuilder\Compiler\Component\Placeholder;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Pathfix;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Placefix;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Customcode\ExtractorInterface;
@@ -196,6 +196,14 @@ class Extractor implements ExtractorInterface
**/
protected Pathfix $pathfix;
/**
* Joomla Database Class.
*
* @var DatabaseInterface
* @since 5.1.2
**/
protected DatabaseInterface $db;
/**
* Current User Object
*
@@ -203,13 +211,6 @@ class Extractor implements ExtractorInterface
**/
protected $user;
/**
* Database object to query local DB
*
* @since 3.2.0
**/
protected $db;
/**
* Database object to query local DB
*
@@ -220,28 +221,30 @@ class Extractor implements ExtractorInterface
/**
* Constructor.
*
* @param Config|null $config The compiler config object.
* @param Gui|null $gui The compiler customcode gui object.
* @param Paths|null $paths The compiler customcode extractor paths object.
* @param Reverse|null $reverse The compiler placeholder reverse object.
* @param Placeholder|null $placeholder The compiler component placeholder object.
* @param Pathfix|null $pathfix The compiler path fixing object.
* @param Config $config The compiler config object.
* @param Gui $gui The compiler customcode gui object.
* @param Paths $paths The compiler customcode extractor paths object.
* @param Reverse $reverse The compiler placeholder reverse object.
* @param Placeholder $placeholder The compiler component placeholder object.
* @param Pathfix $pathfix The compiler path fixing object.
* @param DatabaseInterface $db The Joomla Database Class.
*
* @throws \Exception
* @since 3.2.0
*/
public function __construct(?Config $config = null, ?Gui $gui = null, ?Paths $paths = null,
?Reverse $reverse = null, ?Placeholder $placeholder = null, ?Pathfix $pathfix = null)
public function __construct(Config $config, Gui $gui, Paths $paths,
Reverse $reverse, Placeholder $placeholder, Pathfix $pathfix, DatabaseInterface $db)
{
$this->config = $config ?: Compiler::_('Config');
$this->gui = $gui ?: Compiler::_('Customcode.Gui');
$this->paths = $paths ?: Compiler::_('Customcode.Extractor.Paths');
$this->reverse = $reverse ?: Compiler::_('Placeholder.Reverse');
$this->componentPlaceholder = $placeholder ?: Compiler::_('Component.Placeholder');
$this->pathfix = $pathfix ?: Compiler::_('Utilities.Pathfix');
$this->user = Factory::getUser();
$this->db = Factory::getDbo();
$this->config = $config;
$this->gui = $gui;
$this->paths = $paths;
$this->reverse = $reverse;
$this->componentPlaceholder = $placeholder;
$this->pathfix = $pathfix;
$this->db = $db;
$this->app = Factory::getApplication();
$this->user = $this->app->getIdentity();
// set today's date
$this->today = Factory::getDate()->toSql();
@@ -934,7 +937,6 @@ class Extractor implements ExtractorInterface
}
return false;
}
}
}

View File

@@ -12,18 +12,17 @@
namespace VDM\Joomla\Componentbuilder\Compiler\Customcode\Extractor;
use Joomla\CMS\Factory;
use Joomla\Database\DatabaseInterface;
use Joomla\Filesystem\Folder;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Utilities\JsonHelper;
use VDM\Joomla\Utilities\GetHelper;
use VDM\Joomla\Utilities\String\ClassfunctionHelper;
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
use VDM\Joomla\Componentbuilder\Compiler\Component\Placeholder as ComponentPlaceholder;
use VDM\Joomla\Componentbuilder\Compiler\Customcode;
use VDM\Joomla\Componentbuilder\Compiler\Language\Extractor;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Utilities\JsonHelper;
use VDM\Joomla\Utilities\GetHelper;
use VDM\Joomla\Utilities\String\ClassfunctionHelper;
/**
@@ -82,35 +81,36 @@ class Paths
protected Extractor $extractor;
/**
* Database object to query local DB
* Joomla Database Class.
*
* @since 3.2.0
* @var DatabaseInterface
* @since 5.1.2
**/
protected $db;
protected DatabaseInterface $db;
/**
* Constructor.
*
* @param Config|null $config The compiler config object.
* @param Placeholder|null $placeholder The compiler placeholder object.
* @param ComponentPlaceholder|null $componentPlaceholder The compiler component placeholder object.
* @param Customcode|null $customcode The compiler customcode object.
* @param Extractor|null $extractor The compiler language extractor object.
* @param Config $config The compiler config object.
* @param Placeholder $placeholder The compiler placeholder object.
* @param ComponentPlaceholder $componentPlaceholder The compiler component placeholder object.
* @param Customcode $customcode The compiler customcode object.
* @param Extractor $extractor The compiler language extractor object.
* @param DatabaseInterface $db The Joomla Database Class.
*
* @throws \Exception
* @since 3.2.0
*/
public function __construct(?Config $config = null, ?Placeholder $placeholder = null,
?ComponentPlaceholder $componentPlaceholder = null, ?Customcode $customcode = null,
?Extractor $extractor = null)
public function __construct(Config $config, Placeholder $placeholder,
ComponentPlaceholder $componentPlaceholder, Customcode $customcode,
Extractor $extractor, DatabaseInterface $db)
{
$this->config = $config ?: Compiler::_('Config');
$this->placeholder = $placeholder ?: Compiler::_('Placeholder');
/** @var ComponentPlaceholder $componentPlaceholder */
$componentPlaceholder = $componentPlaceholder ?: Compiler::_('Component.Placeholder');
$this->customcode = $customcode ?: Compiler::_('Customcode');
$this->extractor = $extractor ?: Compiler::_('Language.Extractor');
$this->db = Factory::getDbo();
$this->config = $config;
$this->placeholder = $placeholder;
$componentPlaceholder = $componentPlaceholder;
$this->customcode = $customcode;
$this->extractor = $extractor;
$this->db = $db;
// load the placeholders to local array
$this->componentPlaceholder = $componentPlaceholder->get();
@@ -412,7 +412,6 @@ class Paths
}
return false;
}
}
}

View File

@@ -14,16 +14,16 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Customcode;
use Joomla\CMS\Factory;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Language\Text;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Utilities\GetHelper;
use VDM\Joomla\Utilities\FileHelper;
use VDM\Joomla\Utilities\String\FieldHelper;
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
use Joomla\CMS\Language\Text;
use Joomla\Database\DatabaseInterface;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder\Reverse;
use VDM\Joomla\Componentbuilder\Power\Parser;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Utilities\String\FieldHelper;
use VDM\Joomla\Utilities\FileHelper;
use VDM\Joomla\Utilities\GetHelper;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Customcode\GuiInterface;
@@ -59,14 +59,15 @@ class Gui implements GuiInterface
protected Parser $parser;
/**
* Database object to query local DB
* Joomla Database Class.
*
* @since 3.2.0
* @var DatabaseInterface
* @since 5.1.2
**/
protected $db;
protected DatabaseInterface $db;
/**
* Database object to query local DB
* The application layer
*
* @since 3.2.0
**/
@@ -75,19 +76,21 @@ class Gui implements GuiInterface
/**
* Constructor.
*
* @param Config|null $config The compiler config object.
* @param Reverse|null $reverse The compiler placeholder reverse object.
* @param Parser|null $parser The powers parser object.
* @param Config $config The compiler config object.
* @param Reverse $reverse The compiler placeholder reverse object.
* @param Parser $parser The powers parser object.
* @param DatabaseInterface $db The Joomla Database Class.
*
* @throws \Exception
* @since 3.2.0
*/
public function __construct(?Config $config = null, ?Reverse $reverse = null, ?Parser $parser = null)
public function __construct(Config $config, Reverse $reverse, Parser $parser, DatabaseInterface $db)
{
$this->config = $config ?: Compiler::_('Config');
$this->reverse = $reverse ?: Compiler::_('Placeholder.Reverse');
$this->parser = $parser ?: Compiler::_('Power.Parser');
$this->db = Factory::getDbo();
$this->config = $config;
$this->reverse = $reverse;
$this->parser = $parser;
$this->db = $db;
$this->app = Factory::getApplication();
}
@@ -255,7 +258,6 @@ class Gui implements GuiInterface
// we do not add GUI wrapper placeholder to code
// that already has any customcode placeholders
return strpos($code, '$$$$') === false;
}
}
}

View File

@@ -12,7 +12,7 @@
namespace VDM\Joomla\Componentbuilder\Compiler\Customview;
use Joomla\CMS\Factory;
use Joomla\Database\DatabaseInterface;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\EventInterface as Event;
use VDM\Joomla\Componentbuilder\Compiler\Customcode;
@@ -161,11 +161,12 @@ class Data
protected Custombuttons $custombuttons;
/**
* Database object to query local DB
* Joomla Database Class.
*
* @since 3.2.0
* @var DatabaseInterface
* @since 5.1.2
**/
protected $db;
protected DatabaseInterface $db;
/**
* Constructor.
@@ -183,6 +184,7 @@ class Data
* @param Phpcustomview $phpcustomview The Phpcustomview Class.
* @param Ajaxcustomview $ajaxcustomview The Ajaxcustomview Class.
* @param Custombuttons $custombuttons The Custombuttons Class.
* @param DatabaseInterface $db The Joomla Database Class.
*
* @since 3.2.0
*/
@@ -194,7 +196,8 @@ class Data
Csscustomview $csscustomview,
Phpcustomview $phpcustomview,
Ajaxcustomview $ajaxcustomview,
Custombuttons $custombuttons)
Custombuttons $custombuttons,
DatabaseInterface $db)
{
$this->config = $config;
$this->event = $event;
@@ -209,7 +212,7 @@ class Data
$this->php = $phpcustomview;
$this->ajax = $ajaxcustomview;
$this->custombuttons = $custombuttons;
$this->db = Factory::getDbo();
$this->db = $db;
}
/**

View File

@@ -0,0 +1,774 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Dynamicget;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\FieldonContentPrepare;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\JoinStructure;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\DecodeColumn;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\FilterColumn;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\UikitLoader;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ContentOne;
use VDM\Joomla\Componentbuilder\Compiler\Builder\SiteDecrypt;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ModelExpertFieldInitiator;
use VDM\Joomla\Componentbuilder\Compiler\Builder\SiteFieldData;
use VDM\Joomla\Componentbuilder\Compiler\Builder\SiteFieldDecodeFilter;
use VDM\Joomla\Componentbuilder\Compiler\Builder\OtherJoin;
use VDM\Joomla\Componentbuilder\Compiler\Builder\OtherQuery;
use VDM\Joomla\Componentbuilder\Compiler\Builder\OtherFilter;
use VDM\Joomla\Componentbuilder\Compiler\Builder\OtherWhere;
use VDM\Joomla\Componentbuilder\Compiler\Builder\OtherOrder;
use VDM\Joomla\Componentbuilder\Compiler\Builder\OtherGroup;
use VDM\Joomla\Componentbuilder\Compiler\Builder\EventDispatcher;
use VDM\Joomla\Utilities\ObjectHelper;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Placefix;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
/**
* Dynamic Get Custom Get Methods
*
* @since 5.1.2
*/
final class CustomGetMethods
{
/**
* The Config Class.
*
* @var Config
* @since 5.1.2
*/
protected Config $config;
/**
* The Placeholder Class.
*
* @var Placeholder
* @since 5.1.2
*/
protected Placeholder $placeholder;
/**
* The FieldonContentPrepare Class.
*
* @var FieldonContentPrepare
* @since 5.1.2
*/
protected FieldonContentPrepare $fieldoncontentprepare;
/**
* The JoinStructure Class.
*
* @var JoinStructure
* @since 5.1.2
*/
protected JoinStructure $joinstructure;
/**
* The DecodeColumn Class.
*
* @var DecodeColumn
* @since 5.1.2
*/
protected DecodeColumn $decodecolumn;
/**
* The FilterColumn Class.
*
* @var FilterColumn
* @since 5.1.2
*/
protected FilterColumn $filtercolumn;
/**
* The UikitLoader Class.
*
* @var UikitLoader
* @since 5.1.2
*/
protected UikitLoader $uikitloader;
/**
* The ContentOne Class.
*
* @var ContentOne
* @since 5.1.2
*/
protected ContentOne $contentone;
/**
* The SiteDecrypt Class.
*
* @var SiteDecrypt
* @since 5.1.2
*/
protected SiteDecrypt $sitedecrypt;
/**
* The ModelExpertFieldInitiator Class.
*
* @var ModelExpertFieldInitiator
* @since 5.1.2
*/
protected ModelExpertFieldInitiator $modelexpertfieldinitiator;
/**
* The SiteFieldData Class.
*
* @var SiteFieldData
* @since 5.1.2
*/
protected SiteFieldData $sitefielddata;
/**
* The SiteFieldDecodeFilter Class.
*
* @var SiteFieldDecodeFilter
* @since 5.1.2
*/
protected SiteFieldDecodeFilter $sitefielddecodefilter;
/**
* The OtherJoin Class.
*
* @var OtherJoin
* @since 5.1.2
*/
protected OtherJoin $otherjoin;
/**
* The OtherQuery Class.
*
* @var OtherQuery
* @since 5.1.2
*/
protected OtherQuery $otherquery;
/**
* The OtherFilter Class.
*
* @var OtherFilter
* @since 5.1.2
*/
protected OtherFilter $otherfilter;
/**
* The OtherWhere Class.
*
* @var OtherWhere
* @since 5.1.2
*/
protected OtherWhere $otherwhere;
/**
* The OtherOrder Class.
*
* @var OtherOrder
* @since 5.1.2
*/
protected OtherOrder $otherorder;
/**
* The OtherGroup Class.
*
* @var OtherGroup
* @since 5.1.2
*/
protected OtherGroup $othergroup;
/**
* The EventDispatcher Class.
*
* @var EventDispatcher
* @since 5.1.2
*/
protected EventDispatcher $eventdispatcher;
/**
* Constructor.
*
* @param Config $config The Config Class.
* @param Placeholder $placeholder The Placeholder Class.
* @param FieldonContentPrepare $fieldoncontentprepare The FieldonContentPrepare Class.
* @param JoinStructure $joinstructure The JoinStructure Class.
* @param DecodeColumn $decodecolumn The DecodeColumn Class.
* @param FilterColumn $filtercolumn The FilterColumn Class.
* @param UikitLoader $uikitloader The UikitLoader Class.
* @param ContentOne $contentone The ContentOne Class.
* @param SiteDecrypt $sitedecrypt The SiteDecrypt Class.
* @param ModelExpertFieldInitiator $modelexpertfieldinitiator The ModelExpertFieldInitiator Class.
* @param SiteFieldData $sitefielddata The SiteFieldData Class.
* @param SiteFieldDecodeFilter $sitefielddecodefilter The SiteFieldDecodeFilter Class.
* @param OtherJoin $otherjoin The OtherJoin Class.
* @param OtherQuery $otherquery The OtherQuery Class.
* @param OtherFilter $otherfilter The OtherFilter Class.
* @param OtherWhere $otherwhere The OtherWhere Class.
* @param OtherOrder $otherorder The OtherOrder Class.
* @param OtherGroup $othergroup The OtherGroup Class.
* @param EventDispatcher $eventdispatcher The EventDispatcher Class.
*
* @since 5.1.2
*/
public function __construct(Config $config, Placeholder $placeholder,
FieldonContentPrepare $fieldoncontentprepare,
JoinStructure $joinstructure, DecodeColumn $decodecolumn,
FilterColumn $filtercolumn, UikitLoader $uikitloader,
ContentOne $contentone, SiteDecrypt $sitedecrypt,
ModelExpertFieldInitiator $modelexpertfieldinitiator,
SiteFieldData $sitefielddata,
SiteFieldDecodeFilter $sitefielddecodefilter,
OtherJoin $otherjoin, OtherQuery $otherquery,
OtherFilter $otherfilter, OtherWhere $otherwhere,
OtherOrder $otherorder, OtherGroup $othergroup,
EventDispatcher $eventdispatcher)
{
$this->config = $config;
$this->placeholder = $placeholder;
$this->fieldoncontentprepare = $fieldoncontentprepare;
$this->joinstructure = $joinstructure;
$this->decodecolumn = $decodecolumn;
$this->filtercolumn = $filtercolumn;
$this->uikitloader = $uikitloader;
$this->contentone = $contentone;
$this->sitedecrypt = $sitedecrypt;
$this->modelexpertfieldinitiator = $modelexpertfieldinitiator;
$this->sitefielddata = $sitefielddata;
$this->sitefielddecodefilter = $sitefielddecodefilter;
$this->otherjoin = $otherjoin;
$this->otherquery = $otherquery;
$this->otherfilter = $otherfilter;
$this->otherwhere = $otherwhere;
$this->otherorder = $otherorder;
$this->othergroup = $othergroup;
$this->eventdispatcher = $eventdispatcher;
}
/**
* Get the dynamic get custom item methods.
*
* @param mixed $mainGet The main get object.
* @param string $code The code string.
*
* @return string The generated methods code.
* @since 5.1.2
*/
public function get($mainGet, string $code): string
{
if (empty($mainGet) || empty($code))
{
return '';
}
$methods = '';
$this->eventdispatcher->remove($code);
if ($this->isValidCustomGet($mainGet))
{
$methods = $this->processCustomGet($mainGet->custom_get, $code);
}
$methods = $this->injectDispatcherIfNeeded($methods, $code);
if (StringHelper::check($methods))
{
return $methods . PHP_EOL;
}
return '';
}
/**
* Check if the customGet object is valid.
*
* @param mixed $mainGet The main get object.
*
* @return boolean
* @since 5.1.2
*/
private function isValidCustomGet($mainGet)
{
return ObjectHelper::check($mainGet)
&& isset($mainGet->custom_get)
&& ArrayHelper::check($mainGet->custom_get);
}
/**
* Process all custom_get entries.
*
* @param array $customGets The custom get definitions.
* @param string $code The code string.
*
* @return string
* @since 5.1.2
*/
private function processCustomGet(array $customGets, string $code): string
{
$methods = '';
foreach ($customGets as $get)
{
$this->removeCryptionTypes($code);
if (($default = $this->joinstructure->get($get, $code)) !== null)
{
$methods .= $this->buildCustomMethod($get, $default);
$methods = $this->injectCryptionScript($methods, $default, $code);
}
}
if (StringHelper::check($methods))
{
$methods = str_replace(Placefix::_h('CRYPT'), '', $methods);
}
return $methods;
}
/**
* Remove cryption types for a given code.
*
* @param string $code The code string.
*
* @return void
* @since 5.1.2
*/
private function removeCryptionTypes(string $code): void
{
foreach ($this->config->cryption_types as $cryptionType)
{
$this->sitedecrypt->remove("{$cryptionType}.{$code}");
}
}
/**
* Build the custom method code.
*
* @param array $get The get definition.
* @param array $default The default structure.
*
* @return string
* @since 5.1.2
*/
private function buildCustomMethod(array $get, array $default): string
{
$methods = PHP_EOL . PHP_EOL . Indent::_(1) . "/**";
$methods .= PHP_EOL . Indent::_(1) . " *" . Line::_(__Line__, __Class__) . " Method to get an array of {$default['name']} Objects.";
$methods .= PHP_EOL . Indent::_(1) . " *";
$methods .= PHP_EOL . Indent::_(1) . " * @return mixed An array of {$default['name']} Objects on success, false on failure.";
$methods .= PHP_EOL . Indent::_(1) . " *";
$methods .= PHP_EOL . Indent::_(1) . " */";
$methods .= PHP_EOL . Indent::_(1) . "public function get{$default['methodName']}(\${$default['on_field']})";
$methods .= PHP_EOL . Indent::_(1) . "{" . Placefix::_h("CRYPT");
$methods .= $this->buildDatabaseSetup($get, $default);
$methods .= $this->applyQueryConditions($get, $default);
$methods .= $this->applyAdditionalBuilders($default);
$methods .= $this->buildQueryExecutionBlock($get, $default);
$methods .= PHP_EOL . Indent::_(1) . "}";
return $methods;
}
/**
* Build database setup section.
*
* @param array $get The get definition.
* @param array $default The default structure.
*
* @return string
* @since 5.1.2
*/
private function buildDatabaseSetup(array $get, array $default): string
{
$methods = PHP_EOL . Indent::_(2) . "//" . Line::_(__Line__, __Class__) . " Get a db connection.";
if ($this->config->get('joomla_version', 3) == 3)
{
$methods .= PHP_EOL . Indent::_(2) . "\$db = Joomla__"."_39403062_84fb_46e0_bac4_0023f766e827___Power::getDbo();";
}
else
{
$methods .= PHP_EOL . Indent::_(2) . "\$db = \$this->getDatabase();";
}
$methods .= PHP_EOL . PHP_EOL . Indent::_(2) . "//" . Line::_(__Line__, __Class__) . " Create a new query object.";
$methods .= PHP_EOL . Indent::_(2) . "\$query = \$db->getQuery(true);";
$methods .= PHP_EOL . PHP_EOL . Indent::_(2) . "//" . Line::_(__Line__, __Class__) . " Get from {$get['selection']['table']} as {$default['as']}";
$methods .= PHP_EOL . Indent::_(2) . $get['selection']['select'];
$methods .= PHP_EOL . Indent::_(2) . "\$query->from({$get['selection']['from']});";
return $methods;
}
/**
* Apply query conditions.
*
* @param array $get The get definition.
* @param array $default The default structure.
*
* @return string
* @since 5.1.2
*/
private function applyQueryConditions(array $get, array $default): string
{
$methods = '';
if ($get['operator'] === 'IN' || $get['operator'] === 'NOT IN')
{
$methods .= PHP_EOL . PHP_EOL . Indent::_(2) . "//" . Line::_(__Line__, __Class__) . " Check if \${$default['on_field']} is an array with values.";
$methods .= PHP_EOL . Indent::_(2) . "\$array = (Super_" . "__4b225c51_d293_48e4_b3f6_5136cf5c3f18___Power::check(\${$default['on_field']}, true)) ? json_decode(\${$default['on_field']}, true) : \${$default['on_field']};";
$methods .= PHP_EOL . Indent::_(2) . "if (isset(\$array) && Super_" . "__0a59c65c_9daf_4bc9_baf4_e063ff9e6a8a___Power::check(\$array, true))";
$methods .= PHP_EOL . Indent::_(2) . "{";
$methods .= PHP_EOL . Indent::_(3) . "\$query->where('{$get['join_field']} {$get['operator']} (' . implode(',', \$array) . ')');";
$methods .= PHP_EOL . Indent::_(2) . "}";
$methods .= PHP_EOL . Indent::_(2) . "else";
$methods .= PHP_EOL . Indent::_(2) . "{";
$methods .= PHP_EOL . Indent::_(3) . "return false;";
$methods .= PHP_EOL . Indent::_(2) . "}";
}
else
{
$methods .= PHP_EOL . Indent::_(2) . "\$query->where('{$get['join_field']} {$get['operator']} ' . \$db->quote(\${$default['on_field']}));";
}
return $methods;
}
/**
* Apply additional builder parts (query, filter, where, order, group).
*
* @param array $default The default structure.
*
* @return string
* @since 5.1.2
*/
private function applyAdditionalBuilders(array $default): string
{
$methods = '';
foreach (['otherquery', 'otherfilter', 'otherwhere', 'otherorder', 'othergroup'] as $builderType)
{
foreach ($this->{$builderType}->get(
$this->config->build_target . '.' . $default['code'] . '.' . $default['as'], []
) as $string)
{
$methods .= $string;
}
}
return $methods;
}
/**
* Build query execution and result processing.
*
* @param array $get The get definition.
* @param array $default The default structure.
*
* @return string
* @since 5.1.2
*/
private function buildQueryExecutionBlock(array $get, array $default): string
{
$code = PHP_EOL . PHP_EOL . Indent::_(2) . "//" . Line::_(__LINE__, __CLASS__) . " Reset the query using our newly populated query object.";
$code .= PHP_EOL . Indent::_(2) . '$db->setQuery($query);';
$code .= PHP_EOL . Indent::_(2) . '$db->execute();';
$code .= PHP_EOL . PHP_EOL . Indent::_(2) . "//" . Line::_(__LINE__, __CLASS__) . " check if there was data returned";
$code .= PHP_EOL . Indent::_(2) . 'if ($db->getNumRows())';
$code .= PHP_EOL . Indent::_(2) . '{' . Placefix::_h("DISPATCHER");
$code .= $this->buildConditionalDecodingBlock($get, $default);
$code .= PHP_EOL . Indent::_(2) . "}";
$code .= PHP_EOL . Indent::_(2) . "return false;";
return $code;
}
/**
* Build the conditional field processing block if decoding, UIkit, filters, or joins are needed.
*
* @param array $get The get definition.
* @param array $default The default structure.
*
* @return string The formatted PHP code string to execute the conditional field logic.
* @since 5.1.2
*/
private function buildConditionalDecodingBlock(array $get, array $default): string
{
if (!isset($default['code'], $get['key'], $default['as']))
{
return '';
}
$path = $default['code'] . '.' . $get['key'] . '.' . $default['as'];
$code = $default['code'];
$decodeChecker = $this->sitefielddata->get('decode.' . $path);
$decodeFilter = $this->sitefielddecodefilter->get($this->config->build_target . '.' . $path);
$uikitChecker = $this->sitefielddata->get('uikit.' . $path);
$contentprepareChecker = $this->sitefielddata->get('textareas.' . $path);
$joinedChecker = $this->otherjoin->get($this->config->build_target . '.' . $code . '.' . $default['as']);
$decoder = $this->getDecoderCode($get, $code, $decodeChecker);
$decoderFilter = $this->getDecoderFilterCode($get, $code, $decodeFilter);
$contentPrepare = $this->getContentPrepareCode($get, $code, $contentprepareChecker);
$uikit = $this->getUIKitCode($get, $code, $uikitChecker);
$joinCode = $this->getJoinCode($joinedChecker);
if ($this->hasFieldProcessing($decoder, $decoderFilter, $contentPrepare, $uikit, $joinCode))
{
return $this->buildFieldProcessingBlock($decoder, $decoderFilter, $contentPrepare, $uikit, $joinCode);
}
return PHP_EOL . Indent::_(3) . 'return $db->loadObjectList();';
}
/**
* Generate decoder block code for the matched field set.
*
* @param array $get The get definition.
* @param string $code The code name.
* @param array|null $checker The decoder rules to apply (if any).
*
* @return string The decoder logic code block or an empty string.
* @since 5.1.2
*/
private function getDecoderCode(array $get, string $code, ?array $checker): string
{
return ($checker !== null && ArrayHelper::check($checker))
? $this->decodecolumn->get($get, $checker, '$item', $code, Indent::_(2))
: '';
}
/**
* Generate filter decoder block for field-specific filters.
*
* @param array $get The get definition.
* @param string $code The code name.
* @param array|null $checker The filter configuration to apply (if any).
*
* @return string The filtered decoder code block or an empty string.
* @since 5.1.2
*/
private function getDecoderFilterCode(array $get, string $code, ?array $checker): string
{
return ($checker !== null && ArrayHelper::check($checker))
? $this->filtercolumn->get($get, $checker, '$item', '$items[$nr]', $code, Indent::_(2))
: '';
}
/**
* Generate content preparation code for specified textarea fields.
*
* @param array $get The get definition.
* @param string $code The code name.
* @param array|null $checker The content prepare configuration to apply (if any).
*
* @return string The content prepare code block or an empty string.
* @since 5.1.2
*/
private function getContentPrepareCode(array $get, string $code, ?array $checker): string
{
return ($checker !== null && ArrayHelper::check($checker))
? $this->fieldoncontentprepare->get($get, $checker, '$item', $code, Indent::_(2))
: '';
}
/**
* Generate UIkit-specific field formatting code.
*
* @param array $get The get definition.
* @param string $code The code name.
* @param array|null $checker The UIkit config for visual formatting (if any).
*
* @return string The UIkit loader code block or an empty string.
* @since 5.1.2
*/
private function getUIKitCode(array $get, string $code, ?array $checker): string
{
return ($checker !== null && ArrayHelper::check($checker))
? $this->uikitloader->get($get, $checker, '$item', $code, Indent::_(2))
: '';
}
/**
* Generate and update placeholder code for joined field strings.
*
* @param array|null $joinedChecker The joined fields configuration (if any).
*
* @return string The join code block with placeholders replaced or an empty string.
* @since 5.1.2
*/
private function getJoinCode(?array $joinedChecker): string
{
if ($joinedChecker === null || !ArrayHelper::check($joinedChecker))
{
return '';
}
$code = '';
$placeholders = [
Placefix::_h('TAB') => Indent::_(2),
Placefix::_h('STRING') => '$item',
];
foreach ($joinedChecker as $joinedString)
{
$code .= $this->placeholder->update($joinedString, $placeholders);
}
return $code;
}
/**
* Check if any of the provided code parts contain executable logic.
*
* @param string ...$parts The list of code strings to evaluate.
*
* @return bool True if any string is non-empty and valid.
* @since 5.1.2
*/
private function hasFieldProcessing(string ...$parts): bool
{
foreach ($parts as $part)
{
if (StringHelper::check($part))
{
return true;
}
}
return false;
}
/**
* Build the complete foreach loop block to process all returned items.
*
* @param string $decoder The decoder block.
* @param string $decoderFilter The decoder filter block.
* @param string $contentPrepare The content prepare block.
* @param string $uikit The UIkit block.
* @param string $joinCode The join block.
*
* @return string The complete loop and return block for $items.
* @since 5.1.2
*/
private function buildFieldProcessingBlock(
string $decoder,
string $decoderFilter,
string $contentPrepare,
string $uikit,
string $joinCode
): string
{
$code = PHP_EOL . Indent::_(3) . '$items = $db->loadObjectList();';
$code .= PHP_EOL . PHP_EOL . Indent::_(3) . "//" . Line::_(__LINE__, __CLASS__) . " Convert the parameter fields into objects.";
$code .= PHP_EOL . Indent::_(3) . 'foreach ($items as $nr => &$item)';
$code .= PHP_EOL . Indent::_(3) . '{';
foreach ([$decoder, $decoderFilter, $contentPrepare, $uikit, $joinCode] as $block)
{
if (StringHelper::check($block))
{
$code .= $block;
}
}
$code .= PHP_EOL . Indent::_(3) . '}';
$code .= PHP_EOL . Indent::_(3) . 'return $items;';
return $code;
}
/**
* Inject cryption script into methods.
*
* @param string $methods The current methods string.
* @param array $default The default structure.
* @param string $code The code string.
*
* @return string
* @since 5.1.2
*/
private function injectCryptionScript(string $methods, array $default, $code): string
{
// set the script if it was found
$Component = $this->contentone->get('Component');
$script = '';
foreach ($this->config->cryption_types as $cryptionType)
{
if ($this->sitedecrypt->get("{$cryptionType}.{$code}") !== null)
{
if ('expert' !== $cryptionType)
{
$script .= PHP_EOL . Indent::_(2) . "//"
. Line::_(__Line__, __Class__) . " Get the "
. $cryptionType . " encryption.";
$script .= PHP_EOL . Indent::_(2) . "\$"
. $cryptionType . "key = " . $Component
. "Helper::getCryptKey('"
. $cryptionType . "');";
$script .= PHP_EOL . Indent::_(2) . "//"
. Line::_(__Line__, __Class__)
. " Get the encryption object.";
$script .= PHP_EOL . Indent::_(2) . "\$"
. $cryptionType
. " = new Super_" . "__99175f6d_dba8_4086_8a65_5c4ec175e61d___Power(\$"
. $cryptionType . "key);" . PHP_EOL;
}
elseif ($this->modelexpertfieldinitiator->exists("{$code}.get"))
{
foreach ($this->modelexpertfieldinitiator->get("{$code}.get") as $block)
{
$script .= PHP_EOL . Indent::_(2) . implode(
PHP_EOL . Indent::_(2), $block
);
}
}
}
}
return str_replace(Placefix::_h('CRYPT'), $script, $methods);
}
/**
* Inject dispatcher code if needed.
*
* @param string $methods The methods string.
* @param string $code The code string.
*
* @return string
* @since 5.1.2
*/
private function injectDispatcherIfNeeded(string $methods, string $code): string
{
if (strpos($methods, (string) Placefix::_h('DISPATCHER')) !== false)
{
$methods = str_replace(
Placefix::_h('DISPATCHER'),
$this->eventdispatcher->get($code, ''),
$methods
);
}
return $methods;
}
}

View File

@@ -0,0 +1,209 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Dynamicget;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Builder\SiteDynamicGet;
use VDM\Joomla\Componentbuilder\Compiler\Builder\OtherJoin;
use VDM\Joomla\Componentbuilder\Compiler\Builder\GetAsLookup;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\JoinStructure;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Placefix;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
use VDM\Joomla\Utilities\ArrayHelper;
/**
* Dynamic Get Custom Join
*
* @since 5.1.2
*/
final class CustomJoin
{
/**
* The Config Class.
*
* @var Config
* @since 5.1.2
*/
protected Config $config;
/**
* The SiteDynamicGet Class.
*
* @var SiteDynamicGet
* @since 5.1.2
*/
protected SiteDynamicGet $sitedynamicget;
/**
* The OtherJoin Class.
*
* @var OtherJoin
* @since 5.1.2
*/
protected OtherJoin $otherjoin;
/**
* The GetAsLookup Class.
*
* @var GetAsLookup
* @since 5.1.2
*/
protected GetAsLookup $getaslookup;
/**
* The JoinStructure Class.
*
* @var JoinStructure
* @since 5.1.2
*/
protected JoinStructure $joinstructure;
/**
* Constructor.
*
* @param Config $config The Config Class.
* @param SiteDynamicGet $sitedynamicget The SiteDynamicGet Class.
* @param OtherJoin $otherjoin The OtherJoin Class.
* @param GetAsLookup $getaslookup The GetAsLookup Class.
* @param JoinStructure $joinstructure The JoinStructure Class.
*
* @since 5.1.2
*/
public function __construct(Config $config, SiteDynamicGet $sitedynamicget,
OtherJoin $otherjoin, GetAsLookup $getaslookup,
JoinStructure $joinstructure)
{
$this->config = $config;
$this->sitedynamicget = $sitedynamicget;
$this->otherjoin = $otherjoin;
$this->getaslookup = $getaslookup;
$this->joinstructure = $joinstructure;
}
/**
* Get the dynamic get custom join code.
*
* @param array $gets The array of join definitions.
* @param string $string The target variable name in generated code.
* @param string $code The code identifier for the join.
* @param array $asBucket The array of already processed join aliases.
* @param string $tab The indentation tab string for formatting (optional).
*
* @return string The generated custom join code block or an empty string.
* @since 5.1.2
*/
public function get(array $gets, string $string, string $code, array $asBucket, string $tab = ''): string
{
if (empty($gets) || empty($string) || empty($code))
{
return '';
}
$customJoin = '';
foreach ($gets as $get)
{
// Retrieve join structure
$default = $this->joinstructure->get($get, $code);
if ($default === null)
{
continue;
}
if ($this->check($default, $get, $asBucket))
{
// Build 'other join' string
$otherJoin = PHP_EOL . Indent::_(1) . Placefix::_h('TAB')
. Indent::_(1) . '//' . Line::_( __LINE__, __CLASS__)
. ' set ' . $default['valueName'] . ' to the '
. Placefix::_h('STRING') . ' object.';
$otherJoin .= PHP_EOL . Indent::_(1) . Placefix::_h('TAB')
. Indent::_(1) . Placefix::_h('STRING') . '->'
. $default['valueName'] . ' = $this->get'
. $default['methodName'] . '(' . Placefix::_h('STRING') . '->'
. $this->getaslookup
->get($get['key'] . '.' . $get['on_field'], 'Error')
. ');';
$join_field_ = $this->sitedynamicget->get(
$this->config->build_target .
'.' . $default['code'] . '.' . $default['as'] . '.' . $default['join_field'],
'ZZZ'
);
// Store in other join collection
$this->otherjoin->add(
$this->config->build_target .
'.' . $default['code'] . '.' . $join_field_ . '.' . $default['valueName'],
$otherJoin,
false
);
}
else
{
// Build custom join string
$customJoin .= PHP_EOL . Indent::_(1) . $tab
. Indent::_(1) . '//' . Line::_( __LINE__, __CLASS__)
. ' set ' . $default['valueName'] . ' to the '
. $string . ' object.';
$customJoin .= PHP_EOL . Indent::_(1) . $tab
. Indent::_(1) . $string . '->'
. $default['valueName'] . ' = $this->get'
. $default['methodName'] . '(' . $string . '->'
. $this->getaslookup->get($get['key'] . '.' . $get['on_field'], 'Error')
. ');';
}
}
return $customJoin;
}
/**
* Determine whether a join should be processed as a separate join.
*
* @param array $default The join structure details (passed by reference).
* @param array $get The current join definition (passed by reference).
* @param array $asBucket The list of already processed join aliases (passed by reference).
*
* @return bool True if the join should be processed separately, false otherwise.
* @since 5.1.2
*/
public function check(array $default, array $get, array $asBucket): bool
{
// Extract alias from on_field
list($aJoin) = explode('.', (string) $get['on_field']);
// If alias already in bucket, skip
if (in_array($aJoin, $asBucket))
{
return false;
}
// Check if join exists in dynamic config
if ($this->sitedynamicget->exists(
$this->config->build_target . '.' . $default['code'] . '.' .
$default['as'] . '.' . $default['join_field']
))
{
return true;
}
return false;
}
}

View File

@@ -12,7 +12,7 @@
namespace VDM\Joomla\Componentbuilder\Compiler\Dynamicget;
use Joomla\CMS\Factory;
use Joomla\Database\DatabaseInterface;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Registry;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\EventInterface as Event;
@@ -102,28 +102,30 @@ class Data
protected Dynamicget $dynamic;
/**
* Database object to query local DB
* Joomla Database Class.
*
* @since 3.2.0
* @var DatabaseInterface
* @since 5.1.2
**/
protected $db;
protected DatabaseInterface $db;
/**
* Constructor.
*
* @param Config $config The Config Class.
* @param Registry $registry The Registry Class.
* @param Event $event The EventInterface Class.
* @param Customcode $customcode The Customcode Class.
* @param Dispenser $dispenser The Dispenser Class.
* @param Gui $gui The Gui Class.
* @param Dynamicget $dynamicget The Dynamicget Class.
* @param Config $config The Config Class.
* @param Registry $registry The Registry Class.
* @param Event $event The EventInterface Class.
* @param Customcode $customcode The Customcode Class.
* @param Dispenser $dispenser The Dispenser Class.
* @param Gui $gui The Gui Class.
* @param Dynamicget $dynamicget The Dynamicget Class.
* @param DatabaseInterface $db The Joomla Database Class.
*
* @since 3.2.0
*/
public function __construct(Config $config, Registry $registry, Event $event,
Customcode $customcode, Dispenser $dispenser, Gui $gui,
Dynamicget $dynamicget)
Dynamicget $dynamicget, DatabaseInterface $db)
{
$this->config = $config;
$this->registry = $registry;
@@ -132,7 +134,7 @@ class Data
$this->dispenser = $dispenser;
$this->gui = $gui;
$this->dynamic = $dynamicget;
$this->db = Factory::getDbo();
$this->db = $db;
}
/**

View File

@@ -0,0 +1,197 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Dynamicget;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ModelExpertField;
use VDM\Joomla\Componentbuilder\Compiler\Builder\SiteDecrypt;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
/**
* Custom View Decode Column
*
* @since 5.1.2
*/
final class DecodeColumn
{
/**
* The Config Class.
*
* @var Config
* @since 5.1.2
*/
protected Config $config;
/**
* The Placeholder Class.
*
* @var Placeholder
* @since 5.1.2
*/
protected Placeholder $placeholder;
/**
* The ModelExpertField Class.
*
* @var ModelExpertField
* @since 5.1.2
*/
protected ModelExpertField $expert;
/**
* The SiteDecrypt Class.
*
* @var SiteDecrypt
* @since 5.1.2
*/
protected SiteDecrypt $sitedecrypt;
/**
* The loadTracker array.
*
* @var array
* @since 5.1.2
*/
protected array $loadTracker = [];
/**
* Constructor.
*
* @param Config $config The Config Class.
* @param Placeholder $placeholder The Placeholder Class.
* @param ModelExpertField $modelexpertfield The ModelExpertField Class.
* @param SiteDecrypt $sitedecrypt The SiteDecrypt Class.
*
* @since 5.1.2
*/
public function __construct(Config $config, Placeholder $placeholder,
ModelExpertField $modelexpertfield, SiteDecrypt $sitedecrypt)
{
$this->config = $config;
$this->placeholder = $placeholder;
$this->expert = $modelexpertfield;
$this->sitedecrypt = $sitedecrypt;
}
/**
* Generate the decode logic for a column in the custom view.
*
* @param array $get The get array with view configuration.
* @param array $checker Field decode configuration.
* @param string $string The variable representing the row object.
* @param string $code The calling context code string.
* @param string $tab Optional indentation tab prefix.
*
* @return string The generated decode logic.
* @since 5.1.2
*/
public function get(array $get, array $checker, string $string, string $code, string $tab = ''): string
{
if (empty($get['key']) || empty($get['selection']['select']) || empty($checker) || empty($string) || empty($code))
{
return '';
}
$fieldDecode = '';
foreach ($checker as $field => $array)
{
$key = md5($code . $get['key'] . $string . $field);
if (strpos((string) $get['selection']['select'], (string) $field) !== false
&& !isset($this->loadTracker[$key])
&& ArrayHelper::check($array['decode']))
{
$this->loadTracker[$key] = $key;
$array['decode'] = (array) array_unique(array_reverse((array) $array['decode']));
foreach ($array['decode'] as $decode)
{
$if = '';
$decoder = '';
if ($decode === 'json')
{
$if = PHP_EOL . Indent::_(1) . $tab . Indent::_(1)
. "if (isset({$string}->{$field}) && Super__"."_4b225c51_d293_48e4_b3f6_5136cf5c3f18___Power::check({$string}->{$field}))" . PHP_EOL
. Indent::_(1) . $tab . Indent::_(1) . "{";
$decoder = "{$string}->{$field} = json_decode({$string}->{$field}, true);";
}
elseif ($decode === 'base64')
{
$if = PHP_EOL . Indent::_(1) . $tab . Indent::_(1)
. "if (!empty({$string}->{$field}) && {$string}->{$field} === base64_encode(base64_decode({$string}->{$field})))" . PHP_EOL
. Indent::_(1) . $tab . Indent::_(1) . "{";
$decoder = "{$string}->{$field} = base64_decode({$string}->{$field});";
}
elseif (strpos((string) $decode, '_encryption') !== false || $decode === 'expert_mode')
{
foreach ($this->config->cryption_types as $cryptionType)
{
if ($decode === $cryptionType . '_encryption' || $decode === $cryptionType . '_mode')
{
if ($cryptionType !== 'expert')
{
$if = PHP_EOL . Indent::_(1) . $tab . Indent::_(1)
. "if (!empty({$string}->{$field}) && \${$cryptionType}key && !is_numeric({$string}->{$field}) && {$string}->{$field} === base64_encode(base64_decode({$string}->{$field}, true)))" . PHP_EOL
. Indent::_(1) . $tab . Indent::_(1) . "{";
$decoder = "{$string}->{$field} = rtrim(\${$cryptionType}->decryptString({$string}->{$field}), \"\0\");";
}
elseif ($this->expert->exists($array['admin_view'] . '.' . $field))
{
$_placeholder_for_field = [
'[[[field]]]' => "{$string}->{$field}"
];
$fieldDecode .= $this->placeholder->update(
PHP_EOL . Indent::_(1) . $tab . Indent::_(1)
. implode(
PHP_EOL . Indent::_(1) . $tab . Indent::_(1),
$this->{$cryptionType}->get($array['admin_view'] . '.' . $field . '.get', ['error'])
),
$_placeholder_for_field
);
}
$this->sitedecrypt->set("{$cryptionType}.{$code}", $decode);
}
}
}
if (StringHelper::check($if))
{
$fieldDecode .= PHP_EOL . Indent::_(1) . $tab . Indent::_(1)
. "//" . Line::_(__LINE__, __CLASS__) . " Check if we can decode {$field}" . $if
. PHP_EOL . Indent::_(1) . $tab . Indent::_(2)
. "//" . Line::_(__LINE__, __CLASS__) . " Decode {$field}";
}
if (StringHelper::check($decoder))
{
$fieldDecode .= PHP_EOL . Indent::_(1) . $tab . Indent::_(2) . $decoder
. PHP_EOL . Indent::_(1) . $tab . Indent::_(1) . "}";
}
}
}
}
return $fieldDecode;
}
}

View File

@@ -0,0 +1,179 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Dynamicget;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ContentOne;
use VDM\Joomla\Componentbuilder\Compiler\Builder\EventDispatcher;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
/**
* Dynamic Get Field on Content Prepare
*
* @since 5.1.2
*/
final class FieldonContentPrepare
{
/**
* The Config Class.
*
* @var Config
* @since 5.1.2
*/
protected Config $config;
/**
* The ContentOne Class.
*
* @var ContentOne
* @since 5.1.2
*/
protected ContentOne $contentone;
/**
* The EventDispatcher Class.
*
* @var EventDispatcher
* @since 5.1.2
*/
protected EventDispatcher $eventdispatcher;
/**
* The loadTracker array.
*
* @var array
* @since 5.1.2
*/
protected array $loadTracker = [];
/**
* Constructor.
*
* @param Config $config The Config Class.
* @param ContentOne $contentone The ContentOne Class.
* @param EventDispatcher $eventdispatcher The EventDispatcher Class.
*
* @since 5.1.2
*/
public function __construct(Config $config, ContentOne $contentone,
EventDispatcher $eventdispatcher)
{
$this->config = $config;
$this->contentone = $contentone;
$this->eventdispatcher = $eventdispatcher;
}
/**
* Get the content preparation plugin logic for a field.
*
* @param array $get The get array passed in.
* @param array $checker The checker structure containing field info.
* @param string $string The string name for the object.
* @param string $code The code to use as fallback context.
* @param string $tab Indentation tab prefix.
*
* @return string The content preparation PHP string.
* @since 5.1.2
*/
public function get($get, $checker, $string, $code, $tab = ''): string
{
if (empty($get['key']) || empty($get['selection']['select']) || empty($checker) || empty($string) || empty($code))
{
return '';
}
$fieldPrepare = '';
$runplugins = '';
// set component
$Component = $this->contentone->get('Component');
// set context
$context = (isset($get['context'])) ? $get['context'] : $code;
$context = 'com_' . $this->config->component_code_name . '.' . $context;
// load params builder only once
$params = false;
foreach ($checker as $field => $array)
{
// build load counter
$key = md5($get['key'] . $string . $field);
// check if we should load this again
if (strpos((string) $get['selection']['select'], (string) $field) !== false
&& !isset($this->loadTracker[$key]))
{
// set the key
$this->loadTracker[$key] = $key;
// build decoder string
if (empty($runplugins))
{
$runplugins = PHP_EOL . $tab . Indent::_(1) . "//"
. Line::_(__Line__, __Class__)
. " Load the JEvent Dispatcher";
$runplugins .= PHP_EOL . $tab . Indent::_(1)
. "PluginHelper::importPlugin('content');";
$runplugins .= PHP_EOL . $tab . Indent::_(1)
. '$this->_dispatcher = Joomla__'.'_39403062_84fb_46e0_bac4_0023f766e827___Power::getApplication();';
}
if (!$params)
{
$fieldPrepare .= PHP_EOL . Indent::_(1) . $tab . Indent::_(
1
) . "//" . Line::_(__Line__, __Class__)
. " Check if item has params, or pass whole item.";
$fieldPrepare .= PHP_EOL . Indent::_(1) . $tab . Indent::_(
1
) . "\$params = (isset(" . $string . "->params) && "
. "Super_" . "__4b225c51_d293_48e4_b3f6_5136cf5c3f18___Power::check(" . $string
. "->params)) ? json_decode(" . $string . "->params) : "
. $string . ";";
$params = true;
}
$fieldPrepare .= PHP_EOL . Indent::_(1) . $tab . Indent::_(1)
. "//" . Line::_(__Line__, __Class__)
. " Make sure the content prepare plugins fire on "
. $field;
$fieldPrepare .= PHP_EOL . Indent::_(1) . $tab . Indent::_(1)
. "\$_" . $field . " = new \stdClass();";
$fieldPrepare .= PHP_EOL . Indent::_(1) . $tab . Indent::_(1)
. "\$_" . $field . '->text =& ' . $string . '->' . $field
. '; //' . Line::_(__Line__, __Class__)
. ' value must be in text';
$fieldPrepare .= PHP_EOL . Indent::_(1) . $tab . Indent::_(1)
. "//" . Line::_(__Line__, __Class__)
. " Since all values are now in text (Joomla Limitation), we also add the field name ("
. $field . ") to context";
$fieldPrepare .= PHP_EOL . Indent::_(1) . $tab . Indent::_(1)
. '$this->_dispatcher->triggerEvent("onContentPrepare", array(\''
. $context . '.' . $field . '\', &$_' . $field
. ', &$params, 0));';
}
}
// load dispatcher
if (!empty($runplugins))
{
$this->eventdispatcher->set($code, $runplugins);
}
// return content prepare fix
return $fieldPrepare;
}
}

View File

@@ -0,0 +1,191 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Dynamicget;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
/**
* Custom View Filter Column
*
* @since 5.1.2
*/
final class FilterColumn
{
/**
* A tracker to avoid repeating load logic per field.
*
* @var array
* @since 5.1.2
*/
protected array $loadTracker = [];
/**
* Get the Custom View Field Decode Filter code block.
*
* @param array $get The GET metadata for the current field.
* @param array $filters The filters to apply on the field.
* @param string $string The variable name representing the current object.
* @param string $removeString The variable name for object removal context.
* @param string $code The custom view identifier code.
* @param string $tab The tab level for indent formatting.
*
* @return string The generated PHP filter code block.
* @since 5.1.2
*/
public function get(
array $get,
array $filters,
string $string,
string $removeString,
string $code,
string $tab
): string
{
if (empty($get['key']) || empty($get['selection']['select']) || empty($filters) || empty($string) || empty($code))
{
return '';
}
$filter = '';
if (ArrayHelper::check($filters))
{
foreach ($filters as $field => $ter)
{
if (empty($ter['table_key']))
{
continue;
}
$key = md5($code . $get['key'] . $string . $ter['table_key']);
if (strpos((string) $get['selection']['select'], (string) $ter['table_key']) !== false &&
!isset($this->loadTracker[$key]))
{
$this->loadTracker[$key] = $key;
list($as, $felt) = array_map('trim', explode('.', (string) $ter['table_key']));
if ($get['as'] === $as &&
isset($ter['filter_type']) &&
is_numeric($ter['filter_type']))
{
$filter .= $this->getFilterCodeByType($ter['filter_type'], $string, $removeString, $field, $tab, $as);
}
}
}
}
return $filter;
}
/**
* Generate the PHP code string for a specific filter type.
*
* @param int $type
* @param string $string
* @param string $removeString
* @param string $field
* @param string $tab
* @param string $as
*
* @return string
* @since 5.1.2
*/
protected function getFilterCodeByType(
int $type,
string $string,
string $removeString,
string $field,
string $tab,
string $as
): string
{
$code = '';
$t1 = Indent::_(1) . $tab . Indent::_(1);
$t2 = Indent::_(1) . $tab . Indent::_(2);
$t3 = Indent::_(1) . $tab . Indent::_(3);
switch ($type)
{
case 4: // User Groups
$code .= PHP_EOL . PHP_EOL . $t1 . "//" . Line::_(__LINE__, __CLASS__) . " filter $as based on user groups";
$code .= PHP_EOL . $t1 . "\$remove = (count(array_intersect((array) \$this->groups, (array) {$string}->{$field}))) ? false : true;";
$code .= PHP_EOL . $t1 . "if (\$remove)";
$code .= PHP_EOL . $t1 . "{";
$code .= $this->getRemovalCode($string, $removeString, $t2);
$code .= PHP_EOL . $t1 . "}";
break;
case 9: // Array Value
$code .= PHP_EOL . PHP_EOL . $t1 . "if (Super__"."_0a59c65c_9daf_4bc9_baf4_e063ff9e6a8a___Power::check({$string}->{$field}))";
$code .= PHP_EOL . $t1 . "{";
$code .= PHP_EOL . $t2 . "//" . Line::_(__LINE__, __CLASS__) . " do your thing here";
$code .= PHP_EOL . $t1 . "}";
$code .= PHP_EOL . $t1 . "else";
$code .= PHP_EOL . $t1 . "{";
$code .= $this->getRemovalCode($string, $removeString, $t2);
$code .= PHP_EOL . $t1 . "}";
break;
case 10: // Repeatable Value
$code .= PHP_EOL . PHP_EOL . $t1 . "//" . Line::_(__LINE__, __CLASS__) . " filter $as based on repeatable value";
$code .= PHP_EOL . $t1 . "if (Super__"."_1f28cb53_60d9_4db1_b517_3c7dc6b429ef___Power::check({$string}->{$field}))";
$code .= PHP_EOL . $t1 . "{";
$code .= PHP_EOL . $t2 . "\$array = json_decode({$string}->{$field}, true);";
$code .= PHP_EOL . $t2 . "if (Super__"."_0a59c65c_9daf_4bc9_baf4_e063ff9e6a8a___Power::check(\$array))";
$code .= PHP_EOL . $t2 . "{";
$code .= PHP_EOL . $t3 . "//" . Line::_(__LINE__, __CLASS__) . " do your thing here";
$code .= PHP_EOL . $t2 . "}";
$code .= PHP_EOL . $t2 . "else";
$code .= PHP_EOL . $t2 . "{";
$code .= $this->getRemovalCode($string, $removeString, $t3);
$code .= PHP_EOL . $t2 . "}";
$code .= PHP_EOL . $t1 . "}";
$code .= PHP_EOL . $t1 . "else";
$code .= PHP_EOL . $t1 . "{";
$code .= $this->getRemovalCode($string, $removeString, $t2);
$code .= PHP_EOL . $t1 . "}";
break;
}
return $code;
}
/**
* Generate the PHP code line to remove or unset a variable.
*
* @param string $string
* @param string $removeString
* @param string $indent
*
* @return string
* @since 5.1.2
*/
protected function getRemovalCode(string $string, string $removeString, string $indent): string
{
if ($removeString == $string)
{
return PHP_EOL . $indent . "//" . Line::_(__LINE__, __CLASS__) . " Remove $string if not valid."
. PHP_EOL . $indent . "$string = null;"
. PHP_EOL . $indent . "return false;";
}
return PHP_EOL . $indent . "//" . Line::_(__LINE__, __CLASS__) . " Unset $string if not valid."
. PHP_EOL . $indent . "unset($removeString);"
. PHP_EOL . $indent . "continue;";
}
}

View File

@@ -0,0 +1,818 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Dynamicget;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Builder\SiteDecrypt;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
use VDM\Joomla\Componentbuilder\Compiler\Language;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ContentOne;
use VDM\Joomla\Componentbuilder\Compiler\Builder\SiteFieldData;
use VDM\Joomla\Componentbuilder\Compiler\Builder\SiteFieldDecodeFilter;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ModelExpertFieldInitiator;
use VDM\Joomla\Componentbuilder\Compiler\Builder\EventDispatcher;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\DecodeColumn;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\FilterColumn;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\FieldonContentPrepare;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\UikitLoader;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\Globals;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\CustomJoin;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\Queries;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\QueryFilter;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\QueryWhere;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\QueryOrder;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\QueryGroup;
use VDM\Joomla\Utilities\ObjectHelper;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Placefix;
/**
* Dynamic Get GetItem
*
* @since 5.1.2
*/
final class GetItem
{
/**
* The Config Class.
*
* @var Config
* @since 5.1.2
*/
protected Config $config;
/**
* The SiteDecrypt Class.
*
* @var SiteDecrypt
* @since 5.1.2
*/
protected SiteDecrypt $sitedecrypt;
/**
* The Placeholder Class.
*
* @var Placeholder
* @since 5.1.2
*/
protected Placeholder $placeholder;
/**
* The Language Class.
*
* @var Language
* @since 5.1.2
*/
protected Language $language;
/**
* The ContentOne Class.
*
* @var ContentOne
* @since 5.1.2
*/
protected ContentOne $contentone;
/**
* The SiteFieldData Class.
*
* @var SiteFieldData
* @since 5.1.2
*/
protected SiteFieldData $sitefielddata;
/**
* The SiteFieldDecodeFilter Class.
*
* @var SiteFieldDecodeFilter
* @since 5.1.2
*/
protected SiteFieldDecodeFilter $sitefielddecodefilter;
/**
* The ModelExpertFieldInitiator Class.
*
* @var ModelExpertFieldInitiator
* @since 5.1.2
*/
protected ModelExpertFieldInitiator $modelexpertfieldinitiator;
/**
* The EventDispatcher Class.
*
* @var EventDispatcher
* @since 5.1.2
*/
protected EventDispatcher $eventdispatcher;
/**
* The DecodeColumn Class.
*
* @var DecodeColumn
* @since 5.1.2
*/
protected DecodeColumn $decodecolumn;
/**
* The FilterColumn Class.
*
* @var FilterColumn
* @since 5.1.2
*/
protected FilterColumn $filtercolumn;
/**
* The FieldonContentPrepare Class.
*
* @var FieldonContentPrepare
* @since 5.1.2
*/
protected FieldonContentPrepare $fieldoncontentprepare;
/**
* The UikitLoader Class.
*
* @var UikitLoader
* @since 5.1.2
*/
protected UikitLoader $uikitloader;
/**
* The Globals Class.
*
* @var Globals
* @since 5.1.2
*/
protected Globals $globals;
/**
* The CustomJoin Class.
*
* @var CustomJoin
* @since 5.1.2
*/
protected CustomJoin $customjoin;
/**
* The Queries Class.
*
* @var Queries
* @since 5.1.2
*/
protected Queries $queries;
/**
* The QueryFilter Class.
*
* @var QueryFilter
* @since 5.1.2
*/
protected QueryFilter $queryfilter;
/**
* The QueryWhere Class.
*
* @var QueryWhere
* @since 5.1.2
*/
protected QueryWhere $querywhere;
/**
* The QueryOrder Class.
*
* @var QueryOrder
* @since 5.1.2
*/
protected QueryOrder $queryorder;
/**
* The QueryGroup Class.
*
* @var QueryGroup
* @since 5.1.2
*/
protected QueryGroup $querygroup;
/**
* Constructor.
*
* @param Config $config The Config Class.
* @param SiteDecrypt $sitedecrypt The SiteDecrypt Class.
* @param Placeholder $placeholder The Placeholder Class.
* @param Language $language The Language Class.
* @param ContentOne $contentone The ContentOne Class.
* @param SiteFieldData $sitefielddata The SiteFieldData Class.
* @param SiteFieldDecodeFilter $sitefielddecodefilter The SiteFieldDecodeFilter Class.
* @param ModelExpertFieldInitiator $modelexpertfieldinitiator The ModelExpertFieldInitiator Class.
* @param EventDispatcher $eventdispatcher The EventDispatcher Class.
* @param DecodeColumn $decodecolumn The DecodeColumn Class.
* @param FilterColumn $filtercolumn The FilterColumn Class.
* @param FieldonContentPrepare $fieldoncontentprepare The FieldonContentPrepare Class.
* @param UikitLoader $uikitloader The UikitLoader Class.
* @param Globals $globals The Globals Class.
* @param CustomJoin $customjoin The CustomJoin Class.
* @param Queries $queries The Queries Class.
* @param QueryFilter $queryfilter The QueryFilter Class.
* @param QueryWhere $querywhere The QueryWhere Class.
* @param QueryOrder $queryorder The QueryOrder Class.
* @param QueryGroup $querygroup The QueryGroup Class.
*
* @since 5.1.2
*/
public function __construct(Config $config, SiteDecrypt $sitedecrypt,
Placeholder $placeholder, Language $language,
ContentOne $contentone, SiteFieldData $sitefielddata,
SiteFieldDecodeFilter $sitefielddecodefilter,
ModelExpertFieldInitiator $modelexpertfieldinitiator,
EventDispatcher $eventdispatcher,
DecodeColumn $decodecolumn, FilterColumn $filtercolumn,
FieldonContentPrepare $fieldoncontentprepare,
UikitLoader $uikitloader, Globals $globals,
CustomJoin $customjoin, Queries $queries,
QueryFilter $queryfilter, QueryWhere $querywhere,
QueryOrder $queryorder, QueryGroup $querygroup)
{
$this->config = $config;
$this->sitedecrypt = $sitedecrypt;
$this->placeholder = $placeholder;
$this->language = $language;
$this->contentone = $contentone;
$this->sitefielddata = $sitefielddata;
$this->sitefielddecodefilter = $sitefielddecodefilter;
$this->modelexpertfieldinitiator = $modelexpertfieldinitiator;
$this->eventdispatcher = $eventdispatcher;
$this->decodecolumn = $decodecolumn;
$this->filtercolumn = $filtercolumn;
$this->fieldoncontentprepare = $fieldoncontentprepare;
$this->uikitloader = $uikitloader;
$this->globals = $globals;
$this->customjoin = $customjoin;
$this->queries = $queries;
$this->queryfilter = $queryfilter;
$this->querywhere = $querywhere;
$this->queryorder = $queryorder;
$this->querygroup = $querygroup;
}
/**
* Get the dynamic get item method.
*
* @param mixed $get The get object.
* @param string $code The code string.
* @param string $tab The tab spacing.
* @param string $type The type (main|custom).
*
* @return string The generated PHP code block.
* @since 5.1.2
*/
public function get($get, string $code, string $tab = '', string $type = 'main'): string
{
if (!ObjectHelper::check($get) || empty($code))
{
return PHP_EOL . Indent::_(1) . $tab . Indent::_(1) . "//" . Line::_(__LINE__, __CLASS__) . "add your custom code here.";
}
$this->removeCryptionTypes($code);
$getItem = $this->addPhpBeforeItem($get);
$getItem .= $this->getDatabaseSetup($tab);
$getItem .= $this->buildMainQuery($get, $code, $tab);
$getItem .= $this->buildPostQueryPlaceholder($get);
$getItem = $this->replaceQueryPlaceholderIfNeeded($getItem, $tab);
$getItem .= $this->buildEmptyDataFailSafe($type, $tab, $code);
$getItem .= Placefix::_h("DISPATCHER");
$asBucket = [];
if (isset($get->main_get) && ArrayHelper::check($get->main_get))
{
$getItem .= $this->buildPostProcessFieldChecks($get, $code, $tab, $asBucket);
}
$script = $this->buildCryptionScript($code, $tab);
$getItem = $script . $getItem;
$getItem .= $this->buildGlobals($get, $code, $tab, $asBucket);
$getItem .= $this->buildCustomJoin($get, $code, $tab, $asBucket);
$getItem .= $this->buildCalculation($get, $tab);
$getItem .= $this->buildReturnBlock($type, $tab);
$getItem = $this->injectDispatcherIfNeeded($getItem, $code);
return $getItem;
}
/**
* Remove all cryption type flags for this code.
*
* @param string $code
*
* @return void
* @since 5.1.2
*/
private function removeCryptionTypes(string $code): void
{
foreach ($this->config->cryption_types as $cryptionType)
{
$this->sitedecrypt->remove("{$cryptionType}.{$code}");
}
}
/**
* Add custom PHP before the get item block.
*
* @param object $get
*
* @return string
* @since 5.1.2
*/
private function addPhpBeforeItem(object $get): string
{
if (
isset($get->add_php_before_getitem) && $get->add_php_before_getitem == 1
&& isset($get->php_before_getitem) && StringHelper::check($get->php_before_getitem)
)
{
return $this->placeholder->update_($get->php_before_getitem);
}
return '';
}
/**
* Build the DB connection and query setup.
*
* @param string $tab
*
* @return string
* @since 5.1.2
*/
private function getDatabaseSetup(string $tab): string
{
$dbSetup = PHP_EOL . Indent::_(1) . $tab . Indent::_(1) . "//" . Line::_(__LINE__, __CLASS__) . " Get a db connection.";
if ($this->config->get('joomla_version', 3) == 3)
{
$dbSetup .= PHP_EOL . Indent::_(1) . $tab . Indent::_(1) . "\$db = Joomla__" . "_39403062_84fb_46e0_bac4_0023f766e827___Power::getDbo();";
}
else
{
$dbSetup .= PHP_EOL . Indent::_(1) . $tab . Indent::_(1) . "\$db = \$this->getDatabase();";
}
$dbSetup .= PHP_EOL . PHP_EOL . $tab . Indent::_(2) . "//" . Line::_(__LINE__, __CLASS__) . " Create a new query object.";
$dbSetup .= PHP_EOL . Indent::_(1) . $tab . Indent::_(1) . "\$query = \$db->getQuery(true);";
return $dbSetup;
}
/**
* Append query logic for get, filters, where, order, group.
*
* @param object $get
* @param string $code
* @param string $tab
*
* @return string
* @since 5.1.2
*/
private function buildMainQuery(object $get, string $code, string $tab): string
{
if (empty($get->main_get))
{
return '';
}
$query = $this->queries->get($get->main_get, $code, $tab);
// Optional parts
foreach (['queryfilter' => 'filter', 'querywhere' => 'where', 'queryorder' => 'order', 'querygroup' => 'group'] as $queryType => $field)
{
if (isset($get->{$field}))
{
$query .= $this->{$queryType}->get($get->{$field}, $code, $tab);
}
}
return $query;
}
/**
* Append custom PHP and query placeholder.
*
* @param object $get
*
* @return string
* @since 5.1.2
*/
private function buildPostQueryPlaceholder(object $get): string
{
$post = Placefix::_h("DB_SET_QUERY_DATA");
if (
isset($get->add_php_after_getitem) && $get->add_php_after_getitem == 1
&& isset($get->php_after_getitem) && StringHelper::check($get->php_after_getitem)
)
{
$post .= $this->placeholder->update_($get->php_after_getitem);
}
return $post;
}
/**
* Replace the placeholder with real DB query execution if needed.
*
* @param string $getItem
* @param string $tab
*
* @return string
* @since 5.1.2
*/
private function replaceQueryPlaceholderIfNeeded(string $getItem, string $tab): string
{
if (strpos($getItem, '$data =') === false)
{
$setQuery = PHP_EOL . PHP_EOL . $tab . Indent::_(2) . "//" . Line::_(__LINE__, __CLASS__) . " Reset the query using our newly populated query object.";
$setQuery .= PHP_EOL . Indent::_(1) . $tab . Indent::_(1) . "\$db->setQuery(\$query);";
$setQuery .= PHP_EOL . Indent::_(1) . $tab . Indent::_(1) . "//" . Line::_(__LINE__, __CLASS__) . " Load the results as a stdClass object.";
$setQuery .= PHP_EOL . Indent::_(1) . $tab . Indent::_(1) . "\$data = \$db->loadObject();";
return str_replace(Placefix::_h("DB_SET_QUERY_DATA"), $setQuery, $getItem);
}
return str_replace(Placefix::_h("DB_SET_QUERY_DATA"), '', $getItem);
}
/**
* Add conditional fallback if \$data is empty.
*
* @param string $type
* @param string $tab
* @param string $code
*
* @return string
* @since 5.1.2
*/
private function buildEmptyDataFailSafe(string $type, string $tab, string $code): string
{
$block = PHP_EOL . PHP_EOL . $tab . Indent::_(2) . "if (empty(\$data))" . PHP_EOL;
$block .= Indent::_(1) . $tab . Indent::_(1) . "{";
if ($type === 'main')
{
$langKey = $this->config->lang_prefix . '_' . StringHelper::safe('Not found or access denied', 'U');
$this->language->set($this->config->lang_target, $langKey, 'Not found, or access denied.');
$block .= PHP_EOL . Indent::_(1) . $tab . Indent::_(2)
. "\$app = Joomla__" . "_39403062_84fb_46e0_bac4_0023f766e827___Power::getApplication();";
$block .= PHP_EOL . Indent::_(1) . $tab . Indent::_(2)
. "//" . Line::_(__LINE__, __CLASS__) . " If no data is found redirect to default page and show warning.";
$block .= PHP_EOL . Indent::_(1) . $tab . Indent::_(2)
. "\$app->enqueueMessage(Joomla__" . "_ba6326ef_cb79_4348_80f4_ab086082e3c5___Power::_('{$langKey}'), 'warning');";
if ('site' === $this->config->build_target)
{
if ($this->contentone->exists('SITE_DEFAULT_VIEW')
&& $this->contentone->get('SITE_DEFAULT_VIEW') != $code)
{
$redirect = "Joomla__" . "_d4c76099_4c32_408a_8701_d0a724484dfd___Power::_('index.php?option=com_" . $this->config->component_code_name . "&view=" . $this->contentone->get('SITE_DEFAULT_VIEW') . "')";
}
else
{
$redirect = "Joomla__" . "_eecc143e_b5cf_4c33_ba4d_97da1df61422___Power::root()";
}
$block .= PHP_EOL . Indent::_(1) . $tab . Indent::_(2) . "\$app->redirect({$redirect});";
}
else
{
$block .= PHP_EOL . Indent::_(1) . $tab . Indent::_(2)
. "\$app->redirect('index.php?option=com_" . $this->config->component_code_name . "');";
}
$block .= PHP_EOL . Indent::_(1) . $tab . Indent::_(2) . "return false;";
}
else
{
$block .= PHP_EOL . Indent::_(1) . $tab . Indent::_(2) . "return false;";
}
$block .= PHP_EOL . Indent::_(1) . $tab . Indent::_(1) . "}";
return $block;
}
/**
* Inject dispatcher logic if placeholder exists.
*
* @param string $getItem
* @param string $code
*
* @return string
* @since 5.1.2
*/
private function injectDispatcherIfNeeded(string $getItem, string $code): string
{
if (strpos($getItem, (string) Placefix::_h('DISPATCHER')) !== false)
{
return str_replace(
Placefix::_h('DISPATCHER'),
$this->eventdispatcher->get($code, ''),
$getItem
);
}
return $getItem;
}
/**
* Handle decode, filter, prepare, UIkit field processing.
*
* @param object $get
* @param string $code
* @param string $tab
* @param string[] &$asBucket
*
* @return string
* @since 5.1.2
*/
private function buildPostProcessFieldChecks(object $get, string $code, string $tab, array &$asBucket): string
{
$output = '';
foreach ($get->main_get as $main_get)
{
if (!isset($main_get['key'], $main_get['as']))
{
continue;
}
$path = $code . '.' . $main_get['key'] . '.' . $main_get['as'];
$decodeChecker = $this->sitefielddata->get('decode.' . $path);
$decodeFilter = $this->sitefielddecodefilter->get($this->config->build_target . '.' . $path);
$contentprepareChecker = $this->sitefielddata->get('textareas.' . $path);
$uikitChecker = $this->sitefielddata->get('uikit.' . $path);
$decoder = $this->getDecoderCode($main_get, $code, $tab, $decodeChecker);
$decoderFilter = $this->getDecoderFilterCode($main_get, $code, $tab, $decodeFilter);
$contentPrepare = $this->getContentPrepareCode($main_get, $code, $tab, $contentprepareChecker);
$uikit = $this->getUIKitCode($main_get, $code, $tab, $uikitChecker);
if ($this->hasFieldProcessing($decoder, $decoderFilter, $contentPrepare, $uikit))
{
$output .= $this->buildFieldProcessingBlock($decoder, $decoderFilter, $contentPrepare, $uikit);
}
$asBucket[] = $main_get['as'];
}
return $output;
}
/**
* Generate decoder block code for the matched field set.
*
* @param array $get The get definition.
* @param string $code The code name.
* @param string $tab The tabing string
* @param array|null $checker The decoder rules to apply (if any).
*
* @return string The decoder logic code block or an empty string.
* @since 5.1.2
*/
private function getDecoderCode(array $get, string $code, string $tab, ?array $checker): string
{
return ($checker !== null && ArrayHelper::check($checker))
? $this->decodecolumn->get($get, $checker, '$data', $code, $tab)
: '';
}
/**
* Generate filter decoder block for field-specific filters.
*
* @param array $get The get definition.
* @param string $code The code name.
* @param string $tab The tabing string
* @param array|null $checker The filter configuration to apply (if any).
*
* @return string The filtered decoder code block or an empty string.
* @since 5.1.2
*/
private function getDecoderFilterCode(array $get, string $code, string $tab, ?array $checker): string
{
return ($checker !== null && ArrayHelper::check($checker))
? $this->filtercolumn->get($get, $checker, '$data', '$data', $code, $tab)
: '';
}
/**
* Generate content preparation code for specified textarea fields.
*
* @param array $get The get definition.
* @param string $code The code name.
* @param string $tab The tabing string
* @param array|null $checker The content prepare configuration to apply (if any).
*
* @return string The content prepare code block or an empty string.
* @since 5.1.2
*/
private function getContentPrepareCode(array $get, string $code, string $tab, ?array $checker): string
{
return ($checker !== null && ArrayHelper::check($checker))
? $this->fieldoncontentprepare->get($get, $checker, '$data', $code, $tab)
: '';
}
/**
* Generate UIkit-specific field formatting code.
*
* @param array $get The get definition.
* @param string $code The code name.
* @param string $tab The tabing string
* @param array|null $checker The UIkit config for visual formatting (if any).
*
* @return string The UIkit loader code block or an empty string.
* @since 5.1.2
*/
private function getUIKitCode(array $get, string $code, string $tab, ?array $checker): string
{
return ($checker !== null && ArrayHelper::check($checker))
? $this->uikitloader->get($get, $checker, '$data', $code, $tab)
: '';
}
/**
* Check if any of the provided code parts contain executable logic.
*
* @param string ...$parts The list of code strings to evaluate.
*
* @return bool True if any string is non-empty and valid.
* @since 5.1.2
*/
private function hasFieldProcessing(string ...$parts): bool
{
foreach ($parts as $part)
{
if (StringHelper::check($part))
{
return true;
}
}
return false;
}
/**
* Build the complete foreach loop block to process all returned items.
*
* @param string $decoder The decoder block.
* @param string $decoderFilter The decoder filter block.
* @param string $contentPrepare The content prepare block.
* @param string $uikit The UIkit block.
*
* @return string The complete loop and return block for $items.
* @since 5.1.2
*/
private function buildFieldProcessingBlock(
string $decoder,
string $decoderFilter,
string $contentPrepare,
string $uikit
): string
{
$code = '';
foreach ([$decoder, $decoderFilter, $contentPrepare, $uikit] as $block)
{
if (StringHelper::check($block))
{
$code .= $block;
}
}
return $code;
}
/**
* Build the cryption script injection.
*
* @param string $code
* @param string $tab
*
* @return string
* @since 5.1.2
*/
private function buildCryptionScript(string $code, string $tab): string
{
$script = '';
$component = $this->contentone->get('Component');
foreach ($this->config->cryption_types as $cryptionType)
{
if ($this->sitedecrypt->get("{$cryptionType}.{$code}") !== null)
{
if ('expert' !== $cryptionType)
{
$script .= PHP_EOL . PHP_EOL . Indent::_(1) . $tab . Indent::_(1) . "//" . Line::_(__LINE__, __CLASS__) . " Get the {$cryptionType} encryption.";
$script .= PHP_EOL . Indent::_(1) . $tab . Indent::_(1) . "\${$cryptionType}key = {$component}Helper::getCryptKey('{$cryptionType}');";
$script .= PHP_EOL . Indent::_(1) . $tab . Indent::_(1) . "//" . Line::_(__LINE__, __CLASS__) . " Get the encryption object.";
$script .= PHP_EOL . Indent::_(1) . $tab . Indent::_(1) . "\${$cryptionType} = new Super__"."_99175f6d_dba8_4086_8a65_5c4ec175e61d___Power(\${$cryptionType}key);";
}
elseif ($this->modelexpertfieldinitiator->exists("{$code}.get"))
{
foreach ($this->modelexpertfieldinitiator->get("{$code}.get") as $block)
{
$script .= PHP_EOL . Indent::_(1) . implode(PHP_EOL . Indent::_(1), $block);
}
}
}
}
return $script;
}
/**
* Build the global loader.
*
* @param object $get
* @param string $code
* @param string $tab
* @param string[] $asBucket
*
* @return string
* @since 5.1.2
*/
private function buildGlobals(object $get, string $code, string $tab, array $asBucket): string
{
return $this->globals->get($get->global ?? [], '$data', $asBucket, $tab);
}
/**
* Build the custom join logic.
*
* @param object $get
* @param string $code
* @param string $tab
* @param string[] $asBucket
*
* @return string
* @since 5.1.2
*/
private function buildCustomJoin(object $get, string $code, string $tab, array $asBucket): string
{
return $this->customjoin->get($get->custom_get ?? [], '$data', $code, $asBucket, $tab);
}
/**
* Build the custom calculation logic block.
*
* @param object $get
* @param string $tab
*
* @return string
* @since 5.1.2
*/
private function buildCalculation(object $get, string $tab): string
{
if (isset($get->addcalculation) && $get->addcalculation == 1 && !empty($get->php_calculation))
{
$get->php_calculation = (array) explode(PHP_EOL, (string) $this->placeholder->update_($get->php_calculation));
return PHP_EOL . Indent::_(1) . $tab . Indent::_(1)
. implode(PHP_EOL . Indent::_(1) . $tab . Indent::_(1), $get->php_calculation);
}
return '';
}
/**
* Build return or assignment block for \$data.
*
* @param string $type
* @param string $tab
*
* @return string
* @since 5.1.2
*/
private function buildReturnBlock(string $type, string $tab): string
{
$line = PHP_EOL . PHP_EOL . Indent::_(1) . $tab . Indent::_(1) . "//" . Line::_(__LINE__, __CLASS__);
if ($type === 'custom')
{
$line .= " return data object.";
$line .= PHP_EOL . Indent::_(1) . $tab . Indent::_(1) . "return \$data;";
}
else
{
$line .= " set data object to item.";
$line .= PHP_EOL . Indent::_(1) . $tab . Indent::_(1) . "\$this->_item[\$pk] = \$data;";
}
return $line;
}
}

View File

@@ -0,0 +1,548 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Dynamicget;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Builder\SiteDecrypt;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ContentOne;
use VDM\Joomla\Componentbuilder\Compiler\Builder\SiteFieldData;
use VDM\Joomla\Componentbuilder\Compiler\Builder\SiteFieldDecodeFilter;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ModelExpertFieldInitiator;
use VDM\Joomla\Componentbuilder\Compiler\Builder\EventDispatcher;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\DecodeColumn;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\FilterColumn;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\FieldonContentPrepare;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\UikitLoader;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\Globals;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\CustomJoin;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Utilities\ObjectHelper;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Placefix;
/**
* Dynamic Get GetItems
*
* @since 5.1.2
*/
final class GetItems
{
/**
* The Config Class.
*
* @var Config
* @since 5.1.2
*/
protected Config $config;
/**
* The SiteDecrypt Class.
*
* @var SiteDecrypt
* @since 5.1.2
*/
protected SiteDecrypt $sitedecrypt;
/**
* The Placeholder Class.
*
* @var Placeholder
* @since 5.1.2
*/
protected Placeholder $placeholder;
/**
* The ContentOne Class.
*
* @var ContentOne
* @since 5.1.2
*/
protected ContentOne $contentone;
/**
* The SiteFieldData Class.
*
* @var SiteFieldData
* @since 5.1.2
*/
protected SiteFieldData $sitefielddata;
/**
* The SiteFieldDecodeFilter Class.
*
* @var SiteFieldDecodeFilter
* @since 5.1.2
*/
protected SiteFieldDecodeFilter $sitefielddecodefilter;
/**
* The ModelExpertFieldInitiator Class.
*
* @var ModelExpertFieldInitiator
* @since 5.1.2
*/
protected ModelExpertFieldInitiator $modelexpertfieldinitiator;
/**
* The EventDispatcher Class.
*
* @var EventDispatcher
* @since 5.1.2
*/
protected EventDispatcher $eventdispatcher;
/**
* The DecodeColumn Class.
*
* @var DecodeColumn
* @since 5.1.2
*/
protected DecodeColumn $decodecolumn;
/**
* The FilterColumn Class.
*
* @var FilterColumn
* @since 5.1.2
*/
protected FilterColumn $filtercolumn;
/**
* The FieldonContentPrepare Class.
*
* @var FieldonContentPrepare
* @since 5.1.2
*/
protected FieldonContentPrepare $fieldoncontentprepare;
/**
* The UikitLoader Class.
*
* @var UikitLoader
* @since 5.1.2
*/
protected UikitLoader $uikitloader;
/**
* The Globals Class.
*
* @var Globals
* @since 5.1.2
*/
protected Globals $globals;
/**
* The CustomJoin Class.
*
* @var CustomJoin
* @since 5.1.2
*/
protected CustomJoin $customjoin;
/**
* Constructor.
*
* @param Config $config The Config Class.
* @param SiteDecrypt $sitedecrypt The SiteDecrypt Class.
* @param Placeholder $placeholder The Placeholder Class.
* @param ContentOne $contentone The ContentOne Class.
* @param SiteFieldData $sitefielddata The SiteFieldData Class.
* @param SiteFieldDecodeFilter $sitefielddecodefilter The SiteFieldDecodeFilter Class.
* @param ModelExpertFieldInitiator $modelexpertfieldinitiator The ModelExpertFieldInitiator Class.
* @param EventDispatcher $eventdispatcher The EventDispatcher Class.
* @param DecodeColumn $decodecolumn The DecodeColumn Class.
* @param FilterColumn $filtercolumn The FilterColumn Class.
* @param FieldonContentPrepare $fieldoncontentprepare The FieldonContentPrepare Class.
* @param UikitLoader $uikitloader The UikitLoader Class.
* @param Globals $globals The Globals Class.
* @param CustomJoin $customjoin The CustomJoin Class.
*
* @since 5.1.2
*/
public function __construct(Config $config, SiteDecrypt $sitedecrypt,
Placeholder $placeholder, ContentOne $contentone,
SiteFieldData $sitefielddata,
SiteFieldDecodeFilter $sitefielddecodefilter,
ModelExpertFieldInitiator $modelexpertfieldinitiator,
EventDispatcher $eventdispatcher,
DecodeColumn $decodecolumn, FilterColumn $filtercolumn,
FieldonContentPrepare $fieldoncontentprepare,
UikitLoader $uikitloader, Globals $globals,
CustomJoin $customjoin)
{
$this->config = $config;
$this->sitedecrypt = $sitedecrypt;
$this->placeholder = $placeholder;
$this->contentone = $contentone;
$this->sitefielddata = $sitefielddata;
$this->sitefielddecodefilter = $sitefielddecodefilter;
$this->modelexpertfieldinitiator = $modelexpertfieldinitiator;
$this->eventdispatcher = $eventdispatcher;
$this->decodecolumn = $decodecolumn;
$this->filtercolumn = $filtercolumn;
$this->fieldoncontentprepare = $fieldoncontentprepare;
$this->uikitloader = $uikitloader;
$this->globals = $globals;
$this->customjoin = $customjoin;
}
/**
* Generate the GetItems code block for the dynamicget.
*
* @param object $get The get object.
* @param string $code The component code.
*
* @return string The resulting PHP code string.
* @since 5.1.2
*/
public function get($get, string $code): string
{
if (empty($code) || !ObjectHelper::check($get))
{
return PHP_EOL;
}
$this->removeCryptionTypes($code);
$getItem = PHP_EOL . PHP_EOL . Indent::_(2) . "//"
. Line::_(__LINE__, __CLASS__) . " Insure all item fields are adapted where needed.";
$getItem .= PHP_EOL . Indent::_(2) . "if (Super_" . "__0a59c65c_9daf_4bc9_baf4_e063ff9e6a8a___Power::check(\$items))";
$getItem .= PHP_EOL . Indent::_(2) . "{";
$getItem .= Placefix::_h("DISPATCHER");
$getItem .= PHP_EOL . Indent::_(3) . "foreach (\$items as \$nr => &\$item)";
$getItem .= PHP_EOL . Indent::_(3) . "{";
$getItem .= PHP_EOL . Indent::_(4) . "//" . Line::_(__LINE__, __CLASS__) . " Always create a slug for sef URL's";
$getItem .= PHP_EOL . Indent::_(4) . "\$item->slug = (\$item->id ?? '0') . (isset(\$item->alias) ? ':' . \$item->alias : '');";
$asBucket = [];
if (isset($get->main_get) && ArrayHelper::check($get->main_get))
{
$getItem .= $this->buildPostProcessFieldChecks($get, $code, Indent::_(2), $asBucket);
}
$getItem .= $this->buildGlobals($get, $code, Indent::_(2), $asBucket);
$getItem .= $this->buildCustomJoin($get, $code, Indent::_(2), $asBucket);
$getItem .= $this->buildCalculation($get);
$getItem = $this->injectDispatcherIfNeeded($getItem, $code);
$getItem .= PHP_EOL . Indent::_(3) . "}";
$getItem .= PHP_EOL . Indent::_(2) . "}";
if (strlen($getItem) <= 100)
{
return PHP_EOL;
}
$script = $this->buildCryptionScript($code);
return $script . $getItem;
}
/**
* Remove all cryption type flags for this code.
*
* @param string $code
*
* @return void
* @since 5.1.2
*/
private function removeCryptionTypes(string $code): void
{
foreach ($this->config->cryption_types as $cryptionType)
{
$this->sitedecrypt->remove("{$cryptionType}.{$code}");
}
}
/**
* Handle decode, filter, prepare, UIkit field processing.
*
* @param object $get
* @param string $code
* @param string $tab
* @param string[] &$asBucket
*
* @return string
* @since 5.1.2
*/
private function buildPostProcessFieldChecks(object $get, string $code, string $tab, array &$asBucket): string
{
$output = '';
foreach ($get->main_get as $main_get)
{
if (!isset($main_get['key'], $main_get['as']))
{
continue;
}
$path = $code . '.' . $main_get['key'] . '.' . $main_get['as'];
$decodeChecker = $this->sitefielddata->get('decode.' . $path);
$decodeFilter = $this->sitefielddecodefilter->get($this->config->build_target . '.' . $path);
$contentprepareChecker = $this->sitefielddata->get('textareas.' . $path);
$uikitChecker = $this->sitefielddata->get('uikit.' . $path);
$decoder = $this->getDecoderCode($main_get, $code, $tab, $decodeChecker);
$decoderFilter = $this->getDecoderFilterCode($main_get, $code, $tab, $decodeFilter);
$contentPrepare = $this->getContentPrepareCode($main_get, $code, $tab, $contentprepareChecker);
$uikit = $this->getUIKitCode($main_get, $code, $tab, $uikitChecker);
if ($this->hasFieldProcessing($decoder, $decoderFilter, $contentPrepare, $uikit))
{
$output .= $this->buildFieldProcessingBlock($decoder, $decoderFilter, $contentPrepare, $uikit);
}
$asBucket[] = $main_get['as'];
}
return $output;
}
/**
* Generate decoder block code for the matched field set.
*
* @param array $get The get definition.
* @param string $code The code name.
* @param string $tab The tabing string
* @param array|null $checker The decoder rules to apply (if any).
*
* @return string The decoder logic code block or an empty string.
* @since 5.1.2
*/
private function getDecoderCode(array $get, string $code, string $tab, ?array $checker): string
{
return ($checker !== null && ArrayHelper::check($checker))
? $this->decodecolumn->get($get, $checker, '$item', $code, $tab)
: '';
}
/**
* Generate filter decoder block for field-specific filters.
*
* @param array $get The get definition.
* @param string $code The code name.
* @param string $tab The tabing string
* @param array|null $checker The filter configuration to apply (if any).
*
* @return string The filtered decoder code block or an empty string.
* @since 5.1.2
*/
private function getDecoderFilterCode(array $get, string $code, string $tab, ?array $checker): string
{
return ($checker !== null && ArrayHelper::check($checker))
? $this->filtercolumn->get($get, $checker, '$item', '$items[$nr]', $code, $tab)
: '';
}
/**
* Generate content preparation code for specified textarea fields.
*
* @param array $get The get definition.
* @param string $code The code name.
* @param string $tab The tabing string
* @param array|null $checker The content prepare configuration to apply (if any).
*
* @return string The content prepare code block or an empty string.
* @since 5.1.2
*/
private function getContentPrepareCode(array $get, string $code, string $tab, ?array $checker): string
{
return ($checker !== null && ArrayHelper::check($checker))
? $this->fieldoncontentprepare->get($get, $checker, '$item', $code, $tab)
: '';
}
/**
* Generate UIkit-specific field formatting code.
*
* @param array $get The get definition.
* @param string $code The code name.
* @param string $tab The tabing string
* @param array|null $checker The UIkit config for visual formatting (if any).
*
* @return string The UIkit loader code block or an empty string.
* @since 5.1.2
*/
private function getUIKitCode(array $get, string $code, string $tab, ?array $checker): string
{
return ($checker !== null && ArrayHelper::check($checker))
? $this->uikitloader->get($get, $checker, '$item', $code, $tab)
: '';
}
/**
* Check if any of the provided code parts contain executable logic.
*
* @param string ...$parts The list of code strings to evaluate.
*
* @return bool True if any string is non-empty and valid.
* @since 5.1.2
*/
private function hasFieldProcessing(string ...$parts): bool
{
foreach ($parts as $part)
{
if (StringHelper::check($part))
{
return true;
}
}
return false;
}
/**
* Build the complete foreach loop block to process all returned items.
*
* @param string $decoder The decoder block.
* @param string $decoderFilter The decoder filter block.
* @param string $contentPrepare The content prepare block.
* @param string $uikit The UIkit block.
*
* @return string The complete loop and return block for $items.
* @since 5.1.2
*/
private function buildFieldProcessingBlock(
string $decoder,
string $decoderFilter,
string $contentPrepare,
string $uikit
): string
{
$code = '';
foreach ([$decoder, $decoderFilter, $contentPrepare, $uikit] as $block)
{
if (StringHelper::check($block))
{
$code .= $block;
}
}
return $code;
}
/**
* Build the cryption script injection.
*
* @param string $code
*
* @return string
* @since 5.1.2
*/
private function buildCryptionScript(string $code): string
{
$script = '';
$component = $this->contentone->get('Component');
foreach ($this->config->cryption_types as $cryptionType)
{
if ($this->sitedecrypt->get("{$cryptionType}.{$code}") !== null)
{
if ('expert' !== $cryptionType)
{
$script .= PHP_EOL . PHP_EOL . Indent::_(2) . "//" . Line::_(__LINE__, __CLASS__) . " Get the {$cryptionType} encryption.";
$script .= PHP_EOL . Indent::_(2) . "\${$cryptionType}key = {$component}Helper::getCryptKey('{$cryptionType}');";
$script .= PHP_EOL . Indent::_(2) . "//" . Line::_(__LINE__, __CLASS__) . " Get the encryption object.";
$script .= PHP_EOL . Indent::_(2) . "\${$cryptionType} = new Super__"."_99175f6d_dba8_4086_8a65_5c4ec175e61d___Power(\${$cryptionType}key);";
}
elseif ($this->modelexpertfieldinitiator->exists("{$code}.get"))
{
foreach ($this->modelexpertfieldinitiator->get("{$code}.get") as $block)
{
$script .= PHP_EOL . Indent::_(2) . implode(PHP_EOL . Indent::_(2), $block);
}
}
}
}
return $script;
}
/**
* Build the global loader.
*
* @param object $get
* @param string $code
* @param string $tab
* @param string[] $asBucket
*
* @return string
* @since 5.1.2
*/
private function buildGlobals(object $get, string $code, string $tab, array $asBucket): string
{
return $this->globals->get($get->global ?? [], '$item', $asBucket, $tab);
}
/**
* Build the custom join logic.
*
* @param object $get
* @param string $code
* @param string $tab
* @param string[] $asBucket
*
* @return string
* @since 5.1.2
*/
private function buildCustomJoin(object $get, string $code, string $tab, array $asBucket): string
{
return $this->customjoin->get($get->custom_get ?? [], '$item', $code, $asBucket, $tab);
}
/**
* Build the custom calculation logic block.
*
* @param object $get
*
* @return string
* @since 5.1.2
*/
private function buildCalculation(object $get): string
{
if (isset($get->addcalculation) && $get->addcalculation == 1 && !empty($get->php_calculation))
{
$get->php_calculation = (array) explode(PHP_EOL, (string) $this->placeholder->update_($get->php_calculation));
return PHP_EOL . Indent::_(4) . implode(PHP_EOL . Indent::_(4), $get->php_calculation);
}
return '';
}
/**
* Inject dispatcher logic if placeholder exists.
*
* @param string $getItem
* @param string $code
*
* @return string
* @since 5.1.2
*/
private function injectDispatcherIfNeeded(string $getItem, string $code): string
{
if (strpos($getItem, (string) Placefix::_h('DISPATCHER')) !== false)
{
return str_replace(
Placefix::_h('DISPATCHER'),
$this->eventdispatcher->get($code, ''),
$getItem
);
}
return $getItem;
}
}

View File

@@ -0,0 +1,97 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Dynamicget;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
use VDM\Joomla\Utilities\StringHelper;
/**
* Dynamic Get Globals
*
* @since 5.1.2
*/
final class Globals
{
/**
* Generate PHP code for setting dynamic get global values.
*
* @param array $global The list of global configuration items.
* @param string $string The base string reference to the data source.
* @param array $as The list of aliases to process.
* @param string $tab The tab indentation string (optional).
*
* @return string The generated PHP code for setting global values.
* @since 5.1.2
*/
public function get(array $global, string $string, array $as, string $tab = ''): string
{
if (empty($global) || empty($string) || empty($as))
{
return '';
}
$as = array_unique($as);
$globals = '';
foreach ($global as $glo)
{
if (!isset($glo['as']) ||
!in_array($glo['as'], $as) ||
!isset($glo['type']) ||
!is_numeric($glo['type'])
)
{
continue;
}
switch ($glo['type'])
{
case 1:
// SET STATE
$value = "\$this->setState('" . $glo['as'] . "."
. $glo['name'] . "', " . $string . "->"
. $glo['key'] . ");";
break;
case 2:
// SET THIS
$value = "\$this->" . $glo['as'] . "_"
. $glo['name'] . " = " . $string . "->"
. $glo['key'] . ";";
break;
default:
$value = '';
break;
}
// Only add if the filter is set
if (StringHelper::check($value))
{
$globals .= PHP_EOL
. Indent::_(1) . $tab . Indent::_(1)
. "//" . Line::_(__LINE__, __CLASS__)
. " set the global " . $glo['name'] . " value."
. PHP_EOL
. Indent::_(1) . $tab . Indent::_(1)
. $value;
}
}
return $globals;
}
}

View File

@@ -0,0 +1,106 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Dynamicget;
use VDM\Joomla\Utilities\StringHelper;
/**
* Dynamic Get Join Structure
*
* @since 5.1.2
*/
final class JoinStructure
{
/**
* Get the default method structure for a custom view join.
*
* @param array $get The method definition array.
* @param string $code The code snippet related to the method.
*
* @return array|null The normalized method array or null on failure.
* @since 5.1.2
*/
public function get(array $get, string $code): ?array
{
if (!isset($get['key']) || !isset($get['as']) || empty($code))
{
return null;
}
$key = substr(
(string) StringHelper::safe(
preg_replace('/[0-9]+/', '', md5((string) $get['key'])), 'F'
),
0,
4
);
$method = [];
$method['on_field'] = isset($get['on_field'])
? $this->getFieldName($get['on_field'])
: null;
$method['join_field'] = isset($get['join_field'])
? StringHelper::safe($this->getFieldName($get['join_field']))
: null;
$method['Join_field'] = isset($method['join_field'])
? StringHelper::safe($method['join_field'], 'F')
: null;
$method['name'] = StringHelper::safe($get['selection']['name'], 'F');
$method['code'] = StringHelper::safe($code);
$method['AS'] = StringHelper::safe($get['as'], 'U');
$method['as'] = StringHelper::safe($get['as']);
$method['valueName'] = $method['on_field']
. $method['Join_field']
. $method['name']
. $method['AS'];
$method['methodName'] = StringHelper::safe($method['on_field'], 'F')
. $method['Join_field']
. $method['name']
. $key
. '_'
. $method['AS'];
return $method;
}
/**
* Remove the alias (AS) portion from a dot-notation string.
*
* @param string $string The input string possibly containing a dot (e.g. `a.name`).
*
* @return string The portion after the dot or the original string if no dot found.
* @since 5.1.2
*/
public function getFieldName(string $string): string
{
if (strpos($string, '.') !== false)
{
list(, $field) = array_map('trim', explode('.', $string, 2));
return $field;
}
return $string;
}
}

View File

@@ -0,0 +1,212 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Dynamicget;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Customcode\Dispenser;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\Queries;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\QueryFilter;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\QueryWhere;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\QueryOrder;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\QueryGroup;
use VDM\Joomla\Utilities\ObjectHelper;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
/**
* Dynamic Get List Query
*
* @since 5.1.2
*/
final class ListQuery
{
/**
* The Config Class.
*
* @var Config
* @since 5.1.2
*/
protected Config $config;
/**
* The Dispenser Class.
*
* @var Dispenser
* @since 5.1.2
*/
protected Dispenser $dispenser;
/**
* The Queries Class.
*
* @var Queries
* @since 5.1.2
*/
protected Queries $queries;
/**
* The QueryFilter Class.
*
* @var QueryFilter
* @since 5.1.2
*/
protected QueryFilter $queryfilter;
/**
* The QueryWhere Class.
*
* @var QueryWhere
* @since 5.1.2
*/
protected QueryWhere $querywhere;
/**
* The QueryOrder Class.
*
* @var QueryOrder
* @since 5.1.2
*/
protected QueryOrder $queryorder;
/**
* The QueryGroup Class.
*
* @var QueryGroup
* @since 5.1.2
*/
protected QueryGroup $querygroup;
/**
* Constructor.
*
* @param Config $config The Config Class.
* @param Dispenser $dispenser The Dispenser Class.
* @param Queries $queries The Queries Class.
* @param QueryFilter $queryfilter The QueryFilter Class.
* @param QueryWhere $querywhere The QueryWhere Class.
* @param QueryOrder $queryorder The QueryOrder Class.
* @param QueryGroup $querygroup The QueryGroup Class.
*
* @since 5.1.2
*/
public function __construct(Config $config, Dispenser $dispenser, Queries $queries,
QueryFilter $queryfilter, QueryWhere $querywhere,
QueryOrder $queryorder, QueryGroup $querygroup)
{
$this->config = $config;
$this->dispenser = $dispenser;
$this->queries = $queries;
$this->queryfilter = $queryfilter;
$this->querywhere = $querywhere;
$this->queryorder = $queryorder;
$this->querygroup = $querygroup;
}
/**
* Build the custom view list query code block.
*
* @param object $get The GET configuration object.
* @param string $code The current code name.
* @param bool $return Whether to include `return $query;`.
*
* @return string The full PHP code block as a string.
* @since 5.1.2
*/
public function get($get, $code, $return = true): string
{
if (!ObjectHelper::check($get))
{
return PHP_EOL . Indent::_(2) . "//" . Line::_(__LINE__, __CLASS__)
. "add your custom code here.";
}
if (($get->pagination ?? 0) == 1)
{
$listQuery = PHP_EOL . Indent::_(2) . "//" . Line::_(__LINE__, __CLASS__)
. " Get a db connection.";
}
else
{
$listQuery = PHP_EOL . Indent::_(2) . "//" . Line::_(__LINE__, __CLASS__)
. " Make sure all records load, since no pagination allowed.";
$listQuery .= PHP_EOL . Indent::_(2)
. "\$this->setState('list.limit', 0);";
$listQuery .= PHP_EOL . Indent::_(2) . "//" . Line::_(__LINE__, __CLASS__)
. " Get a db connection.";
}
if ($this->config->get('joomla_version', 3) == 3)
{
$listQuery .= PHP_EOL . Indent::_(2) . "\$db = Joomla__"."_39403062_84fb_46e0_bac4_0023f766e827___Power::getDbo();";
}
else
{
$listQuery .= PHP_EOL . Indent::_(2) . "\$db = \$this->getDatabase();";
}
$listQuery .= PHP_EOL . PHP_EOL . Indent::_(2) . "//" . Line::_(__LINE__, __CLASS__)
. " Create a new query object.";
$listQuery .= PHP_EOL . Indent::_(2) . "\$query = \$db->getQuery(true);";
// Main GET query
$listQuery .= $this->queries->get($get->main_get, $code);
// Custom script
$listQuery .= $this->dispenser->get(
$this->config->build_target . '_php_getlistquery',
$code,
'',
PHP_EOL . PHP_EOL . Indent::_(2) . "//" . Line::_(__LINE__, __CLASS__) . " Filtering.",
true
);
// Optional parts
$listQuery .= $this->applyAdditionalQueries($get, $code);
if ($return)
{
$listQuery .= PHP_EOL . PHP_EOL . Indent::_(2) . "//" . Line::_(__LINE__, __CLASS__)
. " return the query object"
. PHP_EOL . Indent::_(2) . "return \$query;";
}
return $listQuery;
}
/**
* Apply additional query parts (filter, where, order, group).
*
* @param object $get The get object values.
* @param string $code The current code name.
*
* @return string
* @since 5.1.2
*/
private function applyAdditionalQueries(object $get, string $code): string
{
$listQuery = '';
// Optional parts
foreach (['queryfilter' => 'filter', 'querywhere' => 'where', 'queryorder' => 'order', 'querygroup' => 'group'] as $queryType => $field)
{
if (isset($get->{$field}))
{
$listQuery .= $this->{$queryType}->get($get->{$field}, $code);
}
}
return $listQuery;
}
}

View File

@@ -0,0 +1,284 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Dynamicget;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\GetItem;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\GetItems;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\ListQuery;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\CustomGetMethods;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\UikitLoader;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Utilities\ObjectHelper;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
use Joomla\CMS\Factory;
/**
* Dynamic Get Methods
*
* @since 5.1.2
*/
final class Methods
{
/**
* The Config Class.
*
* @var Config
* @since 5.1.2
*/
protected Config $config;
/**
* The Placeholder Class.
*
* @var Placeholder
* @since 5.1.2
*/
protected Placeholder $placeholder;
/**
* The GetItem Class.
*
* @var GetItem
* @since 5.1.2
*/
protected GetItem $getitem;
/**
* The GetItems Class.
*
* @var GetItems
* @since 5.1.2
*/
protected GetItems $getitems;
/**
* The ListQuery Class.
*
* @var ListQuery
* @since 5.1.2
*/
protected ListQuery $listquery;
/**
* The CustomGetMethods Class.
*
* @var CustomGetMethods
* @since 5.1.2
*/
protected CustomGetMethods $customgetmethods;
/**
* The UikitLoader Class.
*
* @var UikitLoader
* @since 5.1.2
*/
protected UikitLoader $uikitloader;
/**
* Constructor.
*
* @param Config $config The Config Class.
* @param Placeholder $placeholder The Placeholder Class.
* @param GetItem $getitem The GetItem Class.
* @param GetItems $getitems The GetItems Class.
* @param ListQuery $listquery The ListQuery Class.
* @param CustomGetMethods $customgetmethods The CustomGetMethods Class.
* @param UikitLoader $uikitloader The UikitLoader Class.
*
* @since 5.1.2
*/
public function __construct(Config $config, Placeholder $placeholder, GetItem $getitem,
GetItems $getitems, ListQuery $listquery,
CustomGetMethods $customgetmethods,
UikitLoader $uikitloader)
{
$this->config = $config;
$this->placeholder = $placeholder;
$this->getitem = $getitem;
$this->getitems = $getitems;
$this->listquery = $listquery;
$this->customgetmethods = $customgetmethods;
$this->uikitloader = $uikitloader;
}
/**
* Get the required data to generate dynamicget methods.
*
* @param array|object $mainView The main view data
* @param string $code The component code
*
* @return string The generated methods
* @since 5.1.2
*/
public function get($mainView, string $code): string
{
if (empty($mainView) || empty($code))
{
return '';
}
$methods = '';
if (
ArrayHelper::check($mainView)
&& isset($mainView['settings'])
&& ObjectHelper::check($mainView['settings'])
&& isset($mainView['settings']->custom_get)
) {
$_dynamic_get = $mainView['settings']->custom_get;
} elseif (ObjectHelper::check($mainView) && isset($mainView->custom_get)) {
$_dynamic_get = $mainView->custom_get;
}
if (isset($_dynamic_get) && ArrayHelper::check($_dynamic_get))
{
foreach ($_dynamic_get as $view)
{
$view->code = StringHelper::safe($code);
$view->Code = StringHelper::safe($view->code, 'F');
$view->CODE = StringHelper::safe($view->code, 'U');
$main = '';
if ($view->gettype == 3)
{
if ($this->config->get('joomla_version', 3) == 3)
{
$main .= PHP_EOL . PHP_EOL . Indent::_(2) . "if (!isset(\$this->initSet) || !\$this->initSet)";
$main .= PHP_EOL . Indent::_(2) . "{";
$main .= PHP_EOL . Indent::_(3) . "\$this->user = Factory::getUser();";
$main .= PHP_EOL . Indent::_(3) . "\$this->userId = \$this->user->get('id');";
$main .= PHP_EOL . Indent::_(3) . "\$this->guest = \$this->user->get('guest');";
$main .= PHP_EOL . Indent::_(3) . "\$this->groups = \$this->user->get('groups');";
$main .= PHP_EOL . Indent::_(3) . "\$this->authorisedGroups = \$this->user->getAuthorisedGroups();";
$main .= PHP_EOL . Indent::_(3) . "\$this->levels = \$this->user->getAuthorisedViewLevels();";
$main .= PHP_EOL . Indent::_(3) . "\$this->initSet = true;";
$main .= PHP_EOL . Indent::_(2) . "}";
}
$main .= $this->getitem->get($view, $view->code, '', 'custom');
$type = 'mixed item data object on success, false on failure.';
}
elseif ($view->gettype == 4)
{
if ($this->config->get('joomla_version', 3) == 3)
{
$main .= PHP_EOL . PHP_EOL . Indent::_(2) . "if (!isset(\$this->initSet) || !\$this->initSet)";
$main .= PHP_EOL . Indent::_(2) . "{";
$main .= PHP_EOL . Indent::_(3) . "\$this->user = Factory::getUser();";
$main .= PHP_EOL . Indent::_(3) . "\$this->userId = \$this->user->get('id');";
$main .= PHP_EOL . Indent::_(3) . "\$this->guest = \$this->user->get('guest');";
$main .= PHP_EOL . Indent::_(3) . "\$this->groups = \$this->user->get('groups');";
$main .= PHP_EOL . Indent::_(3) . "\$this->authorisedGroups = \$this->user->getAuthorisedGroups();";
$main .= PHP_EOL . Indent::_(3) . "\$this->levels = \$this->user->getAuthorisedViewLevels();";
$main .= PHP_EOL . Indent::_(3) . "\$this->initSet = true;";
$main .= PHP_EOL . Indent::_(2) . "}";
}
$main .= PHP_EOL . PHP_EOL . Indent::_(2) . "//" . Line::_(__LINE__, __CLASS__) . " Get the global params";
$main .= PHP_EOL . Indent::_(2) . "\$globalParams = ComponentHelper::getParams('com_" . $this->config->component_code_name . "', true);";
if (
isset($view->add_php_getlistquery)
&& $view->add_php_getlistquery == 1
&& isset($view->php_getlistquery)
&& StringHelper::check($view->php_getlistquery)
) {
$main .= $this->placeholder->update_($view->php_getlistquery);
}
$main .= $this->listquery->get($view, $view->code, false);
if (
isset($view->add_php_before_getitems)
&& $view->add_php_before_getitems == 1
&& isset($view->php_before_getitems)
&& StringHelper::check($view->php_before_getitems)
) {
$main .= $this->placeholder->update_($view->php_before_getitems);
}
$main .= PHP_EOL . PHP_EOL . Indent::_(2) . "//" . Line::_(__LINE__, __CLASS__) . " Reset the query using our newly populated query object.";
$main .= PHP_EOL . Indent::_(2) . "\$db->setQuery(\$query);";
$main .= PHP_EOL . Indent::_(2) . "\$items = \$db->loadObjectList();";
$main .= PHP_EOL . PHP_EOL . Indent::_(2) . "if (empty(\$items))";
$main .= PHP_EOL . Indent::_(2) . "{";
$main .= PHP_EOL . Indent::_(3) . "return false;";
$main .= PHP_EOL . Indent::_(2) . "}";
$main .= $this->getitems->get($view, $view->code);
if (
isset($view->add_php_after_getitems)
&& $view->add_php_after_getitems == 1
&& isset($view->php_after_getitems)
&& StringHelper::check($view->php_after_getitems)
) {
$main .= $this->placeholder->update_($view->php_after_getitems);
}
$main .= PHP_EOL . Indent::_(2) . "//" . Line::_(__LINE__, __CLASS__) . " return items";
$main .= PHP_EOL . Indent::_(2) . "return \$items;";
$type = 'mixed An array of objects on success, false on failure.';
}
$methods .= $this->getMethod($main, $view->getcustom, $type);
$methods .= $this->customgetmethods->get($view, $view->code);
}
}
if (ArrayHelper::check($mainView) && isset($mainView['settings']))
{
$methods .= $this->uikitloader->getUikitComp();
}
return $methods;
}
/**
* Get the main custom method block.
*
* @param string $body The PHP code body
* @param string $name The function name
* @param string $type The doc return type
*
* @return string The built method block
* @since 5.1.2
*/
public function getMethod(string $body, string $name, string $type): string
{
$method = '';
if (StringHelper::check($body))
{
$method .= PHP_EOL . PHP_EOL . Indent::_(1) . "/**";
$method .= PHP_EOL . Indent::_(1) . " * Custom Method";
$method .= PHP_EOL . Indent::_(1) . " *";
$method .= PHP_EOL . Indent::_(1) . " * @return " . $type;
$method .= PHP_EOL . Indent::_(1) . " *";
$method .= PHP_EOL . Indent::_(1) . " */";
$method .= PHP_EOL . Indent::_(1) . "public function " . $name . "()";
$method .= PHP_EOL . Indent::_(1) . "{" . $body;
$method .= PHP_EOL . Indent::_(1) . "}";
}
return $method;
}
}

View File

@@ -0,0 +1,281 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Dynamicget;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\JoinStructure;
use VDM\Joomla\Componentbuilder\Compiler\Builder\SiteDynamicGet;
use VDM\Joomla\Componentbuilder\Compiler\Builder\OtherQuery;
use VDM\Joomla\Componentbuilder\Compiler\Placeholder;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
/**
* Dynamic Get Queries
*
* @since 5.1.2
*/
final class Queries
{
/**
* The Config Class.
*
* @var Config
* @since 5.1.2
*/
protected Config $config;
/**
* The JoinStructure Class.
*
* @var JoinStructure
* @since 5.1.2
*/
protected JoinStructure $joinstructure;
/**
* The SiteDynamicGet Class.
*
* @var SiteDynamicGet
* @since 5.1.2
*/
protected SiteDynamicGet $sitedynamicget;
/**
* The OtherQuery Class.
*
* @var OtherQuery
* @since 5.1.2
*/
protected OtherQuery $otherquery;
/**
* The Placeholder Class.
*
* @var Placeholder
* @since 5.1.2
*/
protected Placeholder $placeholder;
/**
* The custom view query checker array.
*
* @var array
* @since 5.1.2
*/
protected $customViewQueryChecker = [];
/**
* Constructor.
*
* @param Config $config The Config Class.
* @param JoinStructure $joinstructure The JoinStructure Class.
* @param SiteDynamicGet $sitedynamicget The SiteDynamicGet Class.
* @param OtherQuery $otherquery The OtherQuery Class.
* @param Placeholder $placeholder The Placeholder Class.
*
* @since 5.1.2
*/
public function __construct(Config $config, JoinStructure $joinstructure,
SiteDynamicGet $sitedynamicget, OtherQuery $otherquery,
Placeholder $placeholder)
{
$this->config = $config;
$this->joinstructure = $joinstructure;
$this->sitedynamicget = $sitedynamicget;
$this->otherquery = $otherquery;
$this->placeholder = $placeholder;
}
/**
* Get the dynamic get query.
*
* @param array $gets The data to build the query from.
* @param string $code The build code.
* @param string $tab The tab indentation.
* @param string $type The query type (main|custom).
*
* @return string The compiled query string.
* @since 5.1.2
*/
public function get(array $gets, $code, string $tab = '', string $type = 'main'): string
{
if (empty($gets) || empty($code))
{
return '';
}
$query = '';
$mainAsArray = [];
$check = 'zzz';
foreach ($gets as $nr => $theGet)
{
if ($this->isUniqueQueryEntry($theGet, $code))
{
$getItem = $this->buildSelectPart($theGet, $tab);
$getItem .= $this->buildFromOrJoinPart($theGet, $nr, $tab, $type, $check);
$query .= $this->appendWithMethodDefaults($theGet, $code, $getItem, $check, $mainAsArray);
}
}
return $query;
}
/**
* Check if the query entry is unique.
*
* @param array $theGet The query data.
* @param string $code The build code.
*
* @return bool True if unique, false otherwise.
* @since 5.1.2
*/
protected function isUniqueQueryEntry(array $theGet, string $code): bool
{
$checker = md5(serialize($theGet) . $code);
$target = $this->config->build_target;
if (!isset($this->customViewQueryChecker[$target][$checker]))
{
$this->customViewQueryChecker[$target][$checker] = true;
return true;
}
return false;
}
/**
* Build the select part of the query.
*
* @param array $theGet The query data.
* @param string $tab The tab indentation.
*
* @return string The select part.
* @since 5.1.2
*/
protected function buildSelectPart(array $theGet, string $tab): string
{
if (isset($theGet['selection']['type']) && StringHelper::check($theGet['selection']['type']))
{
$getItem = PHP_EOL . PHP_EOL . Indent::_(1) . $tab
. Indent::_(1) . "//" . Line::_(__LINE__, __CLASS__)
. " Get from " . $theGet['selection']['table']
. " as " . $theGet['as'];
$getItem .= PHP_EOL . Indent::_(1) . $tab . Indent::_(1)
. $theGet['selection']['select'];
}
else
{
$getItem = PHP_EOL . PHP_EOL . Indent::_(1) . $tab
. Indent::_(1) . "//" . Line::_(__LINE__, __CLASS__)
. " Get data";
$getItem .= PHP_EOL . $this->placeholder->update_(
$theGet['selection']['select']
);
}
return $getItem;
}
/**
* Build the FROM or JOIN part of the query.
*
* @param array $theGet The query data.
* @param int $nr The current iteration number.
* @param string $tab The tab indentation.
* @param string $type The query type.
* @param string &$check The check variable.
*
* @return string The FROM or JOIN part.
* @since 5.1.2
*/
protected function buildFromOrJoinPart(array $theGet, int $nr, string $tab, string $type, string &$check): string
{
$output = '';
if (
($nr === 0
&& (!isset($theGet['join_field']) || !StringHelper::check($theGet['join_field']))
&& isset($theGet['selection']['type']) && StringHelper::check($theGet['selection']['type']))
|| ($type === 'custom'
&& isset($theGet['selection']['type']) && StringHelper::check($theGet['selection']['type']))
)
{
$output .= PHP_EOL . Indent::_(1) . $tab . Indent::_(1)
. '$query->from(' . $theGet['selection']['from'] . ');';
}
elseif (
isset($theGet['join_field']) && StringHelper::check($theGet['join_field'])
&& isset($theGet['selection']['type']) && StringHelper::check($theGet['selection']['type'])
)
{
$output .= PHP_EOL . Indent::_(1) . $tab . Indent::_(1)
. "\$query->join('" . $theGet['type'] . "', (" . $theGet['selection']['from']
. ") . ' ON (' . \$db->quoteName('" . $theGet['on_field']
. "') . ' " . $theGet['operator']
. " ' . \$db->quoteName('" . $theGet['join_field'] . "') . ')');";
$check = current(explode(".", (string) $theGet['on_field']));
}
return $output;
}
/**
* Append the method defaults handling to the query string.
*
* @param array $theGet The query data.
* @param string $code The build code.
* @param string $getItem The built query part.
* @param string $check The check variable.
* @param array &$mainAsArray The main AS array.
*
* @return string The resulting query addition.
* @since 5.1.2
*/
protected function appendWithMethodDefaults(array $theGet, string $code, string $getItem, string $check, array &$mainAsArray): string
{
$output = '';
if (($default = $this->joinstructure->get($theGet, $code)) !== null)
{
$joinFieldKey = $this->config->build_target . '.' . $default['code'] . '.' . $default['as'] . '.' . $default['join_field'];
if (($join_field_ = $this->sitedynamicget->get($joinFieldKey)) !== null
&& !in_array($check, $mainAsArray))
{
$this->otherquery->add(
$this->config->build_target . '.' . $default['code'] . '.' . $join_field_ . '.' . $default['valueName'],
$getItem,
false
);
}
else
{
$mainAsArray[] = $default['as'];
$output .= $getItem;
}
}
return $output;
}
}

View File

@@ -0,0 +1,288 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Dynamicget;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Builder\SiteFieldData;
use VDM\Joomla\Componentbuilder\Compiler\Builder\SiteFieldDecodeFilter;
use VDM\Joomla\Componentbuilder\Compiler\Builder\SiteMainGet;
use VDM\Joomla\Componentbuilder\Compiler\Builder\OtherFilter;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
/**
* Dynamic Get Query Filter
*
* @since 5.1.2
*/
final class QueryFilter
{
/**
* The Config Class.
*
* @var Config
* @since 5.1.2
*/
protected Config $config;
/**
* The SiteFieldData Class.
*
* @var SiteFieldData
* @since 5.1.2
*/
protected SiteFieldData $sitefielddata;
/**
* The SiteFieldDecodeFilter Class.
*
* @var SiteFieldDecodeFilter
* @since 5.1.2
*/
protected SiteFieldDecodeFilter $sitefielddecodefilter;
/**
* The SiteMainGet Class.
*
* @var SiteMainGet
* @since 5.1.2
*/
protected SiteMainGet $sitemainget;
/**
* The OtherFilter Class.
*
* @var OtherFilter
* @since 5.1.2
*/
protected OtherFilter $otherfilter;
/**
* Constructor.
*
* @param Config $config The Config Class.
* @param SiteFieldData $sitefielddata The SiteFieldData Class.
* @param SiteFieldDecodeFilter $sitefielddecodefilter The SiteFieldDecodeFilter Class.
* @param SiteMainGet $sitemainget The SiteMainGet Class.
* @param OtherFilter $otherfilter The OtherFilter Class.
*
* @since 5.1.2
*/
public function __construct(Config $config, SiteFieldData $sitefielddata,
SiteFieldDecodeFilter $sitefielddecodefilter,
SiteMainGet $sitemainget, OtherFilter $otherfilter)
{
$this->config = $config;
$this->sitefielddata = $sitefielddata;
$this->sitefielddecodefilter = $sitefielddecodefilter;
$this->sitemainget = $sitemainget;
$this->otherfilter = $otherfilter;
}
/**
* Build the dynamic query filters for a dynamic get.
*
* @param array $filter The filter configuration array.
* @param string $code The code representing the view context.
* @param string $tab The indentation tab string.
*
* @return string The generated filter query strings.
* @since 5.1.2
*/
public function get(array $filter, string $code, string $tab = ''): string
{
if (empty($filter) || empty($code))
{
return '';
}
$filters = '';
foreach ($filter as $ter)
{
if (empty($ter['table_key']) || empty($ter['key']) ||
strpos((string) $ter['table_key'], '.') === false)
{
continue;
}
$as = '';
$field = '';
$string = '';
list($as, $field) = array_map('trim', explode('.', (string) $ter['table_key']));
$path = $code . '.' . $ter['key'] . '.' . $as . '.' . $field;
$filterType = $ter['filter_type'] ?? 0;
$operator = $ter['operator'] ?? '=';
switch ($filterType)
{
case 1: // COM_COMPONENTBUILDER_DYNAMIC_GET_ID
$string = PHP_EOL . Indent::_(1) . $tab . Indent::_(1)
. "\$query->where('" . $ter['table_key'] . " "
. $operator . " ' . (int) \$pk);";
break;
case 2: // COM_COMPONENTBUILDER_DYNAMIC_GET_USER
$string = PHP_EOL . Indent::_(1) . $tab . Indent::_(1)
. "\$query->where('" . $ter['table_key'] . " "
. $operator . " ' . (int) \$this->userId);";
break;
case 3: // COM_COMPONENTBUILDER_DYNAMIC_GET_ACCESS_LEVEL
$string = PHP_EOL . Indent::_(1) . $tab . Indent::_(1)
. "\$query->where('" . $ter['table_key'] . " "
. $operator . " (' . implode(',', \$this->levels) . ')');";
break;
case 4: // COM_COMPONENTBUILDER_DYNAMIC_GET_USER_GROUPS
$decodeChecker = $this->sitefielddata->get('decode.' . $path);
$stateKey = $ter['state_key'] ?? 'none';
if (ArrayHelper::check($decodeChecker) || $stateKey === 'array')
{
$this->sitefielddecodefilter
->set($this->config->build_target . '.' . $path, $ter);
}
else
{
$string = PHP_EOL . Indent::_(1) . $tab . Indent::_(1)
. "\$query->where('" . $ter['table_key'] . " "
. $operator . " (' . implode(',', \$this->groups) . ')');";
}
break;
case 5: // COM_COMPONENTBUILDER_DYNAMIC_GET_CATEGORIES
$string = PHP_EOL . Indent::_(2) . $tab . "//" . Line::_(__LINE__, __CLASS__)
. " (TODO) The dynamic category filter is not ready.";
break;
case 6: // COM_COMPONENTBUILDER_DYNAMIC_GET_TAGS
$string = PHP_EOL . Indent::_(2) . $tab . "//" . Line::_(__LINE__, __CLASS__)
. " (TODO) The dynamic tags filter is not ready.";
break;
case 7: // COM_COMPONENTBUILDER_DYNAMIC_GET_DATE
$string = PHP_EOL . Indent::_(2) . $tab . "//" . Line::_(__LINE__, __CLASS__)
. " (TODO) The dynamic date filter is not ready.";
break;
case 8: // COM_COMPONENTBUILDER_DYNAMIC_GET_FUNCTIONVAR
$string = $this->buildFunctionVarFilter($ter, $tab);
break;
case 9: // COM_COMPONENTBUILDER_DYNAMIC_GET_ARRAY_VALUE
case 10: // COM_COMPONENTBUILDER_DYNAMIC_GET_REPEATABLE_VALUE
$this->sitefielddecodefilter
->set($this->config->build_target . '.' . $path, $ter);
break;
case 11: // COM_COMPONENTBUILDER_DYNAMIC_GET_OTHER
if (strpos($as, '(') !== false)
{
list($dump, $as) = array_map('trim', explode('(', $as));
$field = trim(str_replace(')', '', $field));
}
$stateKey = $ter['state_key'] ?? 'error';
$string = PHP_EOL . Indent::_(1) . $tab . Indent::_(1)
. "\$query->where('" . $ter['table_key'] . " "
. $operator . " " . $stateKey . "');";
break;
}
if (StringHelper::check($string))
{
if ($as === 'a' ||
$this->sitemainget->exists($this->config->build_target . '.' . $code . '.' . $as))
{
$filters .= $string;
}
elseif ($as !== 'a')
{
$this->otherfilter->set($this->config->build_target . '.' . $code . '.' . $as . '.' . $field, $string);
}
}
}
return $filters;
}
/**
* Build dynamic filter for "FunctionVar" filter type (case 8).
*
* @param array $ter The filter term configuration.
* @param string $tab The indentation tab string.
*
* @return string The generated filter string.
* @since 5.1.2
*/
protected function buildFunctionVarFilter(array $ter, string $tab): string
{
$string = '';
$operator = $ter['operator'] ?? '=';
$stateKey = $ter['state_key'] ?? 'error';
if ($operator === 'IN' || $operator === 'NOT IN')
{
$string .= PHP_EOL . Indent::_(2) . $tab . "//" . Line::_(__LINE__, __CLASS__) . " Check if "
. $stateKey . " is an array with values.";
$string .= PHP_EOL . Indent::_(2) . $tab . "\$array = " . $stateKey . ";";
$string .= PHP_EOL . Indent::_(2) . $tab . "if (isset(\$array) && Super_" . "__0a59c65c_9daf_4bc9_baf4_e063ff9e6a8a___Power::check(\$array))";
$string .= PHP_EOL . Indent::_(2) . $tab . "{";
$string .= PHP_EOL . Indent::_(2) . $tab . Indent::_(1)
. "\$query->where('" . $ter['table_key'] . " " . $operator
. " (' . implode(',', \$array) . ')');";
$string .= PHP_EOL . Indent::_(2) . $tab . "}";
if (!isset($ter['empty']) || !$ter['empty'])
{
$string .= PHP_EOL . Indent::_(2) . $tab . "else";
$string .= PHP_EOL . Indent::_(2) . $tab . "{";
$string .= PHP_EOL . Indent::_(2) . $tab . Indent::_(1) . "return false;";
$string .= PHP_EOL . Indent::_(2) . $tab . "}";
}
}
else
{
$string .= PHP_EOL . Indent::_(2) . $tab . "//" . Line::_(__LINE__, __CLASS__) . " Check if "
. $stateKey . " is a string or numeric value.";
$string .= PHP_EOL . Indent::_(2) . $tab . "\$checkValue = " . $stateKey . ";";
$string .= PHP_EOL . Indent::_(2) . $tab . "if (isset(\$checkValue) && Super_" . "__1f28cb53_60d9_4db1_b517_3c7dc6b429ef___Power::check(\$checkValue))";
$string .= PHP_EOL . Indent::_(2) . $tab . "{";
$string .= PHP_EOL . Indent::_(2) . $tab . Indent::_(1)
. "\$query->where('" . $ter['table_key'] . " " . $operator
. " ' . \$db->quote(\$checkValue));";
$string .= PHP_EOL . Indent::_(2) . $tab . "}";
$string .= PHP_EOL . Indent::_(2) . $tab . "elseif (is_numeric(\$checkValue))";
$string .= PHP_EOL . Indent::_(2) . $tab . "{";
$string .= PHP_EOL . Indent::_(2) . $tab . Indent::_(1)
. "\$query->where('" . $ter['table_key'] . " " . $operator
. " ' . \$checkValue);";
$string .= PHP_EOL . Indent::_(2) . $tab . "}";
if (!isset($ter['empty']) || !$ter['empty'])
{
$string .= PHP_EOL . Indent::_(2) . $tab . "else";
$string .= PHP_EOL . Indent::_(2) . $tab . "{";
$string .= PHP_EOL . Indent::_(2) . $tab . Indent::_(1) . "return false;";
$string .= PHP_EOL . Indent::_(2) . $tab . "}";
}
}
return $string;
}
}

View File

@@ -0,0 +1,125 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Dynamicget;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Builder\OtherGroup;
use VDM\Joomla\Componentbuilder\Compiler\Builder\SiteMainGet;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
/**
* Dynamic Get Query Group
*
* @since 5.1.2
*/
final class QueryGroup
{
/**
* The Config Class.
*
* @var Config
* @since 5.1.2
*/
protected Config $config;
/**
* The OtherGroup Class.
*
* @var OtherGroup
* @since 5.1.2
*/
protected OtherGroup $othergroup;
/**
* The SiteMainGet Class.
*
* @var SiteMainGet
* @since 5.1.2
*/
protected SiteMainGet $sitemainget;
/**
* Constructor.
*
* @param Config $config The Config Class.
* @param OtherGroup $othergroup The OtherGroup Class.
* @param SiteMainGet $sitemainget The SiteMainGet Class.
*
* @since 5.1.2
*/
public function __construct(Config $config, OtherGroup $othergroup,
SiteMainGet $sitemainget)
{
$this->config = $config;
$this->othergroup = $othergroup;
$this->sitemainget = $sitemainget;
}
/**
* Generate GROUP BY code for the query.
*
* @param array $group The grouping configuration array.
* @param string $code The component code.
* @param string $tab The indentation tab characters.
*
* @return string The generated GROUP BY code.
* @since 5.1.2
*/
public function get(array $group, string $code, string $tab = ''): string
{
if (empty($group) || empty($code))
{
return '';
}
$grouping = '';
foreach ($group as $gr)
{
if (empty($gr['table_key']))
{
continue;
}
list($as, $field) = array_map(
'trim',
explode('.', (string) $gr['table_key'])
);
// Build the GROUP BY string
$string = "\$query->group('" . $gr['table_key'] . "');";
// Determine where to place the GROUP BY
if (
$as === 'a' ||
$this->sitemainget ->exists($this->config->build_target . '.' . $code . '.' . $as)
)
{
$grouping .= PHP_EOL
. Indent::_(1) . $tab
. Indent::_(1) . $string;
}
else
{
$this->othergroup->set(
$this->config->build_target . '.' . $code . '.' . $as . '.' . $field,
PHP_EOL . Indent::_(2) . $string
);
}
}
return $grouping;
}
}

View File

@@ -0,0 +1,130 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Dynamicget;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Builder\OtherOrder;
use VDM\Joomla\Componentbuilder\Compiler\Builder\SiteMainGet;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
/**
* Dynamic Get Query Order
*
* @since 5.1.2
*/
final class QueryOrder
{
/**
* The Config Class.
*
* @var Config
* @since 5.1.2
*/
protected Config $config;
/**
* The OtherOrder Class.
*
* @var OtherOrder
* @since 5.1.2
*/
protected OtherOrder $otherorder;
/**
* The SiteMainGet Class.
*
* @var SiteMainGet
* @since 5.1.2
*/
protected SiteMainGet $sitemainget;
/**
* Constructor.
*
* @param Config $config The Config Class.
* @param OtherOrder $otherorder The OtherOrder Class.
* @param SiteMainGet $sitemainget The SiteMainGet Class.
*
* @since 5.1.2
*/
public function __construct(Config $config, OtherOrder $otherorder,
SiteMainGet $sitemainget)
{
$this->config = $config;
$this->otherorder = $otherorder;
$this->sitemainget = $sitemainget;
}
/**
* Get the ordering part of a query for a dynamic get.
*
* @param array $order The ordering rules array (passed by reference).
* @param string $code The code identifier (passed by reference).
* @param string $tab The tab indentation.
*
* @return string The generated ordering query part.
* @since 5.1.2
*/
public function get(array $order, string $code, string $tab = ''): string
{
if (empty($order) || empty($code))
{
return '';
}
$ordering = '';
foreach ($order as $or)
{
if (empty($or['table_key']) || empty($or['direction']))
{
continue;
}
list($as, $field) = array_map(
'trim',
explode('.', (string) $or['table_key'])
);
// Determine ordering direction
if ('RAND' === $or['direction'])
{
$string = "\$query->order('RAND()');";
}
else
{
$string = "\$query->order('" . $or['table_key'] . " " . $or['direction'] . "');";
}
// Sort placement logic
if (
$as === 'a' ||
$this->sitemainget->exists($this->config->build_target . '.' . $code . '.' . $as)
)
{
$ordering .= PHP_EOL . Indent::_(1) . $tab . Indent::_(1) . $string;
}
else
{
$this->otherorder->set(
$this->config->build_target . '.' . $code . '.' . $as . '.' . $field,
PHP_EOL . Indent::_(2) . $string
);
}
}
return $ordering;
}
}

View File

@@ -0,0 +1,197 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Dynamicget;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Builder\OtherWhere;
use VDM\Joomla\Componentbuilder\Compiler\Builder\SiteMainGet;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
use VDM\Joomla\Utilities\StringHelper;
/**
* Dynamic Get Query Where
*
* @since 5.1.2
*/
final class QueryWhere
{
/**
* The Config Class.
*
* @var Config
* @since 5.1.2
*/
protected Config $config;
/**
* The OtherWhere Class.
*
* @var OtherWhere
* @since 5.1.2
*/
protected OtherWhere $otherwhere;
/**
* The SiteMainGet Class.
*
* @var SiteMainGet
* @since 5.1.2
*/
protected SiteMainGet $sitemainget;
/**
* Constructor.
*
* @param Config $config The Config Class.
* @param OtherWhere $otherwhere The OtherWhere Class.
* @param SiteMainGet $sitemainget The SiteMainGet Class.
*
* @since 5.1.2
*/
public function __construct(Config $config, OtherWhere $otherwhere,
SiteMainGet $sitemainget)
{
$this->config = $config;
$this->otherwhere = $otherwhere;
$this->sitemainget = $sitemainget;
}
/**
* Process and build WHERE clauses for a given dynamic get.
*
* @param array $where The WHERE clause definitions.
* @param string $code The code identifier for the view.
* @param string $tab Optional tab/indentation prefix.
*
* @return string The generated WHERE clauses as a string.
* @since 5.1.2
*/
public function get(array $where, string $code, string $tab = ''): string
{
if (empty($where) || empty($code))
{
return '';
}
$wheres = '';
foreach ($where as $whe)
{
if (empty($whe['table_key']) || empty($whe['value_key']))
{
continue;
}
$as = '';
$field = '';
$value = '';
// Extract table alias and field
list($as, $field) = array_map(
'trim',
explode('.', (string) $whe['table_key'])
);
// Determine value formatting
if (is_numeric($whe['value_key']))
{
$value = " " . $whe['value_key'] . "');";
}
elseif (strpos((string) $whe['value_key'], '$') !== false)
{
if (!empty($whe['operator']) && ($whe['operator'] === 'IN' || $whe['operator'] === 'NOT IN'))
{
$value = " (' . implode(',', " . $whe['value_key'] . ") . ')');";
}
else
{
$value = " ' . \$db->quote(" . $whe['value_key'] . "));";
}
}
elseif (strpos((string) $whe['value_key'], '.') !== false)
{
if (strpos((string) $whe['value_key'], "'") !== false)
{
$value = " ' . \$db->quote(" . $whe['value_key'] . "));";
}
else
{
$value = " " . $whe['value_key'] . "');";
}
}
elseif (StringHelper::check($whe['value_key']))
{
$value = " " . $whe['value_key'] . "');";
}
// Only proceed if we have a valid value
if (StringHelper::check($value))
{
$tabe = ($as === 'a') ? $tab : '';
if (empty($whe['operator']))
{
continue;
}
// Build string based on operator
if ($whe['operator'] === 'IN' || $whe['operator'] === 'NOT IN')
{
$string = "if (isset(" . $whe['value_key'] . ") && "
. "Super_" . "__0a59c65c_9daf_4bc9_baf4_e063ff9e6a8a___Power::check("
. $whe['value_key'] . "))";
$string .= PHP_EOL . Indent::_(1) . $tabe . Indent::_(1) . "{";
$string .= PHP_EOL . Indent::_(1) . $tabe . Indent::_(2)
. "//" . Line::_(__LINE__, __CLASS__) . " Get where "
. $whe['table_key'] . " is " . $whe['value_key'];
$string .= PHP_EOL . Indent::_(1) . $tabe . Indent::_(2)
. "\$query->where('" . $whe['table_key'] . " "
. $whe['operator'] . $value;
$string .= PHP_EOL . Indent::_(1) . $tabe . Indent::_(1) . "}";
$string .= PHP_EOL . Indent::_(1) . $tabe . Indent::_(1) . "else";
$string .= PHP_EOL . Indent::_(1) . $tabe . Indent::_(1) . "{";
$string .= PHP_EOL . Indent::_(1) . $tabe . Indent::_(2) . "return false;";
$string .= PHP_EOL . Indent::_(1) . $tabe . Indent::_(1) . "}";
}
else
{
$string = "//" . Line::_(__LINE__, __CLASS__) . " Get where "
. $whe['table_key'] . " is " . $whe['value_key'];
$string .= PHP_EOL . Indent::_(1) . $tabe . Indent::_(1)
. "\$query->where('" . $whe['table_key'] . " "
. $whe['operator'] . $value;
}
// Append or store WHERE clause
if (
$as === 'a' ||
$this->sitemainget->exists($this->config->build_target . '.' . $code . '.' . $as)
)
{
$wheres .= PHP_EOL . Indent::_(1) . $tab . Indent::_(1) . $string;
}
elseif ($as !== 'a')
{
$this->otherwhere->set(
$this->config->build_target . '.' . $code . '.' . $as . '.' . $field,
PHP_EOL . Indent::_(2) . $string
);
}
}
}
return $wheres;
}
}

View File

@@ -12,7 +12,7 @@
namespace VDM\Joomla\Componentbuilder\Compiler\Dynamicget;
use Joomla\CMS\Factory;
use Joomla\Database\DatabaseInterface;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Builder\GetAsLookup;
use VDM\Joomla\Componentbuilder\Compiler\Builder\SiteFields;
@@ -64,11 +64,12 @@ class Selection
protected SiteFields $sitefields;
/**
* Database object to query local DB
* Joomla Database Class.
*
* @since 3.2.0
* @var DatabaseInterface
* @since 5.1.2
**/
protected $db;
protected DatabaseInterface $db;
/**
* Constructor.
@@ -76,15 +77,16 @@ class Selection
* @param Config $config The Config Class.
* @param GetAsLookup $getaslookup The GetAsLookup Class.
* @param SiteFields $sitefields The SiteFields Class.
* @param DatabaseInterface $db The Joomla Database Class.
*
* @since 3.2.0
*/
public function __construct(Config $config, GetAsLookup $getaslookup, SiteFields $sitefields)
public function __construct(Config $config, GetAsLookup $getaslookup, SiteFields $sitefields, DatabaseInterface $db)
{
$this->config = $config;
$this->getaslookup = $getaslookup;
$this->sitefields = $sitefields;
$this->db = Factory::getDbo();
$this->db = $db;
}
/**

View File

@@ -0,0 +1,166 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Dynamicget;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ContentOne;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line;
/**
* Dynamic Get Uikit Loader
*
* @since 5.1.2
*/
final class UikitLoader
{
/**
* The Config Class.
*
* @var Config
* @since 5.1.2
*/
protected Config $config;
/**
* The ContentOne Class.
*
* @var ContentOne
* @since 5.1.2
*/
protected ContentOne $contentone;
/**
* The load tracker to prevent duplicate UIKit component loading.
*
* @var array
* @since 5.1.2
*/
protected array $loadTracker = [];
/**
* Constructor.
*
* @param Config $config The Config Class.
* @param ContentOne $contentone The ContentOne Class.
*
* @since 5.1.2
*/
public function __construct(Config $config, ContentOne $contentone)
{
$this->config = $config;
$this->contentone = $contentone;
}
/**
* Check if custom view fields contain UIKit components that must be loaded.
*
* This method iterates through the given checker array, determines whether the
* field should have UIKit components loaded based on the selection criteria,
* and appends the relevant code for inclusion.
*
* @param array $get The "get" array containing view configuration data.
* @param array $checker The array of fields and their configurations to check.
* @param string $string The string variable name or object reference in the generated code.
* @param string $code The code identifier used for generating unique load keys.
* @param string $tab Optional indentation tab for formatting generated code.
*
* @return string The generated PHP code string for UIKit component inclusion.
* @since 5.1.2
*/
public function get(array $get, array $checker, string $string, string $code, string $tab = ''): string
{
if (empty($get) || empty($get['key']) || empty($checker) || empty($string) || empty($code))
{
return '';
}
$fieldUikit = '';
foreach ($checker as $field => $array)
{
// Build load counter key
$key = md5($code . $get['key'] . $string . $field);
// Check if this field needs UIKit components loaded and hasn't been processed
if (
strpos((string) $get['selection']['select'], (string) $field) !== false
&& !isset($this->loadTracker[$key])
)
{
// Mark this field as processed
$this->loadTracker[$key] = $key;
// Only load for UIKit version 1 or 2
if (2 == $this->config->uikit || 1 == $this->config->uikit)
{
$fieldUikit .= PHP_EOL . Indent::_(1) . $tab . Indent::_(1)
. "//" . Line::_(__LINE__, __CLASS__) . " Checking if "
. $field . " has UIKit components that must be loaded.";
$fieldUikit .= PHP_EOL . Indent::_(1) . $tab . Indent::_(1)
. "\$this->uikitComp = "
. $this->contentone->get('Component')
. "Helper::getUikitComp(" . $string . "->" . $field . ",\$this->uikitComp);";
}
}
}
return $fieldUikit;
}
/**
* Build and return the PHP method definition for retrieving the UIkit components.
*
* This method dynamically generates the source code for a `getUikitComp()` method
* if the configured UIkit version is either `1` or `2`. The generated method
* checks if the `$this->uikitComp` property is set and valid, and returns it;
* otherwise, it returns `false`.
*
* @return string The generated PHP code for the `getUikitComp()` method, or an
* empty string if the UIkit version is not 1 or 2.
* @since 5.1.2
*/
public function getUikitComp(): string
{
$method = '';
// only load for uikit version 2
if (2 == $this->config->uikit || 1 == $this->config->uikit)
{
// build uikit get method
$method .= PHP_EOL . PHP_EOL . Indent::_(1) . "/**";
$method .= PHP_EOL . Indent::_(1)
. " * Get the uikit needed components";
$method .= PHP_EOL . Indent::_(1) . " *";
$method .= PHP_EOL . Indent::_(1)
. " * @return mixed An array of objects on success.";
$method .= PHP_EOL . Indent::_(1) . " *";
$method .= PHP_EOL . Indent::_(1) . " */";
$method .= PHP_EOL . Indent::_(1)
. "public function getUikitComp()";
$method .= PHP_EOL . Indent::_(1) . "{";
$method .= PHP_EOL . Indent::_(2)
. "if (isset(\$this->uikitComp) && "
. "Super_" . "__0a59c65c_9daf_4bc9_baf4_e063ff9e6a8a___Power::check(\$this->uikitComp))";
$method .= PHP_EOL . Indent::_(2) . "{";
$method .= PHP_EOL . Indent::_(3) . "return \$this->uikitComp;";
$method .= PHP_EOL . Indent::_(2) . "}";
$method .= PHP_EOL . Indent::_(2) . "return false;";
$method .= PHP_EOL . Indent::_(1) . "}";
}
return $method;
}
}

View File

@@ -47,6 +47,7 @@ use VDM\Joomla\Componentbuilder\Compiler\Service\Creator;
use VDM\Joomla\Componentbuilder\Compiler\Service\ArchitectureComHelperClass;
use VDM\Joomla\Componentbuilder\Compiler\Service\ArchitectureController;
use VDM\Joomla\Componentbuilder\Compiler\Service\ArchitectureModel;
use VDM\Joomla\Componentbuilder\Compiler\Service\ArchitectureModule;
use VDM\Joomla\Componentbuilder\Compiler\Service\ArchitecturePlugin;
use VDM\Joomla\Componentbuilder\Power\Service\Git;
use VDM\Joomla\Componentbuilder\Power\Service\Github;
@@ -161,6 +162,7 @@ abstract class Factory extends ExtendingFactory implements FactoryInterface
->registerServiceProvider(new ArchitectureComHelperClass())
->registerServiceProvider(new ArchitectureController())
->registerServiceProvider(new ArchitectureModel())
->registerServiceProvider(new ArchitectureModule())
->registerServiceProvider(new ArchitecturePlugin())
->registerServiceProvider(new Git())
->registerServiceProvider(new Github())

View File

@@ -12,7 +12,7 @@
namespace VDM\Joomla\Componentbuilder\Compiler\Field;
use Joomla\CMS\Factory;
use Joomla\Database\DatabaseInterface;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\EventInterface as Event;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\HistoryInterface as History;
@@ -106,11 +106,12 @@ class Data
protected Rule $rule;
/**
* The database class.
* Joomla Database Class.
*
* @since 3.2.0
*/
protected $db;
* @var DatabaseInterface
* @since 5.1.2
**/
protected DatabaseInterface $db;
/**
* Constructor.
@@ -122,12 +123,13 @@ class Data
* @param Customcode $customcode The Customcode Class.
* @param FieldCustomcode $fieldcustomcode The Customcode Class.
* @param Rule $rule The Rule Class.
* @param DatabaseInterface $db The Joomla Database Class.
*
* @since 3.2.0
*/
public function __construct(Config $config, Event $event, History $history,
Placeholder $placeholder, Customcode $customcode,
FieldCustomcode $fieldcustomcode, Rule $rule)
FieldCustomcode $fieldcustomcode, Rule $rule, DatabaseInterface $db)
{
$this->config = $config;
$this->event = $event;
@@ -136,7 +138,7 @@ class Data
$this->customcode = $customcode;
$this->fieldcustomcode = $fieldcustomcode;
$this->rule = $rule;
$this->db = Factory::getDbo();
$this->db = $db;
}
/**

View File

@@ -12,7 +12,7 @@
namespace VDM\Joomla\Componentbuilder\Compiler\Field;
use Joomla\CMS\Factory;
use Joomla\Database\DatabaseInterface;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Utilities\GetHelper;
@@ -69,20 +69,21 @@ final class Groups
];
/**
* Database object to query local DB
* Joomla Database Class.
*
* @since 3.2.0
*/
protected $db;
* @var DatabaseInterface
* @since 5.1.2
**/
protected DatabaseInterface $db;
/**
* Constructor
*
* @since 3.2.0
*/
public function __construct()
public function __construct(DatabaseInterface $db)
{
$this->db = Factory::getDbo();
$this->db = $db;
}
/**

View File

@@ -16,13 +16,13 @@ use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Component\ComponentHelper;
use VDM\Component\Componentbuilder\Administrator\Helper\ComponentbuilderHelper;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Utilities\JsonHelper;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Componentbuilder\Compiler\Factory as CFactory;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Placefix;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Unique;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Utilities\JsonHelper;
use VDM\Joomla\Utilities\ArrayHelper;
/**
@@ -1093,9 +1093,9 @@ class Get
// set if powers should be added to component (default is true) @deprecated
$this->addPower = CFactory::_('Config')->get('add_power', true);
// set the current user
$this->user = Factory::getUser();
$this->user = $this->app->getIdentity();
// Get a db connection.
$this->db = Factory::getDbo();
$this->db = CFactory::_('Joomla.Database');
// get global placeholders @deprecated
$this->globalPlaceholders = CFactory::_('Component.Placeholder')->get();

View File

@@ -772,17 +772,17 @@ class Infusion extends Interpretation
// set Auto check in function
if (isset($view['checkin']) && $view['checkin'] == 1)
{
// CHECKINCALL <<<DYNAMIC>>>
CFactory::_('Compiler.Builder.Content.Multi')->set($nameListCode . '|CHECKINCALL',
CFactory::_('Architecture.Model.CheckInNow')->getCall()
);
// AUTOCHECKIN <<<DYNAMIC>>>
CFactory::_('Compiler.Builder.Content.Multi')->set($nameListCode . '|AUTOCHECKIN',
$this->setAutoCheckin(
CFactory::_('Architecture.Model.CheckInNow')->getMethod(
$nameSingleCode,
CFactory::_('Config')->component_code_name
)
);
// CHECKINCALL <<<DYNAMIC>>>
CFactory::_('Compiler.Builder.Content.Multi')->set($nameListCode . '|CHECKINCALL',
$this->setCheckinCall()
);
}
else
{
@@ -1351,7 +1351,7 @@ class Infusion extends Interpretation
// CUSTOM_ADMIN_GET_ITEM <<<DYNAMIC>>>
CFactory::_('Compiler.Builder.Content.Multi')->set($view['settings']->code . '|CUSTOM_ADMIN_GET_ITEM',
$this->setCustomViewGetItem(
CFactory::_('Dynamicget.GetItem')->get(
$view['settings']->main_get,
$view['settings']->code, Indent::_(2)
)
@@ -1369,7 +1369,7 @@ class Infusion extends Interpretation
{
// CUSTOM_ADMIN_GET_LIST_QUERY <<<DYNAMIC>>>
CFactory::_('Compiler.Builder.Content.Multi')->set($view['settings']->code . '|CUSTOM_ADMIN_GET_LIST_QUERY',
$this->setCustomViewListQuery(
CFactory::_('Dynamicget.ListQuery')->get(
$view['settings']->main_get, $view['settings']->code
)
);
@@ -1392,7 +1392,7 @@ class Infusion extends Interpretation
// CUSTOM_ADMIN_GET_ITEMS <<<DYNAMIC>>>
CFactory::_('Compiler.Builder.Content.Multi')->set($view['settings']->code . '|CUSTOM_ADMIN_GET_ITEMS',
$this->setCustomViewGetItems(
CFactory::_('Dynamicget.GetItems')->get(
$view['settings']->main_get, $view['settings']->code
)
);
@@ -1408,12 +1408,12 @@ class Infusion extends Interpretation
// CUSTOM_ADMIN_CUSTOM_METHODS <<<DYNAMIC>>>
CFactory::_('Compiler.Builder.Content.Multi')->set($view['settings']->code . '|CUSTOM_ADMIN_CUSTOM_METHODS',
$this->setCustomViewCustomItemMethods(
CFactory::_('Dynamicget.CustomGetMethods')->get(
$view['settings']->main_get, $view['settings']->code
)
);
CFactory::_('Compiler.Builder.Content.Multi')->add($view['settings']->code . '|CUSTOM_ADMIN_CUSTOM_METHODS',
$this->setCustomViewCustomMethods(
CFactory::_('Dynamicget.Methods')->get(
$view, $view['settings']->code
). false
);
@@ -1879,7 +1879,7 @@ class Infusion extends Interpretation
// SITE_GET_ITEM <<<DYNAMIC>>>
CFactory::_('Compiler.Builder.Content.Multi')->set($view['settings']->code . '|SITE_GET_ITEM',
$this->setCustomViewGetItem(
CFactory::_('Dynamicget.GetItem')->get(
$view['settings']->main_get,
$view['settings']->code, Indent::_(2)
)
@@ -1901,7 +1901,7 @@ class Infusion extends Interpretation
);
// SITE_GET_LIST_QUERY <<<DYNAMIC>>>
CFactory::_('Compiler.Builder.Content.Multi')->set($view['settings']->code . '|SITE_GET_LIST_QUERY',
$this->setCustomViewListQuery(
CFactory::_('Dynamicget.ListQuery')->get(
$view['settings']->main_get, $view['settings']->code
)
);
@@ -1914,7 +1914,7 @@ class Infusion extends Interpretation
// SITE_GET_ITEMS <<<DYNAMIC>>>
CFactory::_('Compiler.Builder.Content.Multi')->set($view['settings']->code . '|SITE_GET_ITEMS',
$this->setCustomViewGetItems(
CFactory::_('Dynamicget.GetItems')->get(
$view['settings']->main_get, $view['settings']->code
)
);
@@ -1940,12 +1940,12 @@ class Infusion extends Interpretation
);
// SITE_CUSTOM_METHODS <<<DYNAMIC>>>
CFactory::_('Compiler.Builder.Content.Multi')->set($view['settings']->code . '|SITE_CUSTOM_METHODS',
$this->setCustomViewCustomItemMethods(
CFactory::_('Dynamicget.CustomGetMethods')->get(
$view['settings']->main_get, $view['settings']->code
)
);
CFactory::_('Compiler.Builder.Content.Multi')->add($view['settings']->code . '|SITE_CUSTOM_METHODS',
$this->setCustomViewCustomMethods(
CFactory::_('Dynamicget.Methods')->get(
$view, $view['settings']->code
), false
);
@@ -2228,87 +2228,9 @@ class Infusion extends Interpretation
$_backup_target = CFactory::_('Config')->build_target;
$_backup_lang = CFactory::_('Config')->lang_target;
$_backup_langPrefix = CFactory::_('Config')->lang_prefix;
// infuse module data if set
if (CFactory::_('Joomlamodule.Data')->exists())
{
foreach (CFactory::_('Joomlamodule.Data')->get() as $module)
{
if (ObjectHelper::check($module))
{
// Trigger Event: jcb_ce_onBeforeInfuseModuleData
CFactory::_('Event')->trigger(
'jcb_ce_onBeforeInfuseModuleData', [&$module]
);
CFactory::_('Config')->build_target = $module->key;
CFactory::_('Config')->lang_target = $module->key;
$this->langPrefix = $module->lang_prefix;
CFactory::_('Config')->set('lang_prefix', $module->lang_prefix);
// MODCODE
CFactory::_('Compiler.Builder.Content.Multi')->set($module->key . '|MODCODE',
$this->getModCode($module)
);
// DYNAMICGET
CFactory::_('Compiler.Builder.Content.Multi')->set($module->key . '|DYNAMICGETS',
$this->setCustomViewCustomMethods(
$module, $module->key
)
);
// HELPERCODE
if ($module->add_class_helper >= 1)
{
CFactory::_('Compiler.Builder.Content.Multi')->set($module->key . '|HELPERCODE',
$this->getModHelperCode($module)
);
}
// MODDEFAULT
CFactory::_('Compiler.Builder.Content.Multi')->set($module->key . '|MODDEFAULT',
$this->getModDefault($module, $module->key)
);
// MODDEFAULT_XXX
$this->setModTemplates($module);
// only add install script if needed
if ($module->add_install_script)
{
// INSTALLCLASS
CFactory::_('Compiler.Builder.Content.Multi')->set($module->key . '|INSTALLCLASS',
CFactory::_('Extension.InstallScript')->get($module)
);
}
// FIELDSET
if (isset($module->form_files)
&& ArrayHelper::check(
$module->form_files
))
{
foreach ($module->form_files as $file => $files)
{
foreach ($files as $field_name => $fieldsets)
{
foreach ($fieldsets as $fieldset => $fields)
{
// FIELDSET_ . $file.$field_name.$fieldset
CFactory::_('Compiler.Builder.Content.Multi')->set($module->key .
'|FIELDSET_' . $file . $field_name . $fieldset,
CFactory::_('Compiler.Creator.Fieldset.Extension')->get(
$module, $fields
)
);
}
}
}
}
// MAINXML
CFactory::_('Compiler.Builder.Content.Multi')->set($module->key . '|MAINXML',
$this->getModuleMainXML($module)
);
// Trigger Event: jcb_ce_onAfterInfuseModuleData
CFactory::_('Event')->trigger(
'jcb_ce_onAfterInfuseModuleData', [&$module]
);
}
}
}
// infuse module data if set
CFactory::_('Joomlamodule.Infusion')->set();
// infuse plugin data if set
CFactory::_('Joomlaplugin.Infusion')->set();

View File

@@ -0,0 +1,41 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Model;
/**
* Check In Now Interface
*
* @since 5.1.2
*/
interface CheckInNowInterface
{
/**
* Get the generated call snippet that invokes the check-in method.
*
* @return string The code that calls the generated method.
* @since 5.1.2
*/
public function getCall(): string;
/**
* Build the full `checkInNow()` method code for the given view/table.
*
* @param string $view The view/table suffix (e.g. 'items').
* @param string $component The component name (without 'com_').
*
* @return string The full method code as a string.
* @since 5.1.2
*/
public function getMethod($view, $component): string;
}

View File

@@ -0,0 +1,32 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module;
/**
* Module Dispatcher Interface
*
* @since 5.1.2
*/
interface DispatcherInterface
{
/**
* Get the updated placeholder content for the given module.
*
* @param object $module The module object containing the necessary data.
*
* @return string The updated placeholder content.
* @since 5.1.2
*/
public function get(object $module): string;
}

View File

@@ -0,0 +1,42 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module;
/**
* Module Helper Code Interface
*
* @since 5.1.2
*/
interface HelperInterface
{
/**
* Get Module Helper Class code
*
* @param object $module The module object
*
* @return string The helper class code
* @since 5.1.2
*/
public function get(object $module): string;
/**
* Get Module Helper Header code
*
* @param object $module The module object
*
* @return string The helper header code
* @since 5.1.2
*/
public function header(object $module): string;
}

View File

@@ -0,0 +1,32 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module;
/**
* Module Library Interface
*
* @since 5.1.2
*/
interface LibraryInterface
{
/**
* Get the module's library loading code.
*
* @param object $module The module object
*
* @return string The generated code to load libraries into the document.
* @since 5.1.2
*/
public function get(object $module): string;
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module;
/**
* Module Provider Interface
*
* @since 5.1.2
*/
interface ProviderInterface
{
/**
* Get the updated placeholder content for the given module.
*
* @param object $module The module object containing the necessary data.
*
* @return string The updated placeholder content.
*
* @since 5.0.2
*/
public function get(object $module): string;
}

View File

@@ -0,0 +1,43 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module;
/**
* Module Template Interface
*
* @since 5.1.2
*/
interface TemplateInterface
{
/**
* Get the updated placeholder default template content for the given module.
*
* @param object $module The module object containing the necessary data.
* @param string $key The dispenser key for this given module.
*
* @return string The updated placeholder content.
* @since 5.1.2
*/
public function default(object $module, string $key): string;
/**
* Get the updated placeholder extra template content for the given module.
*
* @param object $module The module object containing the necessary data.
*
* @return void
* @since 5.1.2
*/
public function extra(object $module): void;
}

View File

@@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>

View File

@@ -0,0 +1,52 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Interfaces;
/**
* Module Data Interface
*
* @since 5.1.2
*/
interface ModuleDataInterface
{
/**
* Get the Joomla Module/s
*
* @param int|string|null $module The module id/guid
*
* @return object|array|null if ID|GUID found it returns object, if no ID|GUID given it returns all set
* @since 3.2.0
*/
public function get($module = null);
/**
* Check if the Joomla Module/s exists
*
* @param int|string|null $module The module id|guid
*
* @return bool if ID|GUID found it returns true, if no ID|GUID given it returns true if any are set
* @since 3.2.0
*/
public function exists($module = null): bool;
/**
* Set the module
*
* @param mixed $module The module ID/GUID
*
* @return bool true on success
* @since 5.0.4
*/
public function set($module): bool;
}

View File

@@ -122,6 +122,25 @@ final class Header implements HeaderInterface
*/
protected array $headers = [];
/**
* List of disallowed context strings.
*
* @var array<string>
* @since 5.1.2
*/
protected array $disallowedContexts = [
'admin.helper',
'site.helper',
'plugin.extension.header',
'plugin.provider.header',
'module.provider.header',
'module.dispatcher.header',
'module.dynamicgets.header',
'module.helper.header',
'module.default.template.header',
'module.extra.template.header',
];
/**
* The Namespace Prefix
*
@@ -200,7 +219,7 @@ final class Header implements HeaderInterface
$headers = $this->getHeaders($context);
// add to all except the helper classes
if ('admin.helper' !== $context && 'site.helper' !== $context && 'plugin.extension.header' !== $context && 'plugin.provider.header' !== $context)
if ($this->isAllowedContext($context))
{
$target = 'Administrator';
if ($this->config->get('build_target', 'admin') === 'site')
@@ -554,6 +573,29 @@ final class Header implements HeaderInterface
$headers[] = 'use Joomla\CMS\Form\Field\###FORM_EXTENDS###;';
break;
case 'module.provider.header':
$headers = [];
$headers[] = 'use Joomla\CMS\Extension\Service\Provider\HelperFactory;';
$headers[] = 'use Joomla\CMS\Extension\Service\Provider\Module;';
$headers[] = 'use Joomla\CMS\Extension\Service\Provider\ModuleDispatcherFactory;';
$headers[] = 'use Joomla\DI\ServiceProviderInterface;';
$headers[] = 'use Joomla\DI\Container;';
break;
case 'module.dispatcher.header':
$headers = [];
$headers[] = 'use Joomla\CMS\Dispatcher\AbstractModuleDispatcher;';
$headers[] = 'use Joomla\CMS\Helper\HelperFactoryAwareInterface;';
$headers[] = 'use Joomla\CMS\Helper\HelperFactoryAwareTrait;';
break;
case 'module.dynamicgets.header':
$headers = [];
$headers[] = 'use Joomla\CMS\Application\CMSApplicationInterface;';
$headers[] = 'use Joomla\Database\DatabaseAwareInterface;';
$headers[] = 'use Joomla\Database\DatabaseAwareTrait;';
$headers[] = 'use Joomla\Registry\Registry;';
$headers[] = 'use Joomla\Input\Input;';
break;
case 'plugin.extension.header':
$headers = [];
break;
@@ -588,6 +630,22 @@ final class Header implements HeaderInterface
$this->headers[$context] = $headers;
return $headers;
}
/**
* Determine if the given context is allowed.
*
* Returns true if the context is not in the disallowed list,
* false if the context is disallowed.
*
* @param string $context The context string to evaluate.
*
* @return bool True if allowed, false if disallowed.
* @since 5.1.2
*/
protected function isAllowedContext(string $context): bool
{
return !in_array($context, $this->disallowedContexts, true);
}
}

View File

@@ -12,11 +12,10 @@
namespace VDM\Joomla\Componentbuilder\Compiler\JoomlaFive;
use Joomla\CMS\Factory;
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
use Joomla\Database\DatabaseInterface;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Utilities\JsonHelper;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\HistoryInterface;
@@ -44,23 +43,25 @@ final class History implements HistoryInterface
protected Config $config;
/**
* Database object to query local DB
* Joomla Database Class.
*
* @since 3.2.0
*/
protected $db;
* @var DatabaseInterface
* @since 5.1.2
**/
protected DatabaseInterface $db;
/**
* Constructor
*
* @param Config|null $config The compiler config object.
* @param Config $config The compiler config object.
* @param DatabaseInterface $db The Joomla Database Class.
*
* @since 3.2.0
*/
public function __construct(?Config $config = null)
public function __construct(Config $config, DatabaseInterface $db)
{
$this->config = $config ?: Compiler::_('Config');
$this->db = Factory::getDbo();
$this->config = $config;
$this->db = $db;
}
/**

View File

@@ -122,6 +122,25 @@ final class Header implements HeaderInterface
*/
protected array $headers = [];
/**
* List of disallowed context strings.
*
* @var array<string>
* @since 5.1.2
*/
protected array $disallowedContexts = [
'admin.helper',
'site.helper',
'plugin.extension.header',
'plugin.provider.header',
'module.provider.header',
'module.dispatcher.header',
'module.dynamicgets.header',
'module.helper.header',
'module.default.template.header',
'module.extra.template.header',
];
/**
* The Namespace Prefix
*
@@ -200,7 +219,7 @@ final class Header implements HeaderInterface
$headers = $this->getHeaders($context);
// add to all except the helper classes
if ('admin.helper' !== $context && 'site.helper' !== $context && 'plugin.extension.header' !== $context && 'plugin.provider.header' !== $context)
if ($this->isAllowedContext($context))
{
$target = 'Administrator';
if ($this->config->get('build_target', 'admin') === 'site')
@@ -554,6 +573,29 @@ final class Header implements HeaderInterface
$headers[] = 'use Joomla\CMS\Form\Field\###FORM_EXTENDS###;';
break;
case 'module.provider.header':
$headers = [];
$headers[] = 'use Joomla\CMS\Extension\Service\Provider\HelperFactory;';
$headers[] = 'use Joomla\CMS\Extension\Service\Provider\Module;';
$headers[] = 'use Joomla\CMS\Extension\Service\Provider\ModuleDispatcherFactory;';
$headers[] = 'use Joomla\DI\ServiceProviderInterface;';
$headers[] = 'use Joomla\DI\Container;';
break;
case 'module.dispatcher.header':
$headers = [];
$headers[] = 'use Joomla\CMS\Dispatcher\AbstractModuleDispatcher;';
$headers[] = 'use Joomla\CMS\Helper\HelperFactoryAwareInterface;';
$headers[] = 'use Joomla\CMS\Helper\HelperFactoryAwareTrait;';
break;
case 'module.dynamicgets.header':
$headers = [];
$headers[] = 'use Joomla\CMS\Application\CMSApplicationInterface;';
$headers[] = 'use Joomla\Database\DatabaseAwareInterface;';
$headers[] = 'use Joomla\Database\DatabaseAwareTrait;';
$headers[] = 'use Joomla\Registry\Registry;';
$headers[] = 'use Joomla\Input\Input;';
break;
case 'plugin.extension.header':
$headers = [];
break;
@@ -588,6 +630,22 @@ final class Header implements HeaderInterface
$this->headers[$context] = $headers;
return $headers;
}
/**
* Determine if the given context is allowed.
*
* Returns true if the context is not in the disallowed list,
* false if the context is disallowed.
*
* @param string $context The context string to evaluate.
*
* @return bool True if allowed, false if disallowed.
* @since 5.1.2
*/
protected function isAllowedContext(string $context): bool
{
return !in_array($context, $this->disallowedContexts, true);
}
}

View File

@@ -12,11 +12,10 @@
namespace VDM\Joomla\Componentbuilder\Compiler\JoomlaFour;
use Joomla\CMS\Factory;
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
use Joomla\Database\DatabaseInterface;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Utilities\JsonHelper;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\HistoryInterface;
@@ -44,23 +43,25 @@ final class History implements HistoryInterface
protected Config $config;
/**
* Database object to query local DB
* Joomla Database Class.
*
* @since 3.2.0
*/
protected $db;
* @var DatabaseInterface
* @since 5.1.2
**/
protected DatabaseInterface $db;
/**
* Constructor
*
* @param Config|null $config The compiler config object.
* @param Config $config The compiler config object.
* @param DatabaseInterface $db The Joomla Database Class.
*
* @since 3.2.0
*/
public function __construct(?Config $config = null)
public function __construct(Config $config, DatabaseInterface $db)
{
$this->config = $config ?: Compiler::_('Config');
$this->db = Factory::getDbo();
$this->config = $config;
$this->db = $db;
}
/**

View File

@@ -13,6 +13,7 @@ namespace VDM\Joomla\Componentbuilder\Compiler;
use Joomla\CMS\Factory;
use Joomla\Database\DatabaseInterface;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Language\Text;
use VDM\Joomla\Componentbuilder\Compiler\Config;
@@ -131,11 +132,12 @@ final class JoomlaPower implements PowerInterface
protected Superpower $superpower;
/**
* Database object to query local DB
* Joomla Database Class.
*
* @since 3.2.1
* @var DatabaseInterface
* @since 5.1.2
**/
protected $db;
protected DatabaseInterface $db;
/**
* Database object to query local DB
@@ -152,19 +154,21 @@ final class JoomlaPower implements PowerInterface
* @param Customcode $customcode The compiler customcode object.
* @param Gui $gui The compiler customcode gui object.
* @param Superpower $superpower The JCB superpower object.
* @param DatabaseInterface $db The Joomla Database Class.
*
* @throws \Exception
* @since 3.2.1
*/
public function __construct(Config $config, Placeholder $placeholder,
Customcode $customcode, Gui $gui, Superpower $superpower)
Customcode $customcode, Gui $gui, Superpower $superpower, DatabaseInterface $db)
{
$this->config = $config;
$this->placeholder = $placeholder;
$this->customcode = $customcode;
$this->gui = $gui;
$this->superpower = $superpower;
$this->db = Factory::getDbo();
$this->db = $db;
$this->app = Factory::getApplication();
}

View File

@@ -12,6 +12,7 @@
namespace VDM\Joomla\Componentbuilder\Compiler\JoomlaPower;
use Joomla\Database\DatabaseInterface;
use VDM\Joomla\Utilities\JsonHelper;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Power\ExtractorInterface;
use VDM\Joomla\Componentbuilder\Compiler\Power\Extractor as ExtendingExtractor;
@@ -66,13 +67,14 @@ final class Extractor extends ExtendingExtractor implements ExtractorInterface
/**
* Constructor.
*
* @param int $targetVersion The targeted Joomla version.
* @param DatabaseInterface $db The Joomla Database class.
* @param int $targetVersion The targeted Joomla version.
*
* @since 3.2.1
*/
public function __construct(int $targetVersion)
public function __construct(DatabaseInterface $db, int $targetVersion)
{
parent::__construct();
parent::__construct($db);
$this->targetVersion = $targetVersion;
}

View File

@@ -12,11 +12,10 @@
namespace VDM\Joomla\Componentbuilder\Compiler\JoomlaThree;
use Joomla\CMS\Factory;
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
use Joomla\Database\DatabaseInterface;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Utilities\JsonHelper;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\HistoryInterface;
@@ -44,23 +43,25 @@ final class History implements HistoryInterface
protected Config $config;
/**
* Database object to query local DB
* Joomla Database Class.
*
* @since 3.2.0
*/
protected $db;
* @var DatabaseInterface
* @since 5.1.2
**/
protected DatabaseInterface $db;
/**
* Constructor
*
* @param Config|null $config The compiler config object.
* @param Config $config The compiler config object.
* @param DatabaseInterface $db The Joomla Database Class.
*
* @since 3.2.0
*/
public function __construct(?Config $config = null)
public function __construct(Config $config, DatabaseInterface $db)
{
$this->config = $config ?: Compiler::_('Config');
$this->db = Factory::getDbo();
$this->config = $config;
$this->db = $db;
}
/**
@@ -224,7 +225,6 @@ final class History implements HistoryInterface
// run the update
return $this->db->updateObject('#__ucm_history', $object, 'version_id');
}
}
}

View File

@@ -0,0 +1,435 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Joomlamodule\JoomlaFive;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module\ProviderInterface as Provider;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module\DispatcherInterface as Dispatcher;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module\TemplateInterface as Template;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module\HelperInterface as Helper;
use VDM\Joomla\Componentbuilder\Interfaces\Architecture\Module\MainXMLInterface as MainXML;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\ModuleDataInterface as Data;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\HeaderInterface as Header;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\EventInterface as Event;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\GetScriptInterface as InstallScript;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ContentMulti;
use VDM\Joomla\Componentbuilder\Compiler\Creator\FieldsetExtension;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\Methods;
use VDM\Joomla\Utilities\ObjectHelper;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Componentbuilder\Interfaces\Module\InfusionInterface;
/**
* Joomla 5 module Infusion Class
*
* @since 5.1.2
*/
final class Infusion implements InfusionInterface
{
/**
* The Config Class.
*
* @var Config
* @since 5.1.2
*/
protected Config $config;
/**
* The Provider Class.
*
* @var Provider
* @since 5.1.2
*/
protected Provider $provider;
/**
* The Dispatcher Class.
*
* @var Dispatcher
* @since 5.1.2
*/
protected Dispatcher $dispatcher;
/**
* The Template Class.
*
* @var Template
* @since 5.1.2
*/
protected Template $template;
/**
* The Helper Class.
*
* @var Helper
* @since 5.1.2
*/
protected Helper $helper;
/**
* The MainXML Class.
*
* @var MainXML
* @since 5.1.2
*/
protected MainXML $mainxml;
/**
* The ModuleData Class.
*
* @var Data
* @since 5.1.2
*/
protected Data $data;
/**
* The Header Class.
*
* @var Header
* @since 5.1.2
*/
protected Header $header;
/**
* The Event Class.
*
* @var Event
* @since 5.1.2
*/
protected Event $event;
/**
* The Install Class.
*
* @var InstallScript
* @since 5.1.2
*/
protected InstallScript $installscript;
/**
* The ContentMulti Class.
*
* @var ContentMulti
* @since 5.1.2
*/
protected ContentMulti $contentmulti;
/**
* The FieldsetExtension Class.
*
* @var FieldsetExtension
* @since 5.1.2
*/
protected FieldsetExtension $fieldsetextension;
/**
* The Methods Class.
*
* @var Methods
* @since 5.1.2
*/
protected Methods $methods;
/**
* Constructor.
*
* @param Config $config The Config Class.
* @param Provider $provider The Provider Class.
* @param Dispatcher $dispatcher The Dispatcher Class.
* @param Template $template The Template Class.
* @param Helper $helper The Helper Class.
* @param MainXML $mainxml The MainXML Class.
* @param Data $data The ModuleData Class.
* @param Header $header The Header Class.
* @param Event $event The Event Class.
* @param InstallScript $installscript The GetScript Class.
* @param ContentMulti $contentmulti The ContentMulti Class.
* @param FieldsetExtension $fieldsetextension The FieldsetExtension Class.
* @param Methods $methods The Methods Class.
*
* @since 5.1.2
*/
public function __construct(Config $config, Provider $provider, Dispatcher $dispatcher,
Template $template, Helper $helper, MainXML $mainxml,
Data $data, Header $header, Event $event,
InstallScript $installscript, ContentMulti $contentmulti,
FieldsetExtension $fieldsetextension, Methods $methods)
{
$this->config = $config;
$this->provider = $provider;
$this->dispatcher = $dispatcher;
$this->template = $template;
$this->helper = $helper;
$this->mainxml = $mainxml;
$this->data = $data;
$this->header = $header;
$this->event = $event;
$this->installscript = $installscript;
$this->contentmulti = $contentmulti;
$this->fieldsetextension = $fieldsetextension;
$this->methods = $methods;
}
/**
* Infuse the module data into the content.
*
* @return void
* @since 5.1.2
*/
public function set(): void
{
if (!$this->data->exists())
{
return;
}
foreach ($this->data->get() as $module)
{
if (!ObjectHelper::check($module))
{
continue;
}
$this->triggerBeforeInfusionEvent($module);
$this->setModuleConfiguration($module);
$this->setProviderCode($module);
$this->setDispatcherCode($module);
$this->setDynamicGets($module);
$this->setHelperCode($module);
$this->setDefaultTemplates($module);
$this->setInstallScript($module);
$this->setFieldsets($module);
$this->setMainXml($module);
$this->triggerAfterInfusionEvent($module);
}
}
/**
* Set core configuration from module data.
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function setModuleConfiguration(object $module): void
{
$this->config->build_target = $module->key;
$this->config->lang_target = $module->key;
$this->config->set('lang_prefix', $module->lang_prefix);
}
/**
* Set the provider provider code.
*
* @param object $module The module object being processed.
*
* @return void
* @since 5.1.2
*/
protected function setProviderCode($module): void
{
$header = trim((string) ($this->header->get('module.provider.header', $module->class_name) ?? ''));
if ($header !== '')
{
$header = PHP_EOL . PHP_EOL . $header;
}
$this->contentmulti->set("{$module->key}|PROVIDER_CLASS_HEADER", $header);
$providerContent = $this->provider->get($module);
$this->contentmulti->set("{$module->key}|PROVIDER_CLASS", $providerContent);
}
/**
* Set dispatcher-generated module code.
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function setDispatcherCode(object $module): void
{
$header = trim((string) ($this->header->get('module.dispatcher.header', $module->class_name) ?? ''));
if ($header !== '')
{
$header = PHP_EOL . PHP_EOL . $header;
}
$this->contentmulti->set("{$module->key}|DISPATCHER_CLASS_HEADER", $header);
$code = $this->dispatcher->get($module);
$this->contentmulti->set("{$module->key}|DISPATCHER_CLASS", $code);
}
/**
* Set dynamically generated get methods (dynamicGets).
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function setDynamicGets(object $module): void
{
if ($module->custom_get)
{
$header = trim((string) ($this->header->get('module.dynamicgets.header', $module->class_name) ?? ''));
if ($header !== '')
{
$header = PHP_EOL . PHP_EOL . $header;
}
$this->contentmulti->set("{$module->key}|DYNAMICGETS_HEADER", $header);
$code = $this->methods->get($module, $module->key);
$this->contentmulti->set("{$module->key}|DYNAMICGETS", $code);
}
}
/**
* Set helper class code if enabled.
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function setHelperCode(object $module): void
{
if ($module->add_class_helper >= 1)
{
$header = trim((string) ($this->header->get('module.helper.header', $module->class_name) ?? ''));
$header .= $this->helper->header($module);
if (!empty($header))
{
$header = PHP_EOL . PHP_EOL . trim($header);
}
$this->contentmulti->set("{$module->key}|HELPER_CLASS_HEADER", $header);
$code = $this->helper->get($module);
$this->contentmulti->set("{$module->key}|HELPER_CLASS", $code);
}
}
/**
* Set default and extra templates.
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function setDefaultTemplates(object $module): void
{
$header = trim((string) ($this->header->get('module.default.template.header', $module->class_name) ?? ''));
if ($header !== '')
{
$header = PHP_EOL . PHP_EOL . $header;
}
$this->contentmulti->set("{$module->key}|MODDEFAULT_HEADER", $header);
$header_code = $this->template->header($module);
$this->contentmulti->set("{$module->key}|MODDEFAULT_HEADER_CODE", $header_code);
$code = $this->template->default($module, $module->key);
$this->contentmulti->set("{$module->key}|MODDEFAULT", $code);
$this->template->extra($module);
}
/**
* Set install script content if required.
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function setInstallScript(object $module): void
{
if ($module->add_install_script)
{
$this->contentmulti->set("{$module->key}|INSTALLCLASS",
$this->installscript->get($module));
}
}
/**
* Set all fieldset content based on form files.
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function setFieldsets(object $module): void
{
if (!isset($module->form_files) || !ArrayHelper::check($module->form_files))
{
return;
}
foreach ($module->form_files as $file => $files)
{
foreach ($files as $field_name => $fieldsets)
{
foreach ($fieldsets as $fieldset => $fields)
{
$key = "{$module->key}|FIELDSET_{$file}{$field_name}{$fieldset}";
$content = $this->fieldsetextension->get($module, $fields);
$this->contentmulti->set($key, $content);
}
}
}
}
/**
* Set main XML configuration content.
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function setMainXml(object $module): void
{
$this->contentmulti->set("{$module->key}|MAINXML", $this->mainxml->get($module));
}
/**
* Trigger before-infusion event.
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function triggerBeforeInfusionEvent(object &$module): void
{
$this->event->trigger('jcb_ce_onBeforeInfuseModuleData', [&$module]);
}
/**
* Trigger after-infusion event.
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function triggerAfterInfusionEvent(object &$module): void
{
$this->event->trigger('jcb_ce_onAfterInfuseModuleData', [&$module]);
}
}

View File

@@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>

View File

@@ -0,0 +1,435 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Joomlamodule\JoomlaFour;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module\ProviderInterface as Provider;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module\DispatcherInterface as Dispatcher;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module\TemplateInterface as Template;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module\HelperInterface as Helper;
use VDM\Joomla\Componentbuilder\Interfaces\Architecture\Module\MainXMLInterface as MainXML;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\ModuleDataInterface as Data;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\HeaderInterface as Header;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\EventInterface as Event;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\GetScriptInterface as InstallScript;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ContentMulti;
use VDM\Joomla\Componentbuilder\Compiler\Creator\FieldsetExtension;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\Methods;
use VDM\Joomla\Utilities\ObjectHelper;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Componentbuilder\Interfaces\Module\InfusionInterface;
/**
* Joomla 4 module Infusion Class
*
* @since 5.1.2
*/
final class Infusion implements InfusionInterface
{
/**
* The Config Class.
*
* @var Config
* @since 5.1.2
*/
protected Config $config;
/**
* The Provider Class.
*
* @var Provider
* @since 5.1.2
*/
protected Provider $provider;
/**
* The Dispatcher Class.
*
* @var Dispatcher
* @since 5.1.2
*/
protected Dispatcher $dispatcher;
/**
* The Template Class.
*
* @var Template
* @since 5.1.2
*/
protected Template $template;
/**
* The Helper Class.
*
* @var Helper
* @since 5.1.2
*/
protected Helper $helper;
/**
* The MainXML Class.
*
* @var MainXML
* @since 5.1.2
*/
protected MainXML $mainxml;
/**
* The ModuleData Class.
*
* @var Data
* @since 5.1.2
*/
protected Data $data;
/**
* The Header Class.
*
* @var Header
* @since 5.1.2
*/
protected Header $header;
/**
* The Event Class.
*
* @var Event
* @since 5.1.2
*/
protected Event $event;
/**
* The Install Class.
*
* @var InstallScript
* @since 5.1.2
*/
protected InstallScript $installscript;
/**
* The ContentMulti Class.
*
* @var ContentMulti
* @since 5.1.2
*/
protected ContentMulti $contentmulti;
/**
* The FieldsetExtension Class.
*
* @var FieldsetExtension
* @since 5.1.2
*/
protected FieldsetExtension $fieldsetextension;
/**
* The Methods Class.
*
* @var Methods
* @since 5.1.2
*/
protected Methods $methods;
/**
* Constructor.
*
* @param Config $config The Config Class.
* @param Provider $provider The Provider Class.
* @param Dispatcher $dispatcher The Dispatcher Class.
* @param Template $template The Template Class.
* @param Helper $helper The Helper Class.
* @param MainXML $mainxml The MainXML Class.
* @param Data $data The ModuleData Class.
* @param Header $header The Header Class.
* @param Event $event The Event Class.
* @param InstallScript $installscript The GetScript Class.
* @param ContentMulti $contentmulti The ContentMulti Class.
* @param FieldsetExtension $fieldsetextension The FieldsetExtension Class.
* @param Methods $methods The Methods Class.
*
* @since 5.1.2
*/
public function __construct(Config $config, Provider $provider, Dispatcher $dispatcher,
Template $template, Helper $helper, MainXML $mainxml,
Data $data, Header $header, Event $event,
InstallScript $installscript, ContentMulti $contentmulti,
FieldsetExtension $fieldsetextension, Methods $methods)
{
$this->config = $config;
$this->provider = $provider;
$this->dispatcher = $dispatcher;
$this->template = $template;
$this->helper = $helper;
$this->mainxml = $mainxml;
$this->data = $data;
$this->header = $header;
$this->event = $event;
$this->installscript = $installscript;
$this->contentmulti = $contentmulti;
$this->fieldsetextension = $fieldsetextension;
$this->methods = $methods;
}
/**
* Infuse the module data into the content.
*
* @return void
* @since 5.1.2
*/
public function set(): void
{
if (!$this->data->exists())
{
return;
}
foreach ($this->data->get() as $module)
{
if (!ObjectHelper::check($module))
{
continue;
}
$this->triggerBeforeInfusionEvent($module);
$this->setModuleConfiguration($module);
$this->setProviderCode($module);
$this->setDispatcherCode($module);
$this->setDynamicGets($module);
$this->setHelperCode($module);
$this->setDefaultTemplates($module);
$this->setInstallScript($module);
$this->setFieldsets($module);
$this->setMainXml($module);
$this->triggerAfterInfusionEvent($module);
}
}
/**
* Set core configuration from module data.
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function setModuleConfiguration(object $module): void
{
$this->config->build_target = $module->key;
$this->config->lang_target = $module->key;
$this->config->set('lang_prefix', $module->lang_prefix);
}
/**
* Set the provider provider code.
*
* @param object $module The module object being processed.
*
* @return void
* @since 5.1.2
*/
protected function setProviderCode($module): void
{
$providerHeader = trim((string) ($this->header->get('module.provider.header', $module->class_name) ?? ''));
if ($providerHeader !== '')
{
$providerHeader = PHP_EOL . PHP_EOL . $providerHeader;
}
$this->contentmulti->set("{$module->key}|PROVIDER_CLASS_HEADER", $providerHeader);
$providerContent = $this->provider->get($module);
$this->contentmulti->set("{$module->key}|PROVIDER_CLASS", $providerContent);
}
/**
* Set dispatcher-generated module code.
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function setDispatcherCode(object $module): void
{
$header = trim((string) ($this->header->get('module.dispatcher.header', $module->class_name) ?? ''));
if ($header !== '')
{
$header = PHP_EOL . PHP_EOL . $header;
}
$this->contentmulti->set("{$module->key}|DISPATCHER_CLASS_HEADER", $header);
$code = $this->dispatcher->get($module);
$this->contentmulti->set("{$module->key}|DISPATCHER_CLASS", $code);
}
/**
* Set dynamically generated get methods (dynamicGets).
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function setDynamicGets(object $module): void
{
if ($module->custom_get)
{
$header = trim((string) ($this->header->get('module.dynamicgets.header', $module->class_name) ?? ''));
if ($header !== '')
{
$header = PHP_EOL . PHP_EOL . $header;
}
$this->contentmulti->set("{$module->key}|DYNAMICGETS_HEADER", $header);
$code = $this->methods->get($module, $module->key);
$this->contentmulti->set("{$module->key}|DYNAMICGETS", $code);
}
}
/**
* Set helper class code if enabled.
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function setHelperCode(object $module): void
{
if ($module->add_class_helper >= 1)
{
$header = trim((string) ($this->header->get('module.helper.header', $module->class_name) ?? ''));
$header .= $this->helper->header($module);
if (!empty($header))
{
$header = PHP_EOL . PHP_EOL . trim($header);
}
$this->contentmulti->set("{$module->key}|HELPER_CLASS_HEADER", $header);
$code = $this->helper->get($module);
$this->contentmulti->set("{$module->key}|HELPER_CLASS", $code);
}
}
/**
* Set default and extra templates.
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function setDefaultTemplates(object $module): void
{
$header = trim((string) ($this->header->get('module.default.template.header', $module->class_name) ?? ''));
if (!empty($header))
{
$header = PHP_EOL . PHP_EOL . $header;
}
$this->contentmulti->set("{$module->key}|MODDEFAULT_HEADER", $header);
$header_code = $this->template->header($module);
$this->contentmulti->set("{$module->key}|MODDEFAULT_HEADER_CODE", $header_code);
$code = $this->template->default($module, $module->key);
$this->contentmulti->set("{$module->key}|MODDEFAULT", $code);
$this->template->extra($module);
}
/**
* Set install script content if required.
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function setInstallScript(object $module): void
{
if ($module->add_install_script)
{
$this->contentmulti->set("{$module->key}|INSTALLCLASS",
$this->installscript->get($module));
}
}
/**
* Set all fieldset content based on form files.
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function setFieldsets(object $module): void
{
if (!isset($module->form_files) || !ArrayHelper::check($module->form_files))
{
return;
}
foreach ($module->form_files as $file => $files)
{
foreach ($files as $field_name => $fieldsets)
{
foreach ($fieldsets as $fieldset => $fields)
{
$key = "{$module->key}|FIELDSET_{$file}{$field_name}{$fieldset}";
$content = $this->fieldsetextension->get($module, $fields);
$this->contentmulti->set($key, $content);
}
}
}
}
/**
* Set main XML configuration content.
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function setMainXml(object $module): void
{
$this->contentmulti->set("{$module->key}|MAINXML", $this->mainxml->get($module));
}
/**
* Trigger before-infusion event.
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function triggerBeforeInfusionEvent(object &$module): void
{
$this->event->trigger('jcb_ce_onBeforeInfuseModuleData', [&$module]);
}
/**
* Trigger after-infusion event.
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function triggerAfterInfusionEvent(object &$module): void
{
$this->event->trigger('jcb_ce_onAfterInfuseModuleData', [&$module]);
}
}

View File

@@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>

View File

@@ -9,11 +9,12 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Joomlamodule;
namespace VDM\Joomla\Componentbuilder\Compiler\Joomlamodule\JoomlaThree;
use Joomla\CMS\Factory;
use Joomla\CMS\Filter\OutputFilter;
use Joomla\CMS\Filter\OutputFilter;
use Joomla\Database\DatabaseInterface;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Customcode;
use VDM\Joomla\Componentbuilder\Compiler\Customcode\Gui;
@@ -31,6 +32,7 @@ use VDM\Joomla\Utilities\JsonHelper;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Utilities\GetHelper;
use VDM\Joomla\Utilities\GuidHelper;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\ModuleDataInterface;
/**
@@ -38,7 +40,7 @@ use VDM\Joomla\Utilities\GuidHelper;
*
* @since 3.2.0
*/
class Data
class Data implements ModuleDataInterface
{
/**
* Compiler Joomla Plugins Data
@@ -145,26 +147,28 @@ class Data
protected Templatelayout $templatelayout;
/**
* The Database Class.
* Joomla Database Class.
*
* @since 3.2.0
*/
protected $db;
* @var DatabaseInterface
* @since 5.1.2
**/
protected DatabaseInterface $db;
/**
* Constructor.
*
* @param Config $config The Config Class.
* @param Customcode $customcode The Customcode Class.
* @param Gui $gui The Gui Class.
* @param Placeholder $placeholder The Placeholder Class.
* @param Language $language The Language Class.
* @param Field $field The Field Class.
* @param Fieldname $fieldname The Name Class.
* @param Filesfolders $filesfolders The Filesfolders Class.
* @param Libraries $libraries The Libraries Class.
* @param Dynamicget $dynamicget The Data Class.
* @param Templatelayout $templatelayout The Data Class.
* @param Config $config The Config Class.
* @param Customcode $customcode The Customcode Class.
* @param Gui $gui The Gui Class.
* @param Placeholder $placeholder The Placeholder Class.
* @param Language $language The Language Class.
* @param Field $field The Field Class.
* @param Fieldname $fieldname The Name Class.
* @param Filesfolders $filesfolders The Filesfolders Class.
* @param Libraries $libraries The Libraries Class.
* @param Dynamicget $dynamicget The Data Class.
* @param Templatelayout $templatelayout The Data Class.
* @param DatabaseInterface $db The Joomla Database Class.
*
* @since 3.2.0
*/
@@ -172,7 +176,8 @@ class Data
Placeholder $placeholder, Language $language,
Field $field, Fieldname $fieldname,
Filesfolders $filesfolders, Libraries $libraries,
Dynamicget $dynamicget, Templatelayout $templatelayout)
Dynamicget $dynamicget, Templatelayout $templatelayout,
DatabaseInterface $db)
{
$this->config = $config;
$this->customcode = $customcode;
@@ -185,7 +190,7 @@ class Data
$this->libraries = $libraries;
$this->dynamicget = $dynamicget;
$this->templatelayout = $templatelayout;
$this->db = Factory::getDbo();
$this->db = $db;
}
/**

View File

@@ -0,0 +1,369 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Joomlamodule\JoomlaThree;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module\DispatcherInterface as Dispatcher;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module\TemplateInterface as Template;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\Architecture\Module\HelperInterface as Helper;
use VDM\Joomla\Componentbuilder\Interfaces\Architecture\Module\MainXMLInterface as MainXML;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\ModuleDataInterface as Data;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\HeaderInterface as Header;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\EventInterface as Event;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\GetScriptInterface as InstallScript;
use VDM\Joomla\Componentbuilder\Compiler\Builder\ContentMulti;
use VDM\Joomla\Componentbuilder\Compiler\Creator\FieldsetExtension;
use VDM\Joomla\Componentbuilder\Compiler\Dynamicget\Methods;
use VDM\Joomla\Utilities\ObjectHelper;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Componentbuilder\Interfaces\Module\InfusionInterface;
/**
* Joomla 3 module Infusion Class
*
* @since 5.1.2
*/
final class Infusion implements InfusionInterface
{
/**
* The Config Class.
*
* @var Config
* @since 5.1.2
*/
protected Config $config;
/**
* The DispatcherInterface Class.
*
* @var Dispatcher
* @since 5.1.2
*/
protected Dispatcher $dispatcher;
/**
* The TemplateInterface Class.
*
* @var Template
* @since 5.1.2
*/
protected Template $template;
/**
* The Helper Class.
*
* @var Helper
* @since 5.1.2
*/
protected Helper $helper;
/**
* The MainXMLInterface Class.
*
* @var MainXML
* @since 5.1.2
*/
protected MainXML $mainxml;
/**
* The ModuleDataInterface Class.
*
* @var Data
* @since 5.1.2
*/
protected Data $data;
/**
* The HeaderInterface Class.
*
* @var Header
* @since 5.1.2
*/
protected Header $header;
/**
* The EventInterface Class.
*
* @var Event
* @since 5.1.2
*/
protected Event $event;
/**
* The InstallInterface Class.
*
* @var InstallScript
* @since 5.1.2
*/
protected InstallScript $installscript;
/**
* The ContentMulti Class.
*
* @var ContentMulti
* @since 5.1.2
*/
protected ContentMulti $contentmulti;
/**
* The FieldsetExtension Class.
*
* @var FieldsetExtension
* @since 5.1.2
*/
protected FieldsetExtension $fieldsetextension;
/**
* The Methods Class.
*
* @var Methods
* @since 5.1.2
*/
protected Methods $methods;
/**
* Constructor.
*
* @param Config $config The Config Class.
* @param Dispatcher $dispatcher The DispatcherInterface Class.
* @param Template $template The TemplateInterface Class.
* @param Helper $helper The Helper Class.
* @param MainXML $mainxml The MainXMLInterface Class.
* @param Data $data The ModuleDataInterface Class.
* @param Header $header The HeaderInterface Class.
* @param Event $event The EventInterface Class.
* @param InstallScript $installscript The InstallInterface Class.
* @param ContentMulti $contentmulti The ContentMulti Class.
* @param FieldsetExtension $fieldsetextension The FieldsetExtension Class.
* @param Methods $methods The Methods Class.
*
* @since 5.1.2
*/
public function __construct(Config $config, Dispatcher $dispatcher, Template $template,
Helper $helper, MainXML $mainxml, Data $data,
Header $header, Event $event,
InstallScript $installscript, ContentMulti $contentmulti,
FieldsetExtension $fieldsetextension, Methods $methods)
{
$this->config = $config;
$this->dispatcher = $dispatcher;
$this->template = $template;
$this->helper = $helper;
$this->mainxml = $mainxml;
$this->data = $data;
$this->header = $header;
$this->event = $event;
$this->installscript = $installscript;
$this->contentmulti = $contentmulti;
$this->fieldsetextension = $fieldsetextension;
$this->methods = $methods;
}
/**
* Infuse the module data into the content.
*
* @return void
* @since 5.1.2
*/
public function set(): void
{
if (!$this->data->exists())
{
return;
}
foreach ($this->data->get() as $module)
{
if (!ObjectHelper::check($module))
{
continue;
}
$this->triggerBeforeInfusionEvent($module);
$this->setModuleConfiguration($module);
$this->setDispatcherCode($module);
$this->setDynamicGets($module);
$this->setHelperCode($module);
$this->setDefaultTemplates($module);
$this->setInstallScript($module);
$this->setFieldsets($module);
$this->setMainXml($module);
$this->triggerAfterInfusionEvent($module);
}
}
/**
* Set core configuration from module data.
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function setModuleConfiguration(object $module): void
{
$this->config->build_target = $module->key;
$this->config->lang_target = $module->key;
$this->config->set('lang_prefix', $module->lang_prefix);
}
/**
* Set dispatcher-generated module code.
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function setDispatcherCode(object $module): void
{
$this->contentmulti->set("{$module->key}|MODCODE", $header . $this->dispatcher->get($module));
}
/**
* Set dynamically generated methods.
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function setDynamicGets(object $module): void
{
$this->contentmulti->set("{$module->key}|DYNAMICGETS", $this->methods->get($module, $module->key));
}
/**
* Set helper class code if enabled.
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function setHelperCode(object $module): void
{
if ($module->add_class_helper >= 1)
{
$header = $this->helper->header($module);
$code = $this->helper->get($module);
$this->contentmulti->set("{$module->key}|HELPERCODE", $header . $code);
}
}
/**
* Set default and extra templates.
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function setDefaultTemplates(object $module): void
{
$this->contentmulti->set(
"{$module->key}|MODDEFAULT",
$this->template->default($module, $module->key)
);
$this->template->extra($module);
}
/**
* Set install script content if required.
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function setInstallScript(object $module): void
{
if ($module->add_install_script)
{
$this->contentmulti->set("{$module->key}|INSTALLCLASS",
$this->installscript->get($module));
}
}
/**
* Set all fieldset content based on form files.
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function setFieldsets(object $module): void
{
if (!isset($module->form_files) || !ArrayHelper::check($module->form_files))
{
return;
}
foreach ($module->form_files as $file => $files)
{
foreach ($files as $field_name => $fieldsets)
{
foreach ($fieldsets as $fieldset => $fields)
{
$key = "{$module->key}|FIELDSET_{$file}{$field_name}{$fieldset}";
$content = $this->fieldsetextension->get($module, $fields);
$this->contentmulti->set($key, $content);
}
}
}
}
/**
* Set main XML configuration content.
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function setMainXml(object $module): void
{
$this->contentmulti->set("{$module->key}|MAINXML", $this->mainxml->get($module));
}
/**
* Trigger before-infusion event.
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function triggerBeforeInfusionEvent(object &$module): void
{
$this->event->trigger('jcb_ce_onBeforeInfuseModuleData', [&$module]);
}
/**
* Trigger after-infusion event.
*
* @param object $module
*
* @return void
* @since 5.1.2
*/
protected function triggerAfterInfusionEvent(object &$module): void
{
$this->event->trigger('jcb_ce_onAfterInfuseModuleData', [&$module]);
}
}

View File

@@ -9,10 +9,10 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Compiler\Joomlamodule;
namespace VDM\Joomla\Componentbuilder\Compiler\Joomlamodule\JoomlaThree;
use VDM\Joomla\Componentbuilder\Compiler\Joomlamodule\Data as Module;
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\ModuleDataInterface as Module;
use VDM\Joomla\Componentbuilder\Compiler\Component;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Registry;
@@ -30,6 +30,7 @@ use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Utilities\ObjectHelper;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Utilities\FileHelper;
use VDM\Joomla\Componentbuilder\Interfaces\Module\StructureInterface;
/**
@@ -37,7 +38,7 @@ use VDM\Joomla\Utilities\FileHelper;
*
* @since 3.2.0
*/
class Structure
class Structure implements StructureInterface
{
/**
* The Data Class.
@@ -203,8 +204,8 @@ class Structure
// create the main module file
$this->setMainModFile($module);
// creat the custom get file
$this->setCustomGet($module);
// create the dynamic gets file
$this->setDynamicGets($module);
// set helper file
$this->setHelperFile($module);
@@ -388,14 +389,14 @@ class Structure
}
/**
* Set the custom get file
* Set the dynamic gets file
*
* @param object $module
*
* @return void
* @since 3.2.0
*/
protected function setCustomGet(object $module): void
protected function setDynamicGets(object $module): void
{
if ($module->custom_get)
{

View File

@@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>

View File

@@ -13,7 +13,8 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Joomlaplugin\JoomlaFive;
use Joomla\CMS\Factory;
use Joomla\CMS\Filter\OutputFilter;
use Joomla\CMS\Filter\OutputFilter;
use Joomla\Database\DatabaseInterface;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Customcode;
use VDM\Joomla\Componentbuilder\Compiler\Customcode\Gui;
@@ -121,11 +122,12 @@ final class Data implements PluginDataInterface
protected Filesfolders $filesfolders;
/**
* Database object to query local DB
* Joomla Database Class.
*
* @since 3.2.0
* @var DatabaseInterface
* @since 5.1.2
**/
protected $db;
protected DatabaseInterface $db;
/**
* Define the mappings of traits and classes to their respective methods and services
@@ -151,21 +153,22 @@ final class Data implements PluginDataInterface
/**
* Constructor.
*
* @param Config $config The Config Class.
* @param Customcode $customcode The Customcode Class.
* @param Gui $gui The Gui Class.
* @param Placeholder $placeholder The Placeholder Class.
* @param Language $language The Language Class.
* @param Field $field The Field Class.
* @param FieldName $fieldname The Name Class.
* @param Filesfolders $filesfolders The Filesfolders Class.
* @param Config $config The Config Class.
* @param Customcode $customcode The Customcode Class.
* @param Gui $gui The Gui Class.
* @param Placeholder $placeholder The Placeholder Class.
* @param Language $language The Language Class.
* @param Field $field The Field Class.
* @param FieldName $fieldname The Name Class.
* @param Filesfolders $filesfolders The Filesfolders Class.
* @param DatabaseInterface $db The Joomla Database Class.
*
* @since 5.0.2
*/
public function __construct(Config $config, Customcode $customcode, Gui $gui,
Placeholder $placeholder, Language $language,
Field $field, FieldName $fieldname,
Filesfolders $filesfolders)
Filesfolders $filesfolders, DatabaseInterface $db)
{
$this->config = $config;
$this->customcode = $customcode;
@@ -175,7 +178,7 @@ final class Data implements PluginDataInterface
$this->field = $field;
$this->fieldname = $fieldname;
$this->filesfolders = $filesfolders;
$this->db = Factory::getDbo();
$this->db = $db;
}
/**

View File

@@ -38,7 +38,7 @@ use VDM\Joomla\Componentbuilder\Interfaces\Plugin\StructureInterface;
*
* @since 5.0.2
*/
class Structure implements StructureInterface
final class Structure implements StructureInterface
{
/**
* The Data Class.
@@ -243,11 +243,11 @@ class Structure implements StructureInterface
if (isset($plugin->fields_rules_paths)
&& $plugin->fields_rules_paths == 2)
{
// create fields folder
$this->folder->create($plugin->folder_path . '/src/Field');
// create rules folder
$this->folder->create($plugin->folder_path . '/src/Rule');
// create fields folder
$this->folder->create($plugin->folder_path . '/src/Field');
}
// set forms folder if needed
@@ -498,9 +498,6 @@ class Structure implements StructureInterface
if (isset($plugin->form_files)
&& ArrayHelper::check($plugin->form_files))
{
$Group = ucfirst((string) $plugin->group);
$FileName = $plugin->file_name;
// create forms folder
$this->folder->create($plugin->folder_path . '/forms');
@@ -595,13 +592,13 @@ class Structure implements StructureInterface
if (!isset($plugin->add_rule_path[$file . $field_name . $fieldset]))
{
$plugin->add_rule_path[$file . $field_name . $fieldset] =
"{$this->NamespacePrefix}\\Plugin\\{$Group}\\{$FileName}\\Rule";
"{$this->NamespacePrefix}\\Plugin\\{$plugin->group_namespace}\\{$plugin->namespace}\\Rule";
}
if (!isset($plugin->add_field_path[$file . $field_name . $fieldset]))
{
$plugin->add_field_path[$file . $field_name . $fieldset] =
"{$this->NamespacePrefix}\\Plugin\\{$Group}\\{$FileName}\\Field";
"{$this->NamespacePrefix}\\Plugin\\{$plugin->group_namespace}\\{$plugin->namespace}\\Field";
}
}
@@ -619,13 +616,13 @@ class Structure implements StructureInterface
if (isset($plugin->add_rule_path[$file . $field_name . $fieldset]))
{
$xml .= PHP_EOL . Indent::_(2)
. 'addrulepath="' . $plugin->add_rule_path[$file . $field_name . $fieldset] . '"';
. 'addruleprefix="' . $plugin->add_rule_path[$file . $field_name . $fieldset] . '"';
}
if (isset($plugin->add_field_path[$file . $field_name . $fieldset]))
{
$xml .= PHP_EOL . Indent::_(2)
. 'addfieldpath="' . $plugin->add_field_path[$file . $field_name . $fieldset] . '"';
. 'addfieldprefix="' . $plugin->add_field_path[$file . $field_name . $fieldset] . '"';
}
$xml .= PHP_EOL . Indent::_(1) . '>';

View File

@@ -13,7 +13,8 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Joomlaplugin\JoomlaFour;
use Joomla\CMS\Factory;
use Joomla\CMS\Filter\OutputFilter;
use Joomla\CMS\Filter\OutputFilter;
use Joomla\Database\DatabaseInterface;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Customcode;
use VDM\Joomla\Componentbuilder\Compiler\Customcode\Gui;
@@ -121,11 +122,12 @@ final class Data implements PluginDataInterface
protected Filesfolders $filesfolders;
/**
* Database object to query local DB
* Joomla Database Class.
*
* @since 3.2.0
* @var DatabaseInterface
* @since 5.1.2
**/
protected $db;
protected DatabaseInterface $db;
/**
* Define the mappings of traits and classes to their respective methods and services
@@ -151,21 +153,22 @@ final class Data implements PluginDataInterface
/**
* Constructor.
*
* @param Config $config The Config Class.
* @param Customcode $customcode The Customcode Class.
* @param Gui $gui The Gui Class.
* @param Placeholder $placeholder The Placeholder Class.
* @param Language $language The Language Class.
* @param Field $field The Field Class.
* @param FieldName $fieldname The Name Class.
* @param Filesfolders $filesfolders The Filesfolders Class.
* @param Config $config The Config Class.
* @param Customcode $customcode The Customcode Class.
* @param Gui $gui The Gui Class.
* @param Placeholder $placeholder The Placeholder Class.
* @param Language $language The Language Class.
* @param Field $field The Field Class.
* @param FieldName $fieldname The Name Class.
* @param Filesfolders $filesfolders The Filesfolders Class.
* @param DatabaseInterface $db The Joomla Database Class.
*
* @since 5.0.2
*/
public function __construct(Config $config, Customcode $customcode, Gui $gui,
Placeholder $placeholder, Language $language,
Field $field, FieldName $fieldname,
Filesfolders $filesfolders)
Filesfolders $filesfolders, DatabaseInterface $db)
{
$this->config = $config;
$this->customcode = $customcode;
@@ -175,7 +178,7 @@ final class Data implements PluginDataInterface
$this->field = $field;
$this->fieldname = $fieldname;
$this->filesfolders = $filesfolders;
$this->db = Factory::getDbo();
$this->db = $db;
}
/**

View File

@@ -38,7 +38,7 @@ use VDM\Joomla\Componentbuilder\Interfaces\Plugin\StructureInterface;
*
* @since 5.0.2
*/
class Structure implements StructureInterface
final class Structure implements StructureInterface
{
/**
* The Data Class.

View File

@@ -13,7 +13,8 @@ namespace VDM\Joomla\Componentbuilder\Compiler\Joomlaplugin\JoomlaThree;
use Joomla\CMS\Factory;
use Joomla\CMS\Filter\OutputFilter;
use Joomla\CMS\Filter\OutputFilter;
use Joomla\Database\DatabaseInterface;
use VDM\Joomla\Componentbuilder\Compiler\Config;
use VDM\Joomla\Componentbuilder\Compiler\Customcode;
use VDM\Joomla\Componentbuilder\Compiler\Customcode\Gui;
@@ -120,30 +121,32 @@ final class Data implements PluginDataInterface
protected Filesfolders $filesfolders;
/**
* Database object to query local DB
* Joomla Database Class.
*
* @since 3.2.0
* @var DatabaseInterface
* @since 5.1.2
**/
protected $db;
protected DatabaseInterface $db;
/**
* Constructor.
*
* @param Config $config The Config Class.
* @param Customcode $customcode The Customcode Class.
* @param Gui $gui The Gui Class.
* @param Placeholder $placeholder The Placeholder Class.
* @param Language $language The Language Class.
* @param Field $field The Field Class.
* @param FieldName $fieldname The Name Class.
* @param Filesfolders $filesfolders The Filesfolders Class.
* @param Config $config The Config Class.
* @param Customcode $customcode The Customcode Class.
* @param Gui $gui The Gui Class.
* @param Placeholder $placeholder The Placeholder Class.
* @param Language $language The Language Class.
* @param Field $field The Field Class.
* @param FieldName $fieldname The Name Class.
* @param Filesfolders $filesfolders The Filesfolders Class.
* @param DatabaseInterface $db The Joomla Database Class.
*
* @since 5.0.2
*/
public function __construct(Config $config, Customcode $customcode, Gui $gui,
Placeholder $placeholder, Language $language,
Field $field, FieldName $fieldname,
Filesfolders $filesfolders)
Filesfolders $filesfolders, DatabaseInterface $db)
{
$this->config = $config;
$this->customcode = $customcode;
@@ -153,7 +156,7 @@ final class Data implements PluginDataInterface
$this->field = $field;
$this->fieldname = $fieldname;
$this->filesfolders = $filesfolders;
$this->db = Factory::getDbo();
$this->db = $db;
}
/**

View File

@@ -37,7 +37,7 @@ use VDM\Joomla\Componentbuilder\Interfaces\Plugin\StructureInterface;
*
* @since 3.2.0
*/
class Structure implements StructureInterface
final class Structure implements StructureInterface
{
/**
* The Data Class.

View File

@@ -12,7 +12,7 @@
namespace VDM\Joomla\Componentbuilder\Compiler\Language;
use Joomla\CMS\Factory;
use Joomla\Database\DatabaseInterface;
/**
@@ -31,20 +31,21 @@ final class Insert
protected array $items = [];
/**
* Database object to query local DB
* Joomla Database Class.
*
* @since 5.0.2
* @var DatabaseInterface
* @since 5.1.2
**/
protected $db;
protected DatabaseInterface $db;
/**
* Constructor.
*
* @since 5.0.2
*/
public function __construct()
public function __construct(DatabaseInterface $db)
{
$this->db = Factory::getDbo();
$this->db = $db;
}
/**

Some files were not shown because too many files have changed in this diff Show More