Adds beta search engine to JCB.

This commit is contained in:
2022-11-02 21:48:20 +02:00
parent f2ea22d0ad
commit f1cb398f7a
19 changed files with 1121 additions and 263 deletions

View File

@ -228,14 +228,14 @@ class Agent
if(($values = $this->find($table)) !== null)
{
$table_rows = [];
// set the return value
$this->return = urlencode(base64_encode('index.php?option=com_componentbuilder&view=search'));
// build return value
$this->setReturnValue();
// set the markers
$this->marker = [$this->config->marker_start, $this->config->marker_end];
$this->markerHtml = ['<span class="found_code">','</span>'];
$this->setMarkers();
// start table bucket
$table_rows = [];
foreach ($values as $id => $fields)
{
@ -285,10 +285,10 @@ class Agent
*
* @param string|null $table The table being searched
*
* @return void
* @return int
* @since 3.2.0
*/
public function replace(?string $table = null)
public function replace(?string $table = null): int
{
// set the table name
if (empty($table))
@ -297,6 +297,7 @@ class Agent
}
$set = 1;
$replaced = 0;
// continue loading items until all was loaded
while(($items = $this->get->items($table, $set)) !== null)
@ -308,7 +309,10 @@ class Agent
$this->replace->items($this->find->get($table), $table);
// update the database
$this->set->items($this->replace->get($table), $table);
if ($this->set->items($this->replace->get($table), $table))
{
$replaced++;
}
// reset found items
$this->find->reset($table);
@ -316,6 +320,9 @@ class Agent
$set++;
}
// we return the number of times we replaced
return $replaced;
}
/**
@ -370,14 +377,48 @@ class Agent
{
// get list view
$views = $this->table->get($view, $field, 'list');
$tab = $this->table->get($view, $field, 'tab_name');
// 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>';
return '<a class="hasTooltip btn btn-mini" href="index.php?option=com_componentbuilder' .
'&view=' . $views .
'&task=' . $view . '.edit' .
'&id=' . $id .
'&open_tab=' . $tab .
'&open_field=' . $field .
'&return=' . $this->return . '" title="' .
Text::sprintf('COM_COMPONENTBUILDER_EDIT_S_S_DIRECTLY', $view, $field) . '." ><span class="icon-edit"></span></a>';
}
/**
* Set the return value for this search
*
* @return void
* @since 3.2.0
*/
protected function setReturnValue()
{
// set the return value so the search auto load on return
$this->return = urlencode(base64_encode('index.php?option=com_componentbuilder&view=search' .
'&type_search=' . (int) $this->config->type_search .
'&match_case=' . (int) $this->config->match_case .
'&whole_word=' . (int) $this->config->whole_word .
'&regex_search=' . (int) $this->config->regex_search .
'&search_value=' . (string) urlencode($this->config->search_value) .
'&replace_value=' . (string) urlencode($this->config->replace_value)));
}
/**
* Set the markers of the found code
*
* @return void
* @since 3.2.0
*/
protected function setMarkers()
{
// set the markers
$this->marker = [$this->config->marker_start, $this->config->marker_end];
$this->markerHtml = ['<span class="found_code">','</span>'];
}
}

View File

@ -283,6 +283,7 @@ class Search implements SearchInterface
{
$this->found[$table][$id][$field] = [];
}
// we should add a call to get the item name if the table has a name field TODO
}
}

View File

@ -22,6 +22,17 @@ use VDM\Joomla\Componentbuilder\Abstraction\BaseConfig;
*/
class Config extends BaseConfig
{
/**
* get type search being preformed
*
* @return int the search type 1 = search, 2 = search & replace
* @since 3.2.0
*/
protected function getTypesearch(): ?int
{
return $this->input->get('type_search', 1, 'INT');
}
/**
* get posted search value
*
@ -30,7 +41,7 @@ class Config extends BaseConfig
*/
protected function getSearchvalue(): ?string
{
return $this->input->post->get('search_value', null, 'RAW');
return $this->input->get('search_value', null, 'RAW');
}
/**
@ -41,7 +52,7 @@ class Config extends BaseConfig
*/
protected function getReplacevalue(): string
{
return $this->input->post->get('replace_value', '', 'RAW');
return $this->input->get('replace_value', '', 'RAW');
}
/**
@ -52,7 +63,7 @@ class Config extends BaseConfig
*/
protected function getMatchcase(): int
{
return $this->input->post->get('match_case', 0, 'INT');
return $this->input->get('match_case', 0, 'INT');
}
/**
@ -63,7 +74,7 @@ class Config extends BaseConfig
*/
protected function getWholeword(): int
{
return $this->input->post->get('whole_word', 0, 'INT');
return $this->input->get('whole_word', 0, 'INT');
}
/**
@ -72,9 +83,9 @@ class Config extends BaseConfig
* @return int Regex
* @since 3.2.0
*/
protected function getRegex(): int
protected function getRegexsearch(): int
{
return $this->input->post->get('regex_search', 0, 'INT');
return $this->input->get('regex_search', 0, 'INT');
}
/**
@ -85,7 +96,7 @@ class Config extends BaseConfig
*/
protected function getComponentid(): int
{
return $this->input->post->get('component_id', 0, 'INT');
return $this->input->get('component_id', 0, 'INT');
}
/**
@ -96,7 +107,7 @@ class Config extends BaseConfig
*/
protected function getTablename(): string
{
return $this->input->post->get('table_name', null, 'word');
return $this->input->get('table_name', null, 'word');
}
/**
@ -107,7 +118,7 @@ class Config extends BaseConfig
*/
protected function getFieldname(): string
{
return $this->input->post->get('field_name', null, 'word');
return $this->input->get('field_name', null, 'word');
}
/**
@ -118,7 +129,7 @@ class Config extends BaseConfig
*/
protected function getItemid(): int
{
return $this->input->post->get('item_id', 0, 'INT');
return $this->input->get('item_id', 0, 'INT');
}
/**

View File

@ -112,11 +112,11 @@ class Get implements GetInterface
$query = $this->db->getQuery(true);
// Order it by the ordering field.
$query->select($name);
$query->select($this->db->quoteName($name));
$query->from($this->db->quoteName('#__componentbuilder_' . $table));
// get by id
$query->where($this->db->quoteName('id') . " = " . $id);
$query->where($this->db->quoteName('id') . " = " . (int) $id);
// Reset the query using our newly populated query object.
$this->db->setQuery($query);

View File

@ -17,6 +17,7 @@ use VDM\Joomla\Componentbuilder\Search\Factory;
use VDM\Joomla\Componentbuilder\Search\Config;
use VDM\Joomla\Componentbuilder\Search\Table;
use VDM\Joomla\Componentbuilder\Search\Model\Set as Model;
use VDM\Joomla\Utilities\ArrayHelper;
use VDM\Joomla\Componentbuilder\Search\Interfaces\SetInterface;
@ -152,13 +153,13 @@ class Set implements SetInterface
* Set values to a given table
* Example: $this->items(Array, 'table_name');
*
* @param array $items The items being saved
* @param array|null $items The items being saved
* @param string|null $table The table
*
* @return bool
* @since 3.2.0
*/
public function items(array $items, string $table = null): bool
public function items(?array $items, string $table = null): bool
{
// load the table
if (empty($table))