Release of v5.0.0-alpha8
Add power path override option on component level. Fix the sql build feature. #1032.
This commit is contained in:
@@ -0,0 +1,317 @@
|
||||
<?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 Joomla\CMS\Factory;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Factory as Compiler;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Config;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Registry;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Interfaces\EventInterface;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Customcode;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Customcode\Dispenser;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Customcode\Gui;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Model\Dynamicget;
|
||||
use VDM\Joomla\Utilities\JsonHelper;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
|
||||
|
||||
/**
|
||||
* Dynamic Get Data Class
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Data
|
||||
{
|
||||
/**
|
||||
* The gui mapper array
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected array $guiMapper = [
|
||||
'table' => 'dynamic_get',
|
||||
'id' => null,
|
||||
'field' => null,
|
||||
'type' => 'php'
|
||||
];
|
||||
|
||||
/**
|
||||
* Compiler Config
|
||||
*
|
||||
* @var Config
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* The compiler registry
|
||||
*
|
||||
* @var Registry
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Registry $registry;
|
||||
|
||||
/**
|
||||
* Compiler Event
|
||||
*
|
||||
* @var EventInterface
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected EventInterface $event;
|
||||
|
||||
/**
|
||||
* Compiler Customcode
|
||||
*
|
||||
* @var Customcode
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Customcode $customcode;
|
||||
|
||||
/**
|
||||
* Compiler Customcode Dispenser
|
||||
*
|
||||
* @var Dispenser
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Dispenser $dispenser;
|
||||
|
||||
/**
|
||||
* Compiler Customcode in Gui
|
||||
*
|
||||
* @var Gui
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected Gui $gui;
|
||||
|
||||
/**
|
||||
* Compiler Dynamicget Model
|
||||
*
|
||||
* @var Dynamicget
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Dynamicget $dynamic;
|
||||
|
||||
/**
|
||||
* Database object to query local DB
|
||||
*
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Config|null $config The compiler config object.
|
||||
* @param Registry|null $registry The compiler registry object.
|
||||
* @param EventInterface|null $event The compiler event api object.
|
||||
* @param Customcode|null $customcode The compiler customcode object.
|
||||
* @param Dispenser|null $dispenser The compiler customcode dispenser object.
|
||||
* @param Gui|null $gui The compiler customcode gui.
|
||||
* @param Dynamicget|null $dynamic The compiler dynamicget modeller object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Config $config = null, ?Registry $registry = null,
|
||||
?EventInterface $event = null, ?Customcode $customcode = null,
|
||||
?Dispenser $dispenser = null, ?Gui $gui = null,
|
||||
?Dynamicget $dynamic = null)
|
||||
{
|
||||
$this->config = $config ?: Compiler::_('Config');
|
||||
$this->registry = $registry ?: Compiler::_('Registry');
|
||||
$this->event = $event ?: Compiler::_('Event');
|
||||
$this->customcode = $customcode ?: Compiler::_('Customcode');
|
||||
$this->dispenser = $dispenser ?: Compiler::_('Customcode.Dispenser');
|
||||
$this->gui = $gui ?: Compiler::_('Customcode.Gui');
|
||||
$this->dynamic = $dynamic ?: Compiler::_('Model.Dynamicget');
|
||||
$this->db = Factory::getDbo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Dynamic Get Data
|
||||
*
|
||||
* @param array $ids The ids of the dynamic get
|
||||
* @param string $view_code The view code name
|
||||
* @param string $context The context for events
|
||||
*
|
||||
* @return array|null array of object/s on success
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(array $ids, string $view_code, string $context): ?array
|
||||
{
|
||||
if ($ids === [])
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$ids = implode(',', $ids);
|
||||
|
||||
// Create a new query object.
|
||||
$query = $this->db->getQuery(true);
|
||||
$query->select('a.*');
|
||||
$query->from('#__componentbuilder_dynamic_get AS a');
|
||||
$query->where('a.id IN (' . $ids . ')');
|
||||
$this->db->setQuery($query);
|
||||
$this->db->execute();
|
||||
|
||||
if ($this->db->getNumRows())
|
||||
{
|
||||
$results = $this->db->loadObjectList();
|
||||
|
||||
foreach ($results as $_nr => &$result)
|
||||
{
|
||||
// Trigger Event: jcb_ce_onBeforeModelDynamicGetData
|
||||
$this->event->trigger(
|
||||
'jcb_ce_onBeforeModelDynamicGetData', [&$result, &$result->id, &$view_code, &$context]
|
||||
);
|
||||
|
||||
// set GUI mapper id
|
||||
$this->guiMapper['id'] = (int) $result->id;
|
||||
|
||||
// add calculations if set
|
||||
if ($result->addcalculation == 1
|
||||
&& StringHelper::check(
|
||||
$result->php_calculation
|
||||
))
|
||||
{
|
||||
// set GUI mapper field
|
||||
$guiMapper['field'] = 'php_calculation';
|
||||
$result->php_calculation = $this->gui->set(
|
||||
$this->customcode->update(
|
||||
base64_decode((string) $result->php_calculation)
|
||||
),
|
||||
$this->guiMapper
|
||||
);
|
||||
}
|
||||
|
||||
// setup the router parse
|
||||
if (isset($result->add_php_router_parse)
|
||||
&& $result->add_php_router_parse == 1
|
||||
&& isset($result->php_router_parse)
|
||||
&& StringHelper::check(
|
||||
$result->php_router_parse
|
||||
))
|
||||
{
|
||||
// set GUI mapper field
|
||||
$this->guiMapper['field'] = 'php_router_parse';
|
||||
$result->php_router_parse = $this->gui->set(
|
||||
$this->customcode->update(
|
||||
base64_decode((string) $result->php_router_parse)
|
||||
),
|
||||
$this->guiMapper
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$result->add_php_router_parse = 0;
|
||||
}
|
||||
|
||||
// The array of the php scripts that should be added to the script builder
|
||||
$phpSripts = [
|
||||
'php_before_getitem',
|
||||
'php_after_getitem',
|
||||
'php_before_getitems',
|
||||
'php_after_getitems',
|
||||
'php_getlistquery'
|
||||
];
|
||||
|
||||
// load the php scripts
|
||||
foreach ($phpSripts as $script)
|
||||
{
|
||||
// add php script to the script builder
|
||||
if (isset($result->{'add_' . $script})
|
||||
&& $result->{'add_' . $script} == 1
|
||||
&& isset($result->{$script})
|
||||
&& StringHelper::check(
|
||||
$result->{$script}
|
||||
))
|
||||
{
|
||||
// move all main gets out to the custom script builder
|
||||
if ($result->gettype <= 2)
|
||||
{
|
||||
// set GUI mapper field
|
||||
$this->guiMapper['field'] = $script;
|
||||
$this->guiMapper['prefix'] = PHP_EOL . PHP_EOL;
|
||||
$this->dispenser->set(
|
||||
$result->{$script},
|
||||
$this->config->build_target . '_' . $script,
|
||||
$view_code,
|
||||
null,
|
||||
$this->guiMapper,
|
||||
true,
|
||||
true,
|
||||
true
|
||||
);
|
||||
unset($this->guiMapper['prefix']);
|
||||
// remove from local item
|
||||
unset($result->{$script});
|
||||
unset($result->{'add_' . $script});
|
||||
}
|
||||
else
|
||||
{
|
||||
// set GUI mapper field
|
||||
$this->guiMapper['field'] = $script;
|
||||
$this->guiMapper['prefix'] = PHP_EOL;
|
||||
// only for custom gets
|
||||
$result->{$script} = $this->gui->set(
|
||||
$this->customcode->update(
|
||||
base64_decode((string) $result->{$script})
|
||||
),
|
||||
$this->guiMapper
|
||||
);
|
||||
unset($this->guiMapper['prefix']);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// remove from local item
|
||||
unset($result->{$script});
|
||||
unset($result->{'add_' . $script});
|
||||
}
|
||||
}
|
||||
|
||||
// set the getmethod code name
|
||||
$result->key = StringHelper::safe(
|
||||
$view_code . ' ' . $result->name . ' ' . $result->id
|
||||
);
|
||||
|
||||
// set the dynamic get
|
||||
$this->dynamic->set($result, $view_code, $context);
|
||||
|
||||
// load the events if any is set
|
||||
if ($result->gettype == 1
|
||||
&& JsonHelper::check(
|
||||
$result->plugin_events
|
||||
))
|
||||
{
|
||||
$result->plugin_events = json_decode(
|
||||
(string) $result->plugin_events, true
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$result->plugin_events = '';
|
||||
}
|
||||
|
||||
// Trigger Event: jcb_ce_onAfterModelDynamicGetData
|
||||
$this->event->trigger(
|
||||
'jcb_ce_onAfterModelDynamicGetData', [&$result, &$result->id, &$view_code, &$context]
|
||||
);
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,286 @@
|
||||
<?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 Joomla\CMS\Factory;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Config;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Builder\GetAsLookup;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Builder\SiteFields;
|
||||
use VDM\Joomla\Utilities\StringHelper;
|
||||
use VDM\Joomla\Utilities\ArrayHelper;
|
||||
use VDM\Joomla\Utilities\GetHelper;
|
||||
use VDM\Joomla\Utilities\Component\Helper;
|
||||
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent;
|
||||
|
||||
|
||||
/**
|
||||
* Dynamic Get Selection Class
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
class Selection
|
||||
{
|
||||
/**
|
||||
* Admin view table names
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected array $name;
|
||||
|
||||
/**
|
||||
* The Config Class.
|
||||
*
|
||||
* @var Config
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Config $config;
|
||||
|
||||
/**
|
||||
* The GetAsLookup Class.
|
||||
*
|
||||
* @var GetAsLookup
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected GetAsLookup $getaslookup;
|
||||
|
||||
/**
|
||||
* The SiteFields Class.
|
||||
*
|
||||
* @var SiteFields
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected SiteFields $sitefields;
|
||||
|
||||
/**
|
||||
* Database object to query local DB
|
||||
*
|
||||
* @since 3.2.0
|
||||
**/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param Config $config The Config Class.
|
||||
* @param GetAsLookup $getaslookup The GetAsLookup Class.
|
||||
* @param SiteFields $sitefields The SiteFields Class.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(Config $config, GetAsLookup $getaslookup, SiteFields $sitefields)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->getaslookup = $getaslookup;
|
||||
$this->sitefields = $sitefields;
|
||||
$this->db = Factory::getDbo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Data Selection of the dynamic get
|
||||
*
|
||||
* @param string $methodKey The method unique key
|
||||
* @param string $viewCode The code name of the view
|
||||
* @param string $string The data string
|
||||
* @param string $asset The asset in question
|
||||
* @param string $as The as string
|
||||
* @param string $type The target type (db||view)
|
||||
* @param int|null $rowType The row type
|
||||
*
|
||||
* @return array|null the select query
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function get(string $methodKey, string $viewCode,
|
||||
string $string, string $asset, string $as, string $type, ?int $rowType = null): ?array
|
||||
{
|
||||
if (StringHelper::check($string))
|
||||
{
|
||||
if ('db' === $type)
|
||||
{
|
||||
$table = '#__' . $asset;
|
||||
$queryName = $asset;
|
||||
$view = '';
|
||||
}
|
||||
elseif ('view' === $type)
|
||||
{
|
||||
$view = $this->name($asset);
|
||||
$table = '#__' . $this->config->component_code_name . '_' . $view;
|
||||
$queryName = $view;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// just get all values from table if * is found
|
||||
if ($string === '*' || strpos($string, '*') !== false)
|
||||
{
|
||||
if ($type == 'view')
|
||||
{
|
||||
// TODO move getViewTableColumns to its own class
|
||||
$_string = Helper::_('getViewTableColumns',
|
||||
[$asset, $as, $rowType]
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO move getDbTableColumns to its own class
|
||||
$_string = Helper::_('getDbTableColumns',
|
||||
[$asset, $as, $rowType]
|
||||
);
|
||||
}
|
||||
|
||||
// get only selected values
|
||||
$lines = explode(PHP_EOL, (string) $_string);
|
||||
|
||||
// make sure to set the string to *
|
||||
$string = '*';
|
||||
}
|
||||
else
|
||||
{
|
||||
// get only selected values
|
||||
$lines = explode(PHP_EOL, $string);
|
||||
}
|
||||
|
||||
// only continue if lines are available
|
||||
if (ArrayHelper::check($lines))
|
||||
{
|
||||
$gets = [];
|
||||
$keys = [];
|
||||
|
||||
// first load all options
|
||||
foreach ($lines as $line)
|
||||
{
|
||||
if (strpos($line, 'AS') !== false)
|
||||
{
|
||||
$lineArray = explode("AS", $line);
|
||||
}
|
||||
elseif (strpos($line, 'as') !== false)
|
||||
{
|
||||
$lineArray = explode("as", $line);
|
||||
}
|
||||
else
|
||||
{
|
||||
$lineArray = array($line, null);
|
||||
}
|
||||
|
||||
// set the get and key
|
||||
$get = trim($lineArray[0]);
|
||||
$key = trim($lineArray[1]);
|
||||
|
||||
// only add the view (we must adapt this)
|
||||
if ($this->getaslookup->exists($methodKey . '.' . $get)
|
||||
&& 'a' != $as
|
||||
&& is_numeric($rowType) && 1 == $rowType
|
||||
&& 'view' === $type
|
||||
&& strpos('#' . $key, '#' . $view . '_') === false)
|
||||
{
|
||||
// this is a problem (TODO) since we may want to not add the view name.
|
||||
$key = $view . '_' . trim($key);
|
||||
}
|
||||
|
||||
// continue only if we have get
|
||||
if (StringHelper::check($get))
|
||||
{
|
||||
$gets[] = $this->db->quote($get);
|
||||
if (StringHelper::check($key))
|
||||
{
|
||||
$this->getaslookup->set($methodKey . '.' . $get, $key);
|
||||
}
|
||||
else
|
||||
{
|
||||
$key = str_replace(
|
||||
$as . '.', '', $get
|
||||
);
|
||||
|
||||
$this->getaslookup->set($methodKey . '.' . $get, $key);
|
||||
}
|
||||
|
||||
// set the keys
|
||||
$keys[] = $this->db->quote(
|
||||
$key
|
||||
);
|
||||
|
||||
// make sure we have the view name
|
||||
if (StringHelper::check($view))
|
||||
{
|
||||
// prep the field name
|
||||
$field = str_replace($as . '.', '', $get);
|
||||
// load to the site fields memory bucket
|
||||
$this->sitefields->set($view . '.' . $field . '.' . $methodKey . '___' . $as,
|
||||
['site' => $viewCode, 'get' => $get, 'as' => $as, 'key' => $key]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ArrayHelper::check($gets)
|
||||
&& ArrayHelper::check($keys))
|
||||
{
|
||||
// single joined selection needs the prefix to the values to avoid conflict in the names
|
||||
// so we must still add then AS
|
||||
if ($string == '*' && (is_null($rowType) || 1 != $rowType))
|
||||
{
|
||||
$querySelect = "\$query->select('" . $as . ".*');";
|
||||
}
|
||||
else
|
||||
{
|
||||
$querySelect = '$query->select($db->quoteName('
|
||||
. PHP_EOL . Indent::_(3) . 'array(' . implode(
|
||||
',', $gets
|
||||
) . '),' . PHP_EOL . Indent::_(3) . 'array('
|
||||
. implode(',', $keys) . ')));';
|
||||
}
|
||||
$queryFrom = '$db->quoteName(' . $this->db->quote($table)
|
||||
. ', ' . $this->db->quote($as) . ')';
|
||||
|
||||
// return the select query
|
||||
return [
|
||||
'select' => $querySelect,
|
||||
'from' => $queryFrom,
|
||||
'view' => $viewCode,
|
||||
'name' => $queryName,
|
||||
'table' => $table,
|
||||
'type' => $type,
|
||||
'select_gets' => $gets,
|
||||
'select_keys' => $keys
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Admin view table name
|
||||
*
|
||||
* @param int $id The item id to add
|
||||
*
|
||||
* @return string the admin view code name
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function name(int $id): string
|
||||
{
|
||||
// get name if not set
|
||||
if (!isset($this->name[$id]))
|
||||
{
|
||||
$this->name[$id] = StringHelper::safe(
|
||||
GetHelper::var('admin_view', $id, 'id', 'name_single')
|
||||
);
|
||||
}
|
||||
|
||||
return $this->name[$id] ?? 'error';
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1 @@
|
||||
<html><body bgcolor="#FFFFFF"></body></html>
|
Reference in New Issue
Block a user