mirror of
https://github.com/cosmocode/dokuwiki-plugin-struct.git
synced 2025-08-15 21:43:17 +00:00
make it easier to adjust/extend the search queries
Syntax components can overwrite getSearchConfig() and implement their own SearchConfig that then can overwrite runSQLBuilder() to access the underlying QueryBuilder
This commit is contained in:
@ -507,20 +507,32 @@ class Search
|
||||
/**
|
||||
* Transform the set search parameters into a statement
|
||||
*
|
||||
* Calls runSQLBuilder()
|
||||
*
|
||||
* @return array ($sql, $opts) The SQL and parameters to execute
|
||||
*/
|
||||
public function getSQL()
|
||||
{
|
||||
if (!$this->columns) throw new StructException('nocolname');
|
||||
return $this->runSQLBuilder()->getSQL();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize and execute the SQLBuilder
|
||||
*
|
||||
* Called from getSQL(). Can be overwritten to extend the query using the query builder
|
||||
*
|
||||
* @return SearchSQLBuilder
|
||||
*/
|
||||
protected function runSQLBuilder()
|
||||
{
|
||||
$sqlBuilder = new SearchSQLBuilder();
|
||||
$sqlBuilder->addSchemas($this->schemas);
|
||||
$sqlBuilder->addColumns($this->columns);
|
||||
$sqlBuilder->addFilters($this->filter);
|
||||
$sqlBuilder->addFilters($this->dynamicFilter);
|
||||
$sqlBuilder->addSorts($this->sortby);
|
||||
|
||||
return $sqlBuilder->getSQL();
|
||||
return $sqlBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -167,9 +167,21 @@ class SearchSQLBuilder
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Access to the underlying QueryBuilder
|
||||
*
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
public function getQueryBuilder()
|
||||
{
|
||||
return $this->qb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the SQL query and parameters
|
||||
*
|
||||
* Shortcut for $this->getQueryBuilder()->getSQL()
|
||||
*
|
||||
* @return array ($sql, $params)
|
||||
*/
|
||||
public function getSQL()
|
||||
|
@ -108,7 +108,7 @@ class syntax_plugin_struct_table extends DokuWiki_Syntax_Plugin
|
||||
}
|
||||
|
||||
try {
|
||||
$search = new SearchConfig($config);
|
||||
$search = $this->getSearchConfig($config);
|
||||
if ($format === 'struct_csv') {
|
||||
// no pagination in export
|
||||
$search->setLimit(0);
|
||||
@ -133,6 +133,18 @@ class syntax_plugin_struct_table extends DokuWiki_Syntax_Plugin
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a SearchConfig with the given parsed config
|
||||
*
|
||||
* @param array $config
|
||||
* @return SearchConfig
|
||||
*/
|
||||
protected function getSearchConfig($config)
|
||||
{
|
||||
return new SearchConfig($config);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Filter based on primary key columns, applicable in child classes
|
||||
*
|
||||
|
Reference in New Issue
Block a user