[FEATURE] Add where and order options for DbTableViewHelper
This commit is contained in:
parent
e881d9b045
commit
4c9059be40
@ -17,15 +17,36 @@ class DbTableViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHel
|
|||||||
/**
|
/**
|
||||||
* @param string $table The filename
|
* @param string $table The filename
|
||||||
* @param string $fields The filename
|
* @param string $fields The filename
|
||||||
|
* @param string $where
|
||||||
|
* @param string $orderBy
|
||||||
* @return string HTML Content
|
* @return string HTML Content
|
||||||
*/
|
*/
|
||||||
public function render($table, $fields = ['*']){
|
public function render($table, $fields = ['*'], $where = [], $orderBy = []){
|
||||||
|
|
||||||
|
|
||||||
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('pages')->createQueryBuilder();
|
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('pages')->createQueryBuilder();
|
||||||
$data = $queryBuilder->select(...$fields)->from($table)
|
|
||||||
->execute()
|
$whereExpressions = [];
|
||||||
->fetchAll();
|
if (!empty($where)) {
|
||||||
|
foreach ($where as $key => $row) {
|
||||||
|
$whereExpressions[] = $queryBuilder->expr()->eq($key, $queryBuilder->createNamedParameter($row));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$data = $queryBuilder->select(...$fields)->from($table);
|
||||||
|
if (!empty($whereExpressions)) {
|
||||||
|
$data = $data->where(...$whereExpressions);
|
||||||
|
}
|
||||||
|
if (!empty($orderBy)) {
|
||||||
|
if (!empty($orderBy[key($orderBy)])) {
|
||||||
|
$data = $data->orderBy(key($orderBy), $orderBy[key($orderBy)]);
|
||||||
|
} else {
|
||||||
|
$data = $data->orderBy(key($orderBy));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$data = $data->execute()->fetchAll();
|
||||||
|
|
||||||
|
\TYPO3\CMS\Core\Utility\DebugUtility::debug($data);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user