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

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

View File

@ -175,7 +175,7 @@ class Power implements PowerInterface
*
* @param string $guid The global unique id of the power
*
* @return bool
* @return bool true on successful setting of a power
* @since 3.2.0
*/
protected function set(string $guid): bool
@ -190,39 +190,52 @@ class Power implements PowerInterface
// Create a new query object.
$query = $this->db->getQuery(true);
// select all values
$query->select('a.*');
// from these tables
// from this table
$query->from('#__componentbuilder_power AS a');
$query->where($this->db->quoteName('a.guid') . ' = ' . $this->db->quote($guid));
$this->db->setQuery($query);
$this->db->execute();
if ($this->db->getNumRows())
{
// make sure that in recursion we
// don't try to load this power again
// since during the load of a power we also load
// all powers linked to it
$this->state[$guid] = true;
// get the power data
$this->active[$guid] = $this->db->loadObject();
// make sure to add any language strings found to all language files
// since we can't know where this is used at this point
$tmp_lang_target = $this->config->lang_target;
$this->config->lang_target = 'both';
// we set the fix usr if needed
$this->fixUrl
= '"index.php?option=com_componentbuilder&view=powers&task=power.edit&id='
. $this->active[$guid]->id . '" target="_blank"';
// set some keys
$this->active[$guid]->target_type = 'P0m3R!';
$this->active[$guid]->key = $this->active[$guid]->id . '_' . $this->active[$guid]->target_type;
// now set the name
$this->active[$guid]->name = $this->placeholder->update(
$this->customcode->update($this->active[$guid]->name),
$this->placeholder->active
);
// now set the code_name and class name
$this->active[$guid]->code_name = $this->active[$guid]->class_name = ClassfunctionHelper::safe(
$this->active[$guid]->name
);
// set official name
$this->active[$guid]->official_name = StringHelper::safe(
$this->active[$guid]->name, 'W'
@ -287,6 +300,7 @@ class Power implements PowerInterface
{
// set GUI mapper field
$guiMapper['field'] = 'head';
// base64 Decode code
$this->active[$guid]->head = $this->gui->set(
$this->placeholder->update(
@ -333,6 +347,7 @@ class Power implements PowerInterface
return true;
}
}
// we failed to get the power,
// so we raise an error message
// only if guid is valid
@ -343,6 +358,7 @@ class Power implements PowerInterface
'Error'
);
}
// let's not try again
$this->state[$guid] = false;

View File

@ -17,11 +17,11 @@ use VDM\Joomla\Componentbuilder\Search\Config;
/**
* Search Type Regex
* Search Engine
*
* @since 3.2.0
*/
abstract class Type
abstract class Engine
{
/**
* Search Config

View File

@ -19,6 +19,7 @@ use VDM\Joomla\Componentbuilder\Search\Database\Set;
use VDM\Joomla\Componentbuilder\Search\Agent\Find;
use VDM\Joomla\Componentbuilder\Search\Agent\Replace;
use VDM\Joomla\Componentbuilder\Search\Agent\Search;
use VDM\Joomla\Componentbuilder\Search\Agent\Update;
/**
@ -76,6 +77,14 @@ class Agent
*/
protected Search $search;
/**
* Update
*
* @var Update
* @since 3.2.0
*/
protected Update $update;
/**
* Constructor
*
@ -90,7 +99,7 @@ class Agent
*/
public function __construct(?Config $config = null, ?Get $get = null,
?Set$set = null, ?Find $find = null, ?Replace $replace = null,
?Search $search = null)
?Search $search = null, ?Update $update = null)
{
$this->config = $config ?: Factory::_('Config');
$this->get = $get ?: Factory::_('Get.Database');
@ -98,6 +107,65 @@ class Agent
$this->find = $find ?: Factory::_('Agent.Find');
$this->replace = $replace ?: Factory::_('Agent.Replace');
$this->search = $search ?: Factory::_('Agent.Search');
$this->update = $update ?: Factory::_('Agent.Update');
}
/**
* Get the value of a field in a row and table
*
* @param mixed $value The field value
* @param int $id The item ID
* @param string $field The field key
* @param mixed $line The field line
* @param string|null $table The table
* @param bool $update The switch to triger an update (default is false)
*
* @return mixed
* @since 3.2.0
*/
public function getValue(int $id, string $field, $line = null,
?string $table = null, bool $update = false)
{
// set the table name
if (empty($table))
{
$table = $this->config->table_name;
}
if (($value = $this->get->value($id, $field, $table)) !== null)
{
// try to update the value if required
if ($update && ($updated_value = $this->update->value($value, $line)) !== null)
{
return $updated_value;
}
return $value;
}
return null;
}
/**
* Set the value of a field in a row and table
*
* @param mixed $value The field value
* @param int $id The item ID
* @param string $field The field key
* @param string|null $table The table
*
* @return bool
* @since 3.2.0
*/
public function setValue($value, int $id, string $field, ?string $table = null): bool
{
// set the table name
if (empty($table))
{
$table = $this->config->table_name;
}
return $this->set->value($value, $id, $field, $table);
}
/**

View File

@ -87,17 +87,17 @@ class Get implements GetInterface
}
/**
* Get values from a given table
* Get a value from a given table
* Example: $this->value(23, 'value_key', 'table_name');
*
* @param string $field The field key
* @param int $id The item ID
* @param string $field The field key
* @param string|null $table The table
*
* @return mixed
* @since 3.2.0
*/
public function value(string $field, int $id, string $table = null)
public function value(int $id, string $field, string $table = null)
{
// load the table
if (empty($table))

View File

@ -9,14 +9,14 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Search\Type;
namespace VDM\Joomla\Componentbuilder\Search\Engine;
use VDM\Joomla\Componentbuilder\Search\Config;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Componentbuilder\Search\Interfaces\SearchTypeInterface;
use VDM\Joomla\Componentbuilder\Search\Abstraction\Type;
use VDM\Joomla\Componentbuilder\Search\Abstraction\Engine;
/**
@ -24,7 +24,7 @@ use VDM\Joomla\Componentbuilder\Search\Abstraction\Type;
*
* @since 3.2.0
*/
class Basic extends Type implements SearchTypeInterface
class Basic extends Engine implements SearchTypeInterface
{
/**
* Regex Search Value

View File

@ -9,14 +9,14 @@
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Search\Type;
namespace VDM\Joomla\Componentbuilder\Search\Engine;
use VDM\Joomla\Componentbuilder\Search\Config;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Componentbuilder\Search\Interfaces\SearchTypeInterface;
use VDM\Joomla\Componentbuilder\Search\Abstraction\Type;
use VDM\Joomla\Componentbuilder\Search\Abstraction\Engine;
/**
@ -24,7 +24,7 @@ use VDM\Joomla\Componentbuilder\Search\Abstraction\Type;
*
* @since 3.2.0
*/
class Regex extends Type implements SearchTypeInterface
class Regex extends Engine implements SearchTypeInterface
{
/**
* Regex Search Value

View File

@ -17,8 +17,8 @@ use Joomla\DI\ServiceProviderInterface;
use VDM\Joomla\Componentbuilder\Search\Config;
use VDM\Joomla\Componentbuilder\Search\Table;
use VDM\Joomla\Componentbuilder\Search\Interfaces\SearchTypeInterface as SearchEngine;
use VDM\Joomla\Componentbuilder\Search\Type\Regex;
use VDM\Joomla\Componentbuilder\Search\Type\Basic;
use VDM\Joomla\Componentbuilder\Search\Engine\Regex;
use VDM\Joomla\Componentbuilder\Search\Engine\Basic;
/**

View File

@ -2981,14 +2981,15 @@ class Table
}
/**
* Check if a table exist
* Check if a table (and field) exist
*
* @param string|null $table The area
* @param string|null $field The area
*
* @return bool
* @since 3.2.0
*/
public function exist(?string $table = null): bool
public function exist(?string $table = null, ?string $field = null): bool
{
// load the table
if (empty($table))
@ -2996,9 +2997,20 @@ class Table
$table = $this->config->table_name;
}
if (isset($table) && isset($this->tables[$table]))
if (is_string($table) && isset($this->tables[$table]))
{
return true;
// if we have a field
if (is_string($field))
{
if (isset($this->tables[$table][$field]))
{
return true;
}
}
else
{
return true;
}
}
return false;

View File

@ -33,11 +33,12 @@ abstract class GetHelper
* @param string $operator The operator between $whereString/field and $where/value
* @param string $main The component in which the table is found
*
* @return mix string/int/float
*
* @return mixed string/int/float
* @since 3.0.9
*/
public static function var($table, $where = null, $whereString = 'user', $what = 'id', $operator = '=', $main = null)
public static function var(string $table, ?string $where = null,
string $whereString = 'user', string $what = 'id',
string $operator = '=', ?string $main = null)
{
if(empty($where))
{
@ -85,6 +86,7 @@ abstract class GetHelper
{
return $db->loadResult();
}
return false;
}
@ -99,11 +101,12 @@ abstract class GetHelper
* @param string $main The component in which the table is found
* @param bool $unique The switch to return a unique array
*
* @return array
*
* @return array|null
* @since 3.0.9
*/
public static function vars($table, $where = null, $whereString = 'user', $what = 'id', $operator = 'IN', $main = null, $unique = true)
public static function vars(string $table, ?string $where = null,
string $whereString = 'user', string $what = 'id', string $operator = 'IN',
?string $main = null, bool $unique = true): ?array
{
if(empty($where))
{
@ -147,11 +150,11 @@ abstract class GetHelper
// add strings to array search
if ('IN_STRINGS' === $operator || 'NOT IN_STRINGS' === $operator)
{
$query->where($db->quoteName($whereString) . ' ' . str_replace('_STRINGS', '', $operator) . ' ("' . implode('","',$where) . '")');
$query->where($db->quoteName($whereString) . ' ' . str_replace('_STRINGS', '', $operator) . ' ("' . implode('","', $where) . '")');
}
else
{
$query->where($db->quoteName($whereString) . ' ' . $operator . ' (' . implode(',',$where) . ')');
$query->where($db->quoteName($whereString) . ' ' . $operator . ' (' . implode(',', $where) . ')');
}
$db->setQuery($query);
@ -166,71 +169,83 @@ abstract class GetHelper
return $db->loadColumn();
}
}
return false;
return null;
}
/**
* get all strings between two other strings
*
* @param string $content The content to search
* @param string $start The starting value
* @param string $end The ending value
* @param string $content The content to search
* @param string $start The starting value
* @param string $end The ending value
*
* @return array On success
*
* @return array|null On success
* @since 3.0.9
*/
public static function allBetween($content, $start, $end)
public static function allBetween(string $content, string $start, string $end): ?array
{
// reset bucket
$bucket = array();
$bucket = [];
for ($i = 0; ; $i++)
{
// search for string
$found = self::between($content,$start,$end);
$found = self::between($content, $start, $end);
if (StringHelper::check($found))
{
// add to bucket
$bucket[] = $found;
// build removal string
$remove = $start.$found.$end;
$remove = $start . $found . $end;
// remove from content
$content = str_replace($remove,'',$content);
$content = str_replace($remove, '', $content);
}
else
{
break;
}
// safety catch
if ($i == 500)
{
break;
}
}
// only return unique array of values
return array_unique($bucket);
if (ArrayHelper::check($bucket))
{
return array_unique($bucket);
}
return null;
}
/**
* get a string between two other strings
*
* @param string $content The content to search
* @param string $start The starting value
* @param string $end The ending value
* @param string $default The default value if none found
* @param string $content The content to search
* @param string $start The starting value
* @param string $end The ending value
* @param string $default The default value if none found
*
* @return string On success / empty string on failure
*
* @since 3.0.9
*/
public static function between($content, $start, $end, $default = '')
public static function between(string $content, string $start, string $end, string $default = ''): string
{
$r = explode($start, $content);
if (isset($r[1]))
$array = explode($start, $content);
if (isset($array[1]) && strpos($array[1], $end) !== false)
{
$r = explode($end, $r[1]);
return $r[0];
$array = explode($end, $array[1]);
// return string found between
return $array[0];
}
return $default;
}