Continued development on the search feature
This commit is contained in:
24 files changed
+1907
-347
No files matched your search
@@ -12,6 +12,7 @@
|
||||
namespace VDM\Joomla\Componentbuilder\Search;
|
||||
|
||||
|
||||
use Joomla\CMS\Language\Text;
|
||||
use VDM\Joomla\Componentbuilder\Search\Factory;
|
||||
use VDM\Joomla\Componentbuilder\Search\Config;
|
||||
use VDM\Joomla\Componentbuilder\Search\Database\Get;
|
||||
@@ -20,6 +21,7 @@ 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;
|
||||
use VDM\Joomla\Componentbuilder\Search\Table;
|
||||
|
||||
|
||||
/**
|
||||
@@ -85,21 +87,55 @@ class Agent
|
||||
*/
|
||||
protected Update $update;
|
||||
|
||||
/**
|
||||
* Table
|
||||
*
|
||||
* @var Table
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected Table $table;
|
||||
|
||||
/**
|
||||
* Return value to search view
|
||||
*
|
||||
* @var string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected string $return;
|
||||
|
||||
/**
|
||||
* Marker start and end values
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected array $marker;
|
||||
|
||||
/**
|
||||
* Marker start and end html values
|
||||
*
|
||||
* @var array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected array $markerHtml;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Config|null $config The search config object.
|
||||
* @param Get|null $get The search get database object.
|
||||
* @param Set|null $set The search get database object.
|
||||
* @param Find|null $find The search find object.
|
||||
* @param Replace|null $replace The search replace object.
|
||||
* @param Search|null $search The search object.
|
||||
* @param Config|null $config The search config object.
|
||||
* @param Get|null $get The search get database object.
|
||||
* @param Set|null $set The search get database object.
|
||||
* @param Find|null $find The search find object.
|
||||
* @param Replace|null $replace The search replace object.
|
||||
* @param Search|null $search The search object.
|
||||
* @param Update|null $update The update object.
|
||||
* @param Table|null $table The table object.
|
||||
*
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function __construct(?Config $config = null, ?Get $get = null,
|
||||
?Set$set = null, ?Find $find = null, ?Replace $replace = null,
|
||||
?Search $search = null, ?Update $update = null)
|
||||
?Search $search = null, ?Update $update = null, ?Table $table = null)
|
||||
{
|
||||
$this->config = $config ?: Factory::_('Config');
|
||||
$this->get = $get ?: Factory::_('Get.Database');
|
||||
@@ -108,23 +144,23 @@ class Agent
|
||||
$this->replace = $replace ?: Factory::_('Agent.Replace');
|
||||
$this->search = $search ?: Factory::_('Agent.Search');
|
||||
$this->update = $update ?: Factory::_('Agent.Update');
|
||||
$this->table = $table ?: Factory::_('Table');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function getValue(int $id, string $field, $line = null,
|
||||
?string $table = null, bool $update = false)
|
||||
?string $table = null, bool $update = false): string
|
||||
{
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
@@ -134,13 +170,19 @@ class Agent
|
||||
|
||||
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)
|
||||
// we only return strings that can load in an editor
|
||||
if (is_string($value))
|
||||
{
|
||||
return $updated_value;
|
||||
// try to update the value if required
|
||||
if ($update && ($updated_value = $this->update->value($value, $line)) !== null)
|
||||
{
|
||||
return $updated_value;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
return $value;
|
||||
return '// VALUE CAN NOT BE LOADED (AT THIS TIME) SINCE ITS NOT A STRING';
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -168,6 +210,48 @@ class Agent
|
||||
return $this->set->value($value, $id, $field, $table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Table Ready Search Results
|
||||
*
|
||||
* @param string|null $table The table being searched
|
||||
*
|
||||
* @return array|null
|
||||
* @since 3.2.0
|
||||
*/
|
||||
public function table(?string $table = null): ?array
|
||||
{
|
||||
// set the table name
|
||||
if (empty($table))
|
||||
{
|
||||
$table = $this->config->table_name;
|
||||
}
|
||||
|
||||
if(($values = $this->find($table)) !== null)
|
||||
{
|
||||
$table_rows = [];
|
||||
|
||||
// set the return value
|
||||
$this->return = urlencode(base64_encode('index.php?option=com_componentbuilder&view=search'));
|
||||
|
||||
// set the markers
|
||||
$this->marker = [$this->config->marker_start, $this->config->marker_end];
|
||||
$this->markerHtml = ['<span class="found_code">','</span>'];
|
||||
|
||||
foreach ($values as $id => $fields)
|
||||
{
|
||||
foreach ($fields as $field => $lines)
|
||||
{
|
||||
foreach ($lines as $line => $code)
|
||||
{
|
||||
$table_rows[] = $this->getRow($code, $table, $field, $id, $line);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $table_rows;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search the posted table for the search value and return all
|
||||
*
|
||||
@@ -233,6 +317,68 @@ class Agent
|
||||
$set++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return prepared code string for table
|
||||
*
|
||||
* @param string $code The code value fro the table
|
||||
* @param string|null $table The table
|
||||
* @param string $field The field key
|
||||
* @param int $id The the row id
|
||||
* @param mixed $line The code line where found
|
||||
*
|
||||
* @return array
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getRow(string $code, string $table, string $field, int $id, $line): array
|
||||
{
|
||||
return [
|
||||
'edit' => $this->getRowEditButton($table, $field, $id, $line),
|
||||
'code' => $this->getRowCode($code),
|
||||
'table' => $table,
|
||||
'field' => $field,
|
||||
'id' => $id,
|
||||
'line' => $line
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return prepared code string for table
|
||||
*
|
||||
* @param string $code The code value fro the table
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getRowCode(string $code): string
|
||||
{
|
||||
return str_replace($this->marker, $this->markerHtml, htmlentities($code));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Item button to edit an item
|
||||
*
|
||||
* @param string|null $view The single view
|
||||
* @param string $field The field key
|
||||
* @param int $id The the row id
|
||||
* @param mixed $line The code line where found
|
||||
*
|
||||
* @return string
|
||||
* @since 3.2.0
|
||||
*/
|
||||
protected function getRowEditButton(string $view, string $field, int $id, $line): string
|
||||
{
|
||||
// get list view
|
||||
$views = $this->table->get($view, $field, 'list');
|
||||
|
||||
// return edit link
|
||||
return '<a class="hasTooltip btn btn-mini" href="index.php?option=com_componentbuilder&view=' .
|
||||
$views . '&task=' .
|
||||
$view . '.edit&id=' .
|
||||
$id . '&return=' .
|
||||
$this->return . '" title="' .
|
||||
Text::_('COM_COMPONENTBUILDER_EDIT') . '" ><span class="icon-edit"></span></a>';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ class Basic extends Engine implements SearchTypeInterface
|
||||
parent::__construct($config);
|
||||
|
||||
// quote all regular expression characters
|
||||
$searchValue = \preg_quote($this->searchValue);
|
||||
$searchValue = preg_quote($this->searchValue, '/');
|
||||
|
||||
$start = ''; $end = '';
|
||||
|
||||
|
||||
+3
-3
@@ -20,17 +20,17 @@ namespace VDM\Joomla\Componentbuilder\Search\Interfaces;
|
||||
interface 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);
|
||||
|
||||
/**
|
||||
* Get values from a given table
|
||||
|
||||
@@ -70,7 +70,9 @@ class Agent implements ServiceProviderInterface
|
||||
$container->get('Set.Database'),
|
||||
$container->get('Agent.Find'),
|
||||
$container->get('Agent.Replace'),
|
||||
$container->get('Agent.Search')
|
||||
$container->get('Agent.Search'),
|
||||
$container->get('Agent.Update'),
|
||||
$container->get('Table')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -237,7 +237,7 @@ abstract class StringHelper
|
||||
*
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static function html($var, $charset = 'UTF-8', $shorten = false, $length = 40)
|
||||
public static function html($var, $charset = 'UTF-8', $shorten = false, $length = 40, $addTip = true)
|
||||
{
|
||||
if (self::check($var))
|
||||
{
|
||||
@@ -254,7 +254,7 @@ abstract class StringHelper
|
||||
);
|
||||
if ($shorten)
|
||||
{
|
||||
return self::shorten($string, $length);
|
||||
return self::shorten($string, $length, $addTip);
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user